Changeset 551 for trunk/dll/string.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/string.c

    r333 r551  
    2929#pragma alloc_text(STRINGS,LoadStrings,GetPString)
    3030
    31 static char **strs,*str;
    32 static ULONG  numStr;
     31static char **strs, *str;
     32static ULONG numStr;
    3333
    3434//== LoadStrings() load strings from file ==
    3535
    36 BOOL LoadStrings (char *filename)
     36BOOL LoadStrings(char *filename)
    3737{
    38   BOOL           ok = FALSE;
    39   ULONG          size,len,totalsize;
    40   USHORT         vermajor = 0,verminor = 0;
     38  BOOL ok = FALSE;
     39  ULONG size, len, totalsize;
     40  USHORT vermajor = 0, verminor = 0;
    4141  register char *p;
    4242  register ULONG x;
    43   FILE          *fp;
    44   APIRET        rc;
     43  FILE *fp;
     44  APIRET rc;
    4545
    4646  /* Load strings from requested file or FM3RES.STR
     
    5252    filename = "FM3RES.STR";
    5353  numStr = 0;
    54   if(str)
     54  if (str)
    5555    DosFreeMem(str);
    5656  strs = NULL;
    5757  str = NULL;
    5858
    59   fp = _fsopen(filename,"rb",SH_DENYWR);
     59  fp = _fsopen(filename, "rb", SH_DENYWR);
    6060  if (fp) {
    61     if(fread(&numStr,
    62              sizeof(numStr),
    63              1,
    64              fp) &&
    65        numStr == IDS_NUMSTRS &&
    66        fread(&len,sizeof(len),1,fp) &&
    67        fread(&vermajor,sizeof(vermajor),1,fp) &&
    68        fread(&verminor,sizeof(verminor),1,fp) &&
    69        (vermajor >= VERMAJORBREAK &&
    70         (vermajor > VERMAJORBREAK ||
    71          verminor >= VERMINORBREAK))) {
    72       fseek(fp,0,SEEK_END);
     61    if (fread(&numStr,
     62              sizeof(numStr),
     63              1,
     64              fp) &&
     65        numStr == IDS_NUMSTRS &&
     66        fread(&len, sizeof(len), 1, fp) &&
     67        fread(&vermajor, sizeof(vermajor), 1, fp) &&
     68        fread(&verminor, sizeof(verminor), 1, fp) &&
     69        (vermajor >= VERMAJORBREAK &&
     70         (vermajor > VERMAJORBREAK || verminor >= VERMINORBREAK))) {
     71      fseek(fp, 0, SEEK_END);
    7372      size = ftell(fp) - ((sizeof(ULONG) * 2) + (sizeof(USHORT) * 2));
    7473      if (size && size == len) {
    75         fseek(fp,(sizeof(ULONG) * 2) + (sizeof(USHORT) * 2),SEEK_SET);
    76         /* NOTE:  Make one memory object for both str and strs
    77         * for efficiency.
    78         */
    79         totalsize = size + sizeof(ULONG);
    80         totalsize += (totalsize % sizeof(ULONG));
    81         len = totalsize;
    82         totalsize += (numStr * sizeof(char *));
    83         totalsize += 4;
    84         rc = DosAllocMem((PPVOID)&str,totalsize,
    85                         PAG_COMMIT | PAG_READ | PAG_WRITE);
     74        fseek(fp, (sizeof(ULONG) * 2) + (sizeof(USHORT) * 2), SEEK_SET);
     75        /* NOTE:  Make one memory object for both str and strs
     76        * for efficiency.
     77        */
     78        totalsize = size + sizeof(ULONG);
     79        totalsize += (totalsize % sizeof(ULONG));
     80        len = totalsize;
     81        totalsize += (numStr * sizeof(char *));
     82        totalsize += 4;
     83        rc = DosAllocMem((PPVOID) & str, totalsize,
     84                        PAG_COMMIT | PAG_READ | PAG_WRITE);
    8685        if (!rc && str) {
    87           strs = (char **)(str + len);
    88           if(fread(str,1,size,fp) == size) {
    89             p = str;
    90             for(x = 0;x < numStr;x++) {
    91               if(p - str >= size)
    92                 break;
    93               strs[x] = p;
    94               while(*p)
    95                 p++;
    96               p++;
    97             }
    98             if(x == numStr)
    99               ok = TRUE;
    100           }
    101           if(ok)
    102             /* set pages to readonly */
    103             DosSetMem(str,totalsize,PAG_COMMIT | PAG_READ);
    104         }
     86          strs = (char **)(str + len);
     87          if (fread(str, 1, size, fp) == size) {
     88            p = str;
     89            for (x = 0; x < numStr; x++) {
     90              if (p - str >= size)
     91                break;
     92              strs[x] = p;
     93              while (*p)
     94                p++;
     95              p++;
     96            }
     97            if (x == numStr)
     98              ok = TRUE;
     99          }
     100          if (ok)
     101            /* set pages to readonly */
     102            DosSetMem(str, totalsize, PAG_COMMIT | PAG_READ);
     103        }
    105104      }
    106105    }
     
    110109  if (!ok) {
    111110    numStr = 0;
    112     if(str)
     111    if (str)
    113112      DosFreeMem(str);
    114113    str = NULL;
     
    119118}
    120119
    121 
    122120//== GetPString() return a readonly pointer to the requested string in memory ==
    123121
    124 char *GetPString (ULONG id)
     122char *GetPString(ULONG id)
    125123{
    126124  return id < numStr && str && strs && strs[id] ? strs[id] : NullStr;
    127125}
    128126
    129 
    130127//== StringsLoaded() return TRUE is strings loaded
    131128
    132 BOOL StringsLoaded (void)
     129BOOL StringsLoaded(void)
    133130{
    134     return numStr && str && strs;
     131  return numStr && str && strs;
    135132}
Note: See TracChangeset for help on using the changeset viewer.