21 #include "parser_local_proto.h"
23 #define MD_NEWLINE " "
25 static void usage_rest_md(
bool rest);
26 static void print_flag(
const char *key,
const char *label,
27 const char *description,
bool rest);
29 static void print_escaped(FILE *f,
const char *str,
bool rest);
30 static void print_escaped_for_rest(FILE *f,
const char *str);
31 static void print_escaped_for_md(FILE *f,
const char *str);
32 static void print_escaped_for_rest_options(FILE *f,
const char *str);
33 static void print_escaped_for_md_keywords(FILE *f,
const char *str);
41 void usage_rest_md(
bool rest)
56 fprintf(stdout,
"---\n");
57 fprintf(stdout,
"name: %s\n",
st->pgm_name);
58 fprintf(stdout,
"description: %s\n",
st->module_info.description);
59 fprintf(stdout,
"keywords: ");
61 fprintf(stdout,
"\n---\n\n");
65 fprintf(stdout,
"# %s\n\n",
st->pgm_name);
69 fprintf(stdout,
"## ");
70 fprintf(stdout,
"%s\n",
_(
"NAME"));
72 fprintf(stdout,
"----");
73 fprintf(stdout,
"\n");
74 fprintf(stdout,
"***%s***",
st->pgm_name);
76 if (
st->module_info.label ||
st->module_info.description)
77 fprintf(stdout,
" - ");
79 if (
st->module_info.label)
80 fprintf(stdout,
"%s\n",
st->module_info.label);
82 if (
st->module_info.description) {
83 if (
st->module_info.label)
84 fprintf(stdout,
"\n");
85 fprintf(stdout,
"%s\n",
st->module_info.description);
87 fprintf(stdout,
"\n");
89 fprintf(stdout,
"### ");
90 fprintf(stdout,
"%s\n",
_(
"KEYWORDS"));
92 fprintf(stdout,
"--------\n");
93 fprintf(stdout,
"\n");
94 if (
st->module_info.keywords) {
97 fprintf(stdout,
"\n");
103 fprintf(stdout,
"\n");
105 fprintf(stdout,
"### ");
106 fprintf(stdout,
"%s\n",
_(
"SYNOPSIS"));
108 fprintf(stdout,
"--------\n\n");
109 fprintf(stdout,
"| ");
112 fprintf(stdout,
"\n");
114 fprintf(stdout,
"**%s**",
st->pgm_name);
117 fprintf(stdout,
"\n");
119 fprintf(stdout,
"| ");
120 fprintf(stdout,
"**%s --help**",
st->pgm_name);
123 fprintf(stdout,
"\n");
125 fprintf(stdout,
"| ");
126 fprintf(stdout,
"**%s**",
st->pgm_name);
130 flag = &
st->first_flag;
131 fprintf(stdout,
" [**-");
132 while (flag !=
NULL) {
133 fprintf(stdout,
"%c", flag->
key);
136 fprintf(stdout,
"**] ");
139 fprintf(stdout,
" ");
142 opt = &
st->first_option;
144 while (opt !=
NULL) {
162 fprintf(stdout,
" ");
164 fprintf(stdout,
"[");
165 fprintf(stdout,
"**%s**=", opt->
key);
167 fprintf(stdout,
"\\ ");
168 fprintf(stdout,
"*%s*", type);
170 fprintf(stdout,
" [,");
172 fprintf(stdout,
"\\ ");
173 fprintf(stdout,
"*%s*,...]", type);
176 fprintf(stdout,
"]");
178 fprintf(stdout,
" ");
180 fprintf(stdout,
"\n");
186 fprintf(stdout,
" [**--overwrite**] ");
188 fprintf(stdout,
" [**--verbose**] ");
189 fprintf(stdout,
" [**--quiet**] ");
190 fprintf(stdout,
" [**--ui**]\n");
193 fprintf(stdout,
"\n");
194 if (
st->n_flags || new_prompt) {
195 flag = &
st->first_flag;
197 fprintf(stdout,
"#### ");
198 fprintf(stdout,
"%s\n",
_(
"Flags"));
200 fprintf(stdout,
"~~~~~~\n");
201 fprintf(stdout,
"\n");
202 while (
st->n_flags && flag !=
NULL) {
206 fprintf(stdout,
"\n");
210 print_flag(
"overwrite",
NULL,
211 _(
"Allow output files to overwrite existing files"),
215 fprintf(stdout,
"\n");
218 print_flag(
"help",
NULL,
_(
"Print usage summary"), rest);
221 fprintf(stdout,
"\n");
222 print_flag(
"verbose",
NULL,
_(
"Verbose module output"), rest);
225 fprintf(stdout,
"\n");
226 print_flag(
"quiet",
NULL,
_(
"Quiet module output"), rest);
229 fprintf(stdout,
"\n");
230 print_flag(
"ui",
NULL,
_(
"Force launching GUI dialog"), rest);
231 fprintf(stdout,
"\n");
234 fprintf(stdout,
"\n");
235 opt = &
st->first_option;
237 fprintf(stdout,
"#### ");
238 fprintf(stdout,
"%s\n",
_(
"Parameters"));
240 fprintf(stdout,
"~~~~~~~~~~~\n");
241 fprintf(stdout,
"\n");
243 image_spec_rest[0] =
'\0';
244 while (opt !=
NULL) {
251 fprintf(stdout,
"\n");
253 if (strlen(image_spec_rest) > 0) {
254 fprintf(stdout,
"\n");
255 fprintf(stdout,
"%s", image_spec_rest);
264 fprintf(stdout,
"| ");
265 fprintf(stdout,
"**");
267 fprintf(stdout,
"-");
268 fprintf(stdout,
"-%s**",
key);
271 fprintf(stdout,
"\n");
274 fprintf(stdout,
"| ");
275 print_escaped(stdout,
"\t", rest);
276 print_escaped(stdout,
label, rest);
279 fprintf(stdout,
"\n");
283 fprintf(stdout,
"| ");
284 print_escaped(stdout,
"\t", rest);
313 fprintf(stdout,
"| ");
314 fprintf(stdout,
"**%s**=", opt->
key);
316 fprintf(stdout,
"\\ ");
317 fprintf(stdout,
"*%s*", type);
319 fprintf(stdout,
" [,");
321 fprintf(stdout,
"\\ ");
322 fprintf(stdout,
"*%s*,...]", type);
326 fprintf(stdout,
" **[required]**");
330 fprintf(stdout,
"\n");
333 fprintf(stdout,
"| ");
334 print_escaped(stdout,
"\t", rest);
335 print_escaped(stdout, opt->
label, rest);
341 fprintf(stdout,
"\n");
344 fprintf(stdout,
"| ");
345 print_escaped(stdout,
"\t", rest);
352 fprintf(stdout,
"\n");
354 fprintf(stdout,
"| ");
355 print_escaped(stdout,
"\t", rest);
356 fprintf(stdout,
"%s: *",
_(
"Options"));
357 print_escaped_for_rest_options(stdout, opt->
options);
358 fprintf(stdout,
"*");
364 fprintf(stdout,
"\n");
366 fprintf(stdout,
"| ");
367 print_escaped(stdout,
"\t", rest);
368 fprintf(stdout,
"%s:",
_(
"Default"));
371 fprintf(stdout,
" *");
372 print_escaped(stdout, opt->
def, rest);
373 fprintf(stdout,
"*");
379 while (opt->
opts[i]) {
383 fprintf(stdout,
"\n");
384 char *thumbnails =
NULL;
386 if (strcmp(opt->
gisprompt,
"old,colortable,colortable") ==
388 thumbnails =
"colortables";
389 else if (strcmp(opt->
gisprompt,
"old,barscale,barscale") ==
391 thumbnails =
"barscales";
393 "old,northarrow,northarrow") == 0)
394 thumbnails =
"northarrows";
400 ".. |%s| image:: %s/%s.png\n",
401 opt->
opts[i], thumbnails, opt->
opts[i]);
402 strcat(image_spec_rest, image_spec);
405 print_escaped(stdout,
"\t\t", rest);
406 fprintf(stdout,
"![%s](%s/%s.png) ", opt->
opts[i],
407 thumbnails, opt->
opts[i]);
412 fprintf(stdout,
"| ");
413 print_escaped(stdout,
"\t\t", rest);
415 fprintf(stdout,
"\\ ");
419 if (rest && thumbnails) {
420 fprintf(stdout,
"| ");
421 print_escaped(stdout,
"\t\t", rest);
422 fprintf(stdout,
"|%s| ", opt->
opts[i]);
425 print_escaped(stdout,
"\t", rest);
426 fprintf(stdout,
"**");
427 print_escaped(stdout, opt->
opts[i], rest);
428 fprintf(stdout,
"**: ");
429 print_escaped(stdout, opt->
descs[i], rest);
439 #define do_escape(c, escaped) \
444 void print_escaped(FILE *f,
const char *str,
bool rest)
447 print_escaped_for_rest(f, str);
449 print_escaped_for_md(f, str);
452 void print_escaped_for_rest(FILE *f,
const char *str)
456 for (s = str; *s; s++) {
466 void print_escaped_for_md(FILE *f,
const char *str)
470 for (s = str; *s; s++) {
473 do_escape(
'\t',
" ");
483 void print_escaped_for_rest_options(FILE *f,
const char *str)
487 for (s = str; *s; s++) {
498 void print_escaped_for_md_keywords(FILE *f,
const char *str)
507 if (
st->n_keys > 1 && strcmp(
st->module_info.keywords[1], str) == 0) {
512 fprintf(f,
"[%s](topic_", str_s);
513 for (s = str_s; *s; s++) {
520 fprintf(f,
".html)");
523 if (
st->n_keys > 0 && strcmp(
st->module_info.keywords[0], str) == 0) {
527 fprintf(f,
"[%s](", str_s);
528 for (s = str_s; *s; s++) {
535 fprintf(f,
".html)");
541 fprintf(f,
"[%s](keywords.html#%s)", str_s, str_link);
564 usage_rest_md(
FALSE);
void G_free(void *)
Free allocated memory.
char * G_str_replace(const char *, const char *, const char *)
Replace all occurrences of old_str in buffer with new_str.
void G_strip(char *)
Removes all leading and trailing white space from string.
int G_asprintf(char **, const char *,...) __attribute__((format(printf
const char * G_program_name(void)
Return module name.
char * G_store(const char *)
Copy string to allocated memory.
void G__print_keywords(FILE *fd, void(*format)(FILE *, const char *), int newline)
Print list of keywords (internal use only)
int G__uses_new_gisprompt(void)
#define do_escape(c, escaped)
Format text for reStructuredText output.
void G__usage_markdown(void)
Print module usage description in Markdown format.
void G__usage_rest(void)
Print module usage description in reStructuredText format.
void print_option(const struct Option *opt, bool rest, char *)
Structure that stores flag info.
Structure that stores option information.