parser_html.c 6.0 KB

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