parser_html.c 6.1 KB

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