38 if (strchr(item,
'[') ==
NULL) {
41 if (strrchr(item,
']') ==
NULL) {
44 if (strchr(item,
'[') > strrchr(item,
']')) {
62 idx =
find_pos(
"\"&Xtns\" all options 1", tcl_lines, 0);
64 idx =
find_pos(
"\"&Help\" all options", tcl_lines, 0);
69 "could not parse 'menu.tcl'.\n");
71 insert_str(
" \"&Xtns\" all options 1 {\n", idx, tcl_lines);
76 insert_str(
" \"&Xtns\" all options 1 {\n", idx, tcl_lines);
104 idx =
find_pos(
"\"&Xtns\" all options", tcl_lines, 0);
105 last =
find_pos(
"\" all options", tcl_lines, idx + 1) - 1;
107 last =
find_pos(
"}]", tcl_lines, 0);
113 (
"first line not a submenu specifier in 'entries-gisman'.\n");
118 len = (strrchr(menu,
']') - strchr(menu,
'[')) /
sizeof(
char);
119 strncpy(tmp, strchr(menu,
'[') +
sizeof(
char), len);
121 sprintf(searchstr,
"{cascad \"%s\"", tmp);
123 idx2 =
find_pos(searchstr, tcl_lines, idx);
124 if ((idx2 != -1) && (idx2 < last)) {
125 print_warning(
"submenu '%s' exists in GIS Manager's Xtns menu.\n",
131 insert_here = idx + 1;
132 idx2 =
find_pos(
"{cascad ", tcl_lines, idx);
133 while ((idx2 != -1) && (idx2 < last)) {
135 first_quote = strchr(tcl_lines[idx2],
'\"');
136 second_quote = strchr(first_quote +
sizeof(
char),
'\"');
137 len = (second_quote - first_quote) /
sizeof(
char);
138 strncpy(tmp2, first_quote +
sizeof(
char), len);
139 tmp2[len - 1] =
'\0';
140 if (strcmp(tmp, tmp2) < 0) {
145 idx2 =
find_pos(
"{cascad ", tcl_lines, idx);
149 sprintf(tmp,
" \t\t\t%s {} \"\" 1 {\n", searchstr);
151 insert_str(
" \t\t\t}}\n", insert_here + 1, tcl_lines);
154 terminator =
find_pos(
"}]", tcl_lines, 0);
156 sprintf(tmp,
"#(DO_NOT_REMOVE_THIS_COMMENT) <%s> %s {} \"\" 1 {\n",
157 pkg_short_name, searchstr);
161 return (insert_here + 1);
185 token = strtok(item,
";");
191 strcpy(entry, token);
194 while (token !=
NULL) {
195 token = strtok(
NULL,
";");
197 strcpy(command, token);
202 if (num_tokens > 2) {
203 print_warning(
"invalid number of tokens (%i) in 'entries-gisman'.\n",
209 if ((!strcmp(entry,
"-")) && (!strcmp(entry,
"-"))) {
210 sprintf(tmp,
" \t\t\t {separator}\n");
213 sprintf(tmp,
" \t\t\t {command \"%s\" {} \"%s\" {} -command {%s }}\n",
214 entry, command, command);
240 int n_entries, n_lines, i;
241 int n_lines_org, n_lines_new;
243 FILE *f_gisman, *f_in, *f_out;
246 sprintf(file,
"../entries-gisman");
247 f_gisman = fopen(file,
"r");
248 if (f_gisman ==
NULL) {
249 if (
errno == ENOENT) {
257 "checking for file '%s': %s\n", file,
263 sprintf(file,
"%s/etc/dm/menu.tcl", gisbase);
264 f_in = fopen(file,
"r");
266 if (
errno == ENOENT) {
274 "checking for file '%s': %s\n", file,
281 strcpy(
TMP_GISMAN,
"/tmp/grass.extensions.db.XXXXXX");
287 "could not create temp file '%s': %s\n \
288 Make sure that directory /tmp exists on your system and you have write permission.\n",
TMP_GISMAN, strerror(
errno));
296 "mkdir --verbose %s/etc/dm/gem-entries ; cp -vf ../entries-gisman %s/etc/dm/gem-entries/%s ; \
297 cp -vf %s/etc/dm/menu.tcl %s/etc/dm/menu.tcl.gem.bak ; \
298 cp -vf %s %s/etc/dm/menu.tcl ; chmod -v a+r %s/etc/dm/menu.tcl ;",
299 gisbase, gisbase, pkg_short_name, gisbase, gisbase,
TMP_GISMAN, gisbase, gisbase);
303 "mkdir %s/etc/dm/gem-entries &> %s ; cp -f ../entries-gisman %s/etc/dm/gem-entries/%s &> %s ; \
304 cp -f %s/etc/dm/menu.tcl %s/etc/dm/menu.tcl.gem.bak &> %s ; \
305 cp -f %s %s/etc/dm/menu.tcl &> %s ; chmod a+r %s/etc/dm/menu.tcl &> %s ;",
306 gisbase,
TMP_NULL, gisbase, pkg_short_name,
TMP_NULL, gisbase, gisbase,
TMP_NULL,
TMP_GISMAN, gisbase,
TMP_NULL, gisbase,
TMP_NULL);
312 while (fgets(str,
MAXSTR, f_gisman) !=
NULL) {
315 if (n_entries == 0) {
328 n_lines_org = n_lines;
335 line = (
char **)calloc(n_lines + (n_entries * 2) + 6,
sizeof(
char *));
336 for (i = 0; i < (n_lines + (n_entries * 2) + 6); i++) {
341 line[i] = (
char *)
malloc((1 + strlen(str)) *
sizeof(
char));
342 strcpy(line[i], str);
353 len = (strrchr(str,
']') - strchr(str,
'[')) /
sizeof(
char);
354 strncpy(menu, strchr(str,
'[') +
sizeof(
char), len);
355 menu[len - 1] =
'\0';
364 line_no =
new_item(str, menu, line, line_no);
375 while (line[i] !=
NULL) {
376 fprintf(f_out, line[i]);
388 if ((n_lines_new == 0) || (n_lines_new < n_lines_org)) {
390 (
"file truncation detected. Retaining orginal file 'menu.tcl'.\n");
400 for (i = 0; i < (n_lines + (n_entries * 2) + 6); i++) {
422 sprintf(file,
"../entries-gisman2");
423 f_gisman2 = fopen(file,
"r");
424 if (f_gisman2 ==
NULL) {
425 if (
errno == ENOENT) {
433 "checking for file '%s': %s\n", file,
442 "mkdir --verbose -p %s/etc/gm/Xtns ; cp -fv ../entries-gisman2 %s/etc/gm/Xtns/%s.gem ; ",
443 gisbase, gisbase, pkg_short_name);
447 "mkdir -p %s/etc/gm/Xtns ; cp -f ../entries-gisman2 %s/etc/gm/Xtns/%s.gem ; ",
448 gisbase, gisbase, pkg_short_name);
468 int n_lines_org, n_lines_new;
472 int start_sub, end_sub;
477 sprintf(file,
"%s/etc/dm/menu.tcl", gisbase);
478 f_in = fopen(file,
"r");
480 if (
errno == ENOENT) {
488 "checking for file '%s': %s\n", file,
495 strcpy(
TMP_GISMAN,
"/tmp/grass.extensions.db.XXXXXX");
501 "could not create temp file '%s': %s\n \
502 Make sure that directory /tmp exists on your system and you have write permission.\n",
TMP_GISMAN, strerror(
errno));
508 sprintf(str,
"cp -vf %s/etc/dm/menu.tcl %s/etc/dm/menu.tcl.gem.bak ; \
509 cp -vf %s %s/etc/dm/menu.tcl ; chmod -v a+r %s/etc/dm/menu.tcl ;", gisbase, gisbase,
TMP_GISMAN, gisbase, gisbase);
513 "cp -f %s/etc/dm/menu.tcl %s/etc/dm/menu.tcl.gem.bak &> %s ; \
528 n_lines_org = n_lines;
533 line = (
char **)calloc(n_lines + 1,
sizeof(
char *));
534 for (i = 0; i < n_lines + 1; i++) {
539 line[i] = (
char *)
malloc((1 + strlen(str)) *
sizeof(
char));
540 strcpy(line[i], str);
545 sprintf(str,
"#(DO_NOT_REMOVE_THIS_COMMENT) <%s> {cascad",
550 (
"could not find uninstall information in 'menu.tcl'.\n");
555 lq = strchr(line[pos],
'\"');
557 rq = strchr(lq,
'\"');
559 tmp[(rq - lq) /
sizeof(
char)] =
'\0';
562 start =
find_pos(
"\"&Xtns\" all options 1", line, 0);
563 end =
find_pos(
"\" all options", line, start + 1) - 1;
574 sprintf(str,
"{cascad \"%s\"", tmp);
575 start_sub =
find_pos(str, line, start);
576 if ((start_sub == -1) || (start_sub > end)) {
577 print_warning(
"could not find submenu entry '%s' in 'menu.tcl'.\n",
581 end_sub =
find_pos(
" \t\t\t}}", line, start_sub);
582 if ((end_sub == -1) || (end_sub > end)) {
584 (
"could not find end of submenu entry '%s' in 'menu.tcl'.\n",
592 for (i = 0; i < ((end_sub - start_sub) + 1); i++) {
598 sprintf(str,
"#(DO_NOT_REMOVE_THIS_COMMENT) <%s> {cascad",
605 start =
find_pos(
"\"&Xtns\" all options 1", line, 0);
606 end =
find_pos(
"\" all options", line, start + 1) - 1;
607 if (end - start < 3) {
608 for (i = 0; i < ((end - start) + 1); i++) {
616 while (line[i] !=
NULL) {
617 fprintf(f_out, line[i]);
629 if ((n_lines_new == 0)) {
631 (
"file truncation detected. Retaining orginal file 'menu.tcl'.\n");
640 for (i = 0; i < n_lines + 1; i++) {
645 return (num_removed);
660 sprintf(file,
"%s/etc/gm/Xtns/%s.gem", gisbase, pkg_short_name);
661 f_gisman2 = fopen(file,
"r");
662 if (f_gisman2 ==
NULL) {
663 if (
errno == ENOENT) {
671 "checking for file '%s': %s\n", file,
677 sprintf(str,
"rm -vf %s/etc/gm/Xtns/%s.gem ; ",
678 gisbase, pkg_short_name);
681 sprintf(str,
"rm -f %s/etc/gm/Xtns/%s.gem ; ",
682 gisbase, pkg_short_name);
698 char pkg_short_name[
MAXSTR];
701 int n_entries, n_lines, i;
703 FILE *f_gisman, *f_in, *f_out;
710 sprintf(file,
"%s/etc/dm/menu.tcl", gisbase);
711 f_in = fopen(file,
"r");
713 if (
errno == ENOENT) {
721 "checking for file '%s': %s\n", file,
728 strcpy(
TMP_GISMAN,
"/tmp/grass.extensions.db.XXXXXX");
734 "could not create temp file '%s': %s\n \
735 Make sure that directory /tmp exists on your system and you have write permission.\n",
TMP_GISMAN, strerror(
errno));
741 sprintf(str,
"cp -vf %s/etc/dm/menu.tcl %s/etc/dm/menu.tcl.gem.bak ; \
742 cp -vf %s %s/etc/dm/menu.tcl ; chmod -v a+r %s/etc/dm/menu.tcl ;", gisbase, gisbase,
TMP_GISMAN, gisbase, gisbase);
746 "cp -f %s/etc/dm/menu.tcl %s/etc/dm/menu.tcl.gem.bak &> %s ; \
752 sprintf(dir,
"%s/etc/dm/gem-entries", gisbase);
764 sprintf(file,
"%s/%s", dir, ep->d_name);
765 f_gisman = fopen(file,
"r");
766 if ((!strcmp(ep->d_name,
".")) || (!strcmp(ep->d_name,
".."))) {
770 if (f_gisman ==
NULL) {
775 while (fgets(str,
MAXSTR, f_gisman) !=
NULL) {
799 (
char **)calloc(n_lines + (n_entries * 2) + (n_files * 5) + 1,
801 for (i = 0; i < (n_lines + (n_entries * 2) + (n_files * 5) + 1); i++) {
806 line[i] = (
char *)
malloc((1 + strlen(str)) *
sizeof(
char));
807 strcpy(line[i], str);
818 sprintf(file,
"%s/%s", dir, ep->d_name);
819 if ((!strcmp(ep->d_name,
".")) || (!strcmp(ep->d_name,
".."))) {
822 f_gisman = fopen(file,
"r");
823 if (f_gisman ==
NULL) {
831 len = (strrchr(str,
']') - strchr(str,
'[')) /
sizeof(
char);
832 strncpy(menu, strchr(str,
'[') +
sizeof(
char), len);
833 menu[len - 1] =
'\0';
842 line_no =
new_item(str, menu, line, line_no);
856 while (line[i] !=
NULL) {
857 fprintf(f_out, line[i]);
867 for (i = 0; i < (n_lines + (n_entries * 2) + (n_files * 5) + 1); i++) {
872 return (num_restored);
int restore_entries_gisman(char *gisbase)
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int new_item(char *item, char *menu, char **tcl_lines, int line_no)
EXTERN char GISMAN2_CMD[MAXSTR]
EXTERN char TMP_NULL[MAXSTR]
void print_error(int err_code, char *msg,...)
int check_ext_menu(char **tcl_lines)
int deregister_entries_gisman(char *pkg_short_name, char *gisbase)
void register_entries_gisman(char *pkg_short_name, char *gisbase)
#define ERR_REGISTER_ENTRIES_GISMAN2
int new_submenu(char *pkg_short_name, char *menu, char **tcl_lines)
int is_submenu(char *item)
#define ERR_REGISTER_ENTRIES_GISMAN
void deregister_entries_gisman2(char *pkg_short_name, char *gisbase)
#define ERR_DEREGISTER_ENTRIES_GISMAN2
#define ERR_DEREGISTER_ENTRIES_GISMAN
void print_warning(char *msg,...)
void register_entries_gisman2(char *pkg_short_name, char *gisbase)
EXTERN char GISMAN_CMD[MAXSTR]
EXTERN char TMP_GISMAN[MAXSTR]