78 #include <grass/config.h>
80 #if defined(HAVE_LANGINFO_H)
83 #if defined(__MINGW32__) && defined(USE_NLS)
84 #include <localcharset.h>
93 #include <sys/types.h>
94 #include <grass/gis.h>
95 #include <grass/glocale.h>
96 #include <grass/spawn.h>
100 #define OUT_OF_RANGE 2
101 #define MISSING_VALUE 3
104 static int interactive_ok = 1;
105 static int n_opts = 0;
106 static int n_flags = 0;
107 static int overwrite = 0;
108 static int quiet = 0;
110 static struct Flag first_flag;
111 static struct Flag *current_flag;
113 static struct Option first_option;
114 static struct Option *current_option;
116 static struct GModule module_info;
118 static const char *pgm_name =
NULL;
127 static struct Item first_item;
128 static struct Item *current_item;
129 static int n_items = 0;
130 static int show_options(
int,
const char *);
131 static int show(
const char *,
int);
132 static int set_flag(
int);
133 static int contains(
const char *,
int);
134 static int is_option(
const char *);
135 static int set_option(
char *);
136 static int check_opts();
137 static int check_an_opt(
const char *,
int,
const char *,
const char *);
138 static int check_int(
const char *,
const char *);
139 static int check_double(
const char *,
const char *);
140 static int check_string(
const char *,
const char *);
141 static int check_required(
void);
142 static int split_opts(
void);
143 static int check_multiple_opts(
void);
144 static int check_overwrite(
void);
145 static int interactive(
const char *);
146 static int interactive_flag(
struct Flag *);
147 static int interactive_option(
struct Option *);
148 static int gis_prompt(
struct Option *,
char *);
149 static int split_gisprompt(
const char *,
char *,
char *,
char *);
151 static void G_gui(
void);
152 static void G_tcltk(
void);
153 static void G_usage_xml(
void);
154 static void G_usage_html(
void);
155 static void G_script(
void);
199 flag = (
struct Flag *)G_malloc(
sizeof(
struct Flag));
200 current_flag->next_flag =
flag;
207 G_zero((
char *)flag,
sizeof(
struct Flag));
213 item = (
struct Item *)G_malloc(
sizeof(
struct Item));
255 opt = (
struct Option *)G_malloc(
sizeof(
struct Option));
256 current_option->next_opt = opt;
262 G_zero((
char *)opt,
sizeof(
struct Option));
271 opt->key_desc =
NULL;
272 opt->gisprompt =
NULL;
275 opt->description =
NULL;
276 opt->descriptions =
NULL;
277 opt->guisection =
NULL;
279 current_option = opt;
283 item = (
struct Item *)G_malloc(
sizeof(
struct Item));
337 Opt->type = TYPE_STRING;
338 Opt->key_desc =
"sql_query";
340 Opt->label = _(
"WHERE conditions of SQL statement without 'where' keyword");
341 Opt->description = _(
"Example: income < 1000 and inhab >= 10000");
345 Opt->type = TYPE_STRING;
346 Opt->key_desc =
"name";
349 Opt->description = _(
"Table name");
350 Opt->gisprompt =
"old_dbtable,dbtable,dbtable";
354 Opt->type = TYPE_STRING;
355 Opt->key_desc =
"name";
358 Opt->description = _(
"Driver name");
359 Opt->gisprompt =
"old_dbdriver,dbdriver,dbdriver";
362 Opt->key =
"database";
363 Opt->type = TYPE_STRING;
364 Opt->key_desc =
"name";
367 Opt->description = _(
"Database name");
368 Opt->gisprompt =
"old_dbname,dbname,dbname";
372 Opt->type = TYPE_STRING;
373 Opt->key_desc =
"name";
376 Opt->description = _(
"Name of attribute column");
377 Opt->gisprompt =
"old_dbcolumn,dbcolumn,dbcolumn";
380 Opt->key =
"columns";
381 Opt->type = TYPE_STRING;
382 Opt->key_desc =
"name";
385 Opt->description = _(
"Name of attribute column(s)");
386 Opt->gisprompt =
"old_dbcolumn,dbcolumn,dbcolumn";
392 Opt->type = TYPE_STRING;
393 Opt->key_desc =
"name";
395 Opt->gisprompt =
"old,group,group";
396 Opt->description = _(
"Name of input imagery group");
398 case G_OPT_I_SUBGROUP:
399 Opt->key =
"subgroup";
400 Opt->type = TYPE_STRING;
401 Opt->key_desc =
"name";
403 Opt->gisprompt =
"old,subgroup,subgroup";
404 Opt->description = _(
"Name of input imagery subgroup");
410 Opt->type = TYPE_STRING;
411 Opt->key_desc =
"name";
413 Opt->gisprompt =
"old,cell,raster";
414 Opt->description = _(
"Name of input raster map");
418 Opt->type = TYPE_STRING;
419 Opt->key_desc =
"name";
422 Opt->gisprompt =
"old,cell,raster";
423 Opt->description = _(
"Name of input raster map(s)");
427 Opt->type = TYPE_STRING;
428 Opt->key_desc =
"name";
430 Opt->gisprompt =
"new,cell,raster";
431 Opt->description = _(
"Name for output raster map");
435 Opt->type = TYPE_STRING;
436 Opt->key_desc =
"name";
438 Opt->gisprompt =
"old,cell,raster";
439 Opt->description = _(
"Name of input raster map");
443 Opt->type = TYPE_STRING;
444 Opt->key_desc =
"name";
447 Opt->gisprompt =
"old,cell,raster";
448 Opt->description = _(
"Name of input raster map(s)");
452 Opt->type = TYPE_STRING;
453 Opt->key_desc =
"name";
455 Opt->gisprompt =
"old,cell,raster";
456 Opt->description = _(
"Name of base raster map");
460 Opt->type = TYPE_STRING;
461 Opt->key_desc =
"name";
463 Opt->gisprompt =
"old,cell,raster";
464 Opt->description = _(
"Name of cover raster map");
467 Opt->key =
"elevation";
468 Opt->type = TYPE_STRING;
469 Opt->key_desc =
"name";
471 Opt->gisprompt =
"old,cell,raster";
472 Opt->description = _(
"Name of elevation raster map");
475 Opt->key =
"elevation";
476 Opt->type = TYPE_STRING;
477 Opt->key_desc =
"name";
480 Opt->gisprompt =
"old,cell,raster";
481 Opt->description = _(
"Name of elevation raster map(s)");
487 Opt->type = TYPE_STRING;
488 Opt->key_desc =
"name";
490 Opt->gisprompt =
"old,grid3,3d-raster";
491 Opt->description = _(
"Name of input raster3d map");
493 case G_OPT_R3_INPUTS:
495 Opt->type = TYPE_STRING;
496 Opt->key_desc =
"name";
499 Opt->gisprompt =
"old,grid3,3d-raster";
500 Opt->description = _(
"Name of input raster3d map(s)");
502 case G_OPT_R3_OUTPUT:
504 Opt->type = TYPE_STRING;
505 Opt->key_desc =
"name";
507 Opt->gisprompt =
"new,grid3,3d-raster";
508 Opt->description = _(
"Name for output raster3d map");
512 Opt->type = TYPE_STRING;
513 Opt->key_desc =
"name";
515 Opt->gisprompt =
"old,grid3,3d-raster";
516 Opt->description = _(
"Name of input raster3d map");
520 Opt->type = TYPE_STRING;
521 Opt->key_desc =
"name";
524 Opt->gisprompt =
"old,grid3,3d-raster";
525 Opt->description = _(
"Name of input raster3d map(s)");
531 Opt->type = TYPE_STRING;
532 Opt->key_desc =
"name";
534 Opt->gisprompt =
"old,vector,vector";
535 Opt->description = _(
"Name of input vector map");
539 Opt->type = TYPE_STRING;
540 Opt->key_desc =
"name";
543 Opt->gisprompt =
"old,vector,vector";
544 Opt->description = _(
"Name of input vector map(s)");
548 Opt->type = TYPE_STRING;
549 Opt->key_desc =
"name";
551 Opt->gisprompt =
"new,vector,vector";
552 Opt->description = _(
"Name for output vector map");
556 Opt->type = TYPE_STRING;
557 Opt->key_desc =
"name";
559 Opt->gisprompt =
"old,vector,vector";
560 Opt->description = _(
"Name of input vector map");
564 Opt->type = TYPE_STRING;
565 Opt->key_desc =
"name";
568 Opt->gisprompt =
"old,vector,vector";
569 Opt->description = _(
"Name of input vector map(s)");
573 Opt->type = TYPE_STRING;
576 Opt->answer =
"point,line,boundary,centroid,area";
577 Opt->options =
"point,line,boundary,centroid,area";
578 Opt->description = _(
"Feature type");
582 Opt->type = TYPE_STRING;
585 Opt->answer =
"point,line,boundary,centroid,area,face,kernel";
586 Opt->options =
"point,line,boundary,centroid,area,face,kernel";
587 Opt->description = _(
"Feature type");
591 Opt->type = TYPE_INTEGER;
594 Opt->label = _(
"Layer number");
596 _(
"A single vector map can be connected to multiple database "
597 "tables. This number determines which table to use.");
598 Opt->gisprompt =
"old_layer,layer,layer";
603 Opt->type = TYPE_INTEGER;
605 Opt->description = _(
"Category value");
609 Opt->type = TYPE_STRING;
610 Opt->key_desc =
"range";
612 Opt->label = _(
"Category values");
613 Opt->description = _(
"Example: 1,3,7-9,13");
617 Opt->type = TYPE_INTEGER;
619 Opt->description = _(
"Feature id");
623 Opt->type = TYPE_STRING;
624 Opt->key_desc =
"range";
626 Opt->label = _(
"Feature ids");
627 Opt->description = _(
"Example: 1,3,7-9,13");
633 Opt->type = TYPE_STRING;
634 Opt->key_desc =
"name";
636 Opt->gisprompt =
"old_file,file,input";
637 Opt->description = _(
"Name of input file");
641 Opt->type = TYPE_STRING;
642 Opt->key_desc =
"name";
644 Opt->gisprompt =
"new_file,file,output";
645 Opt->description = _(
"Name for output file");
649 Opt->type = TYPE_STRING;
650 Opt->key_desc =
"character";
653 Opt->label = _(
"Field separator");
654 Opt->description = _(
"Special characters: newline, space, comma, tab");
660 Opt->type = TYPE_STRING;
661 Opt->key_desc =
"name";
663 Opt->answer = DEFAULT_FG_COLOR;
664 Opt->gisprompt =
"old_color,color,color";
665 Opt->label = _(
"Color");
666 Opt->description = _(
"Either a standard color name or R:G:B triplet");
669 Opt->key =
"bgcolor";
670 Opt->type = TYPE_STRING;
671 Opt->key_desc =
"name";
673 Opt->answer = DEFAULT_BG_COLOR;
674 Opt->gisprompt =
"old_color,color,color_none";
675 Opt->label = _(
"Background color");
677 _(
"Either a standard GRASS color, R:G:B triplet, or \"none\"");
693 struct GModule *module;
697 module = &module_info;
701 G_zero((
char *)module,
sizeof(
struct GModule));
748 char *ptr, *tmp_name;
751 char force_gui =
FALSE;
755 i = strlen(tmp_name =
G_store(argv[0]));
768 while (opt !=
NULL) {
772 char **tokens, delm[2];
785 (
const char **)G_calloc(cnt + 1,
sizeof(
const char *));
789 opt->opts[i] =
G_store(tokens[i]);
794 if (opt->descriptions) {
798 (
const char **)G_calloc(cnt + 1,
sizeof(
const char *));
810 while (opt->opts[j]) {
811 if (strcmp(opt->opts[j], tokens[i]) == 0) {
818 G_warning(_(
"BUG in descriptions, option '%s' in <%s> does not exist"),
819 tokens[i], opt->key);
822 opt->descs[j] =
G_store(tokens[i + 1]);
832 if (opt->multiple && opt->answers && opt->answers[0]) {
833 opt->answer = (
char *)G_malloc(strlen(opt->answers[0]) + 1);
834 strcpy(opt->answer, opt->answers[0]);
835 for (i = 1; opt->answers[i]; i++) {
836 opt->answer = (
char *)G_realloc(opt->answer,
837 strlen(opt->answer) +
838 strlen(opt->answers[i]) + 2);
839 strcat(opt->answer,
",");
840 strcat(opt->answer, opt->answers[i]);
843 opt->def = opt->answer;
849 if (argc < 2 && interactive_ok && isatty(0)) {
850 if (
getenv(
"GRASS_UI_TERM")) {
851 interactive(argv[0]);
860 else if (argc < 2 && isatty(0)) {
864 else if (argc >= 2) {
867 if (strcmp(argv[1],
"help") == 0 ||
868 strcmp(argv[1],
"-help") == 0 || strcmp(argv[1],
"--help") == 0) {
875 if (strcmp(argv[1],
"--interface-description") == 0) {
882 if (strcmp(argv[1],
"--html-description") == 0) {
889 if (strcmp(argv[1],
"--tcltk") == 0) {
896 if (strcmp(argv[1],
"--script") == 0) {
906 if (strcmp(ptr,
"help") == 0 ||
907 strcmp(ptr,
"-help") == 0 || strcmp(ptr,
"--help") == 0) {
913 if (strcmp(ptr,
"--o") == 0 || strcmp(ptr,
"--overwrite") == 0) {
918 else if (strcmp(ptr,
"--v") == 0 || strcmp(ptr,
"--verbose") == 0) {
926 G_warning(_(
"Use either --quiet or --verbose flag, not both. Assuming --verbose."));
932 else if (strcmp(ptr,
"--q") == 0 || strcmp(ptr,
"--quiet") == 0) {
940 G_warning(_(
"Use either --quiet or --verbose flag, not both. Assuming --quiet."));
946 else if (strcmp(ptr,
"--ui") == 0) {
951 else if (*ptr ==
'-') {
953 error += set_flag(*ptr);
957 else if (is_option(ptr)) {
958 error += set_option(ptr);
963 else if (need_first_opt && n_opts) {
964 first_option.answer =
G_store(ptr);
965 first_option.count++;
971 fprintf(stderr, _(
"Sorry <%s> is not a valid option\n"), ptr);
988 error += check_multiple_opts();
992 error += check_opts();
995 error += check_required();
1003 if (check_overwrite())
1010 static int uses_new_gisprompt(
void)
1017 if (module_info.overwrite)
1023 opt = &first_option;
1024 while (opt !=
NULL) {
1025 if (opt->gisprompt) {
1026 split_gisprompt(opt->gisprompt, age, element, desc);
1027 if (strcmp(age,
"new") == 0)
1030 opt = opt->next_opt;
1065 const char *key_desc;
1070 new_prompt = uses_new_gisprompt();
1077 if (module_info.label || module_info.description) {
1078 fprintf(stderr, _(
"\nDescription:\n"));
1079 if (module_info.label)
1080 fprintf(stderr,
" %s\n", module_info.label);
1081 if (module_info.description)
1082 fprintf(stderr,
" %s\n", module_info.description);
1084 if (module_info.keywords) {
1085 fprintf(stderr, _(
"\nKeywords:\n"));
1086 fprintf(stderr,
" %s\n", module_info.keywords);
1089 fprintf(stderr, _(
"\nUsage:\n "));
1091 len = show(pgm_name, 1);
1100 for (n = 3; flag !=
NULL; n++, flag = flag->next_flag)
1101 item[n] = flag->key;
1104 len = show(item, len);
1109 opt = &first_option;
1110 while (opt !=
NULL) {
1111 if (opt->key_desc !=
NULL)
1112 key_desc = opt->key_desc;
1113 else if (opt->type == TYPE_STRING)
1114 key_desc =
"string";
1118 n = strlen(opt->key);
1125 strcat(item, opt->key);
1127 strcat(item, key_desc);
1128 if (opt->multiple) {
1130 strcat(item, key_desc);
1131 strcat(item,
",...]");
1136 len = show(item, len);
1138 opt = opt->next_opt;
1142 strcpy(item,
" [--overwrite]");
1143 len = show(item, len);
1146 strcpy(item,
" [--verbose]");
1147 len = show(item, len);
1149 strcpy(item,
" [--quiet]");
1150 len = show(item, len);
1153 fprintf(stderr,
"\n");
1157 fprintf(stderr, _(
"\nFlags:\n"));
1161 while (flag !=
NULL) {
1162 fprintf(stderr,
" -%c ", flag->key);
1165 fprintf(stderr,
"%s\n", flag->label);
1166 if (flag->description)
1167 fprintf(stderr,
" %s\n", flag->description);
1170 else if (flag->description) {
1171 fprintf(stderr,
"%s\n", flag->description);
1174 flag = flag->next_flag;
1179 fprintf(stderr,
" --o %s\n",
1180 _(
"Allow output files to overwrite existing files"));
1182 fprintf(stderr,
" --v %s\n", _(
"Verbose module output"));
1183 fprintf(stderr,
" --q %s\n", _(
"Quiet module output"));
1188 fprintf(stderr, _(
"\nParameters:\n"));
1189 opt = &first_option;
1190 while (opt !=
NULL) {
1191 fprintf(stderr,
" %*s ", maxlen, opt->key);
1194 fprintf(stderr,
"%s\n", opt->label);
1195 if (opt->description) {
1196 fprintf(stderr,
" %*s %s\n",
1197 maxlen,
" ", opt->description);
1200 else if (opt->description) {
1201 fprintf(stderr,
"%s\n", opt->description);
1205 show_options(maxlen, opt->options);
1211 fprintf(stderr, _(
" %*s default: %s\n"), maxlen,
" ",
1217 while (opt->opts[i]) {
1219 fprintf(stderr,
" %*s %s: %s\n",
1220 maxlen,
" ", opt->opts[i], opt->descs[i]);
1226 opt = opt->next_opt;
1241 static void print_escaped_for_xml(FILE * fp,
const char *str)
1243 for (; *str; str++) {
1264 #define do_escape(c,escaped) case c: fputs(escaped,f);break
1265 static void print_escaped_for_html(FILE * f,
const char *str)
1269 for (s = str; *
s; s++) {
1286 static void G_usage_xml(
void)
1296 new_prompt = uses_new_gisprompt();
1300 #if defined(HAVE_LANGINFO_H)
1301 encoding = nl_langinfo(CODESET);
1302 if (!encoding || strlen(encoding) == 0) {
1305 #elif defined(__MINGW32__) && defined(USE_NLS)
1306 encoding = locale_charset();
1307 if (!encoding || strlen(encoding) == 0) {
1319 fprintf(stdout,
"<?xml version=\"1.0\" encoding=\"%s\"?>\n", encoding);
1320 fprintf(stdout,
"<!DOCTYPE task SYSTEM \"grass-interface.dtd\">\n");
1322 fprintf(stdout,
"<task name=\"%s\">\n", pgm_name);
1324 if (module_info.label) {
1325 fprintf(stdout,
"\t<label>\n\t\t");
1326 print_escaped_for_xml(stdout, module_info.label);
1327 fprintf(stdout,
"\n\t</label>\n");
1330 if (module_info.description) {
1331 fprintf(stdout,
"\t<description>\n\t\t");
1332 print_escaped_for_xml(stdout, module_info.description);
1333 fprintf(stdout,
"\n\t</description>\n");
1336 if (module_info.keywords) {
1337 fprintf(stdout,
"\t<keywords>\n\t\t");
1338 print_escaped_for_xml(stdout, module_info.keywords);
1339 fprintf(stdout,
"\n\t</keywords>\n");
1352 opt = &first_option;
1353 while (opt !=
NULL) {
1355 switch (opt->type) {
1369 fprintf(stdout,
"\t<parameter "
1373 "multiple=\"%s\">\n",
1376 opt->required == YES ?
"yes" :
"no",
1377 opt->multiple == YES ?
"yes" :
"no");
1380 fprintf(stdout,
"\t\t<label>\n\t\t\t");
1381 print_escaped_for_xml(stdout, opt->label);
1382 fprintf(stdout,
"\n\t\t</label>\n");
1385 if (opt->description) {
1386 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1387 print_escaped_for_xml(stdout, opt->description);
1388 fprintf(stdout,
"\n\t\t</description>\n");
1391 if (opt->key_desc) {
1392 fprintf(stdout,
"\t\t<keydesc>\n");
1393 top = G_calloc(strlen(opt->key_desc) + 1, 1);
1394 strcpy(top, opt->key_desc);
1395 s = strtok(top,
",");
1396 for (i = 1; s !=
NULL; i++) {
1397 fprintf(stdout,
"\t\t\t<item order=\"%d\">", i);
1398 print_escaped_for_xml(stdout, s);
1399 fprintf(stdout,
"</item>\n");
1400 s = strtok(
NULL,
",");
1402 fprintf(stdout,
"\t\t</keydesc>\n");
1406 if (opt->gisprompt) {
1407 const char *atts[] = {
"age",
"element",
"prompt",
NULL };
1408 top = G_calloc(strlen(opt->gisprompt) + 1, 1);
1409 strcpy(top, opt->gisprompt);
1410 s = strtok(top,
",");
1411 fprintf(stdout,
"\t\t<gisprompt ");
1412 for (i = 0; s !=
NULL && atts[i] !=
NULL; i++) {
1413 fprintf(stdout,
"%s=\"%s\" ", atts[i], s);
1414 s = strtok(
NULL,
",");
1416 fprintf(stdout,
"/>\n");
1421 fprintf(stdout,
"\t\t<default>\n\t\t\t");
1422 print_escaped_for_xml(stdout, opt->def);
1423 fprintf(stdout,
"\n\t\t</default>\n");
1432 fprintf(stdout,
"\t\t<values>\n");
1433 while (opt->opts[i]) {
1434 fprintf(stdout,
"\t\t\t<value>\n");
1435 fprintf(stdout,
"\t\t\t\t<name>");
1436 print_escaped_for_xml(stdout, opt->opts[i]);
1437 fprintf(stdout,
"</name>\n");
1438 if (opt->descs && opt->opts[i] && opt->descs[i]) {
1439 fprintf(stdout,
"\t\t\t\t<description>");
1440 print_escaped_for_xml(stdout, opt->descs[i]);
1441 fprintf(stdout,
"</description>\n");
1443 fprintf(stdout,
"\t\t\t</value>\n");
1446 fprintf(stdout,
"\t\t</values>\n");
1448 if (opt->guisection) {
1449 fprintf(stdout,
"\t\t<guisection>\n\t\t\t");
1450 print_escaped_for_xml(stdout, opt->guisection);
1451 fprintf(stdout,
"\n\t\t</guisection>\n");
1458 opt = opt->next_opt;
1459 fprintf(stdout,
"\t</parameter>\n");
1466 while (flag !=
NULL) {
1467 fprintf(stdout,
"\t<flag name=\"%c\">\n", flag->key);
1470 fprintf(stdout,
"\t\t<label>\n\t\t\t");
1471 print_escaped_for_xml(stdout, flag->label);
1472 fprintf(stdout,
"\n\t\t</label>\n");
1475 if (flag->description) {
1476 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1477 print_escaped_for_xml(stdout, flag->description);
1478 fprintf(stdout,
"\n\t\t</description>\n");
1480 if (flag->guisection) {
1481 fprintf(stdout,
" \t\t<guisection>\n\t\t\t");
1482 print_escaped_for_xml(stdout, flag->guisection);
1483 fprintf(stdout,
"\n\t\t</guisection>\n");
1485 flag = flag->next_flag;
1486 fprintf(stdout,
"\t</flag>\n");
1501 fprintf(stdout,
"\t<flag name=\"%s\">\n",
"overwrite");
1502 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1503 print_escaped_for_xml(stdout,
1504 _(
"Allow output files to overwrite existing files"));
1505 fprintf(stdout,
"\n\t\t</description>\n");
1506 fprintf(stdout,
"\t</flag>\n");
1510 fprintf(stdout,
"\t<flag name=\"%s\">\n",
"verbose");
1511 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1512 print_escaped_for_xml(stdout, _(
"Verbose module output"));
1513 fprintf(stdout,
"\n\t\t</description>\n");
1514 fprintf(stdout,
"\t</flag>\n");
1517 fprintf(stdout,
"\t<flag name=\"%s\">\n",
"quiet");
1518 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1519 print_escaped_for_xml(stdout, _(
"Quiet module output"));
1520 fprintf(stdout,
"\n\t\t</description>\n");
1521 fprintf(stdout,
"\t</flag>\n");
1523 fprintf(stdout,
"</task>\n");
1529 static void G_usage_html(
void)
1536 new_prompt = uses_new_gisprompt();
1544 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
1545 fprintf(stdout,
"<html>\n<head>\n");
1546 fprintf(stdout,
"<title>GRASS GIS manual: %s</title>\n", pgm_name);
1548 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n");
1550 "<link rel=\"stylesheet\" href=\"grassdocs.css\" type=\"text/css\">\n");
1551 fprintf(stdout,
"</head>\n");
1552 fprintf(stdout,
"<body bgcolor=\"white\">\n\n");
1554 "<img src=\"grass_logo.png\" alt=\"GRASS logo\"><hr align=center size=6 noshade>\n\n");
1555 fprintf(stdout,
"<h2>%s</h2>\n", _(
"NAME"));
1556 fprintf(stdout,
"<em><b>%s</b></em> ", pgm_name);
1558 if (module_info.label || module_info.description)
1559 fprintf(stdout,
" - ");
1561 if (module_info.label)
1562 fprintf(stdout,
"%s<BR>\n", module_info.label);
1564 if (module_info.description)
1565 fprintf(stdout,
"%s\n", module_info.description);
1568 fprintf(stdout,
"<h2>%s</h2>\n", _(
"KEYWORDS"));
1569 if (module_info.keywords) {
1570 fprintf(stdout,
"%s", module_info.keywords);
1571 fprintf(stdout,
"\n");
1573 fprintf(stdout,
"<h2>%s</h2>\n", _(
"SYNOPSIS"));
1574 fprintf(stdout,
"<b>%s</b><br>\n", pgm_name);
1575 fprintf(stdout,
"<b>%s help</b><br>\n", pgm_name);
1577 fprintf(stdout,
"<b>%s</b>", pgm_name);
1584 fprintf(stdout,
" [-<b>");
1585 while (flag !=
NULL) {
1586 fprintf(stdout,
"%c", flag->key);
1587 flag = flag->next_flag;
1589 fprintf(stdout,
"</b>] ");
1592 fprintf(stdout,
" ");
1595 opt = &first_option;
1597 while (opt !=
NULL) {
1598 if (opt->key_desc !=
NULL)
1599 type = opt->key_desc;
1601 switch (opt->type) {
1616 fprintf(stdout,
" [");
1617 fprintf(stdout,
"<b>%s</b>=<em>%s</em>", opt->key, type);
1618 if (opt->multiple) {
1619 fprintf(stdout,
"[,<i>%s</i>,...]", type);
1622 fprintf(stdout,
"] ");
1624 opt = opt->next_opt;
1625 fprintf(stdout,
" ");
1629 fprintf(stdout,
" [--<b>overwrite</b>] ");
1631 fprintf(stdout,
" [--<b>verbose</b>] ");
1632 fprintf(stdout,
" [--<b>quiet</b>] ");
1634 fprintf(stdout,
"\n");
1638 fprintf(stdout,
"\n");
1639 if (n_flags || new_prompt) {
1641 fprintf(stdout,
"<h3>%s:</h3>\n", _(
"Flags"));
1642 fprintf(stdout,
"<DL>\n");
1643 while (n_flags && flag !=
NULL) {
1644 fprintf(stdout,
"<DT><b>-%c</b></DT>\n", flag->key);
1647 fprintf(stdout,
"<DD>");
1648 fprintf(stdout,
"%s", flag->label);
1649 fprintf(stdout,
"</DD>\n");
1652 if (flag->description) {
1653 fprintf(stdout,
"<DD>");
1654 fprintf(stdout,
"%s", flag->description);
1655 fprintf(stdout,
"</DD>\n");
1658 flag = flag->next_flag;
1659 fprintf(stdout,
"\n");
1662 fprintf(stdout,
"<DT><b>--overwrite</b></DT>\n");
1663 fprintf(stdout,
"<DD>%s</DD>\n",
1664 _(
"Allow output files to overwrite existing files"));
1667 fprintf(stdout,
"<DT><b>--verbose</b></DT>\n");
1668 fprintf(stdout,
"<DD>%s</DD>\n", _(
"Verbose module output"));
1670 fprintf(stdout,
"<DT><b>--quiet</b></DT>\n");
1671 fprintf(stdout,
"<DD>%s</DD>\n", _(
"Quiet module output"));
1673 fprintf(stdout,
"</DL>\n");
1676 fprintf(stdout,
"\n");
1678 opt = &first_option;
1679 fprintf(stdout,
"<h3>%s:</h3>\n", _(
"Parameters"));
1680 fprintf(stdout,
"<DL>\n");
1682 while (opt !=
NULL) {
1684 if (opt->key_desc !=
NULL)
1685 type = opt->key_desc;
1687 switch (opt->type) {
1701 fprintf(stdout,
"<DT><b>%s</b>=<em>%s", opt->key, type);
1702 if (opt->multiple) {
1703 fprintf(stdout,
"[,<i>%s</i>,...]", type);
1705 fprintf(stdout,
"</em></DT>\n");
1708 fprintf(stdout,
"<DD>");
1709 fprintf(stdout,
"%s", opt->label);
1710 fprintf(stdout,
"</DD>\n");
1712 if (opt->description) {
1713 fprintf(stdout,
"<DD>");
1714 print_escaped_for_html(stdout, opt->description);
1715 fprintf(stdout,
"</DD>\n");
1719 fprintf(stdout,
"<DD>%s: <em>", _(
"Options"));
1720 fprintf(stdout,
"%s", opt->options);
1721 fprintf(stdout,
"</em></DD>\n");
1725 fprintf(stdout,
"<DD>%s: <em>", _(
"Default"));
1726 fprintf(stdout,
"%s", opt->def);
1727 fprintf(stdout,
"</em></DD>\n");
1733 while (opt->opts[i]) {
1735 fprintf(stdout,
"<DD><b>%s</b>: %s</DD>\n",
1736 opt->opts[i], opt->descs[i]);
1741 opt = opt->next_opt;
1742 fprintf(stdout,
"\n");
1744 fprintf(stdout,
"</DL>\n");
1747 fprintf(stdout,
"</body>\n</html>\n");
1753 static void G_script(
void)
1758 fprintf(fp,
"#!/bin/sh\n\n");
1760 "############################################################################\n");
1763 fprintf(fp,
"# AUTHOR(S): %s\n",
G_whoami());
1764 fprintf(fp,
"# PURPOSE: \n");
1765 fprintf(fp,
"# COPYRIGHT: (C) 2014 GRASS Development Team/%s\n",
1769 "# This program is free software; you can redistribute it and/or modify\n");
1771 "# it under the terms of the GNU General Public License as published by\n");
1773 "# the Free Software Foundation; either version 2 of the License, or\n");
1774 fprintf(fp,
"# (at your option) any later version.\n");
1777 "# This program is distributed in the hope that it will be useful,\n");
1779 "# but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
1781 "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
1782 fprintf(fp,
"# GNU General Public License for more details.\n");
1785 "############################################################################\n");
1787 fprintf(fp,
"#%%Module\n");
1788 if (module_info.label)
1789 fprintf(fp,
"#%% label: %s\n", module_info.label);
1790 if (module_info.description)
1791 fprintf(fp,
"#%% description: %s\n", module_info.description);
1792 if (module_info.keywords)
1793 fprintf(fp,
"#%% keywords: %s\n", module_info.keywords);
1794 fprintf(fp,
"#%%End\n");
1799 for (flag = &first_flag;
flag; flag = flag->next_flag) {
1800 fprintf(fp,
"#%%Flag\n");
1801 fprintf(fp,
"#%% key: %c\n", flag->key);
1803 fprintf(fp,
"#%% label: %s\n", flag->label);
1804 if (flag->description)
1805 fprintf(fp,
"#%% description: %s\n", flag->description);
1806 if (flag->guisection)
1807 fprintf(fp,
"#%% guisection: %s\n", flag->guisection);
1808 fprintf(fp,
"#%%End\n");
1815 for (opt = &first_option; opt; opt = opt->next_opt) {
1816 switch (opt->type) {
1831 fprintf(fp,
"#%%Option\n");
1832 fprintf(fp,
"#%% key: %s\n", opt->key);
1833 fprintf(fp,
"#%% type: %s\n", type);
1834 fprintf(fp,
"#%% required: %s\n", opt->required ?
"yes" :
"no");
1835 fprintf(fp,
"#%% multiple: %s\n", opt->multiple ?
"yes" :
"no");
1837 fprintf(fp,
"#%% options: %s\n", opt->options);
1839 fprintf(fp,
"#%% key_desc: %s\n", opt->key_desc);
1841 fprintf(fp,
"#%% label: %s\n", opt->label);
1842 if (opt->description)
1843 fprintf(fp,
"#%% description: %s\n", opt->description);
1844 if (opt->descriptions)
1845 fprintf(fp,
"#%% descriptions: %s\n", opt->descriptions);
1847 fprintf(fp,
"#%% answer: %s\n", opt->answer);
1849 fprintf(fp,
"#%% gisprompt: %s\n", opt->gisprompt);
1850 if (opt->guisection)
1851 fprintf(fp,
"#%% guisection: %s\n", opt->guisection);
1852 fprintf(fp,
"#%%End\n");
1857 "\nif [ -z \"$GISBASE\" ] ; then\n"
1858 " echo \"You must be in GRASS GIS to run this program.\" 1>&2\n"
1862 "if [ \"$1\" != \"@ARGS_PARSED@\" ] ; then\n"
1863 " exec g.parser \"$0\" \"$@\"\n"
1864 "fi\n" "\n" "# CODE GOES HERE\n" "\n");
1872 static void generate_tcl(FILE * fp)
1874 int new_prompt = uses_new_gisprompt();
1878 fprintf(fp,
"begin_dialog {%s} {\n", pgm_name);
1879 fprintf(fp,
" label {%s}\n", module_info.label ? module_info.label :
"");
1880 fprintf(fp,
" desc {%s}\n",
1881 module_info.description ? module_info.description :
"");
1882 fprintf(fp,
" key {%s}\n",
1883 module_info.keywords ? module_info.keywords :
"");
1891 for (flag = &first_flag;
flag; flag = flag->next_flag, optn++) {
1892 fprintf(fp,
"add_flag %d {\n", optn);
1893 fprintf(fp,
" name {%c}\n", flag->key);
1894 fprintf(fp,
" desc {%s}\n", flag->description);
1895 fprintf(fp,
" answer %d\n", flag->answer);
1898 fprintf(fp,
" label {%s}\n", flag->label ? flag->label :
"");
1899 fprintf(fp,
" guisection {%s}\n",
1900 flag->guisection ? flag->guisection :
"");
1908 for (opt = &first_option; opt; opt = opt->next_opt, optn++) {
1909 if (opt->key_desc !=
NULL)
1910 type = opt->key_desc;
1912 switch (opt->type) {
1927 fprintf(fp,
"add_option %d {\n", optn);
1928 fprintf(fp,
" name {%s}\n", opt->key);
1929 fprintf(fp,
" type {%s}\n", type);
1930 fprintf(fp,
" multi %d\n", opt->multiple);
1931 fprintf(fp,
" desc {%s}\n", opt->description);
1932 fprintf(fp,
" required %d\n", opt->required);
1933 fprintf(fp,
" options {%s}\n", opt->options ? opt->options :
"");
1934 fprintf(fp,
" descs {%s}\n",
1935 opt->descriptions ? opt->descriptions :
"");
1936 fprintf(fp,
" answer {%s}\n", opt->answer ? opt->answer :
"");
1937 fprintf(fp,
" prompt {%s}\n",
1938 opt->gisprompt ? opt->gisprompt :
"");
1941 fprintf(fp,
" label {%s}\n", opt->label ? opt->label :
"");
1942 fprintf(fp,
" guisection {%s}\n",
1943 opt->guisection ? opt->guisection :
"");
1949 fprintf(fp,
"add_xflag %d {\n", optn);
1950 fprintf(fp,
" name {overwrite}\n");
1951 fprintf(fp,
" desc {%s}\n",
1952 _(
"Allow output files to overwrite existing files"));
1953 fprintf(fp,
" answer %d\n", overwrite);
1954 fprintf(fp,
" label {%s}\n", _(
"Allow overwrite"));
1955 fprintf(fp,
" guisection {}\n");
1960 fprintf(fp,
"add_xflag %d {\n", optn);
1961 fprintf(fp,
" name {quiet}\n");
1962 fprintf(fp,
" desc {%s}\n", _(
"Run with minimal output messages"));
1963 fprintf(fp,
" answer %d\n", quiet);
1964 fprintf(fp,
" label {%s}\n", _(
"Run quietly"));
1965 fprintf(fp,
" guisection {}\n");
1969 fprintf(fp,
"end_dialog %d\n", optn - 1);
1975 static void G_gui_tcltk(
void)
1985 if (
getenv(
"GRASS_DEBUG_GUI"))
1986 fp = popen(
"tee gui_dump.tcl | \"%GRASS_WISH%\"",
"w");
1988 fp = popen(
"\"%GRASS_WISH%\"",
"w");
1990 if (
getenv(
"GRASS_DEBUG_GUI"))
1991 fp = popen(
"tee gui_dump.tcl | \"$GRASS_WISH\"",
"w");
1993 fp = popen(
"\"$GRASS_WISH\"",
"w");
1999 fprintf(fp,
"source $env(GISBASE)/etc/gui.tcl\n");
2009 static void G_gui_wx(
void)
2011 char script[GPATH_MAX];
2018 sprintf(script,
"%s/etc/wxpython/gui_core/forms.py",
2030 static void G_gui(
void)
2033 char *gui =
getenv(
"GRASS_GUI");
2039 if (gui && (strcmp(gui,
"tcltk") == 0 || strcmp(gui,
"oldtcltk") == 0))
2050 static void G_tcltk(
void)
2057 generate_tcl(stdout);
2067 static int show_options(
int maxlen,
const char *str)
2073 fprintf(stderr, _(
" %*s options: "), maxlen,
" ");
2074 totlen = maxlen + 13;
2076 while ((p2 =
G_index(p1,
','))) {
2078 len = strlen(p1) + 1;
2079 if ((len + totlen) > 76) {
2080 totlen = maxlen + 13;
2081 fprintf(stderr,
"\n %*s", maxlen + 13,
" ");
2083 fprintf(stderr,
"%s,", p1);
2088 if ((len + totlen) > 76)
2089 fprintf(stderr,
"\n %*s", maxlen + 13,
" ");
2090 fprintf(stderr,
"%s\n", p1);
2097 static int show(
const char *item,
int len)
2101 n = strlen(item) + (len > 0);
2104 fprintf(stderr,
"\n ");
2107 fprintf(stderr,
"%s", item);
2111 static int set_flag(
int f)
2118 fprintf(stderr, _(
"Sorry, <%c> is not a valid flag\n"), f);
2125 while (flag !=
NULL) {
2126 if (flag->key == f) {
2130 flag = flag->next_flag;
2133 fprintf(stderr, _(
"Sorry, <%c> is not a valid flag\n"), f);
2140 static int contains(
const char *s,
int c)
2150 static int is_option(
const char *
string)
2152 const char *p = strchr(
string,
'=');
2159 if (!strchr(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", *p))
2165 static int set_option(
char *
string)
2167 struct Option *at_opt =
NULL;
2168 struct Option *opt =
NULL;
2174 for (ptr = the_key; *
string !=
'='; ptr++,
string++)
2181 key_len = strlen(the_key);
2182 for (at_opt = &first_option; at_opt !=
NULL; at_opt = at_opt->next_opt) {
2183 if (at_opt->key ==
NULL || strncmp(the_key, at_opt->key, key_len))
2191 if (strlen(at_opt->key) == key_len) {
2199 fprintf(stderr, _(
"Sorry, <%s=> is ambiguous\n"), the_key);
2205 fprintf(stderr, _(
"Sorry, <%s> is not a valid parameter\n"), the_key);
2211 if (!opt->multiple) {
2212 fprintf(stderr, _(
"Option <%s> does not accept multiple answers\n"), the_key);
2215 opt->answer = (
char *)G_realloc(opt->answer,
2216 strlen(opt->answer) + strlen(
string) +
2218 strcat(opt->answer,
",");
2219 strcat(opt->answer,
string);
2222 opt->answer =
G_store(
string);
2226 static int check_opts(
void)
2237 opt = &first_option;
2238 while (opt !=
NULL) {
2241 if (opt->options && opt->answer) {
2242 if (opt->multiple == 0)
2243 error += check_an_opt(opt->key, opt->type,
2244 opt->options, opt->answer);
2246 for (ans = 0; opt->answers[ans] !=
'\0'; ans++)
2247 error += check_an_opt(opt->key, opt->type,
2248 opt->options, opt->answers[ans]);
2255 error += opt->checker(opt->answer);
2257 opt = opt->next_opt;
2262 static int check_an_opt(
const char *key,
int type,
const char *options,
2271 error = check_int(answer, options);
2274 error = check_double(answer, options);
2277 error = check_string(answer, options);
2290 _(
"\nERROR: illegal range syntax for parameter <%s>\n"), key);
2291 fprintf(stderr, _(
" Presented as: %s\n"), options);
2295 _(
"\nERROR: value <%s> out of range for parameter <%s>\n"),
2297 fprintf(stderr, _(
" Legal range: %s\n"), options);
2300 fprintf(stderr, _(
"\nERROR: Missing value for parameter <%s>\n"),
2306 static int check_int(
const char *ans,
const char *opts)
2310 if (1 != sscanf(ans,
"%d", &d))
2313 if (contains(opts,
'-')) {
2314 if (2 != sscanf(opts,
"%d-%d", &lo, &hi))
2316 if (d < lo || d > hi)
2321 else if (contains(opts,
',')) {
2323 if (1 != sscanf(opts,
"%d", &lo))
2327 while (*opts !=
'\0' && *opts !=
',')
2331 if (*(++opts) ==
'\0')
2336 if (1 != sscanf(opts,
"%d", &lo))
2370 static int check_double(
const char *ans,
const char *opts)
2374 if (1 != sscanf(ans,
"%lf", &d))
2377 if (contains(opts,
'-')) {
2378 if (2 != sscanf(opts,
"%lf-%lf", &lo, &hi))
2380 if (d < lo || d > hi)
2385 else if (contains(opts,
',')) {
2387 if (1 != sscanf(opts,
"%lf", &lo))
2391 while (*opts !=
'\0' && *opts !=
',')
2395 if (*(++opts) ==
'\0')
2400 if (1 != sscanf(opts,
"%lf", &lo))
2408 static int check_string(
const char *ans,
const char *opts)
2413 if (contains(opts,
',')) {
2415 if ((!strncmp(ans, opts, strlen(ans)))
2416 && (*(opts + strlen(ans)) ==
','
2417 || *(opts + strlen(ans)) ==
'\0'))
2419 while (*opts !=
'\0' && *opts !=
',')
2423 if (*(++opts) ==
'\0')
2428 if (!strcmp(ans, opts))
2434 static int check_required(
void)
2444 opt = &first_option;
2445 while (opt !=
NULL) {
2446 if (opt->required && opt->answer ==
NULL) {
2448 _(
"ERROR: Required parameter <%s> not set:\n\t(%s)\n"),
2449 opt->key, (opt->label ? opt->label : opt->description) );
2452 opt = opt->next_opt;
2458 static int split_opts(
void)
2471 opt = &first_option;
2472 while (opt !=
NULL) {
2473 if ( (opt->answer !=
NULL)) {
2476 opt->answers = (
char **)G_malloc(allocated *
sizeof(
char *));
2480 opt->answers[ans_num] =
NULL;
2483 for (len = 0, ptr2 = ptr1; *ptr2 !=
'\0' && *ptr2 !=
',';
2487 opt->answers[ans_num] = (
char *)G_malloc(len + 1);
2488 G_copy(opt->answers[ans_num], ptr1, len);
2489 opt->answers[ans_num][len] = 0;
2493 if (ans_num >= allocated) {
2496 (
char **)G_realloc((
char *)opt->answers,
2497 allocated *
sizeof(
char *));
2500 opt->answers[ans_num] =
NULL;
2512 opt = opt->next_opt;
2518 static int check_multiple_opts(
void)
2530 opt = &first_option;
2531 while (opt !=
NULL) {
2532 if ((opt->answer !=
NULL) && (opt->key_desc !=
NULL)) {
2535 for (ptr = opt->key_desc; *ptr !=
'\0'; ptr++)
2539 for (n = 0; opt->answers[
n] !=
'\0'; n++) ;
2543 _(
"\nERROR: option <%s> must be provided in multiples of %d\n"),
2544 opt->key, n_commas);
2545 fprintf(stderr, _(
" You provided %d items:\n"), n);
2546 fprintf(stderr,
" %s\n", opt->answer);
2550 opt = opt->next_opt;
2556 static int check_overwrite(
void)
2571 if ((overstr =
G__getenv(
"OVERWRITE"))) {
2572 over = atoi(overstr);
2576 if ((overstr =
getenv(
"GRASS_OVERWRITE"))) {
2581 if (overwrite || over) {
2582 module_info.overwrite = 1;
2584 putenv(
"GRASS_OVERWRITE=1");
2589 opt = &first_option;
2590 while (opt !=
NULL) {
2591 if ((opt->answer !=
NULL) && (opt->gisprompt !=
NULL)) {
2592 split_gisprompt(opt->gisprompt, age, element, desc);
2594 if (strcmp(age,
"new") == 0) {
2596 for (i = 0; opt->answers[i]; i++) {
2598 if (!overwrite && !over) {
2601 _(
"ERROR: option <%s>: <%s> exists.\n"),
2602 opt->key, opt->answers[i]);
2606 "GRASS_INFO_ERROR(%d,1): option <%s>: <%s> exists.\n",
2607 getpid(), opt->key, opt->answers[i]);
2608 fprintf(stderr,
"GRASS_INFO_END(%d,1)\n",
2618 opt = opt->next_opt;
2624 static int interactive(
const char *
command)
2631 fprintf(stderr,
"PROGRAMMER ERROR: no flags or options\n");
2635 for (item = &first_item;;) {
2637 interactive_flag(item->
flag);
2639 interactive_option(item->
option);
2652 static int interactive_flag(
struct Flag *flag)
2656 fprintf(stderr, _(
"\nFLAG: Set the following flag?\n"));
2657 sprintf(buff,
" %s?", flag->description);
2658 flag->answer =
G_yes(buff, 0);
2663 static int interactive_option(
struct Option *opt)
2665 char buff[1024], *bptr;
2670 fprintf(stderr, _(
"\nOPTION: %s\n"), opt->description);
2671 fprintf(stderr, _(
" key: %s\n"), opt->key);
2673 fprintf(stderr, _(
" format: %s\n"), opt->key_desc);
2675 fprintf(stderr, _(
" default: %s\n"), opt->def);
2676 fprintf(stderr, _(
"required: %s\n"), opt->required ?
"YES" :
"NO");
2678 fprintf(stderr, _(
"multiple: %s\n"), opt->multiple ?
"YES" :
"NO");
2680 fprintf(stderr, _(
" options: %s\n"), opt->options);
2689 no_prompt = gis_prompt(opt, buff);
2693 fprintf(stderr, _(
"enter option > "));
2694 if (fgets(buff, 1024, stdin) == 0)
2695 exit(EXIT_SUCCESS);;
2705 if (strlen(buff) != 0) {
2709 if (check_an_opt(opt->key, opt->type, opt->options, buff)) {
2710 if (
G_yes(_(
" Try again? "), 1))
2717 if (opt->checker(buff)) {
2718 fprintf(stderr, _(
"Sorry, %s is not accepted.\n"), buff);
2720 if (
G_yes(_(
" Try again? "), 1))
2726 sprintf(buff2,
"%s=%s", opt->key, buff);
2727 if (!opt->gisprompt) {
2728 fprintf(stderr, _(
"\nYou have chosen:\n %s\n"), buff2);
2729 if (
G_yes(_(
"Is this correct? "), 1)) {
2740 if ((strlen(buff) == 0) && opt->required && (set_one == 0))
2742 if ((strlen(buff) == 0) && (set_one > 0) && opt->multiple)
2744 if ((strlen(buff) == 0) && !opt->required)
2746 if ((set_one == 1) && !opt->multiple)
2752 static int split_gisprompt(
const char *gisprompt,
char *age,
char *element,
2758 for (ptr1 = gisprompt, ptr2 = age; *ptr1 !=
'\0'; ptr1++, ptr2++) {
2765 for (ptr1++, ptr2 = element; *ptr1 !=
'\0'; ptr1++, ptr2++) {
2772 for (ptr1++, ptr2 = desc; *ptr1 !=
'\0'; ptr1++, ptr2++) {
2782 static int gis_prompt(
struct Option *opt,
char *buff)
2789 split_gisprompt(opt->gisprompt, age, element, desc);
2795 if (!strcmp(
"old", age)) {
2796 ptr1 =
G_ask_old(
"", buff, element, desc);
2801 else if (!strcmp(
"new", age))
2802 ptr1 =
G_ask_new(
"", buff, element, desc);
2803 else if (!strcmp(
"mapset", age))
2805 else if (!strcmp(
"any", age))
2806 ptr1 =
G_ask_any(
"", buff, element, desc, 1);
2807 else if (!strcmp(
"old_file", age))
2809 else if (!strcmp(
"new_file", age))
2840 G_debug(3,
"G_recreate_command()");
2844 buff = G_calloc(1024,
sizeof(
char));
2848 if (len >= nalloced) {
2849 nalloced += (1024 > len) ? 1024 : len + 1;
2850 buff = G_realloc(buff, nalloced);
2858 while (flag !=
'\0') {
2859 if (flag->answer == 1) {
2865 if (len + slen >= nalloced) {
2867 (nalloced + 1024 > len + slen) ? 1024 : slen + 1;
2868 buff = G_realloc(buff, nalloced);
2875 flag = flag->next_flag;
2879 opt = &first_option;
2880 while (opt !=
'\0') {
2881 if (opt->answer !=
'\0' && opt->answers && opt->answers[0] !=
NULL) {
2882 slen = strlen(opt->key) + strlen(opt->answers[0]) + 4;
2883 if (len + slen >= nalloced) {
2884 nalloced += (nalloced + 1024 > len + slen) ? 1024 : slen + 1;
2885 buff = G_realloc(buff, nalloced);
2890 strcpy(cur, opt->key);
2891 cur = strchr(cur,
'\0');
2894 if (opt->type == TYPE_STRING) {
2898 strcpy(cur, opt->answers[0]);
2899 cur = strchr(cur,
'\0');
2901 for (n = 1; opt->answers[
n] !=
NULL && opt->answers[
n] !=
'\0';
2903 if (opt->answers[n] ==
NULL)
2905 slen = strlen(opt->answers[n]) + 2;
2906 if (len + slen >= nalloced) {
2908 (nalloced + 1024 > len + slen) ? 1024 : slen + 1;
2909 buff = G_realloc(buff, nalloced);
2914 strcpy(cur, opt->answers[n]);
2915 cur = strchr(cur,
'\0');
2918 if (opt->type == TYPE_STRING) {
2924 opt = opt->next_opt;
char * G_mapset(void)
current mapset name
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
struct Option * G_define_standard_option(int opt)
Create standardised Option structure.
char * G__getenv(const char *name)
Get environment variable.
char * G_store(const char *s)
Copy string to allocated memory.
int G_free_tokens(char **tokens)
Free memory allocated to tokens.
struct GModule * G_define_module(void)
Initializes a new module.
char * G_index(const char *str, int delim)
delimiter
void G_important_message(const char *msg,...)
Print a message to stderr even in brief mode (verbosity=1)
int G_copy(void *a, const void *b, int n)
Copies n bytes starting at address b into address a.
int G_yes(const char *question, int dflt)
Ask a yes/no question.
char * G_ask_in_mapset(const char *prompt, char *name, char *element, char *desc)
prompt for existing database file
int G_set_ask_return_msg(const char *msg)
set Hit RETURN msg
int G_disable_interactive(void)
Disables the ability of the parser to operate interactively.
char ** G_tokenize(const char *buf, const char *delim)
Tokenize string.
#define do_escape(c, escaped)
Format text for HTML output.
def error
Display an error message using g.message -e
char * G_ask_new(const char *prompt, char *name, char *element, char *desc)
prompt for new database file
char * G_recreate_command(void)
Creates command to run non-interactive.
struct Flag * G_define_flag(void)
Initializes a Flag struct.
char * G_getenv(const char *name)
Get environment variable.
int G_zero(void *buf, int i)
Zero out a buffer, buf, of length i.
int G_parser(int argc, char **argv)
Parse command line.
struct Option * G_define_option(void)
Initializes an Option struct.
int G_verbose_max(void)
Get max verbosity level.
char * G_ask_old(const char *prompt, char *name, char *element, char *desc)
prompt for existing database file
int G_info_format(void)
Get current message format.
char * G_basename(char *filename, const char *desired_ext)
Truncates filename to the base part (before the last '.') if it matches the extension, otherwise leaves it unchanged.
const char * G_program_name(void)
return module name
char * G_whoami(void)
Gets user's name.
char * G_ask_any(const char *prompt, char *name, char *element, char *desc, int warn)
prompt for any valid file name
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
char * G_ask_new_file(const char *prompt, char *name, char *element, char *desc)
prompt for new file
int G_debug(int level, const char *msg,...)
Print debugging message.
char * G_ask_old_file(const char *prompt, char *name, char *element, char *desc)
prompt for existing file
char * G_fully_qualified_name(const char *name, const char *mapset)
fully qualified file name
int G_verbose_min(void)
Get min verbosity level.
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. returns the mapset name whe...
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int G_is_dirsep(char c)
Checks if a specified character is a valid directory separator character on the host system...
int G_usage(void)
Command line help/usage message.
int G_spawn(const char *command,...)
Spawn new process based on command.