Difference between revisions of "VPP/CodeStyleConventions"
From fd.io
< VPP
| Line 35: | Line 35: | ||
You should see diffs of this sort: | You should see diffs of this sort: | ||
| − | + | +/* '''*INDENT-OFF*''' */ | |
| − | +/* *INDENT-OFF* */ | + | |
VLIB_CLI_COMMAND (test_sr_debug, static) = { | VLIB_CLI_COMMAND (test_sr_debug, static) = { | ||
.path = "test sr debug", | .path = "test sr debug", | ||
| Line 42: | Line 41: | ||
.function = test_sr_debug_fn, | .function = test_sr_debug_fn, | ||
}; | }; | ||
| − | +/* *INDENT-ON* */ | + | +/* '''*INDENT-ON*''' */ |
+ | + | ||
+/* | +/* | ||
| Line 51: | Line 50: | ||
+ * End: | + * End: | ||
+ */ | + */ | ||
| − | ''' | + | |
| + | '''NOTE: The bolded selective switching on/off of indentation to protect macro sanity.''' | ||
* Save file and, assuming you have installed "indent" from apt/rpm, from a bash prompt: | * Save file and, assuming you have installed "indent" from apt/rpm, from a bash prompt: | ||
Revision as of 15:08, 6 August 2016
Introduction
- Link to mailer describing it.
DO I NEED TO APPLY STYLE ?
- If you don't see this at the end of your [.ch] file:
/* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */
you need to apply style.
EMACS
- There is an emacs skel for a set of emacs scripts that will auto-format
Essentially the idea is that the skeleton will put some comments in that EMACS script understands, apply a predefined format style, that more importantly than "GNU" or "Linux" or where "{" goes, DOESN'T MUCK UP MACROS!
Pre-processor macros are a key part of VPP and need special format attention.
C-code style for VPP is "gnu"
- Load the emacs skel by either opening and "M-x eval-buffer" or "M-x load-file" ..
.../build-root/emacs-lisp/fix-coding-style.el
- Now you should have a meta-function "M-x fd-io-styleify"
- Run this against an active buffer containing the VPP code you wish to apply the style to.
You should see diffs of this sort:
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (test_sr_debug, static) = {
.path = "test sr debug",
.short_help = "test sr debug on|off",
.function = test_sr_debug_fn,
};
+/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
NOTE: The bolded selective switching on/off of indentation to protect macro sanity.
- Save file and, assuming you have installed "indent" from apt/rpm, from a bash prompt:
indent <files>
- Fix any warnings or errors
- Here is an example of vnet/vnet/sr/sr.c.
After running the "fd-io-styleify", saving and "git diff"