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++;
970 else if (contains(ptr,
'=') == 0) {
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)
1020 opt = &first_option;
1021 while (opt !=
NULL) {
1022 if (opt->gisprompt) {
1023 split_gisprompt(opt->gisprompt, age, element, desc);
1024 if (strcmp(age,
"new") == 0)
1027 opt = opt->next_opt;
1062 const char *key_desc;
1067 new_prompt = uses_new_gisprompt();
1074 if (module_info.label || module_info.description) {
1075 fprintf(stderr, _(
"\nDescription:\n"));
1076 if (module_info.label)
1077 fprintf(stderr,
" %s\n", module_info.label);
1078 if (module_info.description)
1079 fprintf(stderr,
" %s\n", module_info.description);
1081 if (module_info.keywords) {
1082 fprintf(stderr, _(
"\nKeywords:\n"));
1083 fprintf(stderr,
" %s\n", module_info.keywords);
1086 fprintf(stderr, _(
"\nUsage:\n "));
1088 len = show(pgm_name, 1);
1097 for (n = 3; flag !=
NULL; n++, flag = flag->next_flag)
1098 item[n] = flag->key;
1101 len = show(item, len);
1106 opt = &first_option;
1107 while (opt !=
NULL) {
1108 if (opt->key_desc !=
NULL)
1109 key_desc = opt->key_desc;
1110 else if (opt->type == TYPE_STRING)
1111 key_desc =
"string";
1115 n = strlen(opt->key);
1122 strcat(item, opt->key);
1124 strcat(item, key_desc);
1125 if (opt->multiple) {
1127 strcat(item, key_desc);
1128 strcat(item,
",...]");
1133 len = show(item, len);
1135 opt = opt->next_opt;
1139 strcpy(item,
" [--overwrite]");
1140 len = show(item, len);
1143 strcpy(item,
" [--verbose]");
1144 len = show(item, len);
1146 strcpy(item,
" [--quiet]");
1147 len = show(item, len);
1150 fprintf(stderr,
"\n");
1154 fprintf(stderr, _(
"\nFlags:\n"));
1158 while (flag !=
NULL) {
1159 fprintf(stderr,
" -%c ", flag->key);
1162 fprintf(stderr,
"%s\n", flag->label);
1163 if (flag->description)
1164 fprintf(stderr,
" %s\n", flag->description);
1167 else if (flag->description) {
1168 fprintf(stderr,
"%s\n", flag->description);
1171 flag = flag->next_flag;
1176 fprintf(stderr,
" --o %s\n",
1177 _(
"Allow output files to overwrite existing files"));
1179 fprintf(stderr,
" --v %s\n", _(
"Verbose module output"));
1180 fprintf(stderr,
" --q %s\n", _(
"Quiet module output"));
1185 fprintf(stderr, _(
"\nParameters:\n"));
1186 opt = &first_option;
1187 while (opt !=
NULL) {
1188 fprintf(stderr,
" %*s ", maxlen, opt->key);
1191 fprintf(stderr,
"%s\n", opt->label);
1192 if (opt->description) {
1193 fprintf(stderr,
" %*s %s\n",
1194 maxlen,
" ", opt->description);
1197 else if (opt->description) {
1198 fprintf(stderr,
"%s\n", opt->description);
1202 show_options(maxlen, opt->options);
1208 fprintf(stderr, _(
" %*s default: %s\n"), maxlen,
" ",
1214 while (opt->opts[i]) {
1216 fprintf(stderr,
" %*s %s: %s\n",
1217 maxlen,
" ", opt->opts[i], opt->descs[i]);
1223 opt = opt->next_opt;
1238 static void print_escaped_for_xml(FILE * fp,
const char *str)
1240 for (; *str; str++) {
1261 #define do_escape(c,escaped) case c: fputs(escaped,f);break
1262 static void print_escaped_for_html(FILE * f,
const char *str)
1266 for (s = str; *
s; s++) {
1283 static void G_usage_xml(
void)
1293 new_prompt = uses_new_gisprompt();
1297 #if defined(HAVE_LANGINFO_H)
1298 encoding = nl_langinfo(CODESET);
1299 if (!encoding || strlen(encoding) == 0) {
1302 #elif defined(__MINGW32__) && defined(USE_NLS)
1303 encoding = locale_charset();
1304 if (!encoding || strlen(encoding) == 0) {
1316 fprintf(stdout,
"<?xml version=\"1.0\" encoding=\"%s\"?>\n", encoding);
1317 fprintf(stdout,
"<!DOCTYPE task SYSTEM \"grass-interface.dtd\">\n");
1319 fprintf(stdout,
"<task name=\"%s\">\n", pgm_name);
1321 if (module_info.label) {
1322 fprintf(stdout,
"\t<label>\n\t\t");
1323 print_escaped_for_xml(stdout, module_info.label);
1324 fprintf(stdout,
"\n\t</label>\n");
1327 if (module_info.description) {
1328 fprintf(stdout,
"\t<description>\n\t\t");
1329 print_escaped_for_xml(stdout, module_info.description);
1330 fprintf(stdout,
"\n\t</description>\n");
1333 if (module_info.keywords) {
1334 fprintf(stdout,
"\t<keywords>\n\t\t");
1335 print_escaped_for_xml(stdout, module_info.keywords);
1336 fprintf(stdout,
"\n\t</keywords>\n");
1349 opt = &first_option;
1350 while (opt !=
NULL) {
1352 switch (opt->type) {
1366 fprintf(stdout,
"\t<parameter "
1370 "multiple=\"%s\">\n",
1373 opt->required == YES ?
"yes" :
"no",
1374 opt->multiple == YES ?
"yes" :
"no");
1377 fprintf(stdout,
"\t\t<label>\n\t\t\t");
1378 print_escaped_for_xml(stdout, opt->label);
1379 fprintf(stdout,
"\n\t\t</label>\n");
1382 if (opt->description) {
1383 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1384 print_escaped_for_xml(stdout, opt->description);
1385 fprintf(stdout,
"\n\t\t</description>\n");
1388 if (opt->key_desc) {
1389 fprintf(stdout,
"\t\t<keydesc>\n");
1390 top = G_calloc(strlen(opt->key_desc) + 1, 1);
1391 strcpy(top, opt->key_desc);
1392 s = strtok(top,
",");
1393 for (i = 1; s !=
NULL; i++) {
1394 fprintf(stdout,
"\t\t\t<item order=\"%d\">", i);
1395 print_escaped_for_xml(stdout, s);
1396 fprintf(stdout,
"</item>\n");
1397 s = strtok(
NULL,
",");
1399 fprintf(stdout,
"\t\t</keydesc>\n");
1403 if (opt->gisprompt) {
1404 const char *atts[] = {
"age",
"element",
"prompt",
NULL };
1405 top = G_calloc(strlen(opt->gisprompt) + 1, 1);
1406 strcpy(top, opt->gisprompt);
1407 s = strtok(top,
",");
1408 fprintf(stdout,
"\t\t<gisprompt ");
1409 for (i = 0; s !=
NULL && atts[i] !=
NULL; i++) {
1410 fprintf(stdout,
"%s=\"%s\" ", atts[i], s);
1411 s = strtok(
NULL,
",");
1413 fprintf(stdout,
"/>\n");
1418 fprintf(stdout,
"\t\t<default>\n\t\t\t");
1419 print_escaped_for_xml(stdout, opt->def);
1420 fprintf(stdout,
"\n\t\t</default>\n");
1429 fprintf(stdout,
"\t\t<values>\n");
1430 while (opt->opts[i]) {
1431 fprintf(stdout,
"\t\t\t<value>\n");
1432 fprintf(stdout,
"\t\t\t\t<name>");
1433 print_escaped_for_xml(stdout, opt->opts[i]);
1434 fprintf(stdout,
"</name>\n");
1435 if (opt->descs && opt->opts[i] && opt->descs[i]) {
1436 fprintf(stdout,
"\t\t\t\t<description>");
1437 print_escaped_for_xml(stdout, opt->descs[i]);
1438 fprintf(stdout,
"</description>\n");
1440 fprintf(stdout,
"\t\t\t</value>\n");
1443 fprintf(stdout,
"\t\t</values>\n");
1445 if (opt->guisection) {
1446 fprintf(stdout,
"\t\t<guisection>\n\t\t\t");
1447 print_escaped_for_xml(stdout, opt->guisection);
1448 fprintf(stdout,
"\n\t\t</guisection>\n");
1455 opt = opt->next_opt;
1456 fprintf(stdout,
"\t</parameter>\n");
1463 while (flag !=
NULL) {
1464 fprintf(stdout,
"\t<flag name=\"%c\">\n", flag->key);
1467 fprintf(stdout,
"\t\t<label>\n\t\t\t");
1468 print_escaped_for_xml(stdout, flag->label);
1469 fprintf(stdout,
"\n\t\t</label>\n");
1472 if (flag->description) {
1473 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1474 print_escaped_for_xml(stdout, flag->description);
1475 fprintf(stdout,
"\n\t\t</description>\n");
1477 if (flag->guisection) {
1478 fprintf(stdout,
" \t\t<guisection>\n\t\t\t");
1479 print_escaped_for_xml(stdout, flag->guisection);
1480 fprintf(stdout,
"\n\t\t</guisection>\n");
1482 flag = flag->next_flag;
1483 fprintf(stdout,
"\t</flag>\n");
1498 fprintf(stdout,
"\t<flag name=\"%s\">\n",
"overwrite");
1499 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1500 print_escaped_for_xml(stdout,
1501 _(
"Allow output files to overwrite existing files"));
1502 fprintf(stdout,
"\n\t\t</description>\n");
1503 fprintf(stdout,
"\t</flag>\n");
1507 fprintf(stdout,
"\t<flag name=\"%s\">\n",
"verbose");
1508 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1509 print_escaped_for_xml(stdout, _(
"Verbose module output"));
1510 fprintf(stdout,
"\n\t\t</description>\n");
1511 fprintf(stdout,
"\t</flag>\n");
1514 fprintf(stdout,
"\t<flag name=\"%s\">\n",
"quiet");
1515 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1516 print_escaped_for_xml(stdout, _(
"Quiet module output"));
1517 fprintf(stdout,
"\n\t\t</description>\n");
1518 fprintf(stdout,
"\t</flag>\n");
1520 fprintf(stdout,
"</task>\n");
1526 static void G_usage_html(
void)
1533 new_prompt = uses_new_gisprompt();
1541 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
1542 fprintf(stdout,
"<html>\n<head>\n");
1543 fprintf(stdout,
"<title>GRASS GIS manual: %s</title>\n", pgm_name);
1545 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n");
1547 "<link rel=\"stylesheet\" href=\"grassdocs.css\" type=\"text/css\">\n");
1548 fprintf(stdout,
"</head>\n");
1549 fprintf(stdout,
"<body bgcolor=\"white\">\n\n");
1551 "<img src=\"grass_logo.png\" alt=\"GRASS logo\"><hr align=center size=6 noshade>\n\n");
1552 fprintf(stdout,
"<h2>%s</h2>\n", _(
"NAME"));
1553 fprintf(stdout,
"<em><b>%s</b></em> ", pgm_name);
1555 if (module_info.label || module_info.description)
1556 fprintf(stdout,
" - ");
1558 if (module_info.label)
1559 fprintf(stdout,
"%s<BR>\n", module_info.label);
1561 if (module_info.description)
1562 fprintf(stdout,
"%s\n", module_info.description);
1565 fprintf(stdout,
"<h2>%s</h2>\n", _(
"KEYWORDS"));
1566 if (module_info.keywords) {
1567 fprintf(stdout,
"%s", module_info.keywords);
1568 fprintf(stdout,
"\n");
1570 fprintf(stdout,
"<h2>%s</h2>\n", _(
"SYNOPSIS"));
1571 fprintf(stdout,
"<b>%s</b><br>\n", pgm_name);
1572 fprintf(stdout,
"<b>%s help</b><br>\n", pgm_name);
1574 fprintf(stdout,
"<b>%s</b>", pgm_name);
1581 fprintf(stdout,
" [-<b>");
1582 while (flag !=
NULL) {
1583 fprintf(stdout,
"%c", flag->key);
1584 flag = flag->next_flag;
1586 fprintf(stdout,
"</b>] ");
1589 fprintf(stdout,
" ");
1592 opt = &first_option;
1594 while (opt !=
NULL) {
1595 if (opt->key_desc !=
NULL)
1596 type = opt->key_desc;
1598 switch (opt->type) {
1613 fprintf(stdout,
" [");
1614 fprintf(stdout,
"<b>%s</b>=<em>%s</em>", opt->key, type);
1615 if (opt->multiple) {
1616 fprintf(stdout,
"[,<i>%s</i>,...]", type);
1619 fprintf(stdout,
"] ");
1621 opt = opt->next_opt;
1622 fprintf(stdout,
" ");
1626 fprintf(stdout,
" [--<b>overwrite</b>] ");
1628 fprintf(stdout,
" [--<b>verbose</b>] ");
1629 fprintf(stdout,
" [--<b>quiet</b>] ");
1631 fprintf(stdout,
"\n");
1635 fprintf(stdout,
"\n");
1636 if (n_flags || new_prompt) {
1638 fprintf(stdout,
"<h3>%s:</h3>\n", _(
"Flags"));
1639 fprintf(stdout,
"<DL>\n");
1640 while (n_flags && flag !=
NULL) {
1641 fprintf(stdout,
"<DT><b>-%c</b></DT>\n", flag->key);
1644 fprintf(stdout,
"<DD>");
1645 fprintf(stdout,
"%s", flag->label);
1646 fprintf(stdout,
"</DD>\n");
1649 if (flag->description) {
1650 fprintf(stdout,
"<DD>");
1651 fprintf(stdout,
"%s", flag->description);
1652 fprintf(stdout,
"</DD>\n");
1655 flag = flag->next_flag;
1656 fprintf(stdout,
"\n");
1659 fprintf(stdout,
"<DT><b>--overwrite</b></DT>\n");
1660 fprintf(stdout,
"<DD>%s</DD>\n",
1661 _(
"Allow output files to overwrite existing files"));
1664 fprintf(stdout,
"<DT><b>--verbose</b></DT>\n");
1665 fprintf(stdout,
"<DD>%s</DD>\n", _(
"Verbose module output"));
1667 fprintf(stdout,
"<DT><b>--quiet</b></DT>\n");
1668 fprintf(stdout,
"<DD>%s</DD>\n", _(
"Quiet module output"));
1670 fprintf(stdout,
"</DL>\n");
1673 fprintf(stdout,
"\n");
1675 opt = &first_option;
1676 fprintf(stdout,
"<h3>%s:</h3>\n", _(
"Parameters"));
1677 fprintf(stdout,
"<DL>\n");
1679 while (opt !=
NULL) {
1681 if (opt->key_desc !=
NULL)
1682 type = opt->key_desc;
1684 switch (opt->type) {
1698 fprintf(stdout,
"<DT><b>%s</b>=<em>%s", opt->key, type);
1699 if (opt->multiple) {
1700 fprintf(stdout,
"[,<i>%s</i>,...]", type);
1702 fprintf(stdout,
"</em></DT>\n");
1705 fprintf(stdout,
"<DD>");
1706 fprintf(stdout,
"%s", opt->label);
1707 fprintf(stdout,
"</DD>\n");
1709 if (opt->description) {
1710 fprintf(stdout,
"<DD>");
1711 print_escaped_for_html(stdout, opt->description);
1712 fprintf(stdout,
"</DD>\n");
1716 fprintf(stdout,
"<DD>%s: <em>", _(
"Options"));
1717 fprintf(stdout,
"%s", opt->options);
1718 fprintf(stdout,
"</em></DD>\n");
1722 fprintf(stdout,
"<DD>%s: <em>", _(
"Default"));
1723 fprintf(stdout,
"%s", opt->def);
1724 fprintf(stdout,
"</em></DD>\n");
1730 while (opt->opts[i]) {
1732 fprintf(stdout,
"<DD><b>%s</b>: %s</DD>\n",
1733 opt->opts[i], opt->descs[i]);
1738 opt = opt->next_opt;
1739 fprintf(stdout,
"\n");
1741 fprintf(stdout,
"</DL>\n");
1744 fprintf(stdout,
"</body>\n</html>\n");
1750 static void G_script(
void)
1755 fprintf(fp,
"#!/bin/sh\n\n");
1757 "############################################################################\n");
1760 fprintf(fp,
"# AUTHOR(S): %s\n",
G_whoami());
1761 fprintf(fp,
"# PURPOSE: \n");
1762 fprintf(fp,
"# COPYRIGHT: (C) 2009 GRASS Development Team/%s\n",
1766 "# This program is free software; you can redistribute it and/or modify\n");
1768 "# it under the terms of the GNU General Public License as published by\n");
1770 "# the Free Software Foundation; either version 2 of the License, or\n");
1771 fprintf(fp,
"# (at your option) any later version.\n");
1774 "# This program is distributed in the hope that it will be useful,\n");
1776 "# but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
1778 "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
1779 fprintf(fp,
"# GNU General Public License for more details.\n");
1782 "############################################################################\n");
1784 fprintf(fp,
"#%%Module\n");
1785 if (module_info.label)
1786 fprintf(fp,
"#%% label: %s\n", module_info.label);
1787 if (module_info.description)
1788 fprintf(fp,
"#%% description: %s\n", module_info.description);
1789 if (module_info.keywords)
1790 fprintf(fp,
"#%% keywords: %s\n", module_info.keywords);
1791 fprintf(fp,
"#%%End\n");
1796 for (flag = &first_flag;
flag; flag = flag->next_flag) {
1797 fprintf(fp,
"#%%Flag\n");
1798 fprintf(fp,
"#%% key: %c\n", flag->key);
1800 fprintf(fp,
"#%% label: %s\n", flag->label);
1801 if (flag->description)
1802 fprintf(fp,
"#%% description: %s\n", flag->description);
1803 if (flag->guisection)
1804 fprintf(fp,
"#%% guisection: %s\n", flag->guisection);
1805 fprintf(fp,
"#%%End\n");
1812 for (opt = &first_option; opt; opt = opt->next_opt) {
1813 switch (opt->type) {
1828 fprintf(fp,
"#%%Option\n");
1829 fprintf(fp,
"#%% key: %s\n", opt->key);
1830 fprintf(fp,
"#%% type: %s\n", type);
1831 fprintf(fp,
"#%% required: %s\n", opt->required ?
"yes" :
"no");
1832 fprintf(fp,
"#%% multiple: %s\n", opt->multiple ?
"yes" :
"no");
1834 fprintf(fp,
"#%% options: %s\n", opt->options);
1836 fprintf(fp,
"#%% key_desc: %s\n", opt->key_desc);
1838 fprintf(fp,
"#%% label: %s\n", opt->label);
1839 if (opt->description)
1840 fprintf(fp,
"#%% description: %s\n", opt->description);
1841 if (opt->descriptions)
1842 fprintf(fp,
"#%% descriptions: %s\n", opt->descriptions);
1844 fprintf(fp,
"#%% answer: %s\n", opt->answer);
1846 fprintf(fp,
"#%% gisprompt: %s\n", opt->gisprompt);
1847 if (opt->guisection)
1848 fprintf(fp,
"#%% guisection: %s\n", opt->guisection);
1849 fprintf(fp,
"#%%End\n");
1854 "\nif [ -z \"$GISBASE\" ] ; then\n"
1855 " echo \"You must be in GRASS GIS to run this program.\" 1>&2\n"
1859 "if [ \"$1\" != \"@ARGS_PARSED@\" ] ; then\n"
1860 " exec g.parser \"$0\" \"$@\"\n"
1861 "fi\n" "\n" "# CODE GOES HERE\n" "\n");
1869 static void generate_tcl(FILE * fp)
1871 int new_prompt = uses_new_gisprompt();
1875 fprintf(fp,
"begin_dialog {%s} {\n", pgm_name);
1876 fprintf(fp,
" label {%s}\n", module_info.label ? module_info.label :
"");
1877 fprintf(fp,
" desc {%s}\n",
1878 module_info.description ? module_info.description :
"");
1879 fprintf(fp,
" key {%s}\n",
1880 module_info.keywords ? module_info.keywords :
"");
1888 for (flag = &first_flag;
flag; flag = flag->next_flag, optn++) {
1889 fprintf(fp,
"add_flag %d {\n", optn);
1890 fprintf(fp,
" name {%c}\n", flag->key);
1891 fprintf(fp,
" desc {%s}\n", flag->description);
1892 fprintf(fp,
" answer %d\n", flag->answer);
1895 fprintf(fp,
" label {%s}\n", flag->label ? flag->label :
"");
1896 fprintf(fp,
" guisection {%s}\n",
1897 flag->guisection ? flag->guisection :
"");
1905 for (opt = &first_option; opt; opt = opt->next_opt, optn++) {
1906 if (opt->key_desc !=
NULL)
1907 type = opt->key_desc;
1909 switch (opt->type) {
1924 fprintf(fp,
"add_option %d {\n", optn);
1925 fprintf(fp,
" name {%s}\n", opt->key);
1926 fprintf(fp,
" type {%s}\n", type);
1927 fprintf(fp,
" multi %d\n", opt->multiple);
1928 fprintf(fp,
" desc {%s}\n", opt->description);
1929 fprintf(fp,
" required %d\n", opt->required);
1930 fprintf(fp,
" options {%s}\n", opt->options ? opt->options :
"");
1931 fprintf(fp,
" descs {%s}\n",
1932 opt->descriptions ? opt->descriptions :
"");
1933 fprintf(fp,
" answer {%s}\n", opt->answer ? opt->answer :
"");
1934 fprintf(fp,
" prompt {%s}\n",
1935 opt->gisprompt ? opt->gisprompt :
"");
1938 fprintf(fp,
" label {%s}\n", opt->label ? opt->label :
"");
1939 fprintf(fp,
" guisection {%s}\n",
1940 opt->guisection ? opt->guisection :
"");
1946 fprintf(fp,
"add_xflag %d {\n", optn);
1947 fprintf(fp,
" name {overwrite}\n");
1948 fprintf(fp,
" desc {%s}\n",
1949 _(
"Allow output files to overwrite existing files"));
1950 fprintf(fp,
" answer %d\n", overwrite);
1951 fprintf(fp,
" label {%s}\n", _(
"Allow overwrite"));
1952 fprintf(fp,
" guisection {}\n");
1957 fprintf(fp,
"add_xflag %d {\n", optn);
1958 fprintf(fp,
" name {quiet}\n");
1959 fprintf(fp,
" desc {%s}\n", _(
"Run with minimal output messages"));
1960 fprintf(fp,
" answer %d\n", quiet);
1961 fprintf(fp,
" label {%s}\n", _(
"Run quietly"));
1962 fprintf(fp,
" guisection {}\n");
1966 fprintf(fp,
"end_dialog %d\n", optn - 1);
1972 static void G_gui_tcltk(
void)
1982 if (
getenv(
"GRASS_DEBUG_GUI"))
1983 fp = popen(
"tee gui_dump.tcl | \"%GRASS_WISH%\"",
"w");
1985 fp = popen(
"\"%GRASS_WISH%\"",
"w");
1987 if (
getenv(
"GRASS_DEBUG_GUI"))
1988 fp = popen(
"tee gui_dump.tcl | \"$GRASS_WISH\"",
"w");
1990 fp = popen(
"\"$GRASS_WISH\"",
"w");
1996 fprintf(fp,
"source $env(GISBASE)/etc/gui.tcl\n");
2006 static void G_gui_wx(
void)
2008 char script[GPATH_MAX];
2015 sprintf(script,
"%s/etc/wxpython/gui_core/forms.py",
2027 static void G_gui(
void)
2030 char *gui =
getenv(
"GRASS_GUI");
2036 if (gui && (strcmp(gui,
"tcltk") == 0 || strcmp(gui,
"oldtcltk") == 0))
2047 static void G_tcltk(
void)
2054 generate_tcl(stdout);
2064 static int show_options(
int maxlen,
const char *str)
2070 fprintf(stderr, _(
" %*s options: "), maxlen,
" ");
2071 totlen = maxlen + 13;
2073 while ((p2 =
G_index(p1,
','))) {
2075 len = strlen(p1) + 1;
2076 if ((len + totlen) > 76) {
2077 totlen = maxlen + 13;
2078 fprintf(stderr,
"\n %*s", maxlen + 13,
" ");
2080 fprintf(stderr,
"%s,", p1);
2085 if ((len + totlen) > 76)
2086 fprintf(stderr,
"\n %*s", maxlen + 13,
" ");
2087 fprintf(stderr,
"%s\n", p1);
2094 static int show(
const char *item,
int len)
2098 n = strlen(item) + (len > 0);
2101 fprintf(stderr,
"\n ");
2104 fprintf(stderr,
"%s", item);
2108 static int set_flag(
int f)
2115 fprintf(stderr, _(
"Sorry, <%c> is not a valid flag\n"), f);
2122 while (flag !=
NULL) {
2123 if (flag->key == f) {
2127 flag = flag->next_flag;
2130 fprintf(stderr, _(
"Sorry, <%c> is not a valid flag\n"), f);
2137 static int contains(
const char *s,
int c)
2147 static int is_option(
const char *
string)
2149 const char *p = strchr(
string,
'=');
2156 if (!strchr(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", *p))
2162 static int set_option(
char *
string)
2164 struct Option *at_opt =
NULL;
2165 struct Option *opt =
NULL;
2171 for (ptr = the_key; *
string !=
'='; ptr++,
string++)
2178 key_len = strlen(the_key);
2179 for (at_opt = &first_option; at_opt !=
NULL; at_opt = at_opt->next_opt) {
2180 if (at_opt->key ==
NULL || strncmp(the_key, at_opt->key, key_len))
2188 if (strlen(at_opt->key) == key_len) {
2196 fprintf(stderr, _(
"Sorry, <%s=> is ambiguous\n"), the_key);
2202 fprintf(stderr, _(
"Sorry, <%s> is not a valid parameter\n"), the_key);
2208 if (!opt->multiple) {
2209 fprintf(stderr, _(
"Option <%s> does not accept multiple answers\n"), the_key);
2212 opt->answer = (
char *)G_realloc(opt->answer,
2213 strlen(opt->answer) + strlen(
string) +
2215 strcat(opt->answer,
",");
2216 strcat(opt->answer,
string);
2219 opt->answer =
G_store(
string);
2223 static int check_opts(
void)
2234 opt = &first_option;
2235 while (opt !=
NULL) {
2238 if (opt->options && opt->answer) {
2239 if (opt->multiple == 0)
2240 error += check_an_opt(opt->key, opt->type,
2241 opt->options, opt->answer);
2243 for (ans = 0; opt->answers[ans] !=
'\0'; ans++)
2244 error += check_an_opt(opt->key, opt->type,
2245 opt->options, opt->answers[ans]);
2252 error += opt->checker(opt->answer);
2254 opt = opt->next_opt;
2259 static int check_an_opt(
const char *key,
int type,
const char *options,
2268 error = check_int(answer, options);
2271 error = check_double(answer, options);
2274 error = check_string(answer, options);
2287 _(
"\nERROR: illegal range syntax for parameter <%s>\n"), key);
2288 fprintf(stderr, _(
" Presented as: %s\n"), options);
2292 _(
"\nERROR: value <%s> out of range for parameter <%s>\n"),
2294 fprintf(stderr, _(
" Legal range: %s\n"), options);
2297 fprintf(stderr, _(
"\nERROR: Missing value for parameter <%s>\n"),
2303 static int check_int(
const char *ans,
const char *opts)
2307 if (1 != sscanf(ans,
"%d", &d))
2310 if (contains(opts,
'-')) {
2311 if (2 != sscanf(opts,
"%d-%d", &lo, &hi))
2313 if (d < lo || d > hi)
2318 else if (contains(opts,
',')) {
2320 if (1 != sscanf(opts,
"%d", &lo))
2324 while (*opts !=
'\0' && *opts !=
',')
2328 if (*(++opts) ==
'\0')
2333 if (1 != sscanf(opts,
"%d", &lo))
2367 static int check_double(
const char *ans,
const char *opts)
2371 if (1 != sscanf(ans,
"%lf", &d))
2374 if (contains(opts,
'-')) {
2375 if (2 != sscanf(opts,
"%lf-%lf", &lo, &hi))
2377 if (d < lo || d > hi)
2382 else if (contains(opts,
',')) {
2384 if (1 != sscanf(opts,
"%lf", &lo))
2388 while (*opts !=
'\0' && *opts !=
',')
2392 if (*(++opts) ==
'\0')
2397 if (1 != sscanf(opts,
"%lf", &lo))
2405 static int check_string(
const char *ans,
const char *opts)
2410 if (contains(opts,
',')) {
2412 if ((!strncmp(ans, opts, strlen(ans)))
2413 && (*(opts + strlen(ans)) ==
','
2414 || *(opts + strlen(ans)) ==
'\0'))
2416 while (*opts !=
'\0' && *opts !=
',')
2420 if (*(++opts) ==
'\0')
2425 if (!strcmp(ans, opts))
2431 static int check_required(
void)
2441 opt = &first_option;
2442 while (opt !=
NULL) {
2443 if (opt->required && opt->answer ==
NULL) {
2445 _(
"ERROR: Required parameter <%s> not set:\n\t(%s)\n"),
2446 opt->key, (opt->label ? opt->label : opt->description) );
2449 opt = opt->next_opt;
2455 static int split_opts(
void)
2468 opt = &first_option;
2469 while (opt !=
NULL) {
2470 if ( (opt->answer !=
NULL)) {
2473 opt->answers = (
char **)G_malloc(allocated *
sizeof(
char *));
2477 opt->answers[ans_num] =
NULL;
2480 for (len = 0, ptr2 = ptr1; *ptr2 !=
'\0' && *ptr2 !=
',';
2484 opt->answers[ans_num] = (
char *)G_malloc(len + 1);
2485 G_copy(opt->answers[ans_num], ptr1, len);
2486 opt->answers[ans_num][len] = 0;
2490 if (ans_num >= allocated) {
2493 (
char **)G_realloc((
char *)opt->answers,
2494 allocated *
sizeof(
char *));
2497 opt->answers[ans_num] =
NULL;
2509 opt = opt->next_opt;
2515 static int check_multiple_opts(
void)
2527 opt = &first_option;
2528 while (opt !=
NULL) {
2529 if ((opt->answer !=
NULL) && (opt->key_desc !=
NULL)) {
2532 for (ptr = opt->key_desc; *ptr !=
'\0'; ptr++)
2536 for (n = 0; opt->answers[n] !=
'\0'; n++) ;
2540 _(
"\nERROR: option <%s> must be provided in multiples of %d\n"),
2541 opt->key, n_commas);
2542 fprintf(stderr, _(
" You provided %d items:\n"), n);
2543 fprintf(stderr,
" %s\n", opt->answer);
2547 opt = opt->next_opt;
2553 static int check_overwrite(
void)
2568 if ((overstr =
G__getenv(
"OVERWRITE"))) {
2569 over = atoi(overstr);
2573 if ((overstr =
getenv(
"GRASS_OVERWRITE"))) {
2578 if (overwrite || over) {
2579 module_info.overwrite = 1;
2581 putenv(
"GRASS_OVERWRITE=1");
2586 opt = &first_option;
2587 while (opt !=
NULL) {
2588 if ((opt->answer !=
NULL) && (opt->gisprompt !=
NULL)) {
2589 split_gisprompt(opt->gisprompt, age, element, desc);
2591 if (strcmp(age,
"new") == 0) {
2593 for (i = 0; opt->answers[i]; i++) {
2595 if (!overwrite && !over) {
2598 _(
"ERROR: option <%s>: <%s> exists.\n"),
2599 opt->key, opt->answers[i]);
2603 "GRASS_INFO_ERROR(%d,1): option <%s>: <%s> exists.\n",
2604 getpid(), opt->key, opt->answers[i]);
2605 fprintf(stderr,
"GRASS_INFO_END(%d,1)\n",
2615 opt = opt->next_opt;
2621 static int interactive(
const char *
command)
2628 fprintf(stderr,
"PROGRAMMER ERROR: no flags or options\n");
2632 for (item = &first_item;;) {
2634 interactive_flag(item->
flag);
2636 interactive_option(item->
option);
2649 static int interactive_flag(
struct Flag *flag)
2653 fprintf(stderr, _(
"\nFLAG: Set the following flag?\n"));
2654 sprintf(buff,
" %s?", flag->description);
2655 flag->answer =
G_yes(buff, 0);
2660 static int interactive_option(
struct Option *opt)
2662 char buff[1024], *bptr;
2667 fprintf(stderr, _(
"\nOPTION: %s\n"), opt->description);
2668 fprintf(stderr, _(
" key: %s\n"), opt->key);
2670 fprintf(stderr, _(
" format: %s\n"), opt->key_desc);
2672 fprintf(stderr, _(
" default: %s\n"), opt->def);
2673 fprintf(stderr, _(
"required: %s\n"), opt->required ?
"YES" :
"NO");
2675 fprintf(stderr, _(
"multiple: %s\n"), opt->multiple ?
"YES" :
"NO");
2677 fprintf(stderr, _(
" options: %s\n"), opt->options);
2686 no_prompt = gis_prompt(opt, buff);
2690 fprintf(stderr, _(
"enter option > "));
2691 if (fgets(buff, 1024, stdin) == 0)
2692 exit(EXIT_SUCCESS);;
2702 if (strlen(buff) != 0) {
2706 if (check_an_opt(opt->key, opt->type, opt->options, buff)) {
2707 if (
G_yes(_(
" Try again? "), 1))
2714 if (opt->checker(buff)) {
2715 fprintf(stderr, _(
"Sorry, %s is not accepted.\n"), buff);
2717 if (
G_yes(_(
" Try again? "), 1))
2723 sprintf(buff2,
"%s=%s", opt->key, buff);
2724 if (!opt->gisprompt) {
2725 fprintf(stderr, _(
"\nYou have chosen:\n %s\n"), buff2);
2726 if (
G_yes(_(
"Is this correct? "), 1)) {
2737 if ((strlen(buff) == 0) && opt->required && (set_one == 0))
2739 if ((strlen(buff) == 0) && (set_one > 0) && opt->multiple)
2741 if ((strlen(buff) == 0) && !opt->required)
2743 if ((set_one == 1) && !opt->multiple)
2749 static int split_gisprompt(
const char *gisprompt,
char *age,
char *element,
2755 for (ptr1 = gisprompt, ptr2 = age; *ptr1 !=
'\0'; ptr1++, ptr2++) {
2762 for (ptr1++, ptr2 = element; *ptr1 !=
'\0'; ptr1++, ptr2++) {
2769 for (ptr1++, ptr2 = desc; *ptr1 !=
'\0'; ptr1++, ptr2++) {
2779 static int gis_prompt(
struct Option *opt,
char *buff)
2786 split_gisprompt(opt->gisprompt, age, element, desc);
2792 if (!strcmp(
"old", age)) {
2793 ptr1 =
G_ask_old(
"", buff, element, desc);
2798 else if (!strcmp(
"new", age))
2799 ptr1 =
G_ask_new(
"", buff, element, desc);
2800 else if (!strcmp(
"mapset", age))
2802 else if (!strcmp(
"any", age))
2803 ptr1 =
G_ask_any(
"", buff, element, desc, 1);
2804 else if (!strcmp(
"old_file", age))
2806 else if (!strcmp(
"new_file", age))
2837 G_debug(3,
"G_recreate_command()");
2841 buff = G_calloc(1024,
sizeof(
char));
2845 if (len >= nalloced) {
2846 nalloced += (1024 > len) ? 1024 : len + 1;
2847 buff = G_realloc(buff, nalloced);
2855 while (flag !=
'\0') {
2856 if (flag->answer == 1) {
2862 if (len + slen >= nalloced) {
2864 (nalloced + 1024 > len + slen) ? 1024 : slen + 1;
2865 buff = G_realloc(buff, nalloced);
2872 flag = flag->next_flag;
2876 opt = &first_option;
2877 while (opt !=
'\0') {
2878 if (opt->answer !=
'\0' && opt->answers && opt->answers[0] !=
NULL) {
2879 slen = strlen(opt->key) + strlen(opt->answers[0]) + 4;
2880 if (len + slen >= nalloced) {
2881 nalloced += (nalloced + 1024 > len + slen) ? 1024 : slen + 1;
2882 buff = G_realloc(buff, nalloced);
2887 strcpy(cur, opt->key);
2888 cur = strchr(cur,
'\0');
2891 if (opt->type == TYPE_STRING) {
2895 strcpy(cur, opt->answers[0]);
2896 cur = strchr(cur,
'\0');
2898 for (n = 1; opt->answers[n] !=
NULL && opt->answers[n] !=
'\0';
2900 if (opt->answers[n] ==
NULL)
2902 slen = strlen(opt->answers[n]) + 2;
2903 if (len + slen >= nalloced) {
2905 (nalloced + 1024 > len + slen) ? 1024 : slen + 1;
2906 buff = G_realloc(buff, nalloced);
2911 strcpy(cur, opt->answers[n]);
2912 cur = strchr(cur,
'\0');
2915 if (opt->type == TYPE_STRING) {
2921 opt = opt->next_opt;