Reorder option flags. Change guidelines so that example code is consistent with guidelines

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@231369 65c4cc65-6c06-0410-ace0-fbb531ad65f3
certified/1.8.6
Tilghman Lesher 16 years ago
parent f98c12a57d
commit 23b4a700f4

@ -435,9 +435,9 @@ functions.
When making applications, always ast_strdupa(data) to a local pointer if you When making applications, always ast_strdupa(data) to a local pointer if you
intend to parse the incoming data string. intend to parse the incoming data string.
if (data) if (data) {
mydata = ast_strdupa(data); mydata = ast_strdupa(data);
}
- Use the argument parsing macros to declare arguments and parse them, i.e.: - 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 The functions strdup and strndup can *not* accept a NULL argument. This results
in having code like this: in having code like this:
if (str) if (str) {
newstr = strdup(str); newstr = strdup(str);
else } else {
newstr = NULL; newstr = NULL;
}
However, the ast_strdup and ast_strdupa functions will happily accept a 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: argument without generating an error. The same code can be written as:
@ -666,8 +667,9 @@ const char *postfix = "post";
char *newname; char *newname;
char *name = "data"; 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); snprintf(newname, strlen(name) + strlen(prefix) + strlen(postfix) + 3, "%s/%s/%s", prefix, name, postfix);
|
...vs this alternative: ...vs this alternative:
@ -677,8 +679,9 @@ char *newname;
char *name = "data"; char *name = "data";
int len = 0; 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); snprintf(newname, len, "%s/%s/%s", prefix, name, postfix);
}
* Creating new manager events? * Creating new manager events?
------------------------------ ------------------------------

@ -3141,8 +3141,26 @@ int main(int argc, char *argv[])
if (getenv("HOME")) if (getenv("HOME"))
snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME")); snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
/* Check for options */ /* 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) { 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) #if defined(HAVE_SYSINFO)
case 'e': case 'e':
if ((sscanf(&optarg[1], "%30ld", &option_minmemfree) != 1) || (option_minmemfree < 0)) { 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); ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
break; break;
#endif #endif
case 'd': case 'G':
option_debug++; rungroup = ast_strdupa(optarg);
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);
break; break;
case 'n': case 'g':
ast_set_flag(&ast_options, AST_OPT_FLAG_NO_COLOR); ast_set_flag(&ast_options, AST_OPT_FLAG_DUMP_CORE);
break; break;
case 'r': case 'h':
ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE); show_cli_help();
exit(0);
case 'I':
ast_set_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING);
break; break;
case 'R': case 'i':
ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE | AST_OPT_FLAG_RECONNECT); ast_set_flag(&ast_options, AST_OPT_FLAG_INIT_KEYS);
break; break;
case 'p': case 'L':
ast_set_flag(&ast_options, AST_OPT_FLAG_HIGH_PRIORITY); if ((sscanf(optarg, "%30lf", &option_maxload) != 1) || (option_maxload < 0.0)) {
option_maxload = 0.0;
}
break; break;
case 'v': case 'M':
option_verbose++; if ((sscanf(optarg, "%30d", &option_maxcalls) != 1) || (option_maxcalls < 0)) {
ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK); option_maxcalls = 0;
}
break; break;
case 'm': case 'm':
ast_set_flag(&ast_options, AST_OPT_FLAG_MUTE); ast_set_flag(&ast_options, AST_OPT_FLAG_MUTE);
break; break;
case 'M': case 'n':
if ((sscanf(optarg, "%30d", &option_maxcalls) != 1) || (option_maxcalls < 0)) ast_set_flag(&ast_options, AST_OPT_FLAG_NO_COLOR);
option_maxcalls = 0;
break; break;
case 'L': case 'p':
if ((sscanf(optarg, "%30lf", &option_maxload) != 1) || (option_maxload < 0.0)) ast_set_flag(&ast_options, AST_OPT_FLAG_HIGH_PRIORITY);
option_maxload = 0.0;
break; break;
case 'q': case 'q':
ast_set_flag(&ast_options, AST_OPT_FLAG_QUIET); ast_set_flag(&ast_options, AST_OPT_FLAG_QUIET);
break; break;
case 't': case 'R':
ast_set_flag(&ast_options, AST_OPT_FLAG_CACHE_RECORD_FILES); ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE | AST_OPT_FLAG_RECONNECT);
break;
case 'T':
ast_set_flag(&ast_options, AST_OPT_FLAG_TIMESTAMP);
break; break;
case 'x': case 'r':
ast_set_flag(&ast_options, AST_OPT_FLAG_EXEC); ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
xarg = ast_strdupa(optarg);
break; break;
case 'C': case 's':
ast_copy_string(cfg_paths.config_file, optarg, sizeof(cfg_paths.config_file)); remotesock = ast_strdupa(optarg);
ast_set_flag(&ast_options, AST_OPT_FLAG_OVERRIDE_CONFIG);
break; break;
case 'I': case 'T':
ast_set_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING); ast_set_flag(&ast_options, AST_OPT_FLAG_TIMESTAMP);
break; break;
case 'i': case 't':
ast_set_flag(&ast_options, AST_OPT_FLAG_INIT_KEYS); ast_set_flag(&ast_options, AST_OPT_FLAG_CACHE_RECORD_FILES);
break; break;
case 'g': case 'U':
ast_set_flag(&ast_options, AST_OPT_FLAG_DUMP_CORE); runuser = ast_strdupa(optarg);
break; break;
case 'h':
show_cli_help();
exit(0);
case 'V': case 'V':
show_version(); show_version();
exit(0); exit(0);
case 'U': case 'v':
runuser = ast_strdupa(optarg); option_verbose++;
break; ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
case 'G':
rungroup = ast_strdupa(optarg);
break;
case 's':
remotesock = ast_strdupa(optarg);
break; break;
case 'W': /* White background */ case 'W': /* White background */
ast_set_flag(&ast_options, AST_OPT_FLAG_LIGHT_BACKGROUND); ast_set_flag(&ast_options, AST_OPT_FLAG_LIGHT_BACKGROUND);
ast_clear_flag(&ast_options, AST_OPT_FLAG_FORCE_BLACK_BACKGROUND); ast_clear_flag(&ast_options, AST_OPT_FLAG_FORCE_BLACK_BACKGROUND);
break; break;
case 'B': /* Force black background */ case 'x':
ast_set_flag(&ast_options, AST_OPT_FLAG_FORCE_BLACK_BACKGROUND); ast_set_flag(&ast_options, AST_OPT_FLAG_EXEC);
ast_clear_flag(&ast_options, AST_OPT_FLAG_LIGHT_BACKGROUND); xarg = ast_strdupa(optarg);
break; break;
case '?': case '?':
exit(1); exit(1);

Loading…
Cancel
Save