Changeset 18 for trunk/src/sh_tools.c


Ignore:
Timestamp:
Jan 28, 2006, 9:07:52 PM (19 years ago)
Author:
rainer
Message:

Optimized version of tiger algorithm, and basic ingredients for unit testing (part 2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_tools.c

    r12 r18  
    125125char * sh_tools_safe_name (const char * instr, int flag)
    126126{
    127   unsigned char c;
     127  unsigned char c, d;
    128128  const  char * p;
    129129  char   *q;
     
    133133  int    i = 0;
    134134  unsigned char   val_octal = '\0';
     135  static char ctable[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
     136                             '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
    135137
    136138  SL_ENTER(_("sh_tools_safe_name"));
     
    202204            {
    203205              --i;
    204               sprintf(&outstr[i], "=%02x", c);          /* known to fit  */
     206              d = c % 16; c = c / 16;
     207              outstr[i] = '=';       ++i;
     208              outstr[i] = ctable[c]; ++i;
     209              outstr[i] = ctable[d]; ++i;
    205210            }
    206211
     
    274279            break;
    275280          default:
    276             if (strlen(p) < 3)
     281            if (strlen(p) < 3) /* certainly not an octal number, skip */
    277282              {
    278283                p += strlen(p);
     
    284289                if (val_octal != '\0') {
    285290                  c = val_octal;
    286                   sprintf(&outstr[i], "=%02x", c);       /* known to fit  */
    287                   i+=3;
     291                  d = c % 16; c = c / 16;
     292                  outstr[i] = '=';       ++i;
     293                  outstr[i] = ctable[c]; ++i;
     294                  outstr[i] = ctable[d]; ++i;
    288295                }
    289296                p += 3;
     
    294301        {
    295302          ++p;
    296           if (!p || !(*p))
    297             break;
     303          if (!p || !(*p))
     304            {
     305              outstr[i] = '&'; ++i;
     306              break;
     307            }
    298308
    299309          if (p[0] == 'a' && p[1] == 'm' && p[2] == 'p' && p[3] == ';')
Note: See TracChangeset for help on using the changeset viewer.