Changeset 551 for trunk/dll/internal


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

Indentation cleanup

Location:
trunk/dll/internal
Files:
2 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 
  • trunk/dll/internal/renum.c

    r2 r551  
    1717 */
    1818
     19int main(int argc, char *argv[])
     20{
    1921
    20 int main (int argc,char *argv[]) {
    21 
    22   static   FILE  *fpi,*fpo;
    23   static   int    x = 20000;  /* arbitrary starting number */
    24   static   char   s[256];
    25   static   char   filein[260],fileout[260];
    26   register char  *p;
    27   register int    z;
     22  static FILE *fpi, *fpo;
     23  static int x = 20000;         /* arbitrary starting number */
     24  static char s[256];
     25  static char filein[260], fileout[260];
     26  register char *p;
     27  register int z;
    2828
    2929  printf("\nUsage:  renum dlg.h\n Produces new renumbered dlg.h & dlg.bak\n");
    3030
    31   if(argc < 2)
    32     strcpy(filein,"FM3DLG.H");
     31  if (argc < 2)
     32    strcpy(filein, "FM3DLG.H");
    3333  else
    34     strcpy(filein,argv[1]);
    35   strcpy(fileout,filein);
    36   p = strrchr(filein,'.');
    37   if(p)
    38     strcpy(p,".BAK");
     34    strcpy(filein, argv[1]);
     35  strcpy(fileout, filein);
     36  p = strrchr(filein, '.');
     37  if (p)
     38    strcpy(p, ".BAK");
    3939  else
    40     strcat(p,".BAK");
    41   if(!stricmp(filein,fileout)) {
     40    strcat(p, ".BAK");
     41  if (!stricmp(filein, fileout)) {
    4242    printf(" **Error: input file == output file -- \"%s\" == \"%s\"\n",
    43            filein,fileout);
     43           filein, fileout);
    4444    return 1;
    4545  }
    4646
    4747  remove(filein);
    48   rename(fileout,filein);
    49   fpi = fopen(filein,"r+");
    50   if(fpi) {
    51     fpo = fopen(fileout,"w");
    52     if(fpo) {
    53       while(!feof(fpi)) {
    54         if(!fgets(s,256,fpi))
    55           break;
    56         if(s[strlen(s) - 1] == '\n')
    57           s[strlen(s) - 1] = 0;
    58         p = s;
    59         while(*p == ' ')
    60           p++;
    61         if(p != s)
    62           memmove(s,p,strlen(p) + 1);
    63         if(*s) {
    64           p = &s[strlen(s) - 1];
    65           while(*p == ' ' && p > s)
    66             p--;
    67           if(*p == ' ')
    68             *p = 0;
    69         }
    70         if(!*s) {
    71           fprintf(fpo,"\n");
    72           x = (x - (x % 100)) + 100;
    73         }
    74         else if((*s == '#' && strncmp(s,"#define ",8)) ||
    75                 !strncmp(s,"/*",2) || *s == '*')
    76           fprintf(fpo,"%s%s\n",(*s == '*') ? " " : "",s);
    77         else {
    78           s[39] = 0;
    79           p = &s[strlen(s) - 1];
    80           while(*p == ' ' && p > s)
    81             p--;
    82           if(*p == ' ')
    83             *p = 0;
    84           if(*s) {
    85             fprintf(fpo,"%s",s);
    86             for(z = strlen(s);z < 40;z++)
    87               fprintf(fpo," ");
    88             fprintf(fpo,"%d\n",x++);
    89           }
    90           else
    91             fprintf(fpo,"\n");
    92         }
     48  rename(fileout, filein);
     49  fpi = fopen(filein, "r+");
     50  if (fpi) {
     51    fpo = fopen(fileout, "w");
     52    if (fpo) {
     53      while (!feof(fpi)) {
     54        if (!fgets(s, 256, fpi))
     55          break;
     56        if (s[strlen(s) - 1] == '\n')
     57          s[strlen(s) - 1] = 0;
     58        p = s;
     59        while (*p == ' ')
     60          p++;
     61        if (p != s)
     62          memmove(s, p, strlen(p) + 1);
     63        if (*s) {
     64          p = &s[strlen(s) - 1];
     65          while (*p == ' ' && p > s)
     66            p--;
     67          if (*p == ' ')
     68            *p = 0;
     69        }
     70        if (!*s) {
     71          fprintf(fpo, "\n");
     72          x = (x - (x % 100)) + 100;
     73        }
     74        else if ((*s == '#' && strncmp(s, "#define ", 8)) ||
     75                 !strncmp(s, "/*", 2) || *s == '*')
     76          fprintf(fpo, "%s%s\n", (*s == '*') ? " " : "", s);
     77        else {
     78          s[39] = 0;
     79          p = &s[strlen(s) - 1];
     80          while (*p == ' ' && p > s)
     81            p--;
     82          if (*p == ' ')
     83            *p = 0;
     84          if (*s) {
     85            fprintf(fpo, "%s", s);
     86            for (z = strlen(s); z < 40; z++)
     87              fprintf(fpo, " ");
     88            fprintf(fpo, "%d\n", x++);
     89          }
     90          else
     91            fprintf(fpo, "\n");
     92        }
    9393      }
    9494      fclose(fpo);
     
    9797      fclose(fpi);
    9898      fpi = NULL;
    99       rename(filein,fileout);
    100       printf(" **Error: couldn't open output file \"%s\"\n",fileout);
     99      rename(filein, fileout);
     100      printf(" **Error: couldn't open output file \"%s\"\n", fileout);
    101101      return 1;
    102102    }
    103     if(fpi)
     103    if (fpi)
    104104      fclose(fpi);
    105105  }
    106106  else {
    107     rename(filein,fileout);
    108     printf(" **Error: couldn't open input file \"%s\"\n",filein);
     107    rename(filein, fileout);
     108    printf(" **Error: couldn't open input file \"%s\"\n", filein);
    109109    return 1;
    110110  }
Note: See TracChangeset for help on using the changeset viewer.