- Timestamp:
- 02/20/05 22:35:41 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/reglookup.c
r4 r6 417 417 418 418 419 /* Returns a newly malloc()ed string which contains original string, 420 * except for non-printable or special characters are quoted in hex 421 * with the syntax '\xQQ' where QQ is the hex ascii value of the quoted 422 * character. 423 */ 424 static 425 char* quote_string(const char* str, char* special) 426 { 427 unsigned int i; 428 unsigned int num_written=0; 429 unsigned int len = strlen(str); 430 unsigned int out_len = sizeof(char)*len+1; 431 char* ret_val = malloc(out_len); 432 if(ret_val == NULL) 433 return NULL; 434 435 for(i=0; i<len; i++) 436 { 437 if(str[i] < 32 || str[i] > 126 || strchr(special, str[i]) != NULL) 438 { 439 out_len += 3; 440 ret_val = realloc(ret_val, out_len); 441 if(ret_val == NULL) 442 break; 443 num_written += snprintf(ret_val+num_written, out_len-num_written, 444 "\\x%.2X", str[i]); 445 } 446 else 447 ret_val[num_written++] = str[i]; 448 } 449 ret_val[num_written] = '\0'; 450 451 return ret_val; 452 } 453 454 419 455 /* 420 456 * Iterate over the keys, depth first, calling a function for each key … … 886 922 unsigned char* ascii; 887 923 unsigned char* cur_str; 924 unsigned char* cur_ascii; 925 char* cur_quoted; 888 926 unsigned int cur_str_len; 889 927 unsigned int ascii_max, cur_str_max; … … 951 989 cur_str_max = sizeof(char)*len+1; 952 990 cur_str = malloc(cur_str_max); 991 cur_ascii = malloc(cur_str_max); 953 992 ascii = malloc(ascii_max+4); 954 993 if(ascii == NULL) … … 966 1005 cur_str_len = 0; 967 1006 968 *asciip = '"';969 asciip +=1;970 971 1007 for(i=0; (i < len) && str_rem > 0; i++) 972 1008 { … … 980 1016 if(num_nulls == 2) 981 1017 { 982 uni_to_ascii(cur_str, asciip, str_rem, 0); 983 alen = strlen((char*)asciip); 1018 uni_to_ascii(cur_str, cur_ascii, cur_str_max, 0); 1019 cur_quoted = quote_string((char*)cur_ascii, "|"); 1020 alen = snprintf((char*)asciip, str_rem, "%s", cur_quoted); 984 1021 asciip += alen; 985 1022 str_rem -= alen; 1023 free(cur_quoted); 1024 986 1025 if(*(datap+i+1) == 0 && *(datap+i+2) == 0) 987 1026 break; 988 1027 else 989 1028 { 990 alen = snprintf((char*)asciip, str_rem, "% s", "\" \"");1029 alen = snprintf((char*)asciip, str_rem, "%c", '|'); 991 1030 asciip += alen; 992 1031 str_rem -= alen; … … 999 1038 } 1000 1039 } 1001 snprintf((char*)asciip, str_rem, "%s", "\"");1040 *asciip = 0; 1002 1041 return ascii; 1003 1042 break;
Note: See TracChangeset
for help on using the changeset viewer.