#include #include #include #include #include #include // gcc -mno-cygwin -o rmtag rmtag.c // gcc -mno-cygwin -mwindows -o rmtag rmtag.c #define TAG_MAX_SIZE 2048 #define TOKEN_MAX_SIZE 512 #define FAVOR 1 #define NOFAVOR (!FAVOR) int link_print_flag = FAVOR ; unsigned char *buffer ; struct stat fileInfo; unsigned char getToken(unsigned char *buff, unsigned char *token, int n) { register int i, c ; for( i=0, *token='\0'; (c=*(buff+i)) != '\0' && i<=n; i++ ) { if( c != ' ' && c != '>' && c != '\r' && c != '\n' ) { *(token+i) = tolower(c) ; *(token+i+1) = '\0' ; } else return(c) ; } } int seekEndToken(unsigned char *buff, unsigned char *token) { unsigned char tkn[TOKEN_MAX_SIZE] ; register int i, c ; for( i=1; (c=*(buff+i)) != '\0'; i++ ) { if ( c == '<' ) { getToken((buff+i), tkn, strlen(token)) ; strcat( tkn, ">") ; if( strcmp( token, tkn ) == 0 ) { return( i + strlen(token) -1 ) ; } } } return( i ) ; } unsigned char *checkStringsInTag(unsigned char *tag, unsigned char *strings) { unsigned char lowercase[TAG_MAX_SIZE] ; register int i, length = (TAG_MAX_SIZE -1) > strlen(tag) ? strlen(tag) : TAG_MAX_SIZE -1 ; for( i=0; i0 && *(buff+i)=='<'); i++) { if( j < TAG_MAX_SIZE -3 ) { link[j] = *(buff+i); link[j+1] = '>'; link[j+2] = '\0'; j++; } } if( *(buff+i) == '<' || *(buff+i) == '\0' ) { fprintf( stderr, "Bad file format!\n" ); if( *(buff+i) == '\0' ) { exit(1); } } else if( checkStringsInTag(link, "http") == NULL && flag == FAVOR) { fprintf( fpo, "%s", link ) ; } return( i ) ; } execution(unsigned char *buff, int size, FILE *fpo) { unsigned char token[TOKEN_MAX_SIZE], link[TAG_MAX_SIZE] ; register int i, j ; for( i=0; i") ; } else if( strcmp(token, "") ; } else if( strcmp(token, "") ; // } else if( strcmp(token, "") ; } else if( strcmp(token, " 1 && (fpo=fopen(argv[lp],"wb")) == NULL ) { fprintf( stderr, "File '%s' open error!", argv[lp] ); exit( 1 ) ; } else execution(buffer, data_size, fpo); fclose(fpo) ; free(buffer); } return 0 ; }