Changeset 333 for trunk/dll/string.c
- Timestamp:
- Jul 25, 2006, 8:58:11 PM (19 years ago)
- 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 1 15 #define INCL_DOS 2 16 #define INCL_WIN 17 #include <os2.h> 3 18 4 #include <os2.h>5 19 #include <stdlib.h> 6 20 #include <stdio.h> … … 8 22 #include <share.h> 9 23 #include <io.h> 24 10 25 #include "fm3dll.h" 11 26 #include "fm3str.h" … … 17 32 static ULONG numStr; 18 33 34 //== LoadStrings() load strings from file == 19 35 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; 36 BOOL LoadStrings (char *filename) 37 { 38 BOOL ok = FALSE; 28 39 ULONG size,len,totalsize; 29 40 USHORT vermajor = 0,verminor = 0; … … 31 42 register ULONG x; 32 43 FILE *fp; 44 APIRET rc; 33 45 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) 35 52 filename = "FM3RES.STR"; 36 53 numStr = 0; … … 40 57 str = NULL; 41 58 42 fp = _fsopen(filename, 43 "rb", 44 SH_DENYWR); 45 if(fp) { 59 fp = _fsopen(filename,"rb",SH_DENYWR); 60 if (fp) { 46 61 if(fread(&numStr, 47 62 sizeof(numStr), … … 57 72 fseek(fp,0,SEEK_END); 58 73 size = ftell(fp) - ((sizeof(ULONG) * 2) + (sizeof(USHORT) * 2)); 59 if(size && 60 size == len) { 74 if (size && size == len) { 61 75 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 64 77 * for efficiency. 65 78 */ … … 69 82 totalsize += (numStr * sizeof(char *)); 70 83 totalsize += 4; 71 if(!DosAllocMem((PPVOID)&str,totalsize,72 PAG_COMMIT | PAG_READ | PAG_WRITE) &&73 84 rc = DosAllocMem((PPVOID)&str,totalsize, 85 PAG_COMMIT | PAG_READ | PAG_WRITE); 86 if (!rc && str) { 74 87 strs = (char **)(str + len); 75 88 if(fread(str,1,size,fp) == size) { … … 84 97 } 85 98 if(x == numStr) 86 ret= TRUE;99 ok = TRUE; 87 100 } 88 if( ret)101 if(ok) 89 102 /* set pages to readonly */ 90 DosSetMem(str, 91 totalsize, 92 PAG_COMMIT | PAG_READ); 103 DosSetMem(str,totalsize,PAG_COMMIT | PAG_READ); 93 104 } 94 105 } … … 97 108 } 98 109 99 if (!ret) {110 if (!ok) { 100 111 numStr = 0; 101 112 if(str) … … 105 116 } 106 117 107 return ret;118 return ok; 108 119 } 109 120 110 121 111 char *GetPString (ULONG id) { 122 //== GetPString() return a readonly pointer to the requested string in memory == 112 123 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; 124 char *GetPString (ULONG id) 125 { 126 return id < numStr && str && strs && strs[id] ? strs[id] : NullStr; 118 127 } 119 128 120 129 121 BOOL StringsLoaded (void) { 130 //== StringsLoaded() return TRUE is strings loaded 122 131 123 return (numStr && str && strs); 132 BOOL StringsLoaded (void) 133 { 134 return numStr && str && strs; 124 135 }
Note:
See TracChangeset
for help on using the changeset viewer.