GRASS 8 Programmer's Manual 8.6.0dev(2026)-1878fdfec5
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 SPDX-FileCopyrightText: 2012-2025 GRASS Development Team
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 \author Martin Landa
10 \author Vaclav Petras
11 */
12#include <stdio.h>
13#include <string.h>
14
15#include <grass/gis.h>
16#include <grass/glocale.h>
17
18#include "parser_local_proto.h"
19
20/*!
21 \brief Print a string as the content of a double-quoted YAML scalar.
22
23 Escapes the characters that are special inside a double-quoted YAML
24 scalar (backslash and double quote). Quoting the value lets it contain
25 YAML-significant sequences such as ": " without breaking the parser.
26
27 \param str string to print (escaped) to stdout
28 */
29static void print_yaml_escaped(const char *str)
30{
31 for (const char *p = str; *p; p++) {
32 if (*p == '\\' || *p == '"')
33 fprintf(stdout, "\\");
34 fprintf(stdout, "%c", *p);
35 }
36}
37
38/*!
39 \brief Print module usage description in Markdown format.
40 */
42{
43 if (!st->pgm_name)
44 st->pgm_name = G_program_name();
45 if (!st->pgm_name)
46 st->pgm_name = "??";
47
48 /* print metadata used by man/build*.py */
49 fprintf(stdout, "---\n");
50 fprintf(stdout, "name: %s\n", st->pgm_name);
51 fprintf(stdout, "description: \"");
52 if (st->module_info.label)
53 print_yaml_escaped(st->module_info.label);
54 if (st->module_info.label && st->module_info.description)
55 fprintf(stdout, " ");
56 if (st->module_info.description)
57 print_yaml_escaped(st->module_info.description);
58 fprintf(stdout, "\"\n");
59 fprintf(stdout, "keywords: [ ");
61 fprintf(stdout, " ]");
62 fprintf(stdout, "\n---\n\n");
63
64 /* main header */
65 fprintf(stdout, "# %s\n\n", st->pgm_name);
66
67 /* header */
68 if (st->module_info.label)
69 fprintf(stdout, "%s\n", st->module_info.label);
70
71 if (st->module_info.description) {
72 if (st->module_info.label)
73 fprintf(stdout, "\n");
74 fprintf(stdout, "%s\n", st->module_info.description);
75 }
76
77 const char *tab_indent = " ";
78
79 /* short version */
80 fprintf(stdout, "\n=== \"Command line\"\n\n");
82 fprintf(stdout, "\n=== \"Python (grass.tools)\"\n\n");
84 fprintf(stdout, "\n=== \"Python (grass.script)\"\n\n");
86
87 fprintf(stdout, "\n## %s\n", _("Parameters"));
88
89 /* long version */
90 fprintf(stdout, "\n=== \"Command line\"\n\n");
92 fprintf(stdout, "\n=== \"Python (grass.tools)\"\n\n");
94 fprintf(stdout, "\n=== \"Python (grass.script)\"\n\n");
96}
#define NULL
Definition ccmath.h:32
const char * G_program_name(void)
Return module name.
Definition progrm_nme.c:26
#define FALSE
Definition gis.h:79
#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:927
struct state * st
Definition parser.c:102
void G__usage_markdown(void)
Print module usage description in Markdown format.
Definition parser_md.c:41
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)