source: trunk/dll/string.c@ 333

Last change on this file since 333 was 333, checked in by root, 19 years ago

Comments

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
RevLine 
[333]1
2/***********************************************************************
3
4 $Id: string.c 333 2006-07-25 18:58:11Z root $
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
[2]15#define INCL_DOS
16#define INCL_WIN
[333]17#include <os2.h>
[2]18
19#include <stdlib.h>
20#include <stdio.h>
21#include <string.h>
22#include <share.h>
23#include <io.h>
[333]24
[2]25#include "fm3dll.h"
26#include "fm3str.h"
27#include "version.h"
28
29#pragma alloc_text(STRINGS,LoadStrings,GetPString)
30
31static char **strs,*str;
32static ULONG numStr;
33
[333]34//== LoadStrings() load strings from file ==
[2]35
[333]36BOOL LoadStrings (char *filename)
37{
38 BOOL ok = FALSE;
[2]39 ULONG size,len,totalsize;
40 USHORT vermajor = 0,verminor = 0;
41 register char *p;
42 register ULONG x;
43 FILE *fp;
[333]44 APIRET rc;
[2]45
[333]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)
[2]52 filename = "FM3RES.STR";
53 numStr = 0;
54 if(str)
55 DosFreeMem(str);
56 strs = NULL;
57 str = NULL;
58
[333]59 fp = _fsopen(filename,"rb",SH_DENYWR);
60 if (fp) {
[2]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);
73 size = ftell(fp) - ((sizeof(ULONG) * 2) + (sizeof(USHORT) * 2));
[333]74 if (size && size == len) {
[2]75 fseek(fp,(sizeof(ULONG) * 2) + (sizeof(USHORT) * 2),SEEK_SET);
[333]76 /* NOTE: Make one memory object for both str and strs
[2]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;
[333]84 rc = DosAllocMem((PPVOID)&str,totalsize,
85 PAG_COMMIT | PAG_READ | PAG_WRITE);
86 if (!rc && str) {
[2]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)
[333]99 ok = TRUE;
[2]100 }
[333]101 if(ok)
[2]102 /* set pages to readonly */
[333]103 DosSetMem(str,totalsize,PAG_COMMIT | PAG_READ);
[2]104 }
105 }
106 }
107 fclose(fp);
108 }
109
[333]110 if (!ok) {
[2]111 numStr = 0;
112 if(str)
113 DosFreeMem(str);
114 str = NULL;
115 strs = NULL;
116 }
117
[333]118 return ok;
[2]119}
120
121
[333]122//== GetPString() return a readonly pointer to the requested string in memory ==
[2]123
[333]124char *GetPString (ULONG id)
125{
126 return id < numStr && str && strs && strs[id] ? strs[id] : NullStr;
[2]127}
128
129
[333]130//== StringsLoaded() return TRUE is strings loaded
[2]131
[333]132BOOL StringsLoaded (void)
133{
134 return numStr && str && strs;
[2]135}
Note: See TracBrowser for help on using the repository browser.