85 #include <grass/gis.h>
86 #include <grass/spawn.h>
87 #include <grass/glocale.h>
89 #include "parser_local_proto.h"
100 #define MAX_MATCHES 50
107 static void set_flag(
int);
108 static int contains(
const char *,
int);
109 static int valid_option_name(
const char *);
110 static int is_option(
const char *);
111 static int match_option_1(
const char *,
const char *);
112 static int match_option(
const char *,
const char *);
113 static void set_option(
const char *);
114 static void check_opts(
void);
115 static void check_an_opt(
const char *,
int,
const char *,
const char **,
117 static int check_int(
const char *,
const char **);
118 static int check_double(
const char *,
const char **);
119 static int check_string(
const char *,
const char **,
int *);
120 static void check_required(
void);
121 static void split_opts(
void);
122 static void check_multiple_opts(
void);
123 static int check_overwrite(
void);
124 static void define_keywords(
void);
125 static int module_gui_wx(
void);
126 static void append_error(
const char *);
127 static const char *get_renamed_option(
const char *);
141 st->no_interactive = 1;
164 flag = G_malloc(
sizeof(
struct Flag));
165 st->current_flag->next_flag = flag;
168 flag = &
st->first_flag;
172 G_zero(flag,
sizeof(
struct Flag));
174 st->current_flag = flag;
178 item = G_malloc(
sizeof(
struct Item));
179 st->current_item->next_item = item;
182 item = &
st->first_item;
184 G_zero(item,
sizeof(
struct Item));
189 st->current_item = item;
218 opt = G_malloc(
sizeof(
struct Option));
219 st->current_option->next_opt = opt;
222 opt = &
st->first_option;
225 G_zero(opt,
sizeof(
struct Option));
230 st->current_option = opt;
234 item = G_malloc(
sizeof(
struct Item));
235 st->current_item->next_item = item;
238 item = &
st->first_item;
240 G_zero(item,
sizeof(
struct Item));
244 st->current_item = item;
257 struct GModule *module;
260 module = &
st->module_info;
263 G_zero(module,
sizeof(
struct GModule));
324 const char *gui_envvar;
325 char *ptr, *tmp_name, *
err;
328 char force_gui =
FALSE;
334 st->pgm_path = tmp_name;
338 i = strlen(tmp_name);
346 st->pgm_name = tmp_name;
348 if (!
st->module_info.label && !
st->module_info.description)
349 G_warning(_(
"Bug in UI description. Missing module description"));
353 opt = &
st->first_option;
354 while (
st->n_opts && opt) {
356 st->has_required = 1;
359 G_warning(_(
"Bug in UI description. Missing option key"));
360 if (opt->key && !valid_option_name(opt->key))
361 G_warning(_(
"Bug in UI description. Option key <%s> is not valid"),
363 if (!opt->label && !opt->description)
365 _(
"Bug in UI description. Description for option <%s> missing"),
366 opt->key ? opt->key :
"?");
371 char **tokens, delm[2];
384 opt->opts = G_calloc(cnt + 1,
sizeof(
const char *));
388 opt->opts[i] =
G_store(tokens[i]);
393 if (opt->descriptions) {
396 opt->descs = G_calloc(cnt + 1,
sizeof(
const char *));
410 while (opt->opts[j]) {
411 if (strcmp(opt->opts[j], tokens[i]) == 0) {
418 G_warning(_(
"Bug in UI description. Option '%s' in "
419 "<%s> does not exist"),
420 tokens[i], opt->key);
423 opt->descs[j] =
G_store(tokens[i + 1]);
433 if (opt->multiple && opt->answers && opt->answers[0]) {
434 opt->answer = G_malloc(strlen(opt->answers[0]) + 1);
435 strcpy(opt->answer, opt->answers[0]);
436 for (i = 1; opt->answers[i]; i++) {
438 G_realloc(opt->answer, strlen(opt->answer) +
439 strlen(opt->answers[i]) + 2);
440 strcat(opt->answer,
",");
441 strcat(opt->answer, opt->answers[i]);
444 opt->def = opt->answer;
451 !
st->no_interactive && isatty(0) &&
452 (gui_envvar &&
G_strcasecmp(gui_envvar,
"text") != 0)) {
453 if (module_gui_wx() == 0)
457 if (argc < 2 && st->has_required && isatty(0)) {
461 else if (argc >= 2) {
464 if (strcmp(argv[1],
"help") == 0 || strcmp(argv[1],
"-help") == 0 ||
465 strcmp(argv[1],
"--help") == 0) {
472 if (strcmp(argv[1],
"--help-text") == 0) {
479 if (strcmp(argv[1],
"--interface-description") == 0) {
486 if (strcmp(argv[1],
"--html-description") == 0) {
493 if (strcmp(argv[1],
"--rst-description") == 0) {
500 if (strcmp(argv[1],
"--md-description") == 0) {
507 if (strcmp(argv[1],
"--wps-process-description") == 0) {
514 if (strcmp(argv[1],
"--script") == 0) {
524 if (strcmp(ptr,
"help") == 0 || strcmp(ptr,
"--h") == 0 ||
525 strcmp(ptr,
"-help") == 0 || strcmp(ptr,
"--help") == 0) {
531 if (strcmp(ptr,
"--json") == 0) {
537 if (strcmp(ptr,
"--o") == 0 || strcmp(ptr,
"--overwrite") == 0) {
542 else if (strcmp(ptr,
"--v") == 0 || strcmp(ptr,
"--verbose") == 0) {
547 snprintf(buff,
sizeof(buff),
"GRASS_VERBOSE=%d",
550 if (
st->quiet == 1) {
551 G_warning(_(
"Use either --quiet or --verbose flag, not "
552 "both. Assuming --verbose."));
558 else if (strcmp(ptr,
"--q") == 0 || strcmp(ptr,
"--quiet") == 0) {
563 snprintf(buff,
sizeof(buff),
"GRASS_VERBOSE=%d",
566 if (
st->quiet == -1) {
567 G_warning(_(
"Use either --quiet or --verbose flag, not "
568 "both. Assuming --quiet."));
574 else if (strcmp(ptr,
"--qq") == 0) {
579 snprintf(buff,
sizeof(buff),
"GRASS_VERBOSE=%d",
583 if (
st->quiet == -1) {
584 G_warning(_(
"Use either --qq or --verbose flag, not both. "
591 else if (strcmp(ptr,
"--ui") == 0) {
596 else if (*ptr ==
'-') {
601 else if (is_option(ptr)) {
607 else if (need_first_opt &&
st->n_opts) {
609 st->first_option.count++;
615 G_asprintf(&
err, _(
"Sorry <%s> is not a valid option"), ptr);
626 if (module_gui_wx() != 0)
627 G_fatal_error(_(
"Your installation doesn't include GUI, exiting."));
632 check_multiple_opts();
639 if (!
st->suppress_required)
644 if (
st->n_errors > 0) {
648 fprintf(stderr,
"\n");
649 for (i = 0; i <
st->n_errors; i++) {
650 fprintf(stderr,
"%s: %s\n", _(
"ERROR"),
st->error[i]);
657 if (print_json == 1) {
662 if (!
st->suppress_overwrite) {
663 if (check_overwrite())
691 G_debug(3,
"G_recreate_command()");
695 buff = G_calloc(1024,
sizeof(
char));
702 if (len >= nalloced) {
703 nalloced += (1024 > len) ? 1024 : len + 1;
704 buff = G_realloc(buff, nalloced);
711 slen = strlen(
" --overwrite");
712 if (len + slen >= nalloced) {
713 nalloced += (1024 > len) ? 1024 : len + 1;
714 buff = G_realloc(buff, nalloced);
716 strcpy(cur,
" --overwrite");
730 if (len + slen >= nalloced) {
731 nalloced += (1024 > len) ? 1024 : len + 1;
732 buff = G_realloc(buff, nalloced);
740 flag = &
st->first_flag;
742 if (flag->answer == 1) {
748 if (len + slen >= nalloced) {
750 (nalloced + 1024 > len + slen) ? 1024 : slen + 1;
751 buff = G_realloc(buff, nalloced);
758 flag = flag->next_flag;
762 opt = &
st->first_option;
763 while (
st->n_opts && opt) {
764 if (opt->answer && opt->answer[0] ==
'\0') {
765 slen = strlen(opt->key) + 4;
766 if (len + slen >= nalloced) {
767 nalloced += (nalloced + 1024 > len + slen) ? 1024 : slen + 1;
768 buff = G_realloc(buff, nalloced);
774 cur = strchr(cur,
'\0');
777 if (opt->type == TYPE_STRING) {
783 else if (opt->answer && opt->answers && opt->answers[0]) {
784 slen = strlen(opt->key) + strlen(opt->answers[0]) +
786 if (len + slen >= nalloced) {
787 nalloced += (nalloced + 1024 > len + slen) ? 1024 : slen + 1;
788 buff = G_realloc(buff, nalloced);
794 cur = strchr(cur,
'\0');
797 if (opt->type == TYPE_STRING) {
801 strcpy(cur, opt->answers[0]);
802 cur = strchr(cur,
'\0');
804 for (n = 1; opt->answers[n]; n++) {
805 if (!opt->answers[n])
807 slen = strlen(opt->answers[n]) + 2;
808 if (len + slen >= nalloced) {
810 (nalloced + 1024 > len + slen) ? 1024 : slen + 1;
811 buff = G_realloc(buff, nalloced);
816 strcpy(cur, opt->answers[n]);
817 cur = strchr(cur,
'\0');
820 if (opt->type == TYPE_STRING) {
870 if (
st->n_keys >=
st->n_keys_alloc) {
871 st->n_keys_alloc += 10;
872 st->module_info.keywords = G_realloc(
st->module_info.keywords,
873 st->n_keys_alloc *
sizeof(
char *));
876 st->module_info.keywords[
st->n_keys++] =
G_store(keyword);
888 st->module_info.keywords = (
const char **)tokens;
897 char desc[KEYLENGTH];
899 if (
st->module_info.overwrite)
905 opt = &
st->first_option;
907 if (opt->gisprompt) {
909 if (strcmp(age,
"new") == 0)
934 for (i = 0; i <
st->n_keys; i++) {
936 fprintf(fd,
"%s",
st->module_info.keywords[i]);
939 format(fd,
st->module_info.keywords[i]);
941 if (i < st->n_keys - 1) {
961 return st->module_info.overwrite;
964 void define_keywords(
void)
967 st->n_keys_alloc = 0;
980 int module_gui_wx(
void)
982 char script[GPATH_MAX];
990 snprintf(script, GPATH_MAX,
"%s/gui/wxpython/gui_core/forms.py",
992 if (access(script, F_OK) != -1)
993 G_spawn(getenv(
"GRASS_PYTHON"), getenv(
"GRASS_PYTHON"), script,
1001 void set_flag(
int f)
1005 const char *renamed_key;
1018 flag = &
st->first_flag;
1020 if (flag->key == f) {
1022 if (flag->suppress_required)
1023 st->suppress_required = 1;
1024 if (flag->suppress_overwrite)
1025 st->suppress_overwrite = 1;
1028 flag = flag->next_flag;
1033 renamed_key = get_renamed_option(key);
1038 if (*renamed_key ==
'-') {
1040 if (renamed_key[1] ==
'-') {
1041 if (strcmp(renamed_key,
"--overwrite") == 0) {
1043 G_warning(_(
"Please update the usage of <%s>: "
1044 "flag <%c> has been renamed to <%s>"),
1053 _(
"Please update the usage of <%s>: "
1054 "flag <%c> has been renamed to <%s>"),
1061 for (flag = &
st->first_flag; flag; flag = flag->next_flag) {
1062 if (renamed_key[1] == flag->key) {
1063 G_warning(_(
"Please update the usage of <%s>: "
1064 "flag <%c> has been renamed to <%s>"),
1067 if (flag->suppress_required)
1068 st->suppress_required = 1;
1069 if (flag->suppress_overwrite)
1070 st->suppress_overwrite = 1;
1078 struct Option *opt =
NULL;
1079 for (opt = &
st->first_option; opt; opt = opt->next_opt) {
1080 if (strcmp(renamed_key, opt->key) == 0) {
1082 _(
"Please update the usage of <%s>: "
1083 "flag <%c> has been renamed to option <%s>"),
1100 int contains(
const char *s,
int c)
1110 int valid_option_name(
const char *
string)
1112 int m = strlen(
string);
1113 int n = strspn(
string,
"abcdefghijklmnopqrstuvwxyz0123456789_");
1121 if (
string[m - 1] ==
'_')
1127 int is_option(
const char *
string)
1129 int n = strspn(
string,
"abcdefghijklmnopqrstuvwxyz0123456789_");
1131 return n > 0 &&
string[n] ==
'=' &&
string[0] !=
'_' &&
1132 string[n - 1] !=
'_';
1135 int match_option_1(
const char *
string,
const char *option)
1139 if (*
string ==
'\0')
1142 if (*option ==
'\0')
1145 if (*
string == *option && match_option_1(
string + 1, option + 1))
1148 if (*option ==
'_' && match_option_1(
string, option + 1))
1151 next = strchr(option,
'_');
1156 return match_option_1(
string + 1, next + 1);
1158 return match_option_1(
string, next + 1);
1161 int match_option(
const char *
string,
const char *option)
1163 return (*
string == *option) && match_option_1(
string + 1, option + 1);
1166 void set_option(
const char *
string)
1168 struct Option *at_opt =
NULL;
1169 struct Option *opt =
NULL;
1171 char the_key[KEYLENGTH];
1178 for (ptr = the_key; *
string !=
'='; ptr++,
string++)
1188 key_len = strlen(the_key);
1189 for (at_opt = &
st->first_option; at_opt; at_opt = at_opt->next_opt) {
1193 if (strcmp(the_key, at_opt->key) == 0) {
1194 matches[0] = at_opt;
1199 if (strncmp(the_key, at_opt->key, key_len) == 0 ||
1200 match_option(the_key, at_opt->key)) {
1203 matches[found++] = at_opt;
1209 int length = strlen(matches[0]->key);
1213 for (i = 1; i < found; i++) {
1214 int len = strlen(matches[i]->key);
1221 for (i = 0; prefix && i < found; i++)
1222 if (strncmp(matches[i]->key, matches[shortest]->key, length) != 0)
1225 matches[0] = matches[shortest];
1232 for (i = 0; i < found; i++) {
1233 G_asprintf(&
err, _(
"Option <%s=> matches"), matches[i]->key);
1245 const char *renamed_key = get_renamed_option(the_key);
1250 if (*renamed_key ==
'-') {
1251 if (renamed_key[1] ==
'-')
1253 _(
"Please update the usage of <%s>: "
1254 "option <%s> has been renamed to flag <%s>"),
1258 _(
"Please update the usage of <%s>: "
1259 "option <%s> has been renamed to flag <%c>"),
1266 for (at_opt = &
st->first_option; at_opt;
1267 at_opt = at_opt->next_opt) {
1268 if (strcmp(renamed_key, at_opt->key) == 0) {
1269 G_warning(_(
"Please update the usage of <%s>: "
1270 "option <%s> has been renamed to <%s>"),
1282 G_asprintf(&
err, _(
"%s: Sorry, <%s> is not a valid parameter"),
1288 if (getenv(
"GRASS_FULL_OPTION_NAMES") && strcmp(the_key, opt->key) != 0)
1289 G_warning(_(
"<%s> is an abbreviation for <%s>"), the_key, opt->key);
1293 if (!opt->multiple) {
1294 G_asprintf(&
err, _(
"Option <%s> does not accept multiple answers"),
1299 G_realloc(opt->answer, strlen(opt->answer) + strlen(
string) + 2);
1300 strcat(opt->answer,
",");
1301 strcat(opt->answer,
string);
1304 opt->answer =
G_store(
string);
1307 void check_opts(
void)
1315 opt = &
st->first_option;
1320 if (opt->multiple == 0)
1321 check_an_opt(opt->key, opt->type, opt->options, opt->opts,
1324 for (ans = 0; opt->answers[ans] !=
NULL; ans++)
1325 check_an_opt(opt->key, opt->type, opt->options, opt->opts,
1326 &opt->answers[ans]);
1333 opt->checker(opt->answer);
1335 opt = opt->next_opt;
1339 void check_an_opt(
const char *key,
int type,
const char *options,
1340 const char **opts,
char **answerp)
1342 const char *answer = *answerp;
1353 error = check_int(answer, opts);
1356 error = check_double(answer, opts);
1359 error = check_string(answer, opts, &found);
1367 _(
"Illegal range syntax for parameter <%s>\n"
1368 "\tPresented as: %s"),
1374 _(
"Value <%s> out of range for parameter <%s>\n"
1375 "\tLegal range: %s"),
1376 answer, key, options);
1380 G_asprintf(&
err, _(
"Missing value for parameter <%s>"), key);
1384 G_asprintf(&
err, _(
"Invalid value <%s> for parameter <%s>"), answer,
1390 _(
"Value <%s> ambiguous for parameter <%s>\n"
1391 "\tValid options: %s"),
1392 answer, key, options);
1396 *answerp =
G_store(opts[found]);
1402 int check_int(
const char *ans,
const char **opts)
1407 if (strcmp(ans,
"-") == 0)
1413 if (sscanf(ans,
"%d", &d) != 1)
1419 for (i = 0; opts[i]; i++) {
1420 const char *opt = opts[i];
1423 if (contains(opt,
'-')) {
1424 if (sscanf(opt,
"%d-%d", &lo, &hi) == 2) {
1425 if (d >= lo && d <= hi)
1428 else if (sscanf(opt,
"-%d", &hi) == 1) {
1432 else if (sscanf(opt,
"%d-", &lo) == 1) {
1440 if (sscanf(opt,
"%d", &lo) == 1) {
1452 int check_double(
const char *ans,
const char **opts)
1458 if (strcmp(ans,
"-") == 0)
1464 if (sscanf(ans,
"%lf", &d) != 1)
1470 for (i = 0; opts[i]; i++) {
1471 const char *opt = opts[i];
1474 if (contains(opt,
'-')) {
1475 if (sscanf(opt,
"%lf-%lf", &lo, &hi) == 2) {
1476 if (d >= lo && d <= hi)
1479 else if (sscanf(opt,
"-%lf", &hi) == 1) {
1483 else if (sscanf(opt,
"%lf-", &lo) == 1) {
1491 if (sscanf(opt,
"%lf", &lo) == 1) {
1503 int check_string(
const char *ans,
const char **opts,
int *result)
1505 int len = strlen(ans);
1513 for (i = 0; opts[i]; i++) {
1514 if (strcmp(ans, opts[i]) == 0)
1516 if (strncmp(ans, opts[i], len) == 0 || match_option(ans, opts[i])) {
1519 matches[found++] = i;
1525 int length = strlen(opts[matches[0]]);
1528 for (i = 1; i < found; i++) {
1529 int lengthi = strlen(opts[matches[i]]);
1531 if (lengthi < length) {
1536 for (i = 0; prefix && i < found; i++)
1537 if (strncmp(opts[matches[i]], opts[matches[shortest]], length) != 0)
1540 matches[0] = matches[shortest];
1546 *result = matches[0];
1548 if (found > 0 && getenv(
"GRASS_FULL_OPTION_NAMES") &&
1549 strcmp(ans, opts[matches[0]]) != 0)
1550 G_warning(_(
"<%s> is an abbreviation for <%s>"), ans, opts[matches[0]]);
1562 void check_required(
void)
1572 opt = &
st->first_option;
1574 if (opt->required && !opt->answer) {
1576 _(
"Required parameter <%s> not set:\n"
1578 opt->key, (opt->label ? opt->label : opt->description));
1581 opt = opt->next_opt;
1585 void split_opts(
void)
1597 opt = &
st->first_option;
1602 opt->answers = G_malloc(allocated *
sizeof(
char *));
1606 opt->answers[ans_num] =
NULL;
1609 for (len = 0, ptr2 = ptr1; *ptr2 !=
'\0' && *ptr2 !=
',';
1614 opt->answers[ans_num] = G_malloc(len + 1);
1615 memcpy(opt->answers[ans_num], ptr1, len);
1616 opt->answers[ans_num][len] = 0;
1620 if (ans_num >= allocated) {
1623 G_realloc(opt->answers, allocated *
sizeof(
char *));
1626 opt->answers[ans_num] =
NULL;
1638 opt = opt->next_opt;
1642 void check_multiple_opts(
void)
1654 opt = &
st->first_option;
1657 if (opt->answer && strcmp(opt->answer,
"-") && opt->key_desc) {
1660 for (ptr = opt->key_desc; *ptr !=
'\0'; ptr++)
1664 for (n = 0; opt->answers[n] !=
NULL; n++)
1669 _(
"Option <%s> must be provided in multiples of %d\n"
1670 "\tYou provided %d item(s): %s"),
1671 opt->key, n_commas, n, opt->answer);
1675 opt = opt->next_opt;
1680 int check_overwrite(
void)
1683 char age[KEYLENGTH];
1685 char desc[KEYLENGTH];
1687 const char *overstr;
1690 st->module_info.overwrite = 0;
1698 over = atoi(overstr);
1702 if ((overstr = getenv(
"GRASS_OVERWRITE"))) {
1707 if (
st->overwrite || over) {
1708 st->module_info.overwrite = 1;
1710 putenv(
"GRASS_OVERWRITE=1");
1715 opt = &
st->first_option;
1717 if (opt->answer && opt->gisprompt) {
1720 if (strcmp(age,
"new") == 0) {
1724 for (i = 0; opt->answers[i]; i++) {
1726 if (strcmp(
element,
"file") == 0) {
1727 if (access(opt->answers[i], F_OK) == 0)
1730 else if (strcmp(
element,
"mapset") != 0) {
1739 if (!
st->overwrite && !over) {
1742 fprintf(stderr, _(
"ERROR: "));
1744 _(
"option <%s>: <%s> exists. To "
1745 "overwrite, use the --overwrite "
1747 opt->key, opt->answers[i]);
1748 fprintf(stderr,
"\n");
1751 fprintf(stderr,
"GRASS_INFO_ERROR(%d,1): ",
1754 _(
"option <%s>: <%s> exists. To "
1755 "overwrite, use the --overwrite "
1757 opt->key, opt->answers[i]);
1758 fprintf(stderr,
"\n");
1759 fprintf(stderr,
"GRASS_INFO_END(%d,1)\n",
1769 opt = opt->next_opt;
1781 for (ptr1 = gisprompt, ptr2 = age; *ptr1 !=
'\0'; ptr1++, ptr2++) {
1788 for (ptr1++, ptr2 =
element; *ptr1 !=
'\0'; ptr1++, ptr2++) {
1795 for (ptr1++, ptr2 = desc; *ptr1 !=
'\0'; ptr1++, ptr2++) {
1803 void append_error(
const char *msg)
1805 st->error = G_realloc(
st->error,
sizeof(
char *) * (
st->n_errors + 1));
1809 const char *get_renamed_option(
const char *key)
1811 const char *pgm, *key_new;
1814 if (!
st->renamed_options) {
1816 char path[GPATH_MAX];
1818 snprintf(
path, GPATH_MAX,
"%s/etc/renamed_options",
G_gisbase());
1829 pgm_key = (
char *)G_malloc(strlen(pgm) + strlen(key) + 2);
1864 if (option->gisprompt ==
NULL ||
1865 strcmp(option->gisprompt,
"old,separator,separator") != 0)
1866 G_fatal_error(_(
"%s= is not a separator option"), option->key);
1868 if (option->answer ==
NULL)
1869 G_fatal_error(_(
"No separator given for %s="), option->key);
1871 if (strcmp(option->answer,
"pipe") == 0)
1873 else if (strcmp(option->answer,
"comma") == 0)
1875 else if (strcmp(option->answer,
"space") == 0)
1877 else if (strcmp(option->answer,
"tab") == 0 ||
1878 strcmp(option->answer,
"\\t") == 0)
1880 else if (strcmp(option->answer,
"newline") == 0 ||
1881 strcmp(option->answer,
"\\n") == 0)
1884 sep =
G_store(option->answer);
1886 G_debug(3,
"G_option_to_separator(): key = %s -> sep = '%s'", option->key,
1927 stdinout = !option->answer || !*(option->answer) ||
1928 strcmp(option->answer,
"-") == 0;
1930 if (option->gisprompt ==
NULL)
1932 else if (option->multiple)
1933 G_fatal_error(_(
"Opening multiple files not supported for %s="),
1935 else if (strcmp(option->gisprompt,
"old,file,file") == 0) {
1938 else if ((fp = fopen(option->answer,
"r")) ==
NULL)
1939 G_fatal_error(_(
"Unable to open %s file <%s>: %s"), option->key,
1940 option->answer, strerror(errno));
1942 else if (strcmp(option->gisprompt,
"new,file,file") == 0) {
1945 else if ((fp = fopen(option->answer,
"w")) ==
NULL)
1946 G_fatal_error(_(
"Unable to create %s file <%s>: %s"), option->key,
1947 option->answer, strerror(errno));
1963 if (fp != stdin && fp != stdout && fp != stderr)
void G_free(void *buf)
Free allocated memory.
int G_asprintf(char **out, const char *fmt,...)
char * G_basename(char *filename, const char *desired_ext)
Truncates filename to the base part (before the last '.') if it matches the extension,...
int G_debug(int level, const char *msg,...)
Print debugging message.
const char * G_getenv_nofatal(const char *name)
Get environment variable.
const char * G_find_file(const char *element, char *name, const char *mapset)
Searches for a file from the mapset search list or in a specified mapset.
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int G_suppress_warnings(int flag)
Suppress printing a warning message to stderr.
void G_warning(const char *msg,...)
Print a warning message to stderr.
int G_info_format(void)
Get current message format.
const char * G_gisbase(void)
Get full path name of the top level module directory.
const char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key (case sensitive)
struct Key_Value * G_read_key_value_file(const char *file)
Read key/values pairs from file.
const char * G_mapset(void)
Get current mapset name.
struct GModule * G_define_module(void)
Initializes a new module.
void G__print_keywords(FILE *fd, void(*format)(FILE *, const char *), int newline)
Print list of keywords (internal use only)
FILE * G_open_option_file(const struct Option *option)
Get an input/output file pointer from the option. If the file name is omitted or '-',...
char * G_recreate_command_original_path(void)
Creates command to run non-interactive.
int G_parser(int argc, char **argv)
Parse command line.
void G_set_keywords(const char *keywords)
Set keywords from the string.
int G__uses_new_gisprompt(void)
char * recreate_command(int original_path)
Creates command to run non-interactive.
struct Option * G_define_option(void)
Initializes an Option struct.
void G_add_keyword(const char *keyword)
Add keyword to the list.
int G_get_overwrite(void)
Get overwrite value.
void G_close_option_file(FILE *fp)
Close an input/output file returned by G_open_option_file(). If the file pointer is stdin,...
char * G_recreate_command(void)
Creates command to run non-interactive.
void G_disable_interactive(void)
Disables the ability of the parser to operate interactively.
struct Flag * G_define_flag(void)
Initializes a Flag struct.
char * G_option_to_separator(const struct Option *option)
Get separator string from the option.
void G__split_gisprompt(const char *gisprompt, char *age, char *element, char *desc)
void G__check_option_rules(void)
Check for option rules (internal use only)
int G__has_required_rule(void)
Checks if there is any rule RULE_REQUIRED (internal use only).
void G_usage(void)
Command line help/usage message.
void G__usage_html(void)
Print module usage description in HTML format.
void G__usage_xml(void)
Print module usage description in XML format.
char * G__json(void)
This function generates actinia JSON process chain building blocks from the command line arguments th...
void G__usage_markdown(void)
Print module usage description in Markdown format.
void G__usage_rest(void)
Print module usage description in reStructuredText format.
void G__script(void)
Generate Python script-like output.
void G__wps_print_process_description(void)
Print the WPS 1.0.0 process description XML document to stdout.
int G_is_dirsep(char c)
Checks if a specified character is a valid directory separator character on the host system.
const char * G_original_program_name(void)
Return original path of the executed program.
const char * G_program_name(void)
Return module name.
int G_spawn(const char *command,...)
Spawn new process based on command.
char * G_store(const char *s)
Copy string to allocated memory.
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
char * G_chop(char *line)
Chop leading and trailing white spaces.
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
void G_free_tokens(char **tokens)
Free memory allocated to tokens.
int G_number_of_tokens(char **tokens)
Return number of tokens.
char ** G_tokenize(const char *buf, const char *delim)
Tokenize string.
int G_verbose_max(void)
Get max verbosity level.
int G_verbose(void)
Get current verbosity level.
int G_verbose_min(void)
Get min verbosity level.
int G_verbose_std(void)
Get standard verbosity level.
void G_zero(void *buf, int i)
Zero out a buffer, buf, of length i.