parser_rest.c 6.4 KB

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