2
\file lib/gis/parser_rest.c
4
\brief GIS Library - Argument parsing functions (reStructuredText output)
6
(C) 2012 by the GRASS Development Team
8
This program is free software under the GNU General Public License
9
(>=v2). Read the file COPYING that comes with GRASS for details.
16
#include <grass/gis.h>
17
#include <grass/glocale.h>
19
#include "parser_local_proto.h"
22
static void print_escaped_for_rest(FILE * f, const char *str);
23
static void print_escaped_for_rest_options(FILE * f, const char *str);
27
\brief Print module usage description in reStructuredText format.
29
void G__usage_rest(void)
37
new_prompt = G__uses_new_gisprompt();
40
st->pgm_name = G_program_name();
44
fprintf(stdout, "=================");
45
for (s = 0; s <= strlen(st->pgm_name); s++) {
48
fprintf(stdout, "\n");
49
fprintf(stdout, "GRASS GIS manual: %s\n", st->pgm_name);
50
fprintf(stdout, "=================");
51
for (s = 0; s <= strlen(st->pgm_name); s++) {
54
fprintf(stdout, "\n\n");
56
fprintf(stdout,".. figure:: grass_logo.png\n");
57
fprintf(stdout," :align: center\n");
58
fprintf(stdout," :alt: GRASS logo\n\n");
60
fprintf(stdout,"%s\n----\n", _("NAME"));
61
fprintf(stdout, "**%s**", st->pgm_name);
63
if (st->module_info.label || st->module_info.description)
64
fprintf(stdout, " - ");
66
if (st->module_info.label)
67
fprintf(stdout, "%s\n\n", st->module_info.label);
69
if (st->module_info.description)
70
fprintf(stdout, "%s\n", st->module_info.description);
73
fprintf(stdout, "\n%s\n----------------------\n", _("KEYWORDS"));
74
if (st->module_info.keywords) {
75
G__print_keywords(stdout, NULL);
76
fprintf(stdout, "\n");
78
fprintf(stdout, "\n%s\n----------------------\n", _("SYNOPSIS"));
79
fprintf(stdout, "**%s**\n\n", st->pgm_name);
80
fprintf(stdout, "**%s** --help\n\n", st->pgm_name);
82
fprintf(stdout, "**%s**", st->pgm_name);
86
/* print short version first */
88
flag = &st->first_flag;
89
fprintf(stdout, " [**-");
90
while (flag != NULL) {
91
fprintf(stdout, "%c", flag->key);
92
flag = flag->next_flag;
94
fprintf(stdout, "**] ");
100
opt = &st->first_option;
102
while (opt != NULL) {
103
if (opt->key_desc != NULL)
104
type = opt->key_desc;
121
fprintf(stdout, " [");
122
fprintf(stdout, "**%s** = *%s*", opt->key, type);
124
fprintf(stdout, " [, *%s* ,...]", type);
127
fprintf(stdout, "] ");
130
fprintf(stdout, " ");
134
fprintf(stdout, " [-- **overwrite**] ");
136
fprintf(stdout, " [-- **verbose**] ");
137
fprintf(stdout, " [-- **quiet**] ");
139
fprintf(stdout, "\n");
142
/* now long version */
143
fprintf(stdout, "\n");
144
if (st->n_flags || new_prompt) {
145
flag = &st->first_flag;
146
fprintf(stdout, "%s:\n~~~~~~\n", _("Flags"));
147
while (st->n_flags && flag != NULL) {
148
fprintf(stdout, "**-%c**\n", flag->key);
151
fprintf(stdout, " %s", flag->label);
154
if (flag->description) {
155
fprintf(stdout, " %s", flag->description);
158
flag = flag->next_flag;
159
fprintf(stdout, "\n");
162
fprintf(stdout, "-- **overwrite**\n");
163
fprintf(stdout, " %s\n",
164
_("Allow output files to overwrite existing files"));
167
fprintf(stdout, "-- **verbose**\n");
168
fprintf(stdout, " %s\n", _("Verbose module output"));
170
fprintf(stdout, "-- **quiet**\n");
171
fprintf(stdout, " %s\n", _("Quiet module output"));
173
fprintf(stdout, "\n");
176
fprintf(stdout, "\n");
178
opt = &st->first_option;
179
fprintf(stdout, "%s:\n~~~~~~~~~~~\n", _("Parameters"));
181
while (opt != NULL) {
182
/* TODO: make this a enumeration type? */
183
if (opt->key_desc != NULL)
184
type = opt->key_desc;
200
fprintf(stdout, "**%s** = *%s*", opt->key, type);
202
fprintf(stdout, " [, *%s* ,...]", type);
204
/* fprintf(stdout, "*"); */
206
fprintf(stdout, " **[required]**");
208
fprintf(stdout, "\n\n");
210
fprintf(stdout, "\t");
211
print_escaped_for_rest(stdout, opt->label);
212
/* fprintf(stdout, " %s\n", opt->label); */
213
fprintf(stdout, "\n\n");
215
if (opt->description) {
216
fprintf(stdout, "\t");
217
print_escaped_for_rest(stdout, opt->description);
218
/* fprintf(stdout, " %s\n", opt->description); */
219
fprintf(stdout, "\n\n");
223
fprintf(stdout, "\t%s: *", _("Options"));
224
print_escaped_for_rest_options(stdout, opt->options);
225
/* fprintf(stdout, "%s", opt->options);*/
226
fprintf(stdout, "*\n\n");
230
fprintf(stdout, "\t%s:", _("Default"));
231
/* TODO check if value is empty
232
if (!opt->def.empty()){ */
233
fprintf(stdout, " *");
234
print_escaped_for_rest(stdout, opt->def);
235
/* fprintf(stdout,"%s", opt->def); */
236
fprintf(stdout, "*\n\n");
238
fprintf(stdout, "\n\n");
244
while (opt->opts[i]) {
246
fprintf(stdout, "\t\t**");
247
print_escaped_for_rest(stdout, opt->opts[i]);
248
/*fprintf(stdout,"%s", opt->opts[i]); */
249
fprintf(stdout, "** : ");
250
print_escaped_for_rest(stdout, opt->descs[i]);
251
/* fprintf(stdout, "%s\n", opt->descs[i]); */
252
fprintf(stdout, "\n\n");
259
fprintf(stdout, "\n");
261
fprintf(stdout, "\n");
268
* \brief Format text for reStructuredText output
270
#define do_escape(c,escaped) case c: fputs(escaped,f);break
271
void print_escaped_for_rest(FILE * f, const char *str)
275
for (s = str; *s; s++) {
277
do_escape('\n', "\n\n");
284
void print_escaped_for_rest_options(FILE * f, const char *str)
288
for (s = str; *s; s++) {
290
do_escape('\n', "\n\n");