19 #include "parser_local_proto.h"
21 #define MD_NEWLINE " "
23 static void print_flag(
const char *key,
const char *label,
24 const char *description);
26 static void print_escaped(FILE *f,
const char *str);
27 static void print_escaped_for_md(FILE *f,
const char *str);
28 static void print_escaped_for_md_keywords(FILE *f,
const char *str);
29 static void print_escaped_for_md_options(FILE *f,
const char *str);
49 fprintf(stdout,
"---\n");
50 fprintf(stdout,
"name: %s\n",
st->pgm_name);
51 fprintf(stdout,
"description: %s\n",
st->module_info.description);
52 fprintf(stdout,
"keywords: [ ");
54 fprintf(stdout,
" ]");
55 fprintf(stdout,
"\n---\n\n");
58 fprintf(stdout,
"# %s\n\n",
st->pgm_name);
61 fprintf(stdout,
"## ");
62 fprintf(stdout,
"%s\n",
_(
"NAME"));
63 fprintf(stdout,
"\n");
64 fprintf(stdout,
"***%s***",
st->pgm_name);
66 if (
st->module_info.label ||
st->module_info.description)
67 fprintf(stdout,
" - ");
69 if (
st->module_info.label)
70 fprintf(stdout,
"%s\n",
st->module_info.label);
72 if (
st->module_info.description) {
73 if (
st->module_info.label)
74 fprintf(stdout,
"\n");
75 fprintf(stdout,
"%s\n",
st->module_info.description);
77 fprintf(stdout,
"\n");
78 fprintf(stdout,
"### ");
79 fprintf(stdout,
"%s\n",
_(
"KEYWORDS"));
80 fprintf(stdout,
"\n");
81 if (
st->module_info.keywords) {
84 fprintf(stdout,
"\n");
85 fprintf(stdout,
"### ");
86 fprintf(stdout,
"%s\n",
_(
"SYNOPSIS"));
87 fprintf(stdout,
"\n");
88 fprintf(stdout,
"**%s**",
st->pgm_name);
90 fprintf(stdout,
"\n");
91 fprintf(stdout,
"**%s --help**",
st->pgm_name);
93 fprintf(stdout,
"\n");
94 fprintf(stdout,
"**%s**",
st->pgm_name);
98 flag = &
st->first_flag;
99 fprintf(stdout,
" [**-");
100 while (flag !=
NULL) {
101 fprintf(stdout,
"%c", flag->
key);
104 fprintf(stdout,
"**] ");
107 fprintf(stdout,
" ");
110 opt = &
st->first_option;
112 while (opt !=
NULL) {
130 fprintf(stdout,
" ");
132 fprintf(stdout,
"[");
133 fprintf(stdout,
"**%s**=", opt->
key);
134 fprintf(stdout,
"*%s*", type);
136 fprintf(stdout,
" [,");
137 fprintf(stdout,
"*%s*,...]", type);
140 fprintf(stdout,
"]");
141 fprintf(stdout,
"\n");
147 fprintf(stdout,
" [**--overwrite**] ");
149 fprintf(stdout,
" [**--verbose**] ");
150 fprintf(stdout,
" [**--quiet**] ");
151 fprintf(stdout,
" [**--ui**]\n");
154 fprintf(stdout,
"\n");
155 if (
st->n_flags || new_prompt) {
156 flag = &
st->first_flag;
157 fprintf(stdout,
"#### ");
158 fprintf(stdout,
"%s\n",
_(
"Flags"));
159 fprintf(stdout,
"\n");
160 while (
st->n_flags && flag !=
NULL) {
163 fprintf(stdout,
"\n");
167 print_flag(
"overwrite",
NULL,
168 _(
"Allow output files to overwrite existing files"));
170 fprintf(stdout,
"\n");
173 print_flag(
"help",
NULL,
_(
"Print usage summary"));
175 fprintf(stdout,
"\n");
176 print_flag(
"verbose",
NULL,
_(
"Verbose module output"));
178 fprintf(stdout,
"\n");
179 print_flag(
"quiet",
NULL,
_(
"Quiet module output"));
181 fprintf(stdout,
"\n");
182 print_flag(
"ui",
NULL,
_(
"Force launching GUI dialog"));
183 fprintf(stdout,
"\n");
186 fprintf(stdout,
"\n");
187 opt = &
st->first_option;
188 fprintf(stdout,
"#### ");
189 fprintf(stdout,
"%s\n",
_(
"Parameters"));
190 fprintf(stdout,
"\n");
191 while (opt !=
NULL) {
197 fprintf(stdout,
"\n");
204 fprintf(stdout,
"**");
206 fprintf(stdout,
"-");
207 fprintf(stdout,
"-%s**",
key);
209 fprintf(stdout,
"\n");
211 print_escaped(stdout,
"\t");
212 print_escaped(stdout,
label);
214 fprintf(stdout,
"\n");
217 print_escaped(stdout,
"\t");
244 fprintf(stdout,
"**%s**=", opt->
key);
245 fprintf(stdout,
"*%s*", type);
247 fprintf(stdout,
" [,");
248 fprintf(stdout,
"*%s*,...]", type);
252 fprintf(stdout,
" **[required]**");
255 fprintf(stdout,
"\n");
257 print_escaped(stdout,
"\t");
258 print_escaped(stdout, opt->
label);
263 fprintf(stdout,
"\n");
265 print_escaped(stdout,
"\t");
271 fprintf(stdout,
"\n");
272 print_escaped(stdout,
"\t");
273 fprintf(stdout,
"%s: *",
_(
"Options"));
274 print_escaped_for_md_options(stdout, opt->
options);
275 fprintf(stdout,
"*");
280 fprintf(stdout,
"\n");
281 print_escaped(stdout,
"\t");
282 fprintf(stdout,
"%s:",
_(
"Default"));
285 fprintf(stdout,
" *");
286 print_escaped(stdout, opt->
def);
287 fprintf(stdout,
"*");
293 while (opt->
opts[i]) {
296 fprintf(stdout,
"\n");
297 char *thumbnails =
NULL;
299 if (strcmp(opt->
gisprompt,
"old,colortable,colortable") ==
301 thumbnails =
"colortables";
302 else if (strcmp(opt->
gisprompt,
"old,barscale,barscale") ==
304 thumbnails =
"barscales";
306 "old,northarrow,northarrow") == 0)
307 thumbnails =
"northarrows";
310 print_escaped(stdout,
"\t\t");
311 fprintf(stdout,
" ", opt->
opts[i],
312 thumbnails, opt->
opts[i]);
315 print_escaped(stdout,
"\t\t");
318 print_escaped(stdout,
"\t");
319 fprintf(stdout,
"**");
320 print_escaped(stdout, opt->
opts[i]);
321 fprintf(stdout,
"**: ");
322 print_escaped(stdout, opt->
descs[i]);
332 #define do_escape(c, escaped) \
337 void print_escaped(FILE *f,
const char *str)
339 print_escaped_for_md(f, str);
342 void print_escaped_for_md(FILE *f,
const char *str)
346 for (s = str; *s; s++) {
349 do_escape(
'\t',
" ");
359 void print_escaped_for_md_options(FILE *f,
const char *str)
363 for (s = str; *s; s++) {
374 void print_escaped_for_md_keywords(FILE *f,
const char *str)
383 if (
st->n_keys > 1 && strcmp(
st->module_info.keywords[1], str) == 0) {
388 fprintf(f,
"[%s](topic_", str_s);
389 for (s = str_s; *s; s++) {
399 if (
st->n_keys > 0 && strcmp(
st->module_info.keywords[0], str) == 0) {
403 fprintf(f,
"[%s](", str_s);
404 for (s = str_s; *s; s++) {
418 fprintf(f,
"[%s](keywords.md#%s)", str_s, str_link);
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.
void G_str_to_lower(char *)
Convert string to lower case.
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 Markdown output.
void G__usage_markdown(void)
Print module usage description in Markdown format.
void print_option(const struct Option *opt)
Structure that stores flag info.
Structure that stores option information.