21 #include "parser_local_proto.h"
23 static void usage_rest_md(
bool rest);
24 static void print_flag(
const char *key,
const char *label,
25 const char *description,
bool rest);
27 static void print_escaped(FILE *f,
const char *str,
bool rest);
28 static void print_escaped_for_rest(FILE *f,
const char *str);
29 static void print_escaped_for_md(FILE *f,
const char *str);
30 static void print_escaped_for_rest_options(FILE *f,
const char *str);
31 static void print_escaped_for_md_keywords(FILE *f,
const char *str);
39 void usage_rest_md(
bool rest)
55 G_asprintf(&header,
"%s - GRASS GIS manual",
st->pgm_name);
58 fprintf(stdout,
"%s\n", header);
59 for (s = 0; s < strlen(header); s++) {
62 fprintf(stdout,
"\n");
65 fprintf(stdout,
"# %s\n", header);
67 fprintf(stdout,
"\n");
71 fprintf(stdout,
".. image:: grass_logo.png\n");
72 fprintf(stdout,
" :align: center\n");
73 fprintf(stdout,
" :alt: GRASS logo\n");
76 fprintf(stdout,
"![GRASS logo](./grass_logo.png)\n");
79 fprintf(stdout,
"\n---");
82 fprintf(stdout,
"\n\n");
86 fprintf(stdout,
"## ");
87 fprintf(stdout,
"%s\n",
_(
"NAME"));
89 fprintf(stdout,
"----");
90 fprintf(stdout,
"\n");
91 fprintf(stdout,
"**%s**",
st->pgm_name);
93 if (
st->module_info.label ||
st->module_info.description)
94 fprintf(stdout,
" - ");
96 if (
st->module_info.label)
97 fprintf(stdout,
"%s\n",
st->module_info.label);
99 if (
st->module_info.description) {
100 if (
st->module_info.label)
101 fprintf(stdout,
"\n");
102 fprintf(stdout,
"%s\n",
st->module_info.description);
104 fprintf(stdout,
"\n");
106 fprintf(stdout,
"### ");
107 fprintf(stdout,
"%s\n",
_(
"KEYWORDS"));
109 fprintf(stdout,
"--------\n");
110 fprintf(stdout,
"\n");
111 if (
st->module_info.keywords) {
114 fprintf(stdout,
"\n");
120 fprintf(stdout,
"\n");
122 fprintf(stdout,
"### ");
123 fprintf(stdout,
"%s\n",
_(
"SYNOPSIS"));
125 fprintf(stdout,
"--------\n\n");
126 fprintf(stdout,
"| ");
129 fprintf(stdout,
"\n");
131 fprintf(stdout,
"**%s**",
st->pgm_name);
133 fprintf(stdout,
"\\");
134 fprintf(stdout,
"\n");
136 fprintf(stdout,
"| ");
137 fprintf(stdout,
"**%s --help**",
st->pgm_name);
139 fprintf(stdout,
"\\");
140 fprintf(stdout,
"\n");
142 fprintf(stdout,
"| ");
143 fprintf(stdout,
"**%s**",
st->pgm_name);
147 flag = &
st->first_flag;
148 fprintf(stdout,
" [**-");
149 while (flag !=
NULL) {
150 fprintf(stdout,
"%c", flag->
key);
153 fprintf(stdout,
"**] ");
156 fprintf(stdout,
" ");
159 opt = &
st->first_option;
161 while (opt !=
NULL) {
179 fprintf(stdout,
" ");
181 fprintf(stdout,
"[");
182 fprintf(stdout,
"**%s**=", opt->
key);
184 fprintf(stdout,
"\\ ");
185 fprintf(stdout,
"*%s*", type);
187 fprintf(stdout,
" [,");
189 fprintf(stdout,
"\\ ");
190 fprintf(stdout,
"*%s*,...]", type);
193 fprintf(stdout,
"]");
195 fprintf(stdout,
" ");
197 fprintf(stdout,
"\n");
203 fprintf(stdout,
" [**--overwrite**] ");
205 fprintf(stdout,
" [**--verbose**] ");
206 fprintf(stdout,
" [**--quiet**] ");
207 fprintf(stdout,
" [**--ui**]\n");
210 fprintf(stdout,
"\n");
211 if (
st->n_flags || new_prompt) {
212 flag = &
st->first_flag;
214 fprintf(stdout,
"#### ");
215 fprintf(stdout,
"%s\n",
_(
"Flags"));
217 fprintf(stdout,
"~~~~~~\n");
218 fprintf(stdout,
"\n");
219 while (
st->n_flags && flag !=
NULL) {
222 fprintf(stdout,
"\\");
223 fprintf(stdout,
"\n");
227 print_flag(
"overwrite",
NULL,
228 _(
"Allow output files to overwrite existing files"),
231 fprintf(stdout,
"\\");
232 fprintf(stdout,
"\n");
235 print_flag(
"help",
NULL,
_(
"Print usage summary"), rest);
237 fprintf(stdout,
"\\");
238 fprintf(stdout,
"\n");
239 print_flag(
"verbose",
NULL,
_(
"Verbose module output"), rest);
241 fprintf(stdout,
"\\");
242 fprintf(stdout,
"\n");
243 print_flag(
"quiet",
NULL,
_(
"Quiet module output"), rest);
245 fprintf(stdout,
"\\");
246 fprintf(stdout,
"\n");
247 print_flag(
"ui",
NULL,
_(
"Force launching GUI dialog"), rest);
248 fprintf(stdout,
"\n");
251 fprintf(stdout,
"\n");
252 opt = &
st->first_option;
254 fprintf(stdout,
"#### ");
255 fprintf(stdout,
"%s\n",
_(
"Parameters"));
257 fprintf(stdout,
"~~~~~~~~~~~\n");
258 fprintf(stdout,
"\n");
260 image_spec_rest[0] =
'\0';
261 while (opt !=
NULL) {
266 fprintf(stdout,
"\\");
268 fprintf(stdout,
"\n");
270 if (strlen(image_spec_rest) > 0) {
271 fprintf(stdout,
"\n");
272 fprintf(stdout,
"%s", image_spec_rest);
281 fprintf(stdout,
"| ");
282 fprintf(stdout,
"**");
284 fprintf(stdout,
"-");
285 fprintf(stdout,
"-%s**",
key);
287 fprintf(stdout,
"\\");
288 fprintf(stdout,
"\n");
291 fprintf(stdout,
"| ");
292 print_escaped(stdout,
"\t", rest);
293 print_escaped(stdout,
label, rest);
295 fprintf(stdout,
"\\");
296 fprintf(stdout,
"\n");
299 fprintf(stdout,
"| ");
300 print_escaped(stdout,
"\t", rest);
328 fprintf(stdout,
"| ");
329 fprintf(stdout,
"**%s**=", opt->
key);
331 fprintf(stdout,
"\\ ");
332 fprintf(stdout,
"*%s*", type);
334 fprintf(stdout,
" [,");
336 fprintf(stdout,
"\\ ");
337 fprintf(stdout,
"*%s*,...]", type);
341 fprintf(stdout,
" **[required]**");
344 fprintf(stdout,
"\\");
345 fprintf(stdout,
"\n");
348 fprintf(stdout,
"| ");
349 print_escaped(stdout,
"\t", rest);
350 print_escaped(stdout, opt->
label, rest);
355 fprintf(stdout,
"\\");
356 fprintf(stdout,
"\n");
359 fprintf(stdout,
"| ");
360 print_escaped(stdout,
"\t", rest);
366 fprintf(stdout,
"\\");
367 fprintf(stdout,
"\n");
369 fprintf(stdout,
"| ");
370 print_escaped(stdout,
"\t", rest);
371 fprintf(stdout,
"%s: *",
_(
"Options"));
372 print_escaped_for_rest_options(stdout, opt->
options);
373 fprintf(stdout,
"*");
378 fprintf(stdout,
"\\");
379 fprintf(stdout,
"\n");
381 fprintf(stdout,
"| ");
382 print_escaped(stdout,
"\t", rest);
383 fprintf(stdout,
"%s:",
_(
"Default"));
386 fprintf(stdout,
" *");
387 print_escaped(stdout, opt->
def, rest);
388 fprintf(stdout,
"*");
394 while (opt->
opts[i]) {
397 fprintf(stdout,
"\\");
398 fprintf(stdout,
"\n");
399 char *thumbnails =
NULL;
401 if (strcmp(opt->
gisprompt,
"old,colortable,colortable") ==
403 thumbnails =
"colortables";
404 else if (strcmp(opt->
gisprompt,
"old,barscale,barscale") ==
406 thumbnails =
"barscales";
408 "old,northarrow,northarrow") == 0)
409 thumbnails =
"northarrows";
415 ".. |%s| image:: %s/%s.png\n",
416 opt->
opts[i], thumbnails, opt->
opts[i]);
417 strcat(image_spec_rest, image_spec);
420 print_escaped(stdout,
"\t\t", rest);
421 fprintf(stdout,
"![%s](%s/%s.png) ", opt->
opts[i],
422 thumbnails, opt->
opts[i]);
427 fprintf(stdout,
"| ");
428 print_escaped(stdout,
"\t\t", rest);
430 fprintf(stdout,
"\\ ");
434 if (rest && thumbnails) {
435 fprintf(stdout,
"| ");
436 print_escaped(stdout,
"\t\t", rest);
437 fprintf(stdout,
"|%s| ", opt->
opts[i]);
440 print_escaped(stdout,
"\t", rest);
441 fprintf(stdout,
"**");
442 print_escaped(stdout, opt->
opts[i], rest);
443 fprintf(stdout,
"**: ");
444 print_escaped(stdout, opt->
descs[i], rest);
454 #define do_escape(c, escaped) \
459 void print_escaped(FILE *f,
const char *str,
bool rest)
462 print_escaped_for_rest(f, str);
464 print_escaped_for_md(f, str);
467 void print_escaped_for_rest(FILE *f,
const char *str)
471 for (s = str; *s; s++) {
481 void print_escaped_for_md(FILE *f,
const char *str)
485 for (s = str; *s; s++) {
488 do_escape(
'\t',
" ");
498 void print_escaped_for_rest_options(FILE *f,
const char *str)
502 for (s = str; *s; s++) {
513 void print_escaped_for_md_keywords(FILE *f,
const char *str)
522 if (
st->n_keys > 1 && strcmp(
st->module_info.keywords[1], str) == 0) {
527 fprintf(f,
"[%s](topic_", str_s);
528 for (s = str_s; *s; s++) {
535 fprintf(f,
".html)");
538 if (
st->n_keys > 0 && strcmp(
st->module_info.keywords[0], str) == 0) {
542 fprintf(f,
"[%s](", str_s);
543 for (s = str_s; *s; s++) {
550 fprintf(f,
".html)");
556 fprintf(f,
"[%s](keywords.html#%s)", str_s, str_link);
579 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.