Changeset 551 for trunk/dll/literal.c


Ignore:
Timestamp:
Feb 28, 2007, 2:33:51 AM (19 years ago)
Author:
Gregg Young
Message:

Indentation cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/literal.c

    r409 r551  
    3131static PSZ pszSrcFile = __FILE__;
    3232
    33 static INT index(const CHAR *s,const CHAR c);
     33static INT index(const CHAR * s, const CHAR c);
    3434
    3535#pragma alloc_text(LITERAL,literal,index,fixup,wildcard)
     
    4141 */
    4242
    43 static INT index(const CHAR *s,const CHAR c)
    44 {
    45     CHAR *p;
    46 
    47     p = strchr(s,c);
    48     if(p == NULL || !*p)
    49       return -1;
    50     return (INT)(p - s);
     43static INT index(const CHAR * s, const CHAR c)
     44{
     45  CHAR *p;
     46
     47  p = strchr(s, c);
     48  if (p == NULL || !*p)
     49    return -1;
     50  return (INT) (p - s);
    5151}
    5252
     
    8282UINT literal(PSZ pszBuf)
    8383{
    84   INT   wpos;
    85   INT   iBuf;
    86   UINT  cBufBytes;
    87   INT   iBufSave;
    88   PSZ   pszOut;
    89   PSZ   pszWork;
    90   CHAR  wchar;
    91 
    92   if(!pszBuf || !*pszBuf)
     84  INT wpos;
     85  INT iBuf;
     86  UINT cBufBytes;
     87  INT iBufSave;
     88  PSZ pszOut;
     89  PSZ pszWork;
     90  CHAR wchar;
     91
     92  if (!pszBuf || !*pszBuf)
    9393    return 0;
    9494  cBufBytes = strlen(pszBuf) + 1;
    95   pszWork = pszOut = xmalloc(cBufBytes + 1,pszSrcFile,__LINE__);
    96 
    97   iBuf = 0;                             /* set index to first character */
    98   while(pszBuf[iBuf]) {
    99     switch(pszBuf[iBuf]) {
    100       case '\\':
    101         switch(pszBuf[iBuf + 1]) {
    102           case 'x' :                    /* hexadecimal */
    103             wchar = 0;
    104             iBuf += 2;                  /* get past "\x" */
    105             if(index(HEX,(CHAR)toupper(pszBuf[iBuf])) != -1) {
    106               iBufSave = iBuf;
    107               while(((wpos = index(HEX,(CHAR)toupper(pszBuf[iBuf]))) != -1) &&
    108                     iBuf < iBufSave + 2) {
    109                 wchar = (CHAR)(wchar << 4) + (CHAR)wpos;
    110                 iBuf++;
    111               }
    112             }
    113             else
    114               wchar = 'x';              /* just an x */
    115             iBuf--;
    116             *pszOut++ = wchar;
    117             break;
    118 
    119           case '\\' :                   /* we want a "\" */
     95  pszWork = pszOut = xmalloc(cBufBytes + 1, pszSrcFile, __LINE__);
     96
     97  iBuf = 0;                             /* set index to first character */
     98  while (pszBuf[iBuf]) {
     99    switch (pszBuf[iBuf]) {
     100    case '\\':
     101      switch (pszBuf[iBuf + 1]) {
     102      case 'x':                 /* hexadecimal */
     103        wchar = 0;
     104        iBuf += 2;                      /* get past "\x" */
     105        if (index(HEX, (CHAR) toupper(pszBuf[iBuf])) != -1) {
     106          iBufSave = iBuf;
     107          while (((wpos = index(HEX, (CHAR) toupper(pszBuf[iBuf]))) != -1) &&
     108                 iBuf < iBufSave + 2) {
     109            wchar = (CHAR) (wchar << 4) + (CHAR) wpos;
    120110            iBuf++;
    121             *pszOut++ = '\\';
    122             break;
    123 
    124           case 't' :                    /* tab CHAR */
    125             iBuf++;
    126             *pszOut++ = '\t';
    127             break;
    128 
    129           case 'n' :                    /* new line */
    130             iBuf++;
    131             *pszOut++ = '\n';
    132             break;
    133 
    134           case 'r' :                    /* carr return */
    135             iBuf++;
    136             *pszOut++ = '\r';
    137             break;
    138 
    139           case 'b' :                    /* back space */
    140             iBuf++;
    141             *pszOut++ = '\b';
    142             break;
    143 
    144           case 'f':                     /* formfeed */
    145             iBuf++;
    146             *pszOut++ = '\x0c';
    147             break;
    148 
    149           case 'a':                     /* bell */
    150             iBuf++;
    151             *pszOut++ = '\07';
    152             break;
    153 
    154           case '\'' :                   /* single quote */
    155             iBuf++;
    156             *pszOut++ = '\'';
    157             break;
    158 
    159           case '\"' :                   /* double quote */
    160             iBuf++;
    161             *pszOut++ = '\"';
    162             break;
    163 
    164           default :                     /* decimal */
    165             iBuf++;                     /* get past "\" */
    166             wchar = 0;
    167             if(index(DEC,pszBuf[iBuf]) != -1) {
    168               iBufSave = iBuf;
    169               do {                      /* cvt to binary */
    170                 wchar = (CHAR)(wchar * 10 + (pszBuf[iBuf++] - 48));
    171               } while (index(DEC,pszBuf[iBuf]) != -1 && iBuf < iBufSave + 3);
    172               iBuf--;
    173             }
    174             else
    175               wchar = pszBuf[iBuf];
    176             *pszOut ++ = wchar;
    177             break;
    178         } // switch
    179         break;
    180 
    181       default :
    182         *pszOut++ = pszBuf[iBuf];
    183         break;
    184    } // switch
    185    iBuf++;
    186   } // while
     111          }
     112        }
     113        else
     114          wchar = 'x';                  /* just an x */
     115        iBuf--;
     116        *pszOut++ = wchar;
     117        break;
     118
     119      case '\\':                        /* we want a "\" */
     120        iBuf++;
     121        *pszOut++ = '\\';
     122        break;
     123
     124      case 't':                 /* tab CHAR */
     125        iBuf++;
     126        *pszOut++ = '\t';
     127        break;
     128
     129      case 'n':                 /* new line */
     130        iBuf++;
     131        *pszOut++ = '\n';
     132        break;
     133
     134      case 'r':                 /* carr return */
     135        iBuf++;
     136        *pszOut++ = '\r';
     137        break;
     138
     139      case 'b':                 /* back space */
     140        iBuf++;
     141        *pszOut++ = '\b';
     142        break;
     143
     144      case 'f':                 /* formfeed */
     145        iBuf++;
     146        *pszOut++ = '\x0c';
     147        break;
     148
     149      case 'a':                 /* bell */
     150        iBuf++;
     151        *pszOut++ = '\07';
     152        break;
     153
     154      case '\'':                        /* single quote */
     155        iBuf++;
     156        *pszOut++ = '\'';
     157        break;
     158
     159      case '\"':                        /* double quote */
     160        iBuf++;
     161        *pszOut++ = '\"';
     162        break;
     163
     164      default:                          /* decimal */
     165        iBuf++;                         /* get past "\" */
     166        wchar = 0;
     167        if (index(DEC, pszBuf[iBuf]) != -1) {
     168          iBufSave = iBuf;
     169          do {                          /* cvt to binary */
     170            wchar = (CHAR) (wchar * 10 + (pszBuf[iBuf++] - 48));
     171          } while (index(DEC, pszBuf[iBuf]) != -1 && iBuf < iBufSave + 3);
     172          iBuf--;
     173        }
     174        else
     175          wchar = pszBuf[iBuf];
     176        *pszOut++ = wchar;
     177        break;
     178      }                                 // switch
     179      break;
     180
     181    default:
     182      *pszOut++ = pszBuf[iBuf];
     183      break;
     184    }                                   // switch
     185    iBuf++;
     186  }                                     // while
    187187  *pszOut = 0;                          /* Always terminate, even if not string */
    188188
    189189  cBufBytes = pszOut - pszWork;         /* Calc string length excluding terminator */
    190   memcpy(pszBuf,pszWork,cBufBytes + 1); /* Overwrite including terminator */
     190  memcpy(pszBuf, pszWork, cBufBytes + 1);       /* Overwrite including terminator */
    191191  free(pszWork);
    192192
    193   return cBufBytes;                     /* Return string length */
     193  return cBufBytes;                     /* Return string length */
    194194}
    195195
     
    201201 */
    202202
    203 
    204 BOOL wildcard(const PSZ pszBuf,const PSZ pszWildCard,const BOOL fNotFileSpec)
     203BOOL wildcard(const PSZ pszBuf, const PSZ pszWildCard,
     204              const BOOL fNotFileSpec)
    205205{
    206206  const CHAR *fstr = pszBuf;
    207207  PSZ fcard = pszWildCard;
    208   INT         wmatch = TRUE;
    209 
    210   while(wmatch && *fcard && *fstr) {
    211     switch(*fcard) {
    212       case '?' :                        /* character substitution */
    213         fcard++;
    214          if(fNotFileSpec || (*fstr != '.' && *fstr != '/' && *fstr != '\\'))
    215            fstr++;                      /* skip (match) next character */
    216         break;
    217 
    218       case '*' :
    219         /* find next non-wild character in wildcard */
    220          while(*fcard && (*fcard == '?' || *fcard == '*'))
    221            fcard++;
    222          if(!*fcard)   /* if last char of wildcard is *, it matches */
    223            return TRUE;
    224         /* skip until partition, match, or eos */
    225          while(*fstr && toupper(*fstr) != toupper(*fcard) &&
    226                (fNotFileSpec || (*fstr != '\\' &&
    227                *fstr != '/' && *fstr != '.')))
    228            fstr++;
    229          if(!fNotFileSpec && !*fstr)    /* implicit '.' */
    230            if(*fcard == '.')
    231              fcard++;
    232         break;
    233 
    234       default  :
    235          if(!fNotFileSpec && ((*fstr == '/' || *fstr == '\\') &&
    236             (*fcard == '/' || *fcard == '\\')))
    237            wmatch = TRUE;
    238         else
    239            wmatch = (toupper(*fstr) == toupper(*fcard));
    240         fstr++;
    241         fcard++;
    242         break;
     208  INT wmatch = TRUE;
     209
     210  while (wmatch && *fcard && *fstr) {
     211    switch (*fcard) {
     212    case '?':                           /* character substitution */
     213      fcard++;
     214      if (fNotFileSpec || (*fstr != '.' && *fstr != '/' && *fstr != '\\'))
     215        fstr++;                         /* skip (match) next character */
     216      break;
     217
     218    case '*':
     219      /* find next non-wild character in wildcard */
     220      while (*fcard && (*fcard == '?' || *fcard == '*'))
     221        fcard++;
     222      if (!*fcard)                      /* if last char of wildcard is *, it matches */
     223        return TRUE;
     224      /* skip until partition, match, or eos */
     225      while (*fstr && toupper(*fstr) != toupper(*fcard) &&
     226             (fNotFileSpec || (*fstr != '\\' &&
     227                               *fstr != '/' && *fstr != '.')))
     228        fstr++;
     229      if (!fNotFileSpec && !*fstr)      /* implicit '.' */
     230        if (*fcard == '.')
     231          fcard++;
     232      break;
     233
     234    default:
     235      if (!fNotFileSpec && ((*fstr == '/' || *fstr == '\\') &&
     236                            (*fcard == '/' || *fcard == '\\')))
     237        wmatch = TRUE;
     238      else
     239        wmatch = (toupper(*fstr) == toupper(*fcard));
     240      fstr++;
     241      fcard++;
     242      break;
    243243    }
    244244  }
     
    250250}
    251251
    252 
    253252// fixup - quote literal character array
    254253
    255 PSZ fixup(const PCH pachIn, PSZ pszOutBuf, const UINT cBufBytes, const UINT cInBytes)
    256 {
    257   PCH   pchIn = pachIn;
    258   PCH   pchOut = pszOutBuf;
    259   PSZ   pszTemp;
    260   static CHAR   szTemp[5] = "\\x";      // Constant prefix
     254PSZ fixup(const PCH pachIn, PSZ pszOutBuf, const UINT cBufBytes,
     255          const UINT cInBytes)
     256{
     257  PCH pchIn = pachIn;
     258  PCH pchOut = pszOutBuf;
     259  PSZ pszTemp;
     260  static CHAR szTemp[5] = "\\x";        // Constant prefix
    261261
    262262  // input is a character array, not a string - may not be null terminated
     
    264264  if (pachIn) {
    265265    // Ensure room for null and possible \ escape
    266     while (pchIn - pachIn < cInBytes &&
    267            pchOut - pszOutBuf + 2 < cBufBytes) {
    268       if(!isprint(*pchIn)) {
    269         if(*pchIn == '\r') {
     266    while (pchIn - pachIn < cInBytes && pchOut - pszOutBuf + 2 < cBufBytes) {
     267      if (!isprint(*pchIn)) {
     268        if (*pchIn == '\r') {
    270269          *pchOut++ = '\\';
    271270          *pchOut++ = 'r';
    272271        }
    273         else if(*pchIn == '\n') {
     272        else if (*pchIn == '\n') {
    274273          *pchOut++ = '\\';
    275274          *pchOut++ = 'n';
    276275        }
    277         else if(*pchIn == '\b') {
     276        else if (*pchIn == '\b') {
    278277          *pchOut++ = '\\';
    279278          *pchOut++ = 'b';
    280279        }
    281280        else {
    282           sprintf(szTemp + 2,"%02hx",*pchIn);
     281          sprintf(szTemp + 2, "%02hx", *pchIn);
    283282          for (pszTemp = szTemp; *pszTemp;)
    284283            *pchOut++ = *pszTemp++;
     
    286285        pchIn++;
    287286      }
    288       else if(*pchIn == '\\') {
     287      else if (*pchIn == '\\') {
    289288        *pchOut++ = '\\';
    290289        *pchOut++ = '\\';
     
    293292      else
    294293        *pchOut++ = *pchIn++;
    295     } // while
    296   } // if pachIn
     294    }                                   // while
     295  }                                     // if pachIn
    297296  *pchOut = 0;
    298297  return pszOutBuf;
    299298}
    300 
Note: See TracChangeset for help on using the changeset viewer.