[GRASS-SVN] r47596 - grass/trunk/general/g.parser

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 12 05:10:03 EDT 2011


Author: neteler
Date: 2011-08-12 02:10:03 -0700 (Fri, 12 Aug 2011)
New Revision: 47596

Modified:
   grass/trunk/general/g.parser/g.parser.html
   grass/trunk/general/g.parser/parse.c
   grass/trunk/general/g.parser/translate.c
Log:
support {NULL} to predefined description or label

Modified: grass/trunk/general/g.parser/g.parser.html
===================================================================
--- grass/trunk/general/g.parser/g.parser.html	2011-08-12 08:49:58 UTC (rev 47595)
+++ grass/trunk/general/g.parser/g.parser.html	2011-08-12 09:10:03 UTC (rev 47596)
@@ -62,21 +62,23 @@
 
 <div class="code"><pre>
 #%module
-#%  description: g.parser test script   
+#% description: g.parser test script   
 #%end
 #%flag
-#%  key: f
-#%  description: A flag
+#% key: f
+#% description: A flag
 #%end
 #%option
-#%  key: raster
-#%  type: string
-#%  gisprompt: old,cell,raster
-#%  description: Raster input map
-#%  required : yes
+#% key: raster
+#% type: string
+#% gisprompt: old,cell,raster
+#% description: Raster input map
+#% required : yes
 #%end
 </pre></div>
 
+With <tt>{NULL}</tt> it is possible to suppress a predefined <tt>description</tt>
+or <tt>label</tt>.
 
 <h2>NOTES</h2>
 

Modified: grass/trunk/general/g.parser/parse.c
===================================================================
--- grass/trunk/general/g.parser/parse.c	2011-08-12 08:49:58 UTC (rev 47595)
+++ grass/trunk/general/g.parser/parse.c	2011-08-12 09:10:03 UTC (rev 47596)
@@ -5,6 +5,13 @@
 
 #include <grass/glocale.h>
 
+static char *xstrdup(const char *arg)
+{
+   G_debug(0,"arg: %s", arg);
+   return (G_strcasecmp(arg, "{NULL}") == 0)
+	? NULL : strdup(arg);
+}
+
 int parse_boolean(struct context *ctx, const char *arg)
 {
     if (G_strcasecmp(arg, "yes") == 0)
@@ -59,23 +66,22 @@
     fprintf(stderr, _("Unknown command \"%s\" at line %d\n"), cmd, ctx->line);
 }
 
-void parse_module(struct context *ctx, const char *cmd,
-		  const char *arg)
+void parse_module(struct context *ctx, const char *cmd, const char *arg)
 {
 
     /* Label and description can be internationalized */
     if (G_strcasecmp(cmd, "label") == 0) {
-	ctx->module->label = translate(strdup(arg));
+	ctx->module->label = translate(xstrdup(arg));
 	return;
     }
 
     if (G_strcasecmp(cmd, "description") == 0) {
-	ctx->module->description = translate(strdup(arg));
+	ctx->module->description = translate(xstrdup(arg));
 	return;
     }
 
     if (G_strcasecmp(cmd, "keywords") == 0) {
-	G_add_keyword(translate(strdup(arg)));
+	G_add_keyword(translate(xstrdup(arg)));
 	return;
     }
 
@@ -107,17 +113,17 @@
 
     /* Label, description, and guisection can all be internationalized */
     if (G_strcasecmp(cmd, "label") == 0) {
-	ctx->flag->label = translate(strdup(arg));
+	ctx->flag->label = translate(xstrdup(arg));
 	return;
     }
 
     if (G_strcasecmp(cmd, "description") == 0) {
-	ctx->flag->description = translate(strdup(arg));
+	ctx->flag->description = translate(xstrdup(arg));
 	return;
     }
 
     if (G_strcasecmp(cmd, "guisection") == 0) {
-	ctx->flag->guisection = translate(strdup(arg));
+	ctx->flag->guisection = translate(xstrdup(arg));
 	return;
     }
 
@@ -146,11 +152,10 @@
     return TYPE_STRING;
 }
 
-void parse_option(struct context *ctx, const char *cmd,
-		  const char *arg)
+void parse_option(struct context *ctx, const char *cmd, const char *arg)
 {
     if (G_strcasecmp(cmd, "key") == 0) {
-	ctx->option->key = strdup(arg);
+	ctx->option->key = xstrdup(arg);
 	return;
     }
 
@@ -170,48 +175,48 @@
     }
 
     if (G_strcasecmp(cmd, "options") == 0) {
-	ctx->option->options = strdup(arg);
+	ctx->option->options = xstrdup(arg);
 	return;
     }
 
     if (G_strcasecmp(cmd, "key_desc") == 0) {
-	ctx->option->key_desc = strdup(arg);
+	ctx->option->key_desc = xstrdup(arg);
 	return;
     }
 
     /* Label, description, descriptions, and guisection can all be internationalized */
     if (G_strcasecmp(cmd, "label") == 0) {
-	ctx->option->label = translate(strdup(arg));
+	ctx->option->label = translate(xstrdup(arg));
 	return;
     }
 
     if (G_strcasecmp(cmd, "description") == 0) {
-	ctx->option->description = translate(strdup(arg));
+	ctx->option->description = translate(xstrdup(arg));
 	return;
     }
 
     if (G_strcasecmp(cmd, "descriptions") == 0) {
-	ctx->option->descriptions = translate(strdup(arg));
+	ctx->option->descriptions = translate(xstrdup(arg));
 	return;
     }
 
     if (G_strcasecmp(cmd, "answer") == 0) {
-	ctx->option->answer = strdup(arg);
+	ctx->option->answer = xstrdup(arg);
 	return;
     }
 
     if (G_strcasecmp(cmd, "gisprompt") == 0) {
-	ctx->option->gisprompt = strdup(arg);
+	ctx->option->gisprompt = xstrdup(arg);
 	return;
     }
 
     if (G_strcasecmp(cmd, "guisection") == 0) {
-	ctx->option->guisection = translate(strdup(arg));
+	ctx->option->guisection = translate(xstrdup(arg));
 	return;
     }
 
     if (G_strcasecmp(cmd, "guidependency") == 0) {
-	ctx->option->guidependency = translate(strdup(arg));
+	ctx->option->guidependency = translate(xstrdup(arg));
 	return;
     }
 

Modified: grass/trunk/general/g.parser/translate.c
===================================================================
--- grass/trunk/general/g.parser/translate.c	2011-08-12 08:49:58 UTC (rev 47595)
+++ grass/trunk/general/g.parser/translate.c	2011-08-12 09:10:03 UTC (rev 47596)
@@ -10,6 +10,8 @@
 {
     static const char *domain;
 
+    if (arg == NULL)
+	return arg;
     if (*arg && translate_output) {
 	fputs(arg, stdout);
 	fputs("\n", stdout);



More information about the grass-commit mailing list