diff options
-rw-r--r-- | docs/contributing.txt | 5 | ||||
-rw-r--r-- | docs/style-guide.txt | 46 |
2 files changed, 50 insertions, 1 deletions
diff --git a/docs/contributing.txt b/docs/contributing.txt index 696e63c2c..d9a7d3d00 100644 --- a/docs/contributing.txt +++ b/docs/contributing.txt | |||
@@ -197,6 +197,11 @@ Janitorial Work | |||
197 | 197 | ||
198 | These are dirty jobs, but somebody's gotta do 'em. | 198 | These are dirty jobs, but somebody's gotta do 'em. |
199 | 199 | ||
200 | - Converting applets to use getopt() for option processing. Type 'grep -L | ||
201 | getopt *.c' to get a listing of the applets that currently don't use | ||
202 | getopt. If a .c file processes no options, it should have a line that | ||
203 | reads: /* no options, no getopt */ somewhere in the file. | ||
204 | |||
200 | - Security audits: | 205 | - Security audits: |
201 | http://www.securityfocus.com/frames/?content=/forums/secprog/secure-programming.html | 206 | http://www.securityfocus.com/frames/?content=/forums/secprog/secure-programming.html |
202 | 207 | ||
diff --git a/docs/style-guide.txt b/docs/style-guide.txt index 1f06662ac..b4c3bac02 100644 --- a/docs/style-guide.txt +++ b/docs/style-guide.txt | |||
@@ -26,7 +26,9 @@ Here is the order in which code should be laid out in a file: | |||
26 | - commented author name and email address(es) | 26 | - commented author name and email address(es) |
27 | - commented GPL boilerplate | 27 | - commented GPL boilerplate |
28 | - commented longer description / notes for the program (if needed) | 28 | - commented longer description / notes for the program (if needed) |
29 | - #includes and #defines | 29 | - #includes of .h files with angle brackets (<>) around them |
30 | - #includes of .h files with quotes ("") around them | ||
31 | - #defines (if any, note the section below titled "Avoid the Preprocessor") | ||
30 | - const and global variables | 32 | - const and global variables |
31 | - function declarations (if necessary) | 33 | - function declarations (if necessary) |
32 | - function implementations | 34 | - function implementations |
@@ -607,3 +609,45 @@ illustrates emphasizing logical blocks: | |||
607 | /* clean up */ | 609 | /* clean up */ |
608 | free(line); | 610 | free(line); |
609 | } | 611 | } |
612 | |||
613 | |||
614 | Processing Options with getopt | ||
615 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
616 | |||
617 | If your applet needs to process command-line switches, please use getopt() to | ||
618 | do so. Numerous examples can be seen in many of the existing applets, but | ||
619 | basically it boils down to two things: at the top of the .c file, have this | ||
620 | line in the midst of your #includes: | ||
621 | |||
622 | #include <getopt.h> | ||
623 | |||
624 | And a code block similar to the following near the top of your applet_main() | ||
625 | routine: | ||
626 | |||
627 | while ((opt = getopt(argc, argv, "abc")) > 0) { | ||
628 | switch (opt) { | ||
629 | case 'a': | ||
630 | do_a_opt = 1; | ||
631 | break; | ||
632 | case 'b': | ||
633 | do_b_opt = 1; | ||
634 | break; | ||
635 | case 'c': | ||
636 | do_c_opt = 1; | ||
637 | break; | ||
638 | default: | ||
639 | show_usage(); /* in utility.c */ | ||
640 | } | ||
641 | } | ||
642 | |||
643 | If your applet takes no options (such as 'init'), there should be a line | ||
644 | somewhere in the file reads: | ||
645 | |||
646 | /* no options, no getopt */ | ||
647 | |||
648 | That way, when people go grepping to see which applets need to be converted to | ||
649 | use getopt, they won't get false positives. | ||
650 | |||
651 | Additional Note: Do not use the getopt_long library function and do not try to | ||
652 | hand-roll your own long option parsing. Busybox applets should only support | ||
653 | short options, plus explanations and examples in usage.h. | ||