parser_rst.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. #include <stdio.h>
  2. #include <grass/gis.h>
  3. #include <grass/glocale.h>
  4. #include "parser_local_proto.h"
  5. #include "string.h"
  6. // static void print_escaped_for_html(FILE * f, const char *str);
  7. // static void print_escaped_for_html_options(FILE * f, const char *str);
  8. /*!
  9. \brief Print module usage description in HTML format.
  10. */
  11. void G__usage_rest(void)
  12. {
  13. struct Option *opt;
  14. struct Flag *flag;
  15. const char *type;
  16. int new_prompt = 0;
  17. int s;
  18. new_prompt = G__uses_new_gisprompt();
  19. if (!st->pgm_name) /* v.dave && r.michael */
  20. st->pgm_name = G_program_name();
  21. if (!st->pgm_name)
  22. st->pgm_name = "??";
  23. fprintf(stdout, "=================");
  24. for (s = 0; s <= strlen(st->pgm_name); s++) {
  25. fprintf(stdout, "=");
  26. }
  27. fprintf(stdout, "\n");
  28. fprintf(stdout, "GRASS GIS manual: %s\n", st->pgm_name);
  29. fprintf(stdout, "=================");
  30. for (s = 0; s <= strlen(st->pgm_name); s++) {
  31. fprintf(stdout, "=");
  32. }
  33. fprintf(stdout, "\n\n");
  34. fprintf(stdout,".. figure:: grass_logo.png\n");
  35. fprintf(stdout," :align: center\n");
  36. fprintf(stdout," :alt: GRASS logo\n\n");
  37. fprintf(stdout,"%s\n----\n", _("NAME"));
  38. fprintf(stdout, "**%s**", st->pgm_name); //TODO fix bold + emphase now only bold
  39. if (st->module_info.label || st->module_info.description)
  40. fprintf(stdout, " - ");
  41. if (st->module_info.label)
  42. fprintf(stdout, "%s\n", st->module_info.label);
  43. if (st->module_info.description)
  44. fprintf(stdout, "%s\n", st->module_info.description);
  45. fprintf(stdout, "%s\n--------\n", _("KEYWORDS"));
  46. if (st->module_info.keywords) {
  47. G__print_keywords(stdout, NULL);
  48. fprintf(stdout, "\n");
  49. }
  50. fprintf(stdout, "%s\n--------\n", _("SYNOPSIS"));
  51. fprintf(stdout, "**%s**\n\n", st->pgm_name);
  52. fprintf(stdout, "**%s** help\n\n", st->pgm_name);
  53. fprintf(stdout, "**%s**", st->pgm_name);
  54. /* print short version first */
  55. if (st->n_flags) {
  56. flag = &st->first_flag;
  57. fprintf(stdout, " [**-");
  58. while (flag != NULL) {
  59. fprintf(stdout, "%c", flag->key);
  60. flag = flag->next_flag;
  61. }
  62. fprintf(stdout, "**] ");
  63. }
  64. else
  65. fprintf(stdout, " ");
  66. if (st->n_opts) {
  67. opt = &st->first_option;
  68. while (opt != NULL) {
  69. if (opt->key_desc != NULL)
  70. type = opt->key_desc;
  71. else
  72. switch (opt->type) {
  73. case TYPE_INTEGER:
  74. type = "integer";
  75. break;
  76. case TYPE_DOUBLE:
  77. type = "float";
  78. break;
  79. case TYPE_STRING:
  80. type = "string";
  81. break;
  82. default:
  83. type = "string";
  84. break;
  85. }
  86. if (!opt->required)
  87. fprintf(stdout, " [");
  88. fprintf(stdout, "**%s**=*%s*", opt->key, type);
  89. if (opt->multiple) {
  90. fprintf(stdout, "[,*%s*,...]", type);
  91. }
  92. if (!opt->required)
  93. fprintf(stdout, "] ");
  94. opt = opt->next_opt;
  95. fprintf(stdout, " ");
  96. }
  97. }
  98. if (new_prompt)
  99. fprintf(stdout, " [--**overwrite**] ");
  100. fprintf(stdout, " [--**verbose**] ");
  101. fprintf(stdout, " [--**quiet**] ");
  102. fprintf(stdout, "\n");
  103. /* now long version */
  104. fprintf(stdout, "\n");
  105. if (st->n_flags || new_prompt) {
  106. flag = &st->first_flag;
  107. fprintf(stdout, "%s:\n~~~~~~\n", _("Flags"));
  108. while (st->n_flags && flag != NULL) {
  109. fprintf(stdout, "**-%c**\n", flag->key);
  110. if (flag->label) {
  111. fprintf(stdout, " %s", flag->label);
  112. }
  113. if (flag->description) {
  114. fprintf(stdout, " %s", flag->description);
  115. }
  116. flag = flag->next_flag;
  117. fprintf(stdout, "\n");
  118. }
  119. if (new_prompt) {
  120. fprintf(stdout, "**--overwrite**\n");
  121. fprintf(stdout, " %s\n",
  122. _("Allow output files to overwrite existing files"));
  123. }
  124. fprintf(stdout, "**--verbose**\n");
  125. fprintf(stdout, " %s\n", _("Verbose module output"));
  126. fprintf(stdout, "**--quiet**\n");
  127. fprintf(stdout, " %s\n", _("Quiet module output"));
  128. fprintf(stdout, "\n");
  129. }
  130. fprintf(stdout, "\n");
  131. if (st->n_opts) {
  132. opt = &st->first_option;
  133. fprintf(stdout, "%s:\n~~~~~~~~~~~\n", _("Parameters"));
  134. while (opt != NULL) {
  135. /* TODO: make this a enumeration type? */
  136. if (opt->key_desc != NULL)
  137. type = opt->key_desc;
  138. else
  139. switch (opt->type) {
  140. case TYPE_INTEGER:
  141. type = "integer";
  142. break;
  143. case TYPE_DOUBLE:
  144. type = "float";
  145. break;
  146. case TYPE_STRING:
  147. type = "string";
  148. break;
  149. default:
  150. type = "string";
  151. break;
  152. }
  153. fprintf(stdout, "**%s** = *%s", opt->key, type);
  154. if (opt->multiple) {
  155. fprintf(stdout, "[,*%s*,...]", type);
  156. }
  157. fprintf(stdout, "*");
  158. if (opt->required) {
  159. fprintf(stdout, " ;**[required]**");
  160. }
  161. fprintf(stdout, "\n");
  162. if (opt->label) {
  163. fprintf(stdout, " %s\n", opt->label);
  164. }
  165. if (opt->description) {
  166. fprintf(stdout, " %s\n", opt->description);
  167. }
  168. if (opt->options) {
  169. fprintf(stdout, " %s: *", _("Options"));
  170. // print_escaped_for_html_options(stdout, opt->options);
  171. fprintf(stdout, "%s", opt->options);
  172. fprintf(stdout, "*\n");
  173. }
  174. if (opt->def) {
  175. fprintf(stdout, " %s: *", _("Default"));
  176. // print_escaped_for_html(stdout, opt->def);
  177. fprintf(stdout,"%s", opt->def);
  178. fprintf(stdout, "*\n");
  179. }
  180. if (opt->descs) {
  181. int i = 0;
  182. while (opt->opts[i]) {
  183. if (opt->descs[i]) {
  184. fprintf(stdout, " **");
  185. // print_escaped_for_html(stdout, opt->opts[i]);
  186. fprintf(stdout,"%s", opt->opts[i]);
  187. fprintf(stdout, "**: ");
  188. // print_escaped_for_html(stdout, opt->descs[i]);
  189. fprintf(stdout, "%s\n", opt->descs[i]);
  190. }
  191. i++;
  192. }
  193. }
  194. opt = opt->next_opt;
  195. fprintf(stdout, "\n");
  196. }
  197. fprintf(stdout, "\n");
  198. }
  199. }
  200. /*!
  201. * \brief Format text for HTML output
  202. */
  203. #define do_escape(c,escaped) case c: fputs(escaped,f);break
  204. // void print_escaped_for_html(FILE * f, const char *str)
  205. // {
  206. // const char *s;
  207. //
  208. // for (s = str; *s; s++) {
  209. // switch (*s) {
  210. // do_escape('&', "&amp;");
  211. // do_escape('<', "&lt;");
  212. // do_escape('>', "&gt;");
  213. // do_escape('\n', "<br>");
  214. // do_escape('\t', "&nbsp;&nbsp;&nbsp;&nbsp;");
  215. // default:
  216. // fputc(*s, f);
  217. // }
  218. // }
  219. // }
  220. //
  221. // void print_escaped_for_html_options(FILE * f, const char *str)
  222. // {
  223. // const char *s;
  224. //
  225. // for (s = str; *s; s++) {
  226. // switch (*s) {
  227. // do_escape('&', "&amp;");
  228. // do_escape('<', "&lt;");
  229. // do_escape('>', "&gt;");
  230. // do_escape('\n', "<br>");
  231. // do_escape('\t', "&nbsp;&nbsp;&nbsp;&nbsp;");
  232. // do_escape(',', ", ");
  233. // default:
  234. // fputc(*s, f);
  235. // }
  236. // }
  237. // }
  238. #undef do_escape