void delete_ext_html(char *ext, char *gisbase, char **html) { int pos1, pos2, pos3; int start, end; char item[MAXSTR]; int found; int i; pos1 = find_pos("<b>Drivers sections:</b>", html, 0); /* first go to section on "Drivers" */ if (pos1 < 0) { /* we have a new version of the HTML docs that does not have a "Drivers" section anymore */ /* let's check for the special GEM comment */ pos1 = find_pos ("<!-- GEM Extensions StartHTML. Do not delete or change this comment! -->", html, 0); if (pos1 < 0) { /* sorry, I can't handle these HTML docs */ print_warning ("Unknown format of index.html. Unable to de-register HTML man pages.\n"); return; } } pos2 = find_pos("<hr>", html, pos1); /* the horizontal ruler marks the end of the HTML text */ if (find_pos("<h3>Installed extensions:</h3>", html, pos1) == -1) { /* Extensions section does not exist: bail out! */ print_warning("no extensions section found in index.html.\n"); return; } start = find_pos("<h3>Installed extensions:</h3>", html, pos1); end = find_pos("</ul>", html, start); /* check if the entry exists and if so delete */ found = 0; sprintf(item, "\">%s", ext); pos3 = find_pos(item, html, start); if (pos3 == -1) { /* does not exist: */ print_warning("extension '%s' not listed in index.html.\n", ext); return; } /* delete item, if it was found in the extensions section */ if (pos3 < end) { delete_str(pos3, html); } end--; /* end of extensions section is no one up! */ /* if no more entries left in the extensions list: delete the entire section */ pos3 = find_pos("<ul>", html, start); if ((pos3 != -1) && (end > pos3) && (end - pos3 < 2)) { for (i = 0; i < 4; i++) { delete_str(pos3 - 1, html); } } }
int main(int argc, const char *argv[]) { char a[100]; fgets(a,100,stdin); a[strlen(a)-1]='\0'; delete_str(a); printf("\n"); return 0; }
int main(int argc, char* argv[]) { int randnum = 0; char* nvram = NULL, *value = NULL; char* delimiter = NULL, *tmp, *del; int position=0, c, i = 0, func = 0, val; char help_msg[2048] = "Usage: xobjconf [-s | -x <nvram variable>] {[-a | -m <values> -p <position>] | [ -n <to get # of digits>] | [-i <position>] | [-v <value>] | [-e <value>] | [ -r <position>] | [ -o <new delimiter>]} [-d delimiter]\n\n"; init_gen( ); strcat(help_msg, "xobjconf command summary\n"); strcat(help_msg, "\txobjconf is a function to insert/delete/modify/view nvram variable by delimiter(s).\n"); strcat(help_msg, "\t<nvram variable>:input a nvram variable.\n"); strcat(help_msg, "\tdelimiter:a delimiter which is a seperator.\n"); strcat(help_msg, "\t-s : to specify a nvram variable.\n"); strcat(help_msg, "\t-x : to get total counts of token by specified delimiter.\n"); strcat(help_msg, "\t-d : to specify a delimiter.\n"); strcat(help_msg, "\t-a:insert a value to the nvram variable by delimiter.\n"); strcat(help_msg, "\t-r : remove a value from a nvram variable by specfied position.\n"); strcat(help_msg, "\t-v : remove a value from a nvram variable by specfied value.\n"); strcat(help_msg, "\t-e : to check a value in a nvram variable is exist or not.\n"); strcat(help_msg, "\t-o : to replace delimiters in a token list by new delimiters.\n"); strcat(help_msg, "\t-n : to get digits in a nvram variable by speficied counts.\n"); strcat(help_msg, "\t-m : to change a value by spcified position from a nvram variable.\n"); strcat(help_msg, "\t-i : to return the value which is at the specified position from a nvram variable by delimiter.\n\n"); if(argc <= 1 || ((isgraph(*argv[1]) || ispunct(*argv[1])) && *argv[1]!='-')){ fprintf(stderr, "%s", help_msg); exit(0); } while ((c = getopt(argc, argv, "a:d:e:i:m:n:o:p:r:v:s:x:h")) != -1){ switch (c) { case 'a': func = 1; value = optarg; break; case 'r': func = 2; position = atoi(optarg); break; case 'm': func = 3; value = optarg; break; case 's': nvram = optarg; break; case 'i': func = 4; position = atoi(optarg); break; case 'v': func = 5; value = optarg; position = 1; break; case 'x': func = 6; nvram = optarg; break; case 'e': func = 7; value = optarg; position = 1; break; case 'n': func = 8; val = atoi(optarg); position = 1; break; case 'o': func = 9; value = optarg; break; case 'p': position = atoi(optarg); break; case 'd': delimiter = optarg; break; case 'h': fprintf(stderr, "%s", help_msg); exit(0); break; default: fprintf(stderr, "%s", help_msg); exit(0); break; } } if(nvram_get(nvram) == NULL && delimiter != NULL && nvram != NULL){ if(func == 1 && value != NULL){ nvram_set(nvram, ""); //printf("Inserting '%s' at position 1 ...\n", value); //tmp = StrDup(nvram_get(nvram)); //value = insert_str(tmp, value, delimiter, 1); //tmp = StrDup(insert_str(nvram_get(nvram), value, delimiter, 1)); //nvram_set(nvram, value); nvram_set(nvram, StrDup(insert_str(nvram_get(nvram), value, delimiter, 1))); printf("%s\n", nvram_get(nvram)); } else{ fprintf(stderr, "%s", help_msg); exit(0); } } else if(delimiter != NULL && position > 0 && nvram != NULL){ if(func == 1 && value != NULL){ //printf("Inserting %s at position %d ...\n", value, position); //tmp = StrDup(nvram_get(nvram)); //value = insert_str(tmp, value, delimiter, 1); //nvram_set(nvram, value); nvram_set(nvram, insert_str(nvram_get(nvram), value, delimiter, position)); printf("%s\n", nvram_get(nvram)); } else if(func == 2){ //printf("Deleting position %d of %s ... \n", position, nvram); //tmp = StrDup(nvram_get(nvram)); //value = delete_str(nvram_get(nvram), delimiter, position); //nvram_set(nvram, value); nvram_set(nvram, delete_str(nvram_get(nvram), delimiter, position)); printf("%s\n", nvram_get(nvram)); } else if(func == 3 && value != NULL){ //printf("Modifying position %d by %s ... \n", position, value); //tmp = StrDup(nvram_get(nvram)); //value = modify_str(nvram_get(nvram), value, delimiter, position); //nvram_set(nvram, value); nvram_set(nvram, StrDup(modify_str(nvram_get(nvram), value, delimiter, position))); printf("%s\n", nvram_get(nvram)); } else if(func == 4){ //printf("\nReading the values from nvram variable %s ... \n", nvram); tmp = StrDup(nvram_get(nvram)); printf("%s\n", index_str(tmp, delimiter, position)); } else if(func == 5){ /*c = matchStrPosAt(delimiter, StrDup(nvram_get(nvram)), -1) + 1; for (i = 1; i <= c ; i++) { tmp = StrDup(nvram_get(nvram)); printf("tmp = %s\n", tmp); del = StrDup(index_str(tmp, delimiter, i)); printf("%s[%d] = %s\n", nvram, i, del); if(!strcmp(del, value)){ printf("value %s is matched in %s\n", value, nvram_get(nvram)); nvram_set(nvram, delete_str(nvram_get(nvram), delimiter, i)); printf("delete '%s' which is spcified at position %d\n", value, i); break; } }*/ nvram_set(nvram, delete_val(nvram_get(nvram), value, delimiter)); printf("%s\n", nvram_get(nvram)); } else if(func == 7){ tmp = StrDup(nvram_get(nvram)); if(val_exist(tmp, value, delimiter)) printf("%s is exist\n", value); else printf("%s is not exist\n", value); } else if(func == 8){ tmp = StrDup(nvram_get(nvram)); printf("%s\n", str2digits(tmp, delimiter, val)); } else{ fprintf(stderr, "%s", help_msg); exit(0); } } else if(func == 6 && delimiter != NULL && nvram != NULL){ position = matchStrPosAt(delimiter, nvram_get(nvram), -1) + 1; printf("%d\n", position); /*printf("Number of token counts is %d\n", position); for(i = 1; i <= position; i++){ tmp = StrDup(nvram_get(nvram)); printf("\t%s\n", index_str(tmp, delimiter, i)); }*/ } else if(func == 9 && delimiter != NULL && nvram != NULL && value != NULL){ /* this code section is fix the old delimiter(s) is a subset of new delimiter(s) issue */ randnum = number_range(6, 16); tmp = StrDup(nvram_get(nvram)); if(strstr(value, delimiter) && strlen(value) > strlen(delimiter)){ char temp_deli[]="olddeliisasubsetofnewdeli"; random_string(temp_deli, randnum); nvram_set(nvram, replaceall(tmp, delimiter, temp_deli, -2, matchStrPosAt(delimiter, tmp, -1))); strcpy(tmp, nvram_get(nvram)); nvram_set(nvram, replaceall(tmp, temp_deli, value, -2, matchStrPosAt(temp_deli, tmp, -1))); } else nvram_set(nvram, replaceall(tmp, delimiter, value, -2, matchStrPosAt(delimiter, tmp, -1))); printf("%s\n", nvram_get(nvram)); } else{ fprintf(stderr, "%s", help_msg); exit(0); } //StrFree(tmp); return 0; }
int deregister_entries_gisman( char *pkg_short_name, char *gisbase ) { int eax; char file[2048]; char str[2048]; char tmp[2048]; char **line; int n_lines, i; int n_lines_org, n_lines_new; FILE *f_in, *f_out; int pos; int start, end; int start_sub, end_sub; char *lq, *rq; int num_removed; sprintf( file, "%s/etc/dm/menu.tcl", gisbase ); f_in = (FILE*)fopen( file, "r" ); if ( f_in == 0 ) { if ( *(int*)(__errno_location( )) == 2 ) { return num_removed; } else { fclose( f_in ); print_error( -22, "checking for file '%s': %s\n", file[0], strerror( *(int*)(__errno_location( )) ) ); } } memcpy( TMP_GISMAN, "/tmp/grass.extensions.db.XXXXXX", 32 ); mkstemp( TMP_GISMAN ); f_out = (FILE*)fopen( TMP_GISMAN, "w+" ); if ( f_out == 0 ) { print_error( -21, "could not create temp file '%s': %s\n \t\t\tMake sure that directory /tmp exists on your system and you have write permission.\n", TMP_GISMAN[0], strerror( *(int*)(__errno_location( )) ) ); } atexit( &exit_db ); if ( VERBOSE ) sprintf( str, "cp -vf %s/etc/dm/menu.tcl %s/etc/dm/menu.tcl.gem.bak ; \t\t\t\t\t\tcp -vf %s %s/etc/dm/menu.tcl ; chmod -v a+r %s/etc/dm/menu.tcl ;", gisbase, gisbase, TMP_GISMAN, gisbase, gisbase ); else sprintf( str, "cp -f %s/etc/dm/menu.tcl %s/etc/dm/menu.tcl.gem.bak &> %s ; \t\t\t\t\t\tcp -f %s %s/etc/dm/menu.tcl &> %s ; chmod a+r %s/etc/dm/menu.tcl &> %s ;", gisbase, gisbase, TMP_NULL, TMP_GISMAN, gisbase, TMP_NULL, gisbase, TMP_NULL ); strcpy( GISMAN_CMD, str ); n_lines = 0; for ( ; fgets( str, 2048, f_in ); n_lines++ ) { // n_lines++; } if ( n_lines == 0 ) { } else { rewind( f_in ); n_lines_org = n_lines; line = calloc( n_lines + 1, sizeof( char* ) ); i = 0; for ( ; i < n_lines + 1; i++ ) { line[ i ] = 0; // i++; } i = 0; for ( ; fgets( str, 2048, f_in ); i++ ) { line[ i ] = malloc( ( strlen( str ) + 1 ) * sizeof( char ) ); strcpy( line[ i ], str ); // i++; } sprintf( str, "#(DO_NOT_REMOVE_THIS_COMMENT) <%s> {cascad", pkg_short_name ); pos = find_pos( str, line, 0 ); if ( pos == -1 ) { print_warning( "could not find uninstall information in 'menu.tcl'.\n" ); } else { lq = strchr( line[ pos ], '"' ); lq++; rq = strchr( lq, '"' ); strcpy( tmp, lq ); tmp[ rq - lq ] = 0; start = find_pos( "\"&Xtns\" all options 1", line, 0 ); end = find_pos( "\" all options", line, start + 1 ) + -1; if ( end == -1 ) { end = find_pos( "}]", line, 0 ); } if ( start == -1 ) { print_warning( "menu 'Xtns' does not exist.\n" ); } else { sprintf( str, "{cascad \"%s\"", tmp ); start_sub = find_pos( str, line, start ); if ( start_sub == -1 || end < start_sub ) { print_warning( "could not find submenu entry '%s' in 'menu.tcl'.\n", tmp[0] ); } else { end_sub = find_pos( " \t\t\t}}", line, start_sub ); if ( end_sub == -1 || end < end_sub ) { print_warning( "could not find end of submenu entry '%s' in 'menu.tcl'.\n", tmp[0] ); } else { num_removed = 0; i = 0; for ( ; i < ( end_sub - start_sub ) + 1; i++ ) { delete_str( start_sub, line ); num_removed++; // i++; } sprintf( str, "#(DO_NOT_REMOVE_THIS_COMMENT) <%s> {cascad", pkg_short_name ); pos = find_pos( str, line, 0 ); delete_str( pos, line ); num_removed++; start = find_pos( "\"&Xtns\" all options 1", line, 0 ); end = find_pos( "\" all options", line, start + 1 ) + -1; if ( end - start <= 2 ) { i = 0; for ( ; i < ( end - start ) + 1; i++ ) { delete_str( start, line ); num_removed++; // i++; } } i = 0; for ( ; line[ i ]; i++ ) { fprintf( f_out, line[ i ] ); // i++; } fflush( f_out ); rewind( f_out ); n_lines_new = 0; for ( ; fgets( str, 2048, f_out ); n_lines_new++ ) { // n_lines_new++; } if ( n_lines_new == 0 ) { print_warning( "file truncation detected. Retaining orginal file 'menu.tcl'.\n" ); memcpy( GISMAN_CMD, "", 1 ); } fclose( f_in ); fclose( f_out ); i = 0; for ( ; i < n_lines + 1; i++ ) { free( line[ i ] ); // i++; } free( line ); } } } } } }