[GRASS-SVN] r52615 - grass/trunk/lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Aug 9 16:07:22 PDT 2012


Author: lucadelu
Date: 2012-08-09 16:07:21 -0700 (Thu, 09 Aug 2012)
New Revision: 52615

Modified:
   grass/trunk/lib/gis/parser_rest.c
Log:
improvements for restructeredtext parser

Modified: grass/trunk/lib/gis/parser_rest.c
===================================================================
--- grass/trunk/lib/gis/parser_rest.c	2012-08-09 20:16:09 UTC (rev 52614)
+++ grass/trunk/lib/gis/parser_rest.c	2012-08-09 23:07:21 UTC (rev 52615)
@@ -1,7 +1,7 @@
 /*!
   \file lib/gis/parser_rest.c
   
-  \brief GIS Library - Argument parsing functions (REST output)
+  \brief GIS Library - Argument parsing functions (reStructuredText output)
   
   (C) 2012 by the GRASS Development Team
   
@@ -18,13 +18,13 @@
 
 #include "parser_local_proto.h"
 
-/*!
-static void print_escaped_for_html(FILE * f, const char *str);
-static void print_escaped_for_html_options(FILE * f, const char *str);
-*/
 
+static void print_escaped_for_rest(FILE * f, const char *str);
+static void print_escaped_for_rest_options(FILE * f, const char *str);
+
+
 /*!
-  \brief Print module usage description in HTML format.
+  \brief Print module usage description in reStructuredText format.
 */
 void G__usage_rest(void)
 {
@@ -36,7 +36,7 @@
 
     new_prompt = G__uses_new_gisprompt();
 
-    if (!st->pgm_name)		/* v.dave && r.michael */
+    if (!st->pgm_name)
 	st->pgm_name = G_program_name();
     if (!st->pgm_name)
 	st->pgm_name = "??";
@@ -58,24 +58,24 @@
     fprintf(stdout,"   :alt: GRASS logo\n\n");
     
     fprintf(stdout,"%s\n----\n", _("NAME"));
-    fprintf(stdout, "**%s**", st->pgm_name); /*! TODO fix bold + emphase now only bold */
+    fprintf(stdout, "**%s**", st->pgm_name);
 
     if (st->module_info.label || st->module_info.description)
 	fprintf(stdout, " - ");
 
     if (st->module_info.label)
-	fprintf(stdout, "%s\n", st->module_info.label);
+	fprintf(stdout, "%s\n\n", st->module_info.label);
 
     if (st->module_info.description)
 	fprintf(stdout, "%s\n", st->module_info.description);
 
 
-    fprintf(stdout, "%s\n--------\n", _("KEYWORDS"));
+    fprintf(stdout, "\n%s\n----------------------\n", _("KEYWORDS"));
     if (st->module_info.keywords) {
 	G__print_keywords(stdout, NULL);
 	fprintf(stdout, "\n");
     }
-    fprintf(stdout, "%s\n--------\n", _("SYNOPSIS"));
+    fprintf(stdout, "\n%s\n----------------------\n", _("SYNOPSIS"));
     fprintf(stdout, "**%s**\n\n", st->pgm_name);
     fprintf(stdout, "**%s** help\n\n", st->pgm_name);
 
@@ -119,9 +119,9 @@
 		}
 	    if (!opt->required)
 		fprintf(stdout, " [");
-	    fprintf(stdout, "**%s**=*%s*", opt->key, type);
+	    fprintf(stdout, "**%s** = *%s*", opt->key, type);
 	    if (opt->multiple) {
-		fprintf(stdout, "[,*%s*,...]", type);
+		fprintf(stdout, " [, *%s* ,...]", type);
 	    }
 	    if (!opt->required)
 		fprintf(stdout, "] ");
@@ -131,10 +131,10 @@
 	}
     }
     if (new_prompt)
-	fprintf(stdout, " [--**overwrite**] ");
+	fprintf(stdout, " [-- **overwrite**] ");
 
-    fprintf(stdout, " [--**verbose**] ");
-    fprintf(stdout, " [--**quiet**] ");
+    fprintf(stdout, " [-- **verbose**] ");
+    fprintf(stdout, " [-- **quiet**] ");
 
     fprintf(stdout, "\n");
 
@@ -159,15 +159,15 @@
 	    fprintf(stdout, "\n");
 	}
 	if (new_prompt) {
-	    fprintf(stdout, "**--overwrite**\n");
+	    fprintf(stdout, "-- **overwrite**\n");
 	    fprintf(stdout, "    %s\n",
 		    _("Allow output files to overwrite existing files"));
 	}
 
-	fprintf(stdout, "**--verbose**\n");
+	fprintf(stdout, "-- **verbose**\n");
 	fprintf(stdout, "    %s\n", _("Verbose module output"));
 
-	fprintf(stdout, "**--quiet**\n");
+	fprintf(stdout, "-- **quiet**\n");
 	fprintf(stdout, "    %s\n", _("Quiet module output"));
 
 	fprintf(stdout, "\n");
@@ -197,34 +197,45 @@
 		    type = "string";
 		    break;
 		}
-	    fprintf(stdout, "**%s** = *%s", opt->key, type);
+	    fprintf(stdout, "**%s** = *%s*", opt->key, type);
 	    if (opt->multiple) {
-		fprintf(stdout, "[,*%s*,...]", type);
+		fprintf(stdout, " [, *%s* ,...]", type);
 	    }
-	    fprintf(stdout, "*");
+	    /* fprintf(stdout, "*"); */
 	    if (opt->required) {
-		fprintf(stdout, " ;**[required]**");
+		fprintf(stdout, " **[required]**");
 	    }
-	    fprintf(stdout, "\n");
+	    fprintf(stdout, "\n\n");
 	    if (opt->label) {
-		fprintf(stdout, "    %s\n", opt->label);
+	        fprintf(stdout, "\t");
+		print_escaped_for_rest(stdout, opt->label);
+		/* fprintf(stdout, "    %s\n", opt->label); */
+		fprintf(stdout, "\n\n");
 	    }
 	    if (opt->description) {
-		fprintf(stdout, "    %s\n", opt->description);
+	        fprintf(stdout, "\t");
+	        print_escaped_for_rest(stdout, opt->description);
+		/* fprintf(stdout, "    %s\n", opt->description); */
+		fprintf(stdout, "\n\n");
 	    }
 
 	    if (opt->options) {
-		fprintf(stdout, "    %s: *", _("Options"));
-		/*! print_escaped_for_html_options(stdout, opt->options); */
-		fprintf(stdout, "%s", opt->options);
-		fprintf(stdout, "*\n");
+		fprintf(stdout, "\t%s: *", _("Options"));
+		print_escaped_for_rest_options(stdout, opt->options);
+		/* fprintf(stdout, "%s", opt->options);*/
+		fprintf(stdout, "*\n\n");
 	    }
 
 	    if (opt->def) {
-		fprintf(stdout, "    %s: *", _("Default"));
-		/*! print_escaped_for_html(stdout, opt->def); */
-		fprintf(stdout,"%s", opt->def);
-		fprintf(stdout, "*\n");
+		fprintf(stdout, "\t%s:", _("Default"));
+		/* TODO check if value is empty
+		if (!opt->def.empty()){ */
+		    fprintf(stdout, " *");
+		    print_escaped_for_rest(stdout, opt->def); 
+		    /* fprintf(stdout,"%s", opt->def); */
+		    fprintf(stdout, "*\n\n");
+		/* } */
+		fprintf(stdout, "\n\n");
 	    }
 
 	    if (opt->descs) {
@@ -232,12 +243,13 @@
 
 		while (opt->opts[i]) {
 		    if (opt->descs[i]) {
-			fprintf(stdout, "    **");
-			/*! print_escaped_for_html(stdout, opt->opts[i]); */
-			fprintf(stdout,"%s", opt->opts[i]);
-			fprintf(stdout, "**: ");
-			/*! print_escaped_for_html(stdout, opt->descs[i]); */
-			fprintf(stdout, "%s\n", opt->descs[i]);
+			fprintf(stdout, "\t\t**");
+			print_escaped_for_rest(stdout, opt->opts[i]);
+			/*fprintf(stdout,"%s", opt->opts[i]); */
+			fprintf(stdout, "** : ");
+			print_escaped_for_rest(stdout, opt->descs[i]);
+			/* fprintf(stdout, "%s\n", opt->descs[i]); */
+			fprintf(stdout, "\n\n");
 		    }
 		    i++;
 		}
@@ -253,42 +265,33 @@
 
 
 /*!
- * \brief Format text for HTML output
-
+ * \brief Format text for reStructuredText output
+ */
 #define do_escape(c,escaped) case c: fputs(escaped,f);break
- void print_escaped_for_html(FILE * f, const char *str)
+ void print_escaped_for_rest(FILE * f, const char *str)
  {
      const char *s;
  
      for (s = str; *s; s++) {
  	switch (*s) {
- 	    do_escape('&', "&");
- 	    do_escape('<', "<");
- 	    do_escape('>', ">");
- 	    do_escape('\n', "<br>");
- 	    do_escape('\t', "    ");
+ 	    do_escape('\n', "\n\n");
  	default:
  	    fputc(*s, f);
  	}
      }
  }
  
- void print_escaped_for_html_options(FILE * f, const char *str)
+ void print_escaped_for_rest_options(FILE * f, const char *str)
  {
      const char *s;
  
      for (s = str; *s; s++) {
  	switch (*s) {
- 	    do_escape('&', "&");
- 	    do_escape('<', "<");
- 	    do_escape('>', ">");
- 	    do_escape('\n', "<br>");
- 	    do_escape('\t', "    ");
- 	    do_escape(',',  ", ");
+ 	    do_escape('\n', "\n\n");
  	default:
  	    fputc(*s, f);
  	}
      }
  }
-*/
+
 #undef do_escape



More information about the grass-commit mailing list