[asterisk-commits] tilghman: trunk r231369 - in /trunk: doc/CODING-GUIDELINES main/asterisk.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Nov 25 20:09:59 CST 2009
Author: tilghman
Date: Wed Nov 25 20:09:58 2009
New Revision: 231369
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=231369
Log:
Reorder option flags. Change guidelines so that example code is consistent with guidelines
Modified:
trunk/doc/CODING-GUIDELINES
trunk/main/asterisk.c
Modified: trunk/doc/CODING-GUIDELINES
URL: http://svnview.digium.com/svn/asterisk/trunk/doc/CODING-GUIDELINES?view=diff&rev=231369&r1=231368&r2=231369
==============================================================================
--- trunk/doc/CODING-GUIDELINES (original)
+++ trunk/doc/CODING-GUIDELINES Wed Nov 25 20:09:58 2009
@@ -435,9 +435,9 @@
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 @@
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 @@
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 *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?
------------------------------
Modified: trunk/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/asterisk.c?view=diff&rev=231369&r1=231368&r2=231369
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Wed Nov 25 20:09:58 2009
@@ -3141,8 +3141,26 @@
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,62 +3176,8 @@
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);
- break;
- case 'n':
- ast_set_flag(&ast_options, AST_OPT_FLAG_NO_COLOR);
- break;
- case 'r':
- ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
- break;
- case 'R':
- ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE | AST_OPT_FLAG_RECONNECT);
- break;
- case 'p':
- ast_set_flag(&ast_options, AST_OPT_FLAG_HIGH_PRIORITY);
- break;
- case 'v':
- option_verbose++;
- ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
- 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;
- break;
- case 'L':
- if ((sscanf(optarg, "%30lf", &option_maxload) != 1) || (option_maxload < 0.0))
- option_maxload = 0.0;
- 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);
- break;
- case 'x':
- ast_set_flag(&ast_options, AST_OPT_FLAG_EXEC);
- xarg = ast_strdupa(optarg);
- 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 'I':
- ast_set_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING);
- break;
- case 'i':
- ast_set_flag(&ast_options, AST_OPT_FLAG_INIT_KEYS);
+ case 'G':
+ rungroup = ast_strdupa(optarg);
break;
case 'g':
ast_set_flag(&ast_options, AST_OPT_FLAG_DUMP_CORE);
@@ -3221,25 +3185,66 @@
case 'h':
show_cli_help();
exit(0);
+ case 'I':
+ ast_set_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING);
+ break;
+ case 'i':
+ ast_set_flag(&ast_options, AST_OPT_FLAG_INIT_KEYS);
+ break;
+ case 'L':
+ if ((sscanf(optarg, "%30lf", &option_maxload) != 1) || (option_maxload < 0.0)) {
+ option_maxload = 0.0;
+ }
+ break;
+ 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 'n':
+ ast_set_flag(&ast_options, AST_OPT_FLAG_NO_COLOR);
+ break;
+ 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 'R':
+ ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE | AST_OPT_FLAG_RECONNECT);
+ break;
+ case 'r':
+ ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
+ break;
+ case 's':
+ remotesock = ast_strdupa(optarg);
+ break;
+ case 'T':
+ ast_set_flag(&ast_options, AST_OPT_FLAG_TIMESTAMP);
+ break;
+ case 't':
+ ast_set_flag(&ast_options, AST_OPT_FLAG_CACHE_RECORD_FILES);
+ break;
+ case 'U':
+ runuser = ast_strdupa(optarg);
+ break;
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);
More information about the asterisk-commits
mailing list