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 to 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->description = _(
"Field separator");
659 Opt->type = TYPE_STRING;
660 Opt->key_desc =
"name";
662 Opt->answer = DEFAULT_FG_COLOR;
663 Opt->gisprompt =
"old_color,color,color";
664 Opt->label = _(
"Color");
665 Opt->description = _(
"Either a standard color name or R:G:B triplet");
668 Opt->key =
"bgcolor";
669 Opt->type = TYPE_STRING;
670 Opt->key_desc =
"name";
672 Opt->answer = DEFAULT_BG_COLOR;
673 Opt->gisprompt =
"old_color,color,color_none";
674 Opt->label = _(
"Background color");
676 _(
"Either a standard GRASS color, R:G:B triplet, or \"none\"");
692 struct GModule *module;
696 module = &module_info;
700 G_zero((
char *)module,
sizeof(
struct GModule));
747 char *ptr, *tmp_name;
750 char force_gui =
FALSE;
754 i = strlen(tmp_name =
G_store(argv[0]));
767 while (opt !=
NULL) {
771 char **tokens, delm[2];
784 (
const char **)G_calloc(cnt + 1,
sizeof(
const char *));
788 opt->opts[i] =
G_store(tokens[i]);
793 if (opt->descriptions) {
797 (
const char **)G_calloc(cnt + 1,
sizeof(
const char *));
809 while (opt->opts[j]) {
810 if (strcmp(opt->opts[j], tokens[i]) == 0) {
817 G_warning(_(
"BUG in descriptions, option '%s' in <%s> does not exist"),
818 tokens[i], opt->key);
821 opt->descs[j] =
G_store(tokens[i + 1]);
831 if (opt->multiple && opt->answers && opt->answers[0]) {
832 opt->answer = (
char *)G_malloc(strlen(opt->answers[0]) + 1);
833 strcpy(opt->answer, opt->answers[0]);
834 for (i = 1; opt->answers[i]; i++) {
835 opt->answer = (
char *)G_realloc(opt->answer,
836 strlen(opt->answer) +
837 strlen(opt->answers[i]) + 2);
838 strcat(opt->answer,
",");
839 strcat(opt->answer, opt->answers[i]);
842 opt->def = opt->answer;
848 if (argc < 2 && interactive_ok && isatty(0)) {
849 if (
getenv(
"GRASS_UI_TERM")) {
850 interactive(argv[0]);
859 else if (argc < 2 && isatty(0)) {
863 else if (argc >= 2) {
866 if (strcmp(argv[1],
"help") == 0 ||
867 strcmp(argv[1],
"-help") == 0 || strcmp(argv[1],
"--help") == 0) {
874 if (strcmp(argv[1],
"--interface-description") == 0) {
881 if (strcmp(argv[1],
"--html-description") == 0) {
888 if (strcmp(argv[1],
"--tcltk") == 0) {
895 if (strcmp(argv[1],
"--script") == 0) {
905 if (strcmp(ptr,
"help") == 0 ||
906 strcmp(ptr,
"-help") == 0 || strcmp(ptr,
"--help") == 0) {
912 if (strcmp(ptr,
"--o") == 0 || strcmp(ptr,
"--overwrite") == 0) {
917 else if (strcmp(ptr,
"--v") == 0 || strcmp(ptr,
"--verbose") == 0) {
925 G_warning(_(
"Use either --quiet or --verbose flag, not both. Assuming --verbose."));
931 else if (strcmp(ptr,
"--q") == 0 || strcmp(ptr,
"--quiet") == 0) {
939 G_warning(_(
"Use either --quiet or --verbose flag, not both. Assuming --quiet."));
945 else if (strcmp(ptr,
"--ui") == 0) {
950 else if (*ptr ==
'-') {
952 error += set_flag(*ptr);
956 else if (is_option(ptr)) {
957 error += set_option(ptr);
962 else if (need_first_opt && n_opts) {
963 first_option.answer =
G_store(ptr);
964 first_option.count++;
969 else if (contains(ptr,
'=') == 0) {
970 fprintf(stderr, _(
"Sorry <%s> is not a valid option\n"), ptr);
987 error += check_multiple_opts();
991 error += check_opts();
994 error += check_required();
1002 if (check_overwrite())
1009 static int uses_new_gisprompt(
void)
1019 opt = &first_option;
1020 while (opt !=
NULL) {
1021 if (opt->gisprompt) {
1022 split_gisprompt(opt->gisprompt, age, element, desc);
1023 if (strcmp(age,
"new") == 0)
1026 opt = opt->next_opt;
1061 const char *key_desc;
1066 new_prompt = uses_new_gisprompt();
1073 if (module_info.label || module_info.description) {
1074 fprintf(stderr, _(
"\nDescription:\n"));
1075 if (module_info.label)
1076 fprintf(stderr,
" %s\n", module_info.label);
1077 if (module_info.description)
1078 fprintf(stderr,
" %s\n", module_info.description);
1080 if (module_info.keywords) {
1081 fprintf(stderr, _(
"\nKeywords:\n"));
1082 fprintf(stderr,
" %s\n", module_info.keywords);
1085 fprintf(stderr, _(
"\nUsage:\n "));
1087 len = show(pgm_name, 1);
1096 for (n = 3; flag !=
NULL; n++, flag = flag->next_flag)
1097 item[n] = flag->key;
1100 len = show(item, len);
1105 opt = &first_option;
1106 while (opt !=
NULL) {
1107 if (opt->key_desc !=
NULL)
1108 key_desc = opt->key_desc;
1109 else if (opt->type == TYPE_STRING)
1110 key_desc =
"string";
1114 n = strlen(opt->key);
1121 strcat(item, opt->key);
1123 strcat(item, key_desc);
1124 if (opt->multiple) {
1126 strcat(item, key_desc);
1127 strcat(item,
",...]");
1132 len = show(item, len);
1134 opt = opt->next_opt;
1138 strcpy(item,
" [--overwrite]");
1139 len = show(item, len);
1142 strcpy(item,
" [--verbose]");
1143 len = show(item, len);
1145 strcpy(item,
" [--quiet]");
1146 len = show(item, len);
1149 fprintf(stderr,
"\n");
1153 fprintf(stderr, _(
"\nFlags:\n"));
1157 while (flag !=
NULL) {
1158 fprintf(stderr,
" -%c ", flag->key);
1161 fprintf(stderr,
"%s\n", flag->label);
1162 if (flag->description)
1163 fprintf(stderr,
" %s\n", flag->description);
1166 else if (flag->description) {
1167 fprintf(stderr,
"%s\n", flag->description);
1170 flag = flag->next_flag;
1175 fprintf(stderr,
" --o %s\n",
1176 _(
"Allow output files to overwrite existing files"));
1178 fprintf(stderr,
" --v %s\n", _(
"Verbose module output"));
1179 fprintf(stderr,
" --q %s\n", _(
"Quiet module output"));
1184 fprintf(stderr, _(
"\nParameters:\n"));
1185 opt = &first_option;
1186 while (opt !=
NULL) {
1187 fprintf(stderr,
" %*s ", maxlen, opt->key);
1190 fprintf(stderr,
"%s\n", opt->label);
1191 if (opt->description) {
1192 fprintf(stderr,
" %*s %s\n",
1193 maxlen,
" ", opt->description);
1196 else if (opt->description) {
1197 fprintf(stderr,
"%s\n", opt->description);
1201 show_options(maxlen, opt->options);
1207 fprintf(stderr, _(
" %*s default: %s\n"), maxlen,
" ",
1213 while (opt->opts[i]) {
1215 fprintf(stderr,
" %*s %s: %s\n",
1216 maxlen,
" ", opt->opts[i], opt->descs[i]);
1222 opt = opt->next_opt;
1237 static void print_escaped_for_xml(FILE * fp,
const char *str)
1239 for (; *str; str++) {
1260 #define do_escape(c,escaped) case c: fputs(escaped,f);break
1261 static void print_escaped_for_html(FILE * f,
const char *str)
1265 for (s = str; *
s; s++) {
1282 static void G_usage_xml(
void)
1292 new_prompt = uses_new_gisprompt();
1296 #if defined(HAVE_LANGINFO_H)
1297 encoding = nl_langinfo(CODESET);
1298 if (!encoding || strlen(encoding) == 0) {
1301 #elif defined(__MINGW32__) && defined(USE_NLS)
1302 encoding = locale_charset();
1303 if (!encoding || strlen(encoding) == 0) {
1315 fprintf(stdout,
"<?xml version=\"1.0\" encoding=\"%s\"?>\n", encoding);
1316 fprintf(stdout,
"<!DOCTYPE task SYSTEM \"grass-interface.dtd\">\n");
1318 fprintf(stdout,
"<task name=\"%s\">\n", pgm_name);
1320 if (module_info.label) {
1321 fprintf(stdout,
"\t<label>\n\t\t");
1322 print_escaped_for_xml(stdout, module_info.label);
1323 fprintf(stdout,
"\n\t</label>\n");
1326 if (module_info.description) {
1327 fprintf(stdout,
"\t<description>\n\t\t");
1328 print_escaped_for_xml(stdout, module_info.description);
1329 fprintf(stdout,
"\n\t</description>\n");
1332 if (module_info.keywords) {
1333 fprintf(stdout,
"\t<keywords>\n\t\t");
1334 print_escaped_for_xml(stdout, module_info.keywords);
1335 fprintf(stdout,
"\n\t</keywords>\n");
1348 opt = &first_option;
1349 while (opt !=
NULL) {
1351 switch (opt->type) {
1365 fprintf(stdout,
"\t<parameter "
1369 "multiple=\"%s\">\n",
1372 opt->required == YES ?
"yes" :
"no",
1373 opt->multiple == YES ?
"yes" :
"no");
1376 fprintf(stdout,
"\t\t<label>\n\t\t\t");
1377 print_escaped_for_xml(stdout, opt->label);
1378 fprintf(stdout,
"\n\t\t</label>\n");
1381 if (opt->description) {
1382 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1383 print_escaped_for_xml(stdout, opt->description);
1384 fprintf(stdout,
"\n\t\t</description>\n");
1387 if (opt->key_desc) {
1388 fprintf(stdout,
"\t\t<keydesc>\n");
1389 top = G_calloc(strlen(opt->key_desc) + 1, 1);
1390 strcpy(top, opt->key_desc);
1391 s = strtok(top,
",");
1392 for (i = 1; s !=
NULL; i++) {
1393 fprintf(stdout,
"\t\t\t<item order=\"%d\">", i);
1394 print_escaped_for_xml(stdout, s);
1395 fprintf(stdout,
"</item>\n");
1396 s = strtok(
NULL,
",");
1398 fprintf(stdout,
"\t\t</keydesc>\n");
1402 if (opt->gisprompt) {
1403 const char *atts[] = {
"age",
"element",
"prompt",
NULL };
1404 top = G_calloc(strlen(opt->gisprompt) + 1, 1);
1405 strcpy(top, opt->gisprompt);
1406 s = strtok(top,
",");
1407 fprintf(stdout,
"\t\t<gisprompt ");
1408 for (i = 0; s !=
NULL && atts[i] !=
NULL; i++) {
1409 fprintf(stdout,
"%s=\"%s\" ", atts[i], s);
1410 s = strtok(
NULL,
",");
1412 fprintf(stdout,
"/>\n");
1417 fprintf(stdout,
"\t\t<default>\n\t\t\t");
1418 print_escaped_for_xml(stdout, opt->def);
1419 fprintf(stdout,
"\n\t\t</default>\n");
1428 fprintf(stdout,
"\t\t<values>\n");
1429 while (opt->opts[i]) {
1430 fprintf(stdout,
"\t\t\t<value>\n");
1431 fprintf(stdout,
"\t\t\t\t<name>");
1432 print_escaped_for_xml(stdout, opt->opts[i]);
1433 fprintf(stdout,
"</name>\n");
1434 if (opt->descs && opt->opts[i] && opt->descs[i]) {
1435 fprintf(stdout,
"\t\t\t\t<description>");
1436 print_escaped_for_xml(stdout, opt->descs[i]);
1437 fprintf(stdout,
"</description>\n");
1439 fprintf(stdout,
"\t\t\t</value>\n");
1442 fprintf(stdout,
"\t\t</values>\n");
1444 if (opt->guisection) {
1445 fprintf(stdout,
"\t\t<guisection>\n\t\t\t");
1446 print_escaped_for_xml(stdout, opt->guisection);
1447 fprintf(stdout,
"\n\t\t</guisection>\n");
1454 opt = opt->next_opt;
1455 fprintf(stdout,
"\t</parameter>\n");
1462 while (flag !=
NULL) {
1463 fprintf(stdout,
"\t<flag name=\"%c\">\n", flag->key);
1466 fprintf(stdout,
"\t\t<label>\n\t\t\t");
1467 print_escaped_for_xml(stdout, flag->label);
1468 fprintf(stdout,
"\n\t\t</label>\n");
1471 if (flag->description) {
1472 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1473 print_escaped_for_xml(stdout, flag->description);
1474 fprintf(stdout,
"\n\t\t</description>\n");
1476 if (flag->guisection) {
1477 fprintf(stdout,
" \t\t<guisection>\n\t\t\t");
1478 print_escaped_for_xml(stdout, flag->guisection);
1479 fprintf(stdout,
"\n\t\t</guisection>\n");
1481 flag = flag->next_flag;
1482 fprintf(stdout,
"\t</flag>\n");
1497 fprintf(stdout,
"\t<flag name=\"%s\">\n",
"overwrite");
1498 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1499 print_escaped_for_xml(stdout,
1500 _(
"Allow output files to overwrite existing files"));
1501 fprintf(stdout,
"\n\t\t</description>\n");
1502 fprintf(stdout,
"\t</flag>\n");
1506 fprintf(stdout,
"\t<flag name=\"%s\">\n",
"verbose");
1507 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1508 print_escaped_for_xml(stdout, _(
"Verbose module output"));
1509 fprintf(stdout,
"\n\t\t</description>\n");
1510 fprintf(stdout,
"\t</flag>\n");
1513 fprintf(stdout,
"\t<flag name=\"%s\">\n",
"quiet");
1514 fprintf(stdout,
"\t\t<description>\n\t\t\t");
1515 print_escaped_for_xml(stdout, _(
"Quiet module output"));
1516 fprintf(stdout,
"\n\t\t</description>\n");
1517 fprintf(stdout,
"\t</flag>\n");
1519 fprintf(stdout,
"</task>\n");
1525 static void G_usage_html(
void)
1532 new_prompt = uses_new_gisprompt();
1540 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
1541 fprintf(stdout,
"<html>\n<head>\n");
1542 fprintf(stdout,
"<title>GRASS GIS manual: %s</title>\n", pgm_name);
1544 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n");
1546 "<link rel=\"stylesheet\" href=\"grassdocs.css\" type=\"text/css\">\n");
1547 fprintf(stdout,
"</head>\n");
1548 fprintf(stdout,
"<body bgcolor=\"white\">\n\n");
1550 "<img src=\"grass_logo.png\" alt=\"GRASS logo\"><hr align=center size=6 noshade>\n\n");
1551 fprintf(stdout,
"<h2>%s</h2>\n", _(
"NAME"));
1552 fprintf(stdout,
"<em><b>%s</b></em> ", pgm_name);
1554 if (module_info.label || module_info.description)
1555 fprintf(stdout,
" - ");
1557 if (module_info.label)
1558 fprintf(stdout,
"%s<BR>\n", module_info.label);
1560 if (module_info.description)
1561 fprintf(stdout,
"%s\n", module_info.description);
1564 fprintf(stdout,
"<h2>%s</h2>\n", _(
"KEYWORDS"));
1565 if (module_info.keywords) {
1566 fprintf(stdout,
"%s", module_info.keywords);
1567 fprintf(stdout,
"\n");
1569 fprintf(stdout,
"<h2>%s</h2>\n", _(
"SYNOPSIS"));
1570 fprintf(stdout,
"<b>%s</b><br>\n", pgm_name);
1571 fprintf(stdout,
"<b>%s help</b><br>\n", pgm_name);
1573 fprintf(stdout,
"<b>%s</b>", pgm_name);
1580 fprintf(stdout,
" [-<b>");
1581 while (flag !=
NULL) {
1582 fprintf(stdout,
"%c", flag->key);
1583 flag = flag->next_flag;
1585 fprintf(stdout,
"</b>] ");
1588 fprintf(stdout,
" ");
1591 opt = &first_option;
1593 while (opt !=
NULL) {
1594 if (opt->key_desc !=
NULL)
1595 type = opt->key_desc;
1597 switch (opt->type) {
1612 fprintf(stdout,
" [");
1613 fprintf(stdout,
"<b>%s</b>=<em>%s</em>", opt->key, type);
1614 if (opt->multiple) {
1615 fprintf(stdout,
"[,<i>%s</i>,...]", type);
1618 fprintf(stdout,
"] ");
1620 opt = opt->next_opt;
1621 fprintf(stdout,
" ");
1625 fprintf(stdout,
" [--<b>overwrite</b>] ");
1627 fprintf(stdout,
" [--<b>verbose</b>] ");
1628 fprintf(stdout,
" [--<b>quiet</b>] ");
1630 fprintf(stdout,
"\n");
1634 fprintf(stdout,
"\n");
1635 if (n_flags || new_prompt) {
1637 fprintf(stdout,
"<h3>%s:</h3>\n", _(
"Flags"));
1638 fprintf(stdout,
"<DL>\n");
1639 while (n_flags && flag !=
NULL) {
1640 fprintf(stdout,
"<DT><b>-%c</b></DT>\n", flag->key);
1643 fprintf(stdout,
"<DD>");
1644 fprintf(stdout,
"%s", flag->label);
1645 fprintf(stdout,
"</DD>\n");
1648 if (flag->description) {
1649 fprintf(stdout,
"<DD>");
1650 fprintf(stdout,
"%s", flag->description);
1651 fprintf(stdout,
"</DD>\n");
1654 flag = flag->next_flag;
1655 fprintf(stdout,
"\n");
1658 fprintf(stdout,
"<DT><b>--overwrite</b></DT>\n");
1659 fprintf(stdout,
"<DD>%s</DD>\n",
1660 _(
"Allow output files to overwrite existing files"));
1663 fprintf(stdout,
"<DT><b>--verbose</b></DT>\n");
1664 fprintf(stdout,
"<DD>%s</DD>\n", _(
"Verbose module output"));
1666 fprintf(stdout,
"<DT><b>--quiet</b></DT>\n");
1667 fprintf(stdout,
"<DD>%s</DD>\n", _(
"Quiet module output"));
1669 fprintf(stdout,
"</DL>\n");
1672 fprintf(stdout,
"\n");
1674 opt = &first_option;
1675 fprintf(stdout,
"<h3>%s:</h3>\n", _(
"Parameters"));
1676 fprintf(stdout,
"<DL>\n");
1678 while (opt !=
NULL) {
1680 if (opt->key_desc !=
NULL)
1681 type = opt->key_desc;
1683 switch (opt->type) {
1697 fprintf(stdout,
"<DT><b>%s</b>=<em>%s", opt->key, type);
1698 if (opt->multiple) {
1699 fprintf(stdout,
"[,<i>%s</i>,...]", type);
1701 fprintf(stdout,
"</em></DT>\n");
1704 fprintf(stdout,
"<DD>");
1705 fprintf(stdout,
"%s", opt->label);
1706 fprintf(stdout,
"</DD>\n");
1708 if (opt->description) {
1709 fprintf(stdout,
"<DD>");
1710 print_escaped_for_html(stdout, opt->description);
1711 fprintf(stdout,
"</DD>\n");
1715 fprintf(stdout,
"<DD>%s: <em>", _(
"Options"));
1716 fprintf(stdout,
"%s", opt->options);
1717 fprintf(stdout,
"</em></DD>\n");
1721 fprintf(stdout,
"<DD>%s: <em>", _(
"Default"));
1722 fprintf(stdout,
"%s", opt->def);
1723 fprintf(stdout,
"</em></DD>\n");
1729 while (opt->opts[i]) {
1731 fprintf(stdout,
"<DD><b>%s</b>: %s</DD>\n",
1732 opt->opts[i], opt->descs[i]);
1737 opt = opt->next_opt;
1738 fprintf(stdout,
"\n");
1740 fprintf(stdout,
"</DL>\n");
1743 fprintf(stdout,
"</body>\n</html>\n");
1749 static void G_script(
void)
1754 fprintf(fp,
"#!/bin/sh\n\n");
1756 "############################################################################\n");
1759 fprintf(fp,
"# AUTHOR(S): %s\n",
G_whoami());
1760 fprintf(fp,
"# PURPOSE: \n");
1761 fprintf(fp,
"# COPYRIGHT: (C) 2009 GRASS Development Team/%s\n",
1765 "# This program is free software; you can redistribute it and/or modify\n");
1767 "# it under the terms of the GNU General Public License as published by\n");
1769 "# the Free Software Foundation; either version 2 of the License, or\n");
1770 fprintf(fp,
"# (at your option) any later version.\n");
1773 "# This program is distributed in the hope that it will be useful,\n");
1775 "# but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
1777 "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
1778 fprintf(fp,
"# GNU General Public License for more details.\n");
1781 "############################################################################\n");
1783 fprintf(fp,
"#%%Module\n");
1784 if (module_info.label)
1785 fprintf(fp,
"#%% label: %s\n", module_info.label);
1786 if (module_info.description)
1787 fprintf(fp,
"#%% description: %s\n", module_info.description);
1788 if (module_info.keywords)
1789 fprintf(fp,
"#%% keywords: %s\n", module_info.keywords);
1790 fprintf(fp,
"#%%End\n");
1795 for (flag = &first_flag; flag; flag = flag->next_flag) {
1796 fprintf(fp,
"#%%Flag\n");
1797 fprintf(fp,
"#%% key: %c\n", flag->key);
1799 fprintf(fp,
"#%% label: %s\n", flag->label);
1800 if (flag->description)
1801 fprintf(fp,
"#%% description: %s\n", flag->description);
1802 if (flag->guisection)
1803 fprintf(fp,
"#%% guisection: %s\n", flag->guisection);
1804 fprintf(fp,
"#%%End\n");
1811 for (opt = &first_option; opt; opt = opt->next_opt) {
1812 switch (opt->type) {
1827 fprintf(fp,
"#%%Option\n");
1828 fprintf(fp,
"#%% key: %s\n", opt->key);
1829 fprintf(fp,
"#%% type: %s\n", type);
1830 fprintf(fp,
"#%% required: %s\n", opt->required ?
"yes" :
"no");
1831 fprintf(fp,
"#%% multiple: %s\n", opt->multiple ?
"yes" :
"no");
1833 fprintf(fp,
"#%% options: %s\n", opt->options);
1835 fprintf(fp,
"#%% key_desc: %s\n", opt->key_desc);
1837 fprintf(fp,
"#%% label: %s\n", opt->label);
1838 if (opt->description)
1839 fprintf(fp,
"#%% description: %s\n", opt->description);
1840 if (opt->descriptions)
1841 fprintf(fp,
"#%% descriptions: %s\n", opt->descriptions);
1843 fprintf(fp,
"#%% answer: %s\n", opt->answer);
1845 fprintf(fp,
"#%% gisprompt: %s\n", opt->gisprompt);
1846 if (opt->guisection)
1847 fprintf(fp,
"#%% guisection: %s\n", opt->guisection);
1848 fprintf(fp,
"#%%End\n");
1853 "\nif [ -z \"$GISBASE\" ] ; then\n"
1854 " echo \"You must be in GRASS GIS to run this program.\" 1>&2\n"
1858 "if [ \"$1\" != \"@ARGS_PARSED@\" ] ; then\n"
1859 " exec g.parser \"$0\" \"$@\"\n"
1860 "fi\n" "\n" "# CODE GOES HERE\n" "\n");
1868 static void generate_tcl(FILE * fp)
1870 int new_prompt = uses_new_gisprompt();
1874 fprintf(fp,
"begin_dialog {%s} {\n", pgm_name);
1875 fprintf(fp,
" label {%s}\n", module_info.label ? module_info.label :
"");
1876 fprintf(fp,
" desc {%s}\n",
1877 module_info.description ? module_info.description :
"");
1878 fprintf(fp,
" key {%s}\n",
1879 module_info.keywords ? module_info.keywords :
"");
1887 for (flag = &first_flag; flag; flag = flag->next_flag, optn++) {
1888 fprintf(fp,
"add_flag %d {\n", optn);
1889 fprintf(fp,
" name {%c}\n", flag->key);
1890 fprintf(fp,
" desc {%s}\n", flag->description);
1891 fprintf(fp,
" answer %d\n", flag->answer);
1894 fprintf(fp,
" label {%s}\n", flag->label ? flag->label :
"");
1895 fprintf(fp,
" guisection {%s}\n",
1896 flag->guisection ? flag->guisection :
"");
1904 for (opt = &first_option; opt; opt = opt->next_opt, optn++) {
1905 if (opt->key_desc !=
NULL)
1906 type = opt->key_desc;
1908 switch (opt->type) {
1923 fprintf(fp,
"add_option %d {\n", optn);
1924 fprintf(fp,
" name {%s}\n", opt->key);
1925 fprintf(fp,
" type {%s}\n", type);
1926 fprintf(fp,
" multi %d\n", opt->multiple);
1927 fprintf(fp,
" desc {%s}\n", opt->description);
1928 fprintf(fp,
" required %d\n", opt->required);
1929 fprintf(fp,
" options {%s}\n", opt->options ? opt->options :
"");
1930 fprintf(fp,
" descs {%s}\n",
1931 opt->descriptions ? opt->descriptions :
"");
1932 fprintf(fp,
" answer {%s}\n", opt->answer ? opt->answer :
"");
1933 fprintf(fp,
" prompt {%s}\n",
1934 opt->gisprompt ? opt->gisprompt :
"");
1937 fprintf(fp,
" label {%s}\n", opt->label ? opt->label :
"");
1938 fprintf(fp,
" guisection {%s}\n",
1939 opt->guisection ? opt->guisection :
"");
1945 fprintf(fp,
"add_xflag %d {\n", optn);
1946 fprintf(fp,
" name {overwrite}\n");
1947 fprintf(fp,
" desc {%s}\n",
1948 _(
"Allow output files to overwrite existing files"));
1949 fprintf(fp,
" answer %d\n", overwrite);
1950 fprintf(fp,
" label {%s}\n", _(
"Allow overwrite"));
1951 fprintf(fp,
" guisection {}\n");
1956 fprintf(fp,
"add_xflag %d {\n", optn);
1957 fprintf(fp,
" name {quiet}\n");
1958 fprintf(fp,
" desc {%s}\n", _(
"Run with minimal output messages"));
1959 fprintf(fp,
" answer %d\n", quiet);
1960 fprintf(fp,
" label {%s}\n", _(
"Run quietly"));
1961 fprintf(fp,
" guisection {}\n");
1965 fprintf(fp,
"end_dialog %d\n", optn - 1);
1971 static void G_gui_tcltk(
void)
1981 if (
getenv(
"GRASS_DEBUG_GUI"))
1982 fp = popen(
"tee gui_dump.tcl | \"%GRASS_WISH%\"",
"w");
1984 fp = popen(
"\"%GRASS_WISH%\"",
"w");
1986 if (
getenv(
"GRASS_DEBUG_GUI"))
1987 fp = popen(
"tee gui_dump.tcl | \"$GRASS_WISH\"",
"w");
1989 fp = popen(
"\"$GRASS_WISH\"",
"w");
1995 fprintf(fp,
"source $env(GISBASE)/etc/gui.tcl\n");
2005 static void G_gui_wx(
void)
2007 char script[GPATH_MAX];
2014 sprintf(script,
"%s/etc/wxpython/gui_modules/menuform.py",
2026 static void G_gui(
void)
2029 char *gui =
getenv(
"GRASS_GUI");
2035 if (gui && (strcmp(gui,
"tcltk") == 0 || strcmp(gui,
"oldtcltk") == 0))
2046 static void G_tcltk(
void)
2053 generate_tcl(stdout);
2063 static int show_options(
int maxlen,
const char *str)
2069 fprintf(stderr, _(
" %*s options: "), maxlen,
" ");
2070 totlen = maxlen + 13;
2072 while ((p2 =
G_index(p1,
','))) {
2074 len = strlen(p1) + 1;
2075 if ((len + totlen) > 76) {
2076 totlen = maxlen + 13;
2077 fprintf(stderr,
"\n %*s", maxlen + 13,
" ");
2079 fprintf(stderr,
"%s,", p1);
2084 if ((len + totlen) > 76)
2085 fprintf(stderr,
"\n %*s", maxlen + 13,
" ");
2086 fprintf(stderr,
"%s\n", p1);
2093 static int show(
const char *item,
int len)
2097 n = strlen(item) + (len > 0);
2100 fprintf(stderr,
"\n ");
2103 fprintf(stderr,
"%s", item);
2107 static int set_flag(
int f)
2114 fprintf(stderr, _(
"Sorry, <%c> is not a valid flag\n"), f);
2121 while (flag !=
NULL) {
2122 if (flag->key == f) {
2126 flag = flag->next_flag;
2129 fprintf(stderr, _(
"Sorry, <%c> is not a valid flag\n"), f);
2136 static int contains(
const char *s,
int c)
2146 static int is_option(
const char *
string)
2148 const char *p = strchr(
string,
'=');
2155 if (!strchr(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", *p))
2161 static int set_option(
char *
string)
2163 struct Option *at_opt =
NULL;
2164 struct Option *opt =
NULL;
2170 for (ptr = the_key; *
string !=
'='; ptr++,
string++)
2177 key_len = strlen(the_key);
2178 for (at_opt = &first_option; at_opt !=
NULL; at_opt = at_opt->next_opt) {
2179 if (at_opt->key ==
NULL || strncmp(the_key, at_opt->key, key_len))
2187 if (strlen(at_opt->key) == key_len) {
2195 fprintf(stderr, _(
"Sorry, <%s=> is ambiguous\n"), the_key);
2201 fprintf(stderr, _(
"Sorry, <%s> is not a valid parameter\n"), the_key);
2207 if (!opt->multiple) {
2208 fprintf(stderr, _(
"Option <%s> does not accept multiple answers\n"), the_key);
2211 opt->answer = (
char *)G_realloc(opt->answer,
2212 strlen(opt->answer) + strlen(
string) +
2214 strcat(opt->answer,
",");
2215 strcat(opt->answer,
string);
2218 opt->answer =
G_store(
string);
2222 static int check_opts(
void)
2233 opt = &first_option;
2234 while (opt !=
NULL) {
2237 if (opt->options && opt->answer) {
2238 if (opt->multiple == 0)
2239 error += check_an_opt(opt->key, opt->type,
2240 opt->options, opt->answer);
2242 for (ans = 0; opt->answers[ans] !=
'\0'; ans++)
2243 error += check_an_opt(opt->key, opt->type,
2244 opt->options, opt->answers[ans]);
2251 error += opt->checker(opt->answer);
2253 opt = opt->next_opt;
2258 static int check_an_opt(
const char *key,
int type,
const char *options,
2267 error = check_int(answer, options);
2270 error = check_double(answer, options);
2273 error = check_string(answer, options);
2286 _(
"\nERROR: illegal range syntax for parameter <%s>\n"), key);
2287 fprintf(stderr, _(
" Presented as: %s\n"), options);
2291 _(
"\nERROR: value <%s> out of range for parameter <%s>\n"),
2293 fprintf(stderr, _(
" Legal range: %s\n"), options);
2296 fprintf(stderr, _(
"\nERROR: Missing value for parameter <%s>\n"),
2302 static int check_int(
const char *ans,
const char *opts)
2306 if (1 != sscanf(ans,
"%d", &d))
2309 if (contains(opts,
'-')) {
2310 if (2 != sscanf(opts,
"%d-%d", &lo, &hi))
2312 if (d < lo || d > hi)
2317 else if (contains(opts,
',')) {
2319 if (1 != sscanf(opts,
"%d", &lo))
2323 while (*opts !=
'\0' && *opts !=
',')
2327 if (*(++opts) ==
'\0')
2332 if (1 != sscanf(opts,
"%d", &lo))
2366 static int check_double(
const char *ans,
const char *opts)
2370 if (1 != sscanf(ans,
"%lf", &d))
2373 if (contains(opts,
'-')) {
2374 if (2 != sscanf(opts,
"%lf-%lf", &lo, &hi))
2376 if (d < lo || d > hi)
2381 else if (contains(opts,
',')) {
2383 if (1 != sscanf(opts,
"%lf", &lo))
2387 while (*opts !=
'\0' && *opts !=
',')
2391 if (*(++opts) ==
'\0')
2396 if (1 != sscanf(opts,
"%lf", &lo))
2404 static int check_string(
const char *ans,
const char *opts)
2409 if (contains(opts,
',')) {
2411 if ((!strncmp(ans, opts, strlen(ans)))
2412 && (*(opts + strlen(ans)) ==
','
2413 || *(opts + strlen(ans)) ==
'\0'))
2415 while (*opts !=
'\0' && *opts !=
',')
2419 if (*(++opts) ==
'\0')
2424 if (!strcmp(ans, opts))
2430 static int check_required(
void)
2440 opt = &first_option;
2441 while (opt !=
NULL) {
2442 if (opt->required && opt->answer ==
NULL) {
2444 _(
"ERROR: Required parameter <%s> not set:\n\t(%s)\n"),
2445 opt->key, (opt->label ? opt->label : opt->description) );
2448 opt = opt->next_opt;
2454 static int split_opts(
void)
2467 opt = &first_option;
2468 while (opt !=
NULL) {
2469 if ( (opt->answer !=
NULL)) {
2472 opt->answers = (
char **)G_malloc(allocated *
sizeof(
char *));
2476 opt->answers[ans_num] =
NULL;
2479 for (len = 0, ptr2 = ptr1; *ptr2 !=
'\0' && *ptr2 !=
',';
2483 opt->answers[ans_num] = (
char *)G_malloc(len + 1);
2484 G_copy(opt->answers[ans_num], ptr1, len);
2485 opt->answers[ans_num][len] = 0;
2489 if (ans_num >= allocated) {
2492 (
char **)G_realloc((
char *)opt->answers,
2493 allocated *
sizeof(
char *));
2496 opt->answers[ans_num] =
NULL;
2508 opt = opt->next_opt;
2514 static int check_multiple_opts(
void)
2526 opt = &first_option;
2527 while (opt !=
NULL) {
2528 if ((opt->answer !=
NULL) && (opt->key_desc !=
NULL)) {
2531 for (ptr = opt->key_desc; *ptr !=
'\0'; ptr++)
2535 for (n = 0; opt->answers[n] !=
'\0'; n++) ;
2539 _(
"\nERROR: option <%s> must be provided in multiples of %d\n"),
2540 opt->key, n_commas);
2541 fprintf(stderr, _(
" You provided %d items:\n"), n);
2542 fprintf(stderr,
" %s\n", opt->answer);
2546 opt = opt->next_opt;
2552 static int check_overwrite(
void)
2567 if ((overstr =
G__getenv(
"OVERWRITE"))) {
2568 over = atoi(overstr);
2572 if ((overstr =
getenv(
"GRASS_OVERWRITE"))) {
2577 if (overwrite || over) {
2578 module_info.overwrite = 1;
2580 putenv(
"GRASS_OVERWRITE=1");
2585 opt = &first_option;
2586 while (opt !=
NULL) {
2587 if ((opt->answer !=
NULL) && (opt->gisprompt !=
NULL)) {
2588 split_gisprompt(opt->gisprompt, age, element, desc);
2590 if (strcmp(age,
"new") == 0) {
2592 for (i = 0; opt->answers[i]; i++) {
2594 if (!overwrite && !over) {
2597 _(
"ERROR: option <%s>: <%s> exists.\n"),
2598 opt->key, opt->answers[i]);
2602 "GRASS_INFO_ERROR(%d,1): option <%s>: <%s> exists.\n",
2603 getpid(), opt->key, opt->answers[i]);
2604 fprintf(stderr,
"GRASS_INFO_END(%d,1)\n",
2614 opt = opt->next_opt;
2620 static int interactive(
const char *
command)
2627 fprintf(stderr,
"PROGRAMMER ERROR: no flags or options\n");
2631 for (item = &first_item;;) {
2633 interactive_flag(item->
flag);
2635 interactive_option(item->
option);
2648 static int interactive_flag(
struct Flag *flag)
2652 fprintf(stderr, _(
"\nFLAG: Set the following flag?\n"));
2653 sprintf(buff,
" %s?", flag->description);
2654 flag->answer =
G_yes(buff, 0);
2659 static int interactive_option(
struct Option *opt)
2661 char buff[1024], *bptr;
2666 fprintf(stderr, _(
"\nOPTION: %s\n"), opt->description);
2667 fprintf(stderr, _(
" key: %s\n"), opt->key);
2669 fprintf(stderr, _(
" format: %s\n"), opt->key_desc);
2671 fprintf(stderr, _(
" default: %s\n"), opt->def);
2672 fprintf(stderr, _(
"required: %s\n"), opt->required ?
"YES" :
"NO");
2674 fprintf(stderr, _(
"multiple: %s\n"), opt->multiple ?
"YES" :
"NO");
2676 fprintf(stderr, _(
" options: %s\n"), opt->options);
2685 no_prompt = gis_prompt(opt, buff);
2689 fprintf(stderr, _(
"enter option > "));
2690 if (fgets(buff, 1024, stdin) == 0)
2691 exit(EXIT_SUCCESS);;
2701 if (strlen(buff) != 0) {
2705 if (check_an_opt(opt->key, opt->type, opt->options, buff)) {
2706 if (
G_yes(_(
" Try again? "), 1))
2713 if (opt->checker(buff)) {
2714 fprintf(stderr, _(
"Sorry, %s is not accepted.\n"), buff);
2716 if (
G_yes(_(
" Try again? "), 1))
2722 sprintf(buff2,
"%s=%s", opt->key, buff);
2723 if (!opt->gisprompt) {
2724 fprintf(stderr, _(
"\nYou have chosen:\n %s\n"), buff2);
2725 if (
G_yes(_(
"Is this correct? "), 1)) {
2736 if ((strlen(buff) == 0) && opt->required && (set_one == 0))
2738 if ((strlen(buff) == 0) && (set_one > 0) && opt->multiple)
2740 if ((strlen(buff) == 0) && !opt->required)
2742 if ((set_one == 1) && !opt->multiple)
2748 static int split_gisprompt(
const char *gisprompt,
char *age,
char *element,
2754 for (ptr1 = gisprompt, ptr2 = age; *ptr1 !=
'\0'; ptr1++, ptr2++) {
2761 for (ptr1++, ptr2 = element; *ptr1 !=
'\0'; ptr1++, ptr2++) {
2768 for (ptr1++, ptr2 = desc; *ptr1 !=
'\0'; ptr1++, ptr2++) {
2778 static int gis_prompt(
struct Option *opt,
char *buff)
2785 split_gisprompt(opt->gisprompt, age, element, desc);
2791 if (!strcmp(
"old", age)) {
2792 ptr1 =
G_ask_old(
"", buff, element, desc);
2797 else if (!strcmp(
"new", age))
2798 ptr1 =
G_ask_new(
"", buff, element, desc);
2799 else if (!strcmp(
"mapset", age))
2801 else if (!strcmp(
"any", age))
2802 ptr1 =
G_ask_any(
"", buff, element, desc, 1);
2803 else if (!strcmp(
"old_file", age))
2805 else if (!strcmp(
"new_file", age))
2836 G_debug(3,
"G_recreate_command()");
2840 buff = G_calloc(1024,
sizeof(
char));
2844 if (len >= nalloced) {
2845 nalloced += (1024 > len) ? 1024 : len + 1;
2846 buff = G_realloc(buff, nalloced);
2854 while (flag !=
'\0') {
2855 if (flag->answer == 1) {
2861 if (len + slen >= nalloced) {
2863 (nalloced + 1024 > len + slen) ? 1024 : slen + 1;
2864 buff = G_realloc(buff, nalloced);
2871 flag = flag->next_flag;
2875 opt = &first_option;
2876 while (opt !=
'\0') {
2877 if (opt->answer !=
'\0' && opt->answers && opt->answers[0] !=
NULL) {
2878 slen = strlen(opt->key) + strlen(opt->answers[0]) + 4;
2879 if (len + slen >= nalloced) {
2880 nalloced += (nalloced + 1024 > len + slen) ? 1024 : slen + 1;
2881 buff = G_realloc(buff, nalloced);
2886 strcpy(cur, opt->key);
2887 cur = strchr(cur,
'\0');
2890 if (opt->type == TYPE_STRING) {
2894 strcpy(cur, opt->answers[0]);
2895 cur = strchr(cur,
'\0');
2897 for (n = 1; opt->answers[n] !=
NULL && opt->answers[n] !=
'\0';
2899 if (opt->answers[n] ==
NULL)
2901 slen = strlen(opt->answers[n]) + 2;
2902 if (len + slen >= nalloced) {
2904 (nalloced + 1024 > len + slen) ? 1024 : slen + 1;
2905 buff = G_realloc(buff, nalloced);
2910 strcpy(cur, opt->answers[n]);
2911 cur = strchr(cur,
'\0');
2914 if (opt->type == TYPE_STRING) {
2920 opt = opt->next_opt;