Changeset 6


Ignore:
Timestamp:
02/20/05 22:35:41 (20 years ago)
Author:
tim
Message:

Updated MULTI_SZ output. Strings are now '|' delimited and quoted.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/reglookup.c

    r4 r6  
    417417
    418418
     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 */
     424static
     425char* 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
    419455/*
    420456 * Iterate over the keys, depth first, calling a function for each key
     
    886922  unsigned char* ascii;
    887923  unsigned char* cur_str;
     924  unsigned char* cur_ascii;
     925  char* cur_quoted;
    888926  unsigned int cur_str_len;
    889927  unsigned int ascii_max, cur_str_max;
     
    951989    cur_str_max = sizeof(char)*len+1;
    952990    cur_str = malloc(cur_str_max);
     991    cur_ascii = malloc(cur_str_max);
    953992    ascii = malloc(ascii_max+4);
    954993    if(ascii == NULL)
     
    9661005    cur_str_len = 0;
    9671006
    968     *asciip = '"';
    969     asciip +=1;
    970    
    9711007    for(i=0; (i < len) && str_rem > 0; i++)
    9721008    {
     
    9801016      if(num_nulls == 2)
    9811017      {
    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);
    9841021        asciip += alen;
    9851022        str_rem -= alen;
     1023        free(cur_quoted);
     1024
    9861025        if(*(datap+i+1) == 0 && *(datap+i+2) == 0)
    9871026          break;
    9881027        else
    9891028        {
    990           alen = snprintf((char*)asciip, str_rem, "%s", "\" \"");
     1029          alen = snprintf((char*)asciip, str_rem, "%c", '|');
    9911030          asciip += alen;
    9921031          str_rem -= alen;
     
    9991038      }
    10001039    }
    1001     snprintf((char*)asciip, str_rem, "%s", "\"");
     1040    *asciip = 0;
    10021041    return ascii;
    10031042    break;
Note: See TracChangeset for help on using the changeset viewer.