GRASS 8 Programmer's Manual 8.6.0dev(2026)-671d6f71cd
Loading...
Searching...
No Matches
parser_md.c
Go to the documentation of this file.
1/*!
2 \file lib/gis/parser_md.c
3
4 \brief GIS Library - Argument parsing functions (Markdown output)
5
6 (C) 2012-2025 by the GRASS Development Team
7
8 This program is free software under the GNU General Public License
9 (>=v2). Read the file COPYING that comes with GRASS for details.
10
11 \author Martin Landa
12 \author Vaclav Petras
13 */
14#include <stdio.h>
15#include <string.h>
16
17#include <grass/gis.h>
18#include <grass/glocale.h>
19
20#include "parser_local_proto.h"
21
22/*!
23 \brief Print a string as the content of a double-quoted YAML scalar.
24
25 Escapes the characters that are special inside a double-quoted YAML
26 scalar (backslash and double quote). Quoting the value lets it contain
27 YAML-significant sequences such as ": " without breaking the parser.
28
29 \param str string to print (escaped) to stdout
30 */
31static void print_yaml_escaped(const char *str)
32{
33 for (const char *p = str; *p; p++) {
34 if (*p == '\\' || *p == '"')
35 fprintf(stdout, "\\");
36 fprintf(stdout, "%c", *p);
37 }
38}
39
40/*!
41 \brief Print module usage description in Markdown format.
42 */
44{
45 if (!st->pgm_name)
46 st->pgm_name = G_program_name();
47 if (!st->pgm_name)
48 st->pgm_name = "??";
49
50 /* print metadata used by man/build*.py */
51 fprintf(stdout, "---\n");
52 fprintf(stdout, "name: %s\n", st->pgm_name);
53 fprintf(stdout, "description: \"");
54 if (st->module_info.label)
55 print_yaml_escaped(st->module_info.label);
56 if (st->module_info.label && st->module_info.description)
57 fprintf(stdout, " ");
58 if (st->module_info.description)
59 print_yaml_escaped(st->module_info.description);
60 fprintf(stdout, "\"\n");
61 fprintf(stdout, "keywords: [ ");
63 fprintf(stdout, " ]");
64 fprintf(stdout, "\n---\n\n");
65
66 /* main header */
67 fprintf(stdout, "# %s\n\n", st->pgm_name);
68
69 /* header */
70 if (st->module_info.label)
71 fprintf(stdout, "%s\n", st->module_info.label);
72
73 if (st->module_info.description) {
74 if (st->module_info.label)
75 fprintf(stdout, "\n");
76 fprintf(stdout, "%s\n", st->module_info.description);
77 }
78
79 const char *tab_indent = " ";
80
81 /* short version */
82 fprintf(stdout, "\n=== \"Command line\"\n\n");
84 fprintf(stdout, "\n=== \"Python (grass.tools)\"\n\n");
86 fprintf(stdout, "\n=== \"Python (grass.script)\"\n\n");
88
89 fprintf(stdout, "\n## %s\n", _("Parameters"));
90
91 /* long version */
92 fprintf(stdout, "\n=== \"Command line\"\n\n");
94 fprintf(stdout, "\n=== \"Python (grass.tools)\"\n\n");
96 fprintf(stdout, "\n=== \"Python (grass.script)\"\n\n");
98}
#define NULL
Definition ccmath.h:32
const char * G_program_name(void)
Return module name.
Definition progrm_nme.c:28
#define FALSE
Definition gis.h:82
#define _(str)
Definition glocale.h:10
void G__print_keywords(FILE *fd, void(*format)(FILE *, const char *), int newline)
Print list of keywords (internal use only)
Definition parser.c:929
struct state * st
Definition parser.c:104
void G__usage_markdown(void)
Print module usage description in Markdown format.
Definition parser_md.c:43
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_python_long_version(FILE *file, const char *indent, bool tools_api)
void G__md_print_python_short_version(FILE *file, const char *indent, bool tools_api)