Reorder option flags. Change guidelines so that example code is consistent with...
authorTilghman Lesher <tilghman@meg.abyt.es>
Thu, 26 Nov 2009 02:09:58 +0000 (02:09 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Thu, 26 Nov 2009 02:09:58 +0000 (02:09 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@231369 65c4cc65-6c06-0410-ace0-fbb531ad65f3

doc/CODING-GUIDELINES
main/asterisk.c

index 4261f20..d1ae32d 100644 (file)
@@ -435,9 +435,9 @@ functions.
 When making applications, always ast_strdupa(data) to a local pointer if you
 intend to parse the incoming data string.
 
-       if (data)
+       if (data) {
                mydata = ast_strdupa(data);
-
+       }
 
 - Use the argument parsing macros to declare arguments and parse them, i.e.:
 
@@ -521,10 +521,11 @@ throughout the code to log that this has occurred.
 The functions strdup and strndup can *not* accept a NULL argument. This results
 in having code like this:
 
-       if (str)
+       if (str) {
                newstr = strdup(str);
-       else
+       } else {
                newstr = NULL;
+       }
 
 However, the ast_strdup and ast_strdupa functions will happily accept a NULL
 argument without generating an error.  The same code can be written as:
@@ -666,8 +667,9 @@ const char *postfix = "post";
 char *newname;
 char *name = "data";
 
-if (name && (newname = alloca(strlen(name) + strlen(prefix) + strlen(postfix) + 3)))
+if (name && (newname = alloca(strlen(name) + strlen(prefix) + strlen(postfix) + 3))) {
        snprintf(newname, strlen(name) + strlen(prefix) + strlen(postfix) + 3, "%s/%s/%s", prefix, name, postfix);
+|
 
 ...vs this alternative:
 
@@ -677,8 +679,9 @@ char *newname;
 char *name = "data";
 int len = 0;
 
-if (name && (len = strlen(name) + strlen(prefix) + strlen(postfix) + 3) && (newname = alloca(len)))
+if (name && (len = strlen(name) + strlen(prefix) + strlen(postfix) + 3) && (newname = alloca(len))) {
        snprintf(newname, len, "%s/%s/%s", prefix, name, postfix);
+}
 
 * Creating new manager events?
 ------------------------------
index 22bfe7e..4dee9da 100644 (file)
@@ -3141,8 +3141,26 @@ int main(int argc, char *argv[])
        if (getenv("HOME")) 
                snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
        /* Check for options */
-       while ((c = getopt(argc, argv, "mtThfFdvVqprRgciInx:U:G:C:L:M:e:s:WB")) != -1) {
+       while ((c = getopt(argc, argv, "BC:cde:FfG:ghIiL:M:mnpqRrs:TtU:VvWx:")) != -1) {
+               /*!\note Please keep the ordering here to alphabetical, capital letters
+                * first.  This will make it easier in the future to select unused
+                * option flags for new features. */
                switch (c) {
+               case 'B': /* Force black background */
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_FORCE_BLACK_BACKGROUND);
+                       ast_clear_flag(&ast_options, AST_OPT_FLAG_LIGHT_BACKGROUND);
+                       break;
+               case 'C':
+                       ast_copy_string(cfg_paths.config_file, optarg, sizeof(cfg_paths.config_file));
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_OVERRIDE_CONFIG);
+                       break;
+               case 'c':
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_CONSOLE);
+                       break;
+               case 'd':
+                       option_debug++;
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
+                       break;
 #if defined(HAVE_SYSINFO)
                case 'e':
                        if ((sscanf(&optarg[1], "%30ld", &option_minmemfree) != 1) || (option_minmemfree < 0)) {
@@ -3158,88 +3176,75 @@ int main(int argc, char *argv[])
                        ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
                        break;
 #endif
-               case 'd':
-                       option_debug++;
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
-                       break;
-               case 'c':
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_CONSOLE);
+               case 'G':
+                       rungroup = ast_strdupa(optarg);
                        break;
-               case 'n':
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_NO_COLOR);
+               case 'g':
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_DUMP_CORE);
                        break;
-               case 'r':
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
+               case 'h':
+                       show_cli_help();
+                       exit(0);
+               case 'I':
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING);
                        break;
-               case 'R':
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE | AST_OPT_FLAG_RECONNECT);
+               case 'i':
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_INIT_KEYS);
                        break;
-               case 'p':
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_HIGH_PRIORITY);
+               case 'L':
+                       if ((sscanf(optarg, "%30lf", &option_maxload) != 1) || (option_maxload < 0.0)) {
+                               option_maxload = 0.0;
+                       }
                        break;
-               case 'v':
-                       option_verbose++;
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
+               case 'M':
+                       if ((sscanf(optarg, "%30d", &option_maxcalls) != 1) || (option_maxcalls < 0)) {
+                               option_maxcalls = 0;
+                       }
                        break;
                case 'm':
                        ast_set_flag(&ast_options, AST_OPT_FLAG_MUTE);
                        break;
-               case 'M':
-                       if ((sscanf(optarg, "%30d", &option_maxcalls) != 1) || (option_maxcalls < 0))
-                               option_maxcalls = 0;
+               case 'n':
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_NO_COLOR);
                        break;
-               case 'L':
-                       if ((sscanf(optarg, "%30lf", &option_maxload) != 1) || (option_maxload < 0.0))
-                               option_maxload = 0.0;
+               case 'p':
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_HIGH_PRIORITY);
                        break;
                case 'q':
                        ast_set_flag(&ast_options, AST_OPT_FLAG_QUIET);
                        break;
-               case 't':
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_CACHE_RECORD_FILES);
-                       break;
-               case 'T':
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_TIMESTAMP);
+               case 'R':
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE | AST_OPT_FLAG_RECONNECT);
                        break;
-               case 'x':
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_EXEC);
-                       xarg = ast_strdupa(optarg);
+               case 'r':
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
                        break;
-               case 'C':
-                       ast_copy_string(cfg_paths.config_file, optarg, sizeof(cfg_paths.config_file));
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_OVERRIDE_CONFIG);
+               case 's':
+                       remotesock = ast_strdupa(optarg);
                        break;
-               case 'I':
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING);
+               case 'T':
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_TIMESTAMP);
                        break;
-               case 'i':
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_INIT_KEYS);
+               case 't':
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_CACHE_RECORD_FILES);
                        break;
-               case 'g':
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_DUMP_CORE);
+               case 'U':
+                       runuser = ast_strdupa(optarg);
                        break;
-               case 'h':
-                       show_cli_help();
-                       exit(0);
                case 'V':
                        show_version();
                        exit(0);
-               case 'U':
-                       runuser = ast_strdupa(optarg);
-                       break;
-               case 'G':
-                       rungroup = ast_strdupa(optarg);
-                       break;
-               case 's':
-                       remotesock = ast_strdupa(optarg);
+               case 'v':
+                       option_verbose++;
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
                        break;
                case 'W': /* White background */
                        ast_set_flag(&ast_options, AST_OPT_FLAG_LIGHT_BACKGROUND);
                        ast_clear_flag(&ast_options, AST_OPT_FLAG_FORCE_BLACK_BACKGROUND);
                        break;
-               case 'B': /* Force black background */
-                       ast_set_flag(&ast_options, AST_OPT_FLAG_FORCE_BLACK_BACKGROUND);
-                       ast_clear_flag(&ast_options, AST_OPT_FLAG_LIGHT_BACKGROUND);
+               case 'x':
+                       ast_set_flag(&ast_options, AST_OPT_FLAG_EXEC);
+                       xarg = ast_strdupa(optarg);
                        break;
                case '?':
                        exit(1);