source: trunk/dll/string.c@ 551

Last change on this file since 551 was 551, checked in by Gregg Young, 18 years ago

Indentation cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
RevLine 
[333]1
2/***********************************************************************
3
4 $Id: string.c 551 2007-02-28 01:33:51Z gyoung $
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
[551]31static char **strs, *str;
32static ULONG numStr;
[2]33
[333]34//== LoadStrings() load strings from file ==
[2]35
[551]36BOOL LoadStrings(char *filename)
[333]37{
[551]38 BOOL ok = FALSE;
39 ULONG size, len, totalsize;
40 USHORT vermajor = 0, verminor = 0;
[2]41 register char *p;
42 register ULONG x;
[551]43 FILE *fp;
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;
[551]54 if (str)
[2]55 DosFreeMem(str);
56 strs = NULL;
57 str = NULL;
58
[551]59 fp = _fsopen(filename, "rb", SH_DENYWR);
[333]60 if (fp) {
[551]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);
[2]72 size = ftell(fp) - ((sizeof(ULONG) * 2) + (sizeof(USHORT) * 2));
[333]73 if (size && size == len) {
[551]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);
[333]85 if (!rc && str) {
[551]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 }
[2]104 }
105 }
106 fclose(fp);
107 }
108
[333]109 if (!ok) {
[2]110 numStr = 0;
[551]111 if (str)
[2]112 DosFreeMem(str);
113 str = NULL;
114 strs = NULL;
115 }
116
[333]117 return ok;
[2]118}
119
[333]120//== GetPString() return a readonly pointer to the requested string in memory ==
[2]121
[551]122char *GetPString(ULONG id)
[333]123{
124 return id < numStr && str && strs && strs[id] ? strs[id] : NullStr;
[2]125}
126
[333]127//== StringsLoaded() return TRUE is strings loaded
[2]128
[551]129BOOL StringsLoaded(void)
[333]130{
[551]131 return numStr && str && strs;
[2]132}
Note: See TracBrowser for help on using the repository browser.