16 #include <grass/gis.h>
17 #include <grass/glocale.h>
19 #include "parser_local_proto.h"
21 static void print_cli_flag(FILE *
file,
const char *key,
const char *label,
22 const char *description,
const char *indent);
23 static void print_cli_option(FILE *
file,
const struct Option *opt,
25 static void print_cli_example(FILE *
file,
const char *indent);
27 void print_cli_flag(FILE *
file,
const char *key,
const char *label,
28 const char *description,
const char *indent)
30 fprintf(
file,
"%s**", indent);
33 fprintf(
file,
"-%s**", key);
34 fprintf(
file, MD_NEWLINE);
37 fprintf(
file,
"%s", indent);
40 fprintf(
file, MD_NEWLINE);
43 if (description !=
NULL) {
44 fprintf(
file,
"%s", indent);
50 void print_cli_option(FILE *
file,
const struct Option *opt,
const char *indent)
54 if (opt->key_desc !=
NULL)
71 fprintf(
file,
"%s**%s**=", indent, opt->key);
72 fprintf(
file,
"*%s*", type);
75 fprintf(
file,
"*%s*,...]", type);
79 fprintf(
file,
" **[required]**");
81 fprintf(
file, MD_NEWLINE);
84 fprintf(
file,
"%s", indent);
88 if (opt->description) {
90 fprintf(
file, MD_NEWLINE);
93 fprintf(
file,
"%s", indent);
99 fprintf(
file, MD_NEWLINE);
101 fprintf(
file,
"%s", indent);
103 fprintf(
file,
"%s: *", _(
"Allowed values"));
108 if (opt->def && opt->def[0] !=
'\0') {
109 fprintf(
file, MD_NEWLINE);
111 fprintf(
file,
"%s", indent);
113 fprintf(
file,
"%s:", _(
"Default"));
122 while (opt->opts[i]) {
124 fprintf(
file, MD_NEWLINE);
126 fprintf(
file,
"%s", indent);
127 char *thumbnails =
NULL;
128 if (opt->gisprompt) {
129 if (strcmp(opt->gisprompt,
"old,colortable,colortable") ==
131 thumbnails =
"colortables";
132 else if (strcmp(opt->gisprompt,
"old,barscale,barscale") ==
134 thumbnails =
"barscales";
135 else if (strcmp(opt->gisprompt,
136 "old,northarrow,northarrow") == 0)
137 thumbnails =
"northarrows";
141 fprintf(
file,
" ", opt->opts[i],
142 thumbnails, opt->opts[i]);
151 fprintf(
file,
"**: ");
159 void print_cli_example(FILE *
file,
const char *indent)
161 fprintf(
file,
"\n%sExample:\n", indent);
163 fprintf(
file,
"\n%s```sh\n", indent);
164 fprintf(
file,
"%s%s", indent,
st->pgm_name);
166 const struct Option *first_required_rule_option =
168 const struct Option *opt =
NULL;
172 opt = &
st->first_option;
174 while (opt !=
NULL) {
175 if (opt->key_desc !=
NULL)
176 type = opt->key_desc;
192 if (opt->required || first_required_rule_option == opt) {
194 fprintf(
file,
"%s=", opt->key);
200 else if (opt->options && opt->type == TYPE_STRING) {
219 fprintf(
file,
"%s", value);
222 if (opt->type == TYPE_INTEGER) {
225 else if (opt->type == TYPE_DOUBLE) {
226 fprintf(
file,
"0.0");
229 fprintf(
file,
"%s", type);
237 fprintf(
file,
"\n%s```\n", indent);
249 fprintf(
file,
"%s**%s**", indent,
st->pgm_name);
254 flag = &
st->first_flag;
255 fprintf(
file,
"%s[**-", indent);
256 while (flag !=
NULL) {
257 fprintf(
file,
"%c", flag->key);
258 flag = flag->next_flag;
260 fprintf(
file,
"**]");
265 opt = &
st->first_option;
267 while (opt !=
NULL) {
268 if (opt->key_desc !=
NULL)
269 type = opt->key_desc;
285 fprintf(
file,
"%s", indent);
288 fprintf(
file,
"**%s**=", opt->key);
289 fprintf(
file,
"*%s*", type);
291 fprintf(
file,
" [,");
292 fprintf(
file,
"*%s*,...]", type);
302 fprintf(
file,
"%s[**--overwrite**]\n", indent);
304 fprintf(
file,
"%s[**--verbose**]\n", indent);
305 fprintf(
file,
"%s[**--quiet**]\n", indent);
306 fprintf(
file,
"%s[**--qq**]\n", indent);
307 fprintf(
file,
"%s[**--ui**]\n", indent);
309 print_cli_example(
file, indent);
322 opt = &
st->first_option;
323 while (opt !=
NULL) {
324 print_cli_option(
file, opt, indent);
326 fprintf(
file, MD_NEWLINE);
332 if (
st->n_flags || new_prompt) {
333 flag = &
st->first_flag;
334 while (
st->n_flags && flag !=
NULL) {
335 print_cli_flag(
file, &flag->key, flag->label, flag->description,
337 fprintf(
file, MD_NEWLINE);
339 flag = flag->next_flag;
342 print_cli_flag(
file,
"overwrite",
NULL,
343 _(
"Allow output files to overwrite existing files"),
345 fprintf(
file, MD_NEWLINE);
350 print_cli_flag(
file,
"help",
NULL, _(
"Print usage summary"), indent);
351 fprintf(
file, MD_NEWLINE);
353 print_cli_flag(
file,
"verbose",
NULL, _(
"Verbose module output"), indent);
354 fprintf(
file, MD_NEWLINE);
356 print_cli_flag(
file,
"quiet",
NULL, _(
"Quiet module output"), indent);
357 fprintf(
file, MD_NEWLINE);
359 print_cli_flag(
file,
"qq",
NULL, _(
"Very quiet module output"), indent);
360 fprintf(
file, MD_NEWLINE);
362 print_cli_flag(
file,
"ui",
NULL, _(
"Force launching GUI dialog"), indent);
void G_free(void *buf)
Free allocated memory.
int G__uses_new_gisprompt(void)
const struct Option * G__first_required_option_from_rules(void)
void G__md_print_cli_long_version(FILE *file, const char *indent)
void G__md_print_cli_short_version(FILE *file, const char *indent)
void G__md_print_escaped(FILE *f, const char *str)
void G__md_print_escaped_for_options(FILE *f, const char *str)
char * G_store(const char *s)
Copy string to allocated memory.
char * G_chop(char *line)
Chop leading and trailing white spaces.
void G_free_tokens(char **tokens)
Free memory allocated to tokens.
char ** G_tokenize(const char *buf, const char *delim)
Tokenize string.