Changeset 333 for trunk/dll/string.c


Ignore:
Timestamp:
Jul 25, 2006, 8:58:11 PM (19 years ago)
Author:
root
Message:

Comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/string.c

    r2 r333  
     1
     2/***********************************************************************
     3
     4  $Id$
     5
     6  External strings file support
     7
     8  Copyright (c) 1993-98 M. Kimes
     9  Copyright (c) 2006 Steven H. Levine
     10
     11  22 Jul 06 SHL Comments
     12
     13***********************************************************************/
     14
    115#define INCL_DOS
    216#define INCL_WIN
     17#include <os2.h>
    318
    4 #include <os2.h>
    519#include <stdlib.h>
    620#include <stdio.h>
     
    822#include <share.h>
    923#include <io.h>
     24
    1025#include "fm3dll.h"
    1126#include "fm3str.h"
     
    1732static ULONG  numStr;
    1833
     34//== LoadStrings() load strings from file ==
    1935
    20 BOOL LoadStrings (char *filename) {
    21 
    22   /*
    23    * Load strings from FM3RES.STR, with some error-checking.
    24    * Return TRUE on success, FALSE on error.
    25    */
    26 
    27   BOOL           ret = FALSE;
     36BOOL LoadStrings (char *filename)
     37{
     38  BOOL           ok = FALSE;
    2839  ULONG          size,len,totalsize;
    2940  USHORT         vermajor = 0,verminor = 0;
     
    3142  register ULONG x;
    3243  FILE          *fp;
     44  APIRET        rc;
    3345
    34   if(!filename)
     46  /* Load strings from requested file or FM3RES.STR
     47   * with some quiet error-checking.
     48   * Return TRUE on success, FALSE on error.
     49   */
     50
     51  if (!filename)
    3552    filename = "FM3RES.STR";
    3653  numStr = 0;
     
    4057  str = NULL;
    4158
    42   fp = _fsopen(filename,
    43                "rb",
    44                SH_DENYWR);
    45   if(fp) {
     59  fp = _fsopen(filename,"rb",SH_DENYWR);
     60  if (fp) {
    4661    if(fread(&numStr,
    4762             sizeof(numStr),
     
    5772      fseek(fp,0,SEEK_END);
    5873      size = ftell(fp) - ((sizeof(ULONG) * 2) + (sizeof(USHORT) * 2));
    59       if(size &&
    60          size == len) {
     74      if (size && size == len) {
    6175        fseek(fp,(sizeof(ULONG) * 2) + (sizeof(USHORT) * 2),SEEK_SET);
    62         /*
    63          * NOTE:  Make one memory object for both str and strs
     76        /* NOTE:  Make one memory object for both str and strs
    6477         * for efficiency.
    6578         */
     
    6982        totalsize += (numStr * sizeof(char *));
    7083        totalsize += 4;
    71         if(!DosAllocMem((PPVOID)&str,totalsize,
    72                         PAG_COMMIT | PAG_READ | PAG_WRITE) &&
    73           str) {
     84        rc = DosAllocMem((PPVOID)&str,totalsize,
     85                         PAG_COMMIT | PAG_READ | PAG_WRITE);
     86        if (!rc && str) {
    7487          strs = (char **)(str + len);
    7588          if(fread(str,1,size,fp) == size) {
     
    8497            }
    8598            if(x == numStr)
    86               ret = TRUE;
     99              ok = TRUE;
    87100          }
    88           if(ret)
     101          if(ok)
    89102            /* set pages to readonly */
    90             DosSetMem(str,
    91                       totalsize,
    92                       PAG_COMMIT | PAG_READ);
     103            DosSetMem(str,totalsize,PAG_COMMIT | PAG_READ);
    93104        }
    94105      }
     
    97108  }
    98109
    99   if(!ret) {
     110  if (!ok) {
    100111    numStr = 0;
    101112    if(str)
     
    105116  }
    106117
    107   return ret;
     118  return ok;
    108119}
    109120
    110121
    111 char *GetPString (ULONG id) {
     122//== GetPString() return a readonly pointer to the requested string in memory ==
    112123
    113   /*
    114    * return a readonly pointer to the requested string in memory
    115    */
    116 
    117   return (id < numStr && str && strs && strs[id]) ? strs[id] : NullStr;
     124char *GetPString (ULONG id)
     125{
     126  return id < numStr && str && strs && strs[id] ? strs[id] : NullStr;
    118127}
    119128
    120129
    121 BOOL StringsLoaded (void) {
     130//== StringsLoaded() return TRUE is strings loaded
    122131
    123   return (numStr && str && strs);
     132BOOL StringsLoaded (void)
     133{
     134    return numStr && str && strs;
    124135}
Note: See TracChangeset for help on using the changeset viewer.