int main() { int i,j,k,t,s,delta, d_str, j_sdvig, index; char dir1[15] = "win"; char dir2[15] = "winXP"; char del; char raz = '\\'; char str[260] = "C:\\win\\explorer.exe+C:\\Wpn\\sys\\tem32+C:\\win\\Distrib"; char *ptr[10]; char *ptr_dir1[10]; char *ptr_raz[10]; printf("delim: "); scanf("%c",&del); char *suf = str; //C:\\Windows\\system32+C:\\User\\test+C:\\user\\explorer.exe+C:\\Windows\\Distrib /* printf("paths: "); scanf("%s",&str); printf("dir1: "); scanf("%s",&dir1); printf("dir2: "); scanf("%s",&dir2);*/ delta = slen(dir1) - slen(dir2); d_str = slen(str); //printf("delta = %d\n", delta); i = stok(str, del, ptr); k = stok(dir1, raz, ptr_dir1); //t = stok(ptr[0], raz, ptr_raz); //printf("k = %d\n", k); int f = 0; for(j = 0; j < i; j++) { sspn(ptr[j]); } for (j = 0; j < i; j++) { t = stok(ptr[j], raz, ptr_raz); if(k > 1){ for (s = 0; s < k; s++) { f += sequal(ptr_dir1[s], ptr_raz[s]); if (f == k) { index = ptr_raz[s+1] - suf; if (delta < 0) { for (j_sdvig = d_str - delta; j_sdvig > index + delta; j_sdvig--) { str[j_sdvig - delta] = str[j_sdvig]; } for (j_sdvig = j; j_sdvig < i; j_sdvig++) { ptr[j_sdvig + 1] = ptr[j_sdvig + 1] - delta; } ptr_raz[s +1] = ptr_raz[s + 1] - delta; } if (delta > 0) { //d_str = d_str - delta; for (j_sdvig = index; j_sdvig < d_str; j_sdvig++) { str[j_sdvig - delta] = str[j_sdvig]; } str[d_str-delta] = '\0'; for (j_sdvig = j; j_sdvig < i; j_sdvig++) { ptr[j_sdvig + 1] = ptr[j_sdvig + 1] - delta; } ptr_raz[s + 1] = ptr_raz[s + 1] - delta; } //shift(*ptr, *ptr_raz, str, d_str, index, delta, s, j); suntok(ptr[j], raz, ptr_raz, t); scopy(dir2, ptr[j]); f = 0; } suntok(ptr[j], raz, ptr_raz, t); } } for (s = 0; s < t; s++) { f += sequal(dir1, ptr_raz[s]); //printf("f = %d\n", f); if(f == 1){ //printf("s = %d\n", s); index = ptr_raz[s+1] - suf; ///printf("index= %d\n ", index); if (delta < 0) { for (j_sdvig = d_str - delta; j_sdvig > index + delta; j_sdvig--) { str[j_sdvig - delta] = str[j_sdvig]; } for (j_sdvig = j; j_sdvig < i; j_sdvig++) { ptr[j_sdvig + 1] = ptr[j_sdvig + 1] - delta; } ptr_raz[s + 1] = ptr_raz[s + 1] - delta; } if (delta > 0) { for (j_sdvig = index; j_sdvig < d_str; j_sdvig++) { str[j_sdvig - delta] = str[j_sdvig]; } str[d_str-delta] = '\0'; for (j_sdvig = j; j_sdvig < i; j_sdvig++) { ptr[j_sdvig + 1] = ptr[j_sdvig + 1] - delta; } ptr_raz[s + 1] = ptr_raz[s + 1] - delta; } scopy(dir2, ptr_raz[s]); f = 0; } suntok(ptr[j], raz, ptr_raz, t); } //f = 0; } suntok(str, del, ptr, i); printf("%s",str); return 0; }
int check(char *s) { char d_ru[] = "ru"; char d_com[] = "com"; char d_org[] = "org"; char err_sym[] = {':', '*', '?', '<', ' ', '>', '|', '"', '\\', '@', ',', ';', '#', '$', '%', '^', '&', '(', ')', '\0'}; char IP_num[]="0123456789"; char prot_h[] = "http:"; char prot_s[] = "smb:"; char prot_f[] = "ftp:"; char prot_r[] = "rsync:"; char *slash_ptr[50]; char *dot_ptr[10]; int count_slash, count_dot, ERROR; int i; /* Length of string */ if (slen(s) == 0) { printf("\tInsufficient length(0)\n"); return ERROR = ERROR_LENGTH; } /* The less length of string is 10 */ if (slen(s) < 10) { printf("\tToo short string / not enough information about path\n"); return ERROR = ERROR_LENGTH; } /* Length of string >= 261 */ if (slen(s) >= string_size) { printf("\tNot correct lenght string(>= 261)\n"); return ERROR = ERROR_LENGTH; } count_slash = stok(s, '/', slash_ptr); // Counting number of slashes and stok it /* slashes verification */ if ((count_slash >= 3) && (*slash_ptr[1] == '\0') && (*slash_ptr[2] != '\0') && (*slash_ptr[0] != '\0')) { ERROR = NO_ERROR; } else { printf("\tIncorrectly placed slashes\n"); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_SLASHES; } /* protocol verification and counting number of dots */ if ((sequal(*slash_ptr, prot_h) == 1) || (sequal(*slash_ptr, prot_s) == 1) || (sequal(*slash_ptr, prot_f) == 1) || (sequal(*slash_ptr, prot_r) == 1)){ count_dot = stok(*(slash_ptr + 2), '.', dot_ptr); // Counting number of dots } else { printf("\tProtocol is false %s\n", *slash_ptr); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_PROTOCOL; } /* If it's domain */ if (count_dot == 2) { if (slen(*(dot_ptr)) == 0) { printf("\tLength of addres before the first dot == NULL\n"); suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_LENGTH; } if (scspn(*(dot_ptr), err_sym) == -1) {// check on err_sym (*address*) if (scspn(*(dot_ptr + 1), err_sym) >= 0) { //check on err_sym (*.ru) printf("\tFounded invalid symbols in the top domain\n"); suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_INV_SYMB; } if ((sequal(*(dot_ptr + 1), d_com) == 1) || (sequal(*(dot_ptr + 1), d_org) == 1) || (sequal(*(dot_ptr + 1), d_ru) == 1)) { // the top domain verification /* check directory */ for (i = 3; i < count_slash; i++) { if ((*slash_ptr[i] == '\0') && ((i + 1) < count_slash)) { printf("\tIncorrect length of directory\n"); suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_LENGTH_LL; } if (scspn(slash_ptr[i], err_sym) >= 0) { printf("\tFounded invalid symbols in directory\n"); suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_INV_SYMB; } } suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = NO_ERROR; } else { printf("\tThe top domain is false"); suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_DOMAIN; } } else { printf("\tNot correct domain, founded invalid symbols\n"); suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_INV_SYMB; } } else if (count_dot == 4) {// If it's IP address for (i = 0; i < count_dot; i++) { if (slen(*(dot_ptr + i)) == 0) { printf("\tIncorrect length of the ip\n"); suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_LENGTH_IP; } if (scspn(*(dot_ptr + i), err_sym) >= 0) { printf("not correct IP, founded invalid symbols\n"); suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_INV_SYMB; } if (sspn(*(dot_ptr + i), IP_num) == -1 ){ printf("not correct IP, founded invalid symbols for IP(not numeral)\n"); suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_INV_SYMB; } if ((atoi_str(*(dot_ptr + i)) > 255) || (atoi_str(*(dot_ptr + i)) < 0)) { printf("Not correct IP(> 255 or < 0)\n"); suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_RANGE_IP; } } /* check directory */ for (i = 3; i < count_slash; i++) { if ((*slash_ptr[i] == '\0') && ((i + 1) < count_slash)) { printf("\tIncorrect length of directory\n"); suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_LENGTH_LL; } if (scspn(slash_ptr[i], err_sym) >= 0) { printf("\tFounded invalid symbols in directory\n"); suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_INV_SYMB; } } suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = NO_ERROR; } else { printf("\tNot correct domain \\ IP (dots)\n"); suntok(*(slash_ptr + 2), '.', dot_ptr, count_dot); suntok(s, '/', slash_ptr, count_slash); return ERROR = ERROR_DOTS; } }