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/internal/mkstr.c

    r243 r551  
    1212
    1313***********************************************************************/
    14 
    1514
    1615#define INCL_DOS
     
    3231 */
    3332
    34 int index (const char *s,const char c) {
    35 
    36     char *p;
    37 
    38     p = strchr(s,c);
    39     if(p == NULL || !*p)
    40       return -1;
    41     return (int)(p - s);
     33int index(const char *s, const char c)
     34{
     35
     36  char *p;
     37
     38  p = strchr(s, c);
     39  if (p == NULL || !*p)
     40    return -1;
     41  return (int)(p - s);
    4242}
    43 
    4443
    4544/*
     
    6867#define DEC "0123456789"
    6968
    70 int literal (char *fsource) {
    71 
    72   register int wpos,w;
    73   int          len,oldw;
    74   char        *fdestin,*freeme,wchar;
    75 
    76   if(!fsource || !*fsource)
     69int literal(char *fsource)
     70{
     71
     72  register int wpos, w;
     73  int len, oldw;
     74  char *fdestin, *freeme, wchar;
     75
     76  if (!fsource || !*fsource)
    7777    return 0;
    7878  len = strlen(fsource) + 1;
    7979  freeme = fdestin = malloc(len + 1);
    80   memset(fdestin,0,len);              /* start out with zero'd string */
    81 
    82   w = 0;                              /* set index to first character */
    83   while(fsource[w]) {                 /* until end of string */
    84     switch(fsource[w]) {
    85       case '\\':
    86         switch(fsource[w + 1]) {
    87           case 'x' :                  /* hexadecimal */
    88             wchar = 0;
    89             w += 2;                   /* get past "\x" */
    90             if(index(HEX,(char)toupper(fsource[w])) != -1) {
    91               oldw = w;
    92               while(((wpos = index(HEX,(char)toupper(fsource[w]))) != -1) &&
    93                     w < oldw + 2) {
    94                 wchar = (char)(wchar << 4) + (char)wpos;
    95                 w++;
    96               }
    97             }
    98             else
    99               wchar = 'x';            /* just an x */
    100             w--;
    101             *fdestin++ = wchar;
    102             break;
    103 
    104           case '\\' :                 /* we want a "\" */
    105             w++;
    106             *fdestin++ = '\\';
    107             break;
    108 
    109           case 't' :                  /* tab char */
    110             w++;
    111             *fdestin++ = '\t';
    112             break;
    113 
    114           case 'n' :                  /* new line */
    115             w++;
    116             *fdestin++ = '\n';
    117             break;
    118 
    119           case 'r' :                  /* carr return */
    120             w++;
    121             *fdestin++ = '\r';
    122             break;
    123 
    124           case 'b' :                  /* back space */
    125             w++;
    126             *fdestin++ = '\b';
    127             break;
    128 
    129           case 'f':                   /* formfeed */
    130             w++;
    131             *fdestin++ = '\x0c';
    132             break;
    133 
    134           case 'a':                   /* bell */
    135             w++;
    136             *fdestin++ = '\07';
    137             break;
    138 
    139           case '\'' :                 /* single quote */
    140             w++;
    141             *fdestin++ = '\'';
    142             break;
    143 
    144           case '\"' :                 /* double quote */
    145             w++;
    146             *fdestin++ = '\"';
    147             break;
    148 
    149           default :                   /* decimal */
    150             w++;                      /* get past "\" */
    151             wchar = 0;
    152             if(index(DEC,fsource[w]) != -1) {
    153               oldw = w;
    154               do {                    /* cvt to binary */
    155                 wchar = (char)(wchar * 10 + (fsource[w++] - 48));
    156               } while (index(DEC,fsource[w]) != -1 && w < oldw + 3);
    157               w--;
    158             }
    159             else
    160               wchar = fsource[w];
    161             *fdestin ++ = wchar;
    162             break;
    163         }
    164         break;
    165 
    166       default :
    167         *fdestin++ = fsource[w];
    168         break;
    169    }
    170    w++;
     80  memset(fdestin, 0, len);              /* start out with zero'd string */
     81
     82  w = 0;                                /* set index to first character */
     83  while (fsource[w]) {                  /* until end of string */
     84    switch (fsource[w]) {
     85    case '\\':
     86      switch (fsource[w + 1]) {
     87      case 'x':                 /* hexadecimal */
     88        wchar = 0;
     89        w += 2;                         /* get past "\x" */
     90        if (index(HEX, (char)toupper(fsource[w])) != -1) {
     91          oldw = w;
     92          while (((wpos = index(HEX, (char)toupper(fsource[w]))) != -1) &&
     93                w < oldw + 2) {
     94            wchar = (char)(wchar << 4) + (char)wpos;
     95            w++;
     96          }
     97        }
     98        else
     99          wchar = 'x';                  /* just an x */
     100        w--;
     101        *fdestin++ = wchar;
     102        break;
     103
     104      case '\\':                        /* we want a "\" */
     105        w++;
     106        *fdestin++ = '\\';
     107        break;
     108
     109      case 't':                 /* tab char */
     110        w++;
     111        *fdestin++ = '\t';
     112        break;
     113
     114      case 'n':                 /* new line */
     115        w++;
     116        *fdestin++ = '\n';
     117        break;
     118
     119      case 'r':                 /* carr return */
     120        w++;
     121        *fdestin++ = '\r';
     122        break;
     123
     124      case 'b':                 /* back space */
     125        w++;
     126        *fdestin++ = '\b';
     127        break;
     128
     129      case 'f':                 /* formfeed */
     130        w++;
     131        *fdestin++ = '\x0c';
     132        break;
     133
     134      case 'a':                 /* bell */
     135        w++;
     136        *fdestin++ = '\07';
     137        break;
     138
     139      case '\'':                        /* single quote */
     140        w++;
     141        *fdestin++ = '\'';
     142        break;
     143
     144      case '\"':                        /* double quote */
     145        w++;
     146        *fdestin++ = '\"';
     147        break;
     148
     149      default:                          /* decimal */
     150        w++;                            /* get past "\" */
     151        wchar = 0;
     152        if (index(DEC, fsource[w]) != -1) {
     153          oldw = w;
     154          do {                          /* cvt to binary */
     155            wchar = (char)(wchar * 10 + (fsource[w++] - 48));
     156          } while (index(DEC, fsource[w]) != -1 && w < oldw + 3);
     157          w--;
     158        }
     159        else
     160          wchar = fsource[w];
     161        *fdestin++ = wchar;
     162        break;
     163      }
     164      break;
     165
     166    default:
     167      *fdestin++ = fsource[w];
     168      break;
     169    }
     170    w++;
    171171  }
    172   *fdestin = 0;                               /* terminate the string */
     172  *fdestin = 0;                         /* terminate the string */
    173173
    174174  len = fdestin - freeme;
    175   memcpy(fsource,freeme,len + 1);             /* swap 'em */
     175  memcpy(fsource, freeme, len + 1);     /* swap 'em */
    176176  free(freeme);
    177177
    178   return len;                                 /* return length of string */
     178  return len;                           /* return length of string */
    179179}
    180180
    181 
    182 int main (void) {
    183 
    184   FILE       *fpin,*fpout;
    185   ULONG       len,x = 0,totallen = 0,thislen;
    186   USHORT      vermajor = 0,verminor = 0;
     181int main(void)
     182{
     183
     184  FILE *fpin, *fpout;
     185  ULONG len, x = 0, totallen = 0, thislen;
     186  USHORT vermajor = 0, verminor = 0;
    187187  static char str[8192];
    188   char       *outfile = "FM3RES.STR",*infile = "FM3DLL.STR";
     188  char *outfile = "FM3RES.STR", *infile = "FM3DLL.STR";
    189189
    190190  vermajor = VERMAJOR;
    191191  verminor = VERMINOR;
    192192  printf("\nFM/2 resource string compiler copyright (c) 1998 by M. Kimes"
    193          "\n Compiles FM3DLL.STR into FM3RES.STR.  For FM/2 version %d.%d.\n",
    194          vermajor,
    195          verminor);
     193         "\n Compiles FM3DLL.STR into FM3RES.STR.  For FM/2 version %d.%d.\n",
     194         vermajor, verminor);
    196195  /* open input file */
    197   fpin = fopen(infile,"r");
    198   if(fpin) {
     196  fpin = fopen(infile, "r");
     197  if (fpin) {
    199198    /* open (create) output file */
    200     fpout = fopen(outfile,"wb");
    201     if(fpout) {
     199    fpout = fopen(outfile, "wb");
     200    if (fpout) {
    202201      /* skip space for numstrs and textlen parameter in outfile */
    203       if(fseek(fpout,(sizeof(ULONG) * 2) + (sizeof(USHORT) * 2),SEEK_SET)) {
    204         printf("\n **Seek error on %s!\n",outfile);
    205         fclose(fpin);
    206         fclose(fpout);
    207         remove(outfile);
    208         return 1;
     202      if (fseek(fpout, (sizeof(ULONG) * 2) + (sizeof(USHORT) * 2), SEEK_SET)) {
     203        printf("\n **Seek error on %s!\n", outfile);
     204        fclose(fpin);
     205        fclose(fpout);
     206        remove(outfile);
     207        return 1;
    209208      }
    210209      /* step through strings, reading from input, writing to output */
    211       while(!feof(fpin)) {
    212         if(!fgets(str,sizeof(str),fpin))
    213           break;
    214         str[8191] = 0;
    215         if(*str &&
    216            str[strlen(str) - 1] == '\n')
    217           str[strlen(str) - 1] = 0;
    218         len = (*str) ? literal(str) : 0;
    219         /* write string to output file, including terminating NULL */
    220         thislen = fwrite(str,1,len + 1,fpout);
    221         if(thislen != len + 1) {
    222           printf("\n **Write error on %s!\n",outfile);
    223           fclose(fpin);
    224           fclose(fpout);
    225           remove(outfile);
    226           return 1;
    227         }
    228         totallen += thislen;
    229         x++;
    230       }
    231       if(x > IDS_NUMSTRS)
    232         printf("\n **Warning:  There are more strings in file "
    233                "than there should be -- should be %lu, are %lu.\n",
    234                IDS_NUMSTRS,
    235                x);
    236       else if(x < IDS_NUMSTRS) {
    237         printf("\n **Error -- insufficient strings in file -- "
    238                "should be %lu, are %lu.\n",
    239                IDS_NUMSTRS,
    240                x);
    241         fclose(fpin);
    242         fclose(fpout);
    243         remove(outfile);
    244         return 1;
     210      while (!feof(fpin)) {
     211        if (!fgets(str, sizeof(str), fpin))
     212          break;
     213        str[8191] = 0;
     214        if (*str && str[strlen(str) - 1] == '\n')
     215          str[strlen(str) - 1] = 0;
     216        len = (*str) ? literal(str) : 0;
     217        /* write string to output file, including terminating NULL */
     218        thislen = fwrite(str, 1, len + 1, fpout);
     219        if (thislen != len + 1) {
     220          printf("\n **Write error on %s!\n", outfile);
     221          fclose(fpin);
     222          fclose(fpout);
     223          remove(outfile);
     224          return 1;
     225        }
     226        totallen += thislen;
     227        x++;
     228      }
     229      if (x > IDS_NUMSTRS)
     230        printf("\n **Warning:  There are more strings in file "
     231               "than there should be -- should be %lu, are %lu.\n",
     232               IDS_NUMSTRS, x);
     233      else if (x < IDS_NUMSTRS) {
     234        printf("\n **Error -- insufficient strings in file -- "
     235               "should be %lu, are %lu.\n", IDS_NUMSTRS, x);
     236        fclose(fpin);
     237        fclose(fpout);
     238        remove(outfile);
     239        return 1;
    245240      }
    246241      /* start output file with number of strings (long),
    247242       * size of text (long), and version (2 shorts) */
    248       if(fseek(fpout,0,SEEK_SET) ||
    249          fwrite(&x,sizeof(x),1,fpout) != 1 ||
    250          fwrite(&totallen,sizeof(totallen),1,fpout) != 1 ||
    251          fwrite(&vermajor,sizeof(vermajor),1,fpout) != 1 ||
    252          fwrite(&verminor,sizeof(verminor),1,fpout) != 1) {
    253         printf("\n **Error -- bad seek or write to %s!\n",outfile);
    254         fclose(fpin);
    255         fclose(fpout);
    256         remove(outfile);
    257         return 1;
     243      if (fseek(fpout, 0, SEEK_SET) ||
     244          fwrite(&x, sizeof(x), 1, fpout) != 1 ||
     245          fwrite(&totallen, sizeof(totallen), 1, fpout) != 1 ||
     246          fwrite(&vermajor, sizeof(vermajor), 1, fpout) != 1 ||
     247          fwrite(&verminor, sizeof(verminor), 1, fpout) != 1) {
     248        printf("\n **Error -- bad seek or write to %s!\n", outfile);
     249        fclose(fpin);
     250        fclose(fpout);
     251        remove(outfile);
     252        return 1;
    258253      }
    259254      fclose(fpout);
    260255      printf("\n%s successfully written from %s (%lu strings).\n",
    261              outfile,infile,x);
     256             outfile, infile, x);
    262257    }
    263258    else
    264       printf("\n **Can't create %s!\n",outfile);
     259      printf("\n **Can't create %s!\n", outfile);
    265260    fclose(fpin);
    266261  }
    267262  else
    268     printf("\n **Can't open %s!\n",infile);
     263    printf("\n **Can't open %s!\n", infile);
    269264  return 0;
    270265}
    271 
Note: See TracChangeset for help on using the changeset viewer.