Subversion Repositories SvarDOS

Rev

Rev 586 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 586 Rev 591
Line 1... Line 1...
1
/*
1
/*
2
 * functions that read/write from/to the localcfg country.sys-like file.
2
 * functions that reads/writes from/to the localcfg country.sys-like file.
3
 * Copyright (C) Mateusz Viste 2015
3
 * Copyright (C) Mateusz Viste 2015-2022
4
 */
4
 */
5
 
5
 
6
#include <stdio.h>
6
#include <stdio.h>
7
#include <string.h>
7
#include <string.h>
8
 
8
 
9
#include "country.h"
9
#include "country.h"
10
 
10
 
11
 
11
 
-
 
12
struct funchdr {
-
 
13
  unsigned char funcname[8];
12
#define READSHORT(x) (short)(x[0] | (x[1] << 8))
14
  unsigned short funcsiz;
-
 
15
};
-
 
16
 
13
 
17
 
14
/* fills a country struct with default values */
18
/* fills a country struct with default values */
15
static void country_default(struct country *countrydata) {
19
static void country_default(struct country *countrydata) {
-
 
20
 
16
  /* first clears the memory */
21
  /* first clear the memory */
17
  memset(countrydata, 0, sizeof(struct country));
22
  bzero(countrydata, sizeof(struct country));
-
 
23
 
18
  /* fill in fields - only non-zero values */
24
  /* fill in CTYINFO fields (non-zero values only) */
19
  countrydata->id = 1;
25
  countrydata->CTYINFO.id = 1;
20
  countrydata->codepage = 437;
26
  countrydata->CTYINFO.codepage = 437;
21
  /* countrydata->datefmt = COUNTRY_DATE_MDY;
27
  /* countrydata->CTYINFO.datefmt = COUNTRY_DATE_MDY;
22
  countrydata->timefmt = COUNTRY_TIME12; */
28
  countrydata->CTYINFO.timefmt = COUNTRY_TIME12; */
23
  countrydata->currency[0] = '$';
29
  countrydata->CTYINFO.currsym[0] = '$';
24
  countrydata->decimal = '.';
30
  countrydata->CTYINFO.decimal[0] = '.';
25
  countrydata->thousands = ',';
31
  countrydata->CTYINFO.thousands[0] = ',';
26
  countrydata->datesep = '/';
32
  countrydata->CTYINFO.datesep[0] = '/';
27
  countrydata->timesep = ':';
33
  countrydata->CTYINFO.timesep[0] = ':';
28
  countrydata->currencyprec = 2;
34
  countrydata->CTYINFO.currprec = 2;
29
  /* countrydata->currencydecsym = 0; */
35
  /* countrydata->CTYINFO.currencydecsym = 0; */
30
  /* countrydata->currencyspace = 0; */
36
  /* countrydata->CTYINFO.currencyspace = 0; */
31
  /* countrydata->currencypos = 0; */
37
  /* countrydata->CTYINFO.currencypos = 0; */
-
 
38
 
-
 
39
  /* fill in YESNO fields (non-zero values only) */
32
  countrydata->yes = 'Y';
40
  countrydata->YESNO.yes[0] = 'Y';
33
  countrydata->no = 'N';
41
  countrydata->YESNO.no[0] = 'N';
34
}
42
}
35
 
43
 
36
 
44
 
37
/* Loads data from a country.sys file into a country struct.
45
/* Loads data from a country.sys file into a country struct.
38
 * Returns 0 on success, non-zero otherwise. */
46
 * Returns 0 on success, non-zero otherwise. */
39
int country_read(struct country *countrydata, char *fname) {
47
int country_read(struct country *countrydata, const char *fname) {
40
  unsigned char filebuff[1024];
48
  unsigned char filebuff[1024];
41
  unsigned char buff[64];
-
 
42
  short firstentryoffs;
49
  short firstentryoffs;
43
  unsigned char *subfunctions[16] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
50
  unsigned char *subfunctions[16] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
44
                                     NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
51
                                     NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
45
  short filesize;
52
  short filesize;
46
  short subfunctionscount;
53
  short subfunctionscount;
Line 56... Line 63...
56
  if (fd == NULL) return(0); /* "file doesn't exist" is not an error condition */
63
  if (fd == NULL) return(0); /* "file doesn't exist" is not an error condition */
57
  filesize = fread(filebuff, 1, sizeof(filebuff), fd);
64
  filesize = fread(filebuff, 1, sizeof(filebuff), fd);
58
  fclose(fd);
65
  fclose(fd);
59
 
66
 
60
  /* check that it's a country file - should start with 0xFF COUNTRY 0x00 */
67
  /* check that it's a country file - should start with 0xFF COUNTRY 0x00 */
61
  if (filebuff[0] != 0xFF) return(-2);
-
 
62
  if (strcmp((char *)filebuff + 1, "COUNTRY") != 0) return(-2);
68
  if (memcmp(filebuff, "\377COUNTRY\0", 9) != 0) return(-2);
63
 
69
 
64
  /* check that it's one of my country.sys files - should contain a trailer */
70
  /* check that it's one of my country.sys files - should contain a trailer */
65
  memcpy(buff, filebuff + filesize - 8, 8);
-
 
66
  buff[8] = 0;
-
 
67
  if (strcmp((char *)buff, "LOCALCFG") != 0) return(-3);
71
  if (memcmp(filebuff + filesize - 8, "LOCALCFG", 8) != 0) return(-3);
68
 
72
 
69
  /* read the offset of the entries index - must be at least 23 */
73
  /* read the offset of the entries index - must be at least 23 */
70
  functiondata = filebuff + 19;
74
  functiondata = filebuff + 19;
71
  firstentryoffs = READSHORT(functiondata);
75
  firstentryoffs = *((unsigned short *)functiondata);
72
  if ((firstentryoffs < 23) || (firstentryoffs >= filesize)) return(-4);
76
  if ((firstentryoffs < 23) || (firstentryoffs >= filesize)) return(-4);
73
  functiondata = filebuff + firstentryoffs;
77
  functiondata = filebuff + firstentryoffs;
74
 
78
 
75
  /* how many entries do we have? I expect exactly one. */
79
  /* how many entries do we have? I expect exactly one. */
76
  if (READSHORT(functiondata) != 1) return(-5);
80
  if (*((unsigned short *)functiondata) != 1) return(-5);
77
  /* skip to the first country entry */
81
  /* skip to the first country entry */
78
  functiondata += 2;
82
  functiondata += 2;
79
 
83
 
80
  /* skip directly to the subfunctions of the first country */
84
  /* skip directly to the subfunctions of the first country */
81
  /* ddwords: size, country, codepage, reserved, reserved, offset */
85
  /* ddwords: size, country, codepage, reserved, reserved, offset */
Line 84... Line 88...
84
  /* printf("Country = %d\n", READSHORT(functiondata[0]); */
88
  /* printf("Country = %d\n", READSHORT(functiondata[0]); */
85
  functiondata += 2; /* skip country */
89
  functiondata += 2; /* skip country */
86
  /* printf("Codepage = %d\n", READSHORT(functiondata)); */
90
  /* printf("Codepage = %d\n", READSHORT(functiondata)); */
87
  functiondata += 2; /* skip codepage */
91
  functiondata += 2; /* skip codepage */
88
  functiondata += 4; /* skip reserved fields */
92
  functiondata += 4; /* skip reserved fields */
89
  firstentryoffs = READSHORT(functiondata); /* read offset of the subfunctions index */
93
  firstentryoffs = *((unsigned short *)functiondata); /* read offset of the subfunctions index */
90
  functiondata = filebuff + firstentryoffs;
94
  functiondata = filebuff + firstentryoffs;
91
 
95
 
92
  /* read all subfunctions, but no more than 15 */
96
  /* read all subfunctions, but no more than 15 */
93
  subfunctionscount = READSHORT(functiondata);
97
  subfunctionscount = *((unsigned short *)functiondata);
94
  /* printf("Found %d subfunctions\n", subfunctionscount); */
98
  /* printf("Found %d subfunctions\n", subfunctionscount); */
95
  functiondata += 2;
99
  functiondata += 2;
96
  for (x = 0; (x < 15) && (x < subfunctionscount); x++) {
100
  for (x = 0; (x < 15) && (x < subfunctionscount); x++) {
97
    short size = READSHORT(functiondata);
101
    short size = *((unsigned short *)functiondata);
98
    functiondata += 2;
102
    functiondata += 2;
99
    functiondata += 2; /* skip ID of the subfunction */
103
    functiondata += 2; /* skip ID of the subfunction */
100
    subfunctions[x] = filebuff + READSHORT(functiondata);
104
    subfunctions[x] = filebuff + *((unsigned short *)functiondata);
101
    /* printf("subfunction %d at 0x%p\n", x, subfunctions[x]); */
105
    /* printf("subfunction %d at 0x%p\n", x, subfunctions[x]); */
102
    functiondata += size - 2;
106
    functiondata += size - 2;
103
  }
107
  }
104
 
108
 
105
  /* load every subfunction, and feed the country struct with data */
109
  /* load every subfunction, and feed the country struct with data */
106
  for (x = 0; subfunctions[x] != NULL; x++) {
110
  for (x = 0; subfunctions[x] != NULL; x++) {
107
    short functionsize;
-
 
108
    /* the function name should always start with 0xFF */
-
 
109
    if (subfunctions[x][0] != 0xFF) return(-6);
-
 
110
    /* load the subfunction's name, and act accordingly */
-
 
111
    memcpy(buff, subfunctions[x] + 1, 7);
-
 
112
    buff[7] = 0;
-
 
113
    functiondata = subfunctions[x] + 8;
111
    struct funchdr *hdr = (void *)(subfunctions[x]);
114
    functionsize = READSHORT(functiondata);
-
 
115
    functiondata = subfunctions[x] + 10;
112
    functiondata = subfunctions[x] + 10;
116
    /* */
113
    /* */
117
    if (strcmp((char *)buff, "YESNO  ") == 0) {
114
    if ((memcmp(hdr->funcname, "\377YESNO  ", 8) == 0) && (hdr->funcsiz == 4)) {
118
      if (functionsize != 4) continue;
-
 
119
      countrydata->yes = functiondata[0];
115
      memcpy(&(countrydata->YESNO), functiondata, hdr->funcsiz);
120
      countrydata->no = functiondata[2];
-
 
121
    } else if (strcmp((char *)buff, "CTYINFO") == 0) {
116
    } else if ((memcmp(hdr->funcname, "\377CTYINFO", 8) == 0) && (hdr->funcsiz == 22)) {
122
      if (functionsize != 22) continue;
-
 
123
      /* ID */
-
 
124
      countrydata->id = READSHORT(functiondata);
-
 
125
      functiondata += 2;
-
 
126
      /* codepage */
-
 
127
      countrydata->codepage = READSHORT(functiondata);
-
 
128
      functiondata += 2;
-
 
129
      /* date format */
-
 
130
      countrydata->datefmt = READSHORT(functiondata);
-
 
131
      functiondata += 2;
-
 
132
      /* currency symbol */
-
 
133
      countrydata->currency[0] = functiondata[0];
-
 
134
      countrydata->currency[1] = functiondata[1];
-
 
135
      countrydata->currency[2] = functiondata[2];
-
 
136
      countrydata->currency[3] = functiondata[3];
-
 
137
      countrydata->currency[4] = 0;
-
 
138
      functiondata += 5;
-
 
139
      /* thousands separator, decimal sep, date sep, time sep */
-
 
140
      countrydata->thousands = READSHORT(functiondata);
-
 
141
      functiondata += 2;
-
 
142
      countrydata->decimal = READSHORT(functiondata);
-
 
143
      functiondata += 2;
-
 
144
      countrydata->datesep = READSHORT(functiondata);
-
 
145
      functiondata += 2;
-
 
146
      countrydata->timesep = READSHORT(functiondata);
-
 
147
      functiondata += 2;
-
 
148
      /* currency format */
-
 
149
      countrydata->currencypos = *functiondata & 1;
-
 
150
      countrydata->currencyspace = (*functiondata >> 1) & 1;
117
      memcpy(&(countrydata->CTYINFO), functiondata, hdr->funcsiz);
151
      countrydata->currencydecsym = (*functiondata >> 2) & 1;
-
 
152
      functiondata += 1;
-
 
153
      /* currency precision */
-
 
154
      countrydata->currencyprec = *functiondata;
-
 
155
      functiondata += 1;
-
 
156
      /* time format */
-
 
157
      countrydata->timefmt = *functiondata;
-
 
158
      functiondata += 1;
-
 
159
    }
118
    }
160
  }
119
  }
161
 
120
 
162
  return(0);
121
  return(0);
163
}
122
}
164
 
123
 
165
 
124
 
166
#define MSB(x) (((x) >> 8) & 0xff)
125
#define MSB(x) (((x) >> 8) & 0xff)
167
#define LSB(x) ((x) & 0xff)
126
#define LSB(x) ((x) & 0xff)
168
 
127
 
169
#define DWORDB1(x) ((x) & 0xff)
-
 
170
#define DWORDB2(x) (((x) >> 8) & 0xff)
-
 
171
#define DWORDB3(x) (((x) >> 16) & 0xff)
-
 
172
#define DWORDB4(x) (((x) >> 24) & 0xff)
-
 
173
 
-
 
174
 
128
 
175
/* Computes a new country.sys file based on data from a country struct.
129
/* Computes a new country.sys file based on data from a country struct.
176
 * Returns 0 on success, non-zero otherwise. */
130
 * Returns 0 on success, non-zero otherwise. */
177
int country_write(char *fname, struct country *c) {
131
int country_write(const char *fname, struct country *c) {
178
  unsigned char filebuff[1024];
132
  unsigned char filebuff[1024];
179
  short filesize = 0;
133
  short filesize = 0;
180
  FILE *fd;
134
  FILE *fd;
181
  int x;
135
  int x;
182
  short subfunction_id[7] = {1,2,4,5,6,7,35};
136
  short subfunction_id[7] = {1,2,4,5,6,7,35};
Line 230... Line 184...
230
                                          224,  83, 226, 227, 228, 229, 230, 231,
184
                                          224,  83, 226, 227, 228, 229, 230, 231,
231
                                          232, 233, 234, 235, 236, 237, 238, 239,
185
                                          232, 233, 234, 235, 236, 237, 238, 239,
232
                                          240, 241, 242, 243, 244, 245, 246, 247,
186
                                          240, 241, 242, 243, 244, 245, 246, 247,
233
                                          248, 249, 250, 251, 252, 253, 254, 255};
187
                                          248, 249, 250, 251, 252, 253, 254, 255};
234
 
188
 
-
 
189
  /* zero out filebuff */
-
 
190
  bzero(filebuff, sizeof(filebuff));
-
 
191
 
235
  /* compute the country.sys structures */
192
  /* compute the country.sys structures */
236
  memcpy(filebuff, "\377COUNTRY\0\0\0\0\0\0\0\0\1\0\1", 19); /* header */
193
  memcpy(filebuff, "\377COUNTRY\0\0\0\0\0\0\0\0\1\0\1", 19); /* header */
237
  filesize = 19;
194
  filesize = 19;
238
  /* first entry offset (always current offset+4) */
195
  /* first entry offset (always current offset+4) */
239
  filebuff[filesize + 0] = DWORDB1(filesize+4);
-
 
240
  filebuff[filesize + 1] = DWORDB2(filesize+4);
-
 
241
  filebuff[filesize + 2] = DWORDB3(filesize+4);
-
 
242
  filebuff[filesize + 3] = DWORDB4(filesize+4);
-
 
243
  filesize += 4;
196
  filesize += 4;
-
 
197
  memcpy(filebuff + filesize - 4, &filesize, sizeof(filesize));
244
  /* number of entries */
198
  /* number of entries */
245
  filebuff[filesize++] = 1;
199
  filebuff[filesize] = 1;
246
  filebuff[filesize++] = 0;
200
  filesize += 2;
247
  /* first (and only) entry / size, country, codepage, reserved(2), offset */
201
  /* first (and only) entry / size, country, codepage, reserved(2), offset */
248
  filebuff[filesize++] = 12; /* size LSB */
202
  filebuff[filesize++] = 12; /* size LSB */
249
  filebuff[filesize++] = 0;  /* size MSB */
203
  filebuff[filesize++] = 0;  /* size MSB */
250
  filebuff[filesize++] = LSB(c->id);   /* country LSB */
204
  filebuff[filesize++] = LSB(c->CTYINFO.id);   /* country LSB */
251
  filebuff[filesize++] = MSB(c->id);   /* country MSB */
205
  filebuff[filesize++] = MSB(c->CTYINFO.id);   /* country MSB */
252
  filebuff[filesize++] = LSB(c->codepage); /* codepage LSB */
206
  filebuff[filesize++] = LSB(c->CTYINFO.codepage); /* codepage LSB */
253
  filebuff[filesize++] = MSB(c->codepage); /* codepage MSB */
207
  filebuff[filesize++] = MSB(c->CTYINFO.codepage); /* codepage MSB */
254
  filebuff[filesize++] = 0; /* reserved */
-
 
255
  filebuff[filesize++] = 0; /* reserved */
-
 
256
  filebuff[filesize++] = 0; /* reserved */
-
 
257
  filebuff[filesize++] = 0; /* reserved */
208
  filesize += 4;       /* reserved bytes */
258
  filebuff[filesize + 0] = DWORDB1(filesize+4); /* offset for subfunctions list (ptr + 4) */
-
 
259
  filebuff[filesize + 1] = DWORDB2(filesize+4); /* offset for subfunctions list (ptr + 4) */
-
 
260
  filebuff[filesize + 2] = DWORDB3(filesize+4); /* offset for subfunctions list (ptr + 4) */
-
 
261
  filebuff[filesize + 3] = DWORDB4(filesize+4); /* offset for subfunctions list (ptr + 4) */
-
 
-
 
209
 
262
  filesize += 4;
210
  filesize += 4;
-
 
211
  memcpy(filebuff + filesize - 4, &filesize, sizeof(filesize));
-
 
212
 
263
  /* index of subfunctions */
213
  /* index of subfunctions */
264
  filebuff[filesize++] = 7; /* there are 7 subfunctions */
214
  filebuff[filesize] = 7; /* there are 7 subfunctions */
265
  filebuff[filesize++] = 0;
215
  filesize += 2;
266
  for (x = 0; x < 7; x++) { /* dump each subfunction (size, id, offset) */
216
  for (x = 0; x < 7; x++) { /* dump each subfunction (size, id, offset) */
267
    /* size is always 6 */
217
    /* size is always 6 */
268
    filebuff[filesize++] = 6;
218
    filebuff[filesize] = 6;
269
    filebuff[filesize++] = 0;
219
    filesize += 2;
270
    /* id of the subfunction */
220
    /* id of the subfunction */
271
    filebuff[filesize++] = LSB(subfunction_id[x]);
221
    filebuff[filesize++] = LSB(subfunction_id[x]);
272
    filebuff[filesize++] = MSB(subfunction_id[x]);
222
    filebuff[filesize++] = MSB(subfunction_id[x]);
273
    /* remember the offset of the subfunction pointer for later */
223
    /* remember the offset of the subfunction pointer for later */
274
    subfunction_ptr[x] = filesize;
224
    subfunction_ptr[x] = filesize;
275
    filesize += 4;
225
    filesize += 4;
276
  }
226
  }
-
 
227
 
277
  /* write the CTYINFO subfunction */
228
  /* write the CTYINFO subfunction */
278
  filebuff[subfunction_ptr[0]+0] = DWORDB1(filesize); /* update the    */
-
 
279
  filebuff[subfunction_ptr[0]+1] = DWORDB2(filesize); /* subfunction   */
-
 
280
  filebuff[subfunction_ptr[0]+2] = DWORDB3(filesize); /* pointer with  */
-
 
281
  filebuff[subfunction_ptr[0]+3] = DWORDB4(filesize); /* correct value */
229
  memcpy(filebuff + subfunction_ptr[0], &filesize, sizeof(filesize));
-
 
230
 
282
  /* subfunction header */
231
  /* subfunction header */
283
  memcpy(filebuff + filesize, "\377CTYINFO", 8);
232
  memcpy(filebuff + filesize, "\377CTYINFO", 8);
284
  filesize += 8;
233
  filesize += 8;
285
  /* subfunction size */
234
  /* subfunction size */
286
  filebuff[filesize++] = 22;
235
  filebuff[filesize] = 22;
287
  filebuff[filesize++] = 0;
236
  filesize += 2;
-
 
237
 
288
  /* country preferences */
238
  /* country preferences */
289
  filebuff[filesize++] = LSB(c->id); /* ID */
-
 
290
  filebuff[filesize++] = MSB(c->id); /* ID */
239
  memcpy(filebuff + filesize, &(c->CTYINFO), 22);
291
  filebuff[filesize++] = LSB(c->codepage); /* CP */
-
 
292
  filebuff[filesize++] = MSB(c->codepage); /* CP */
-
 
293
  filebuff[filesize++] = LSB(c->datefmt); /* date format */
-
 
294
  filebuff[filesize++] = MSB(c->datefmt); /* date format */
-
 
295
  for (x = 0; x < 5; x++) {
-
 
296
    filebuff[filesize++] = c->currency[x]; /* currency */
-
 
297
  }
-
 
298
  filebuff[filesize++] = LSB(c->thousands);  /* thousands separator LSB */
-
 
299
  filebuff[filesize++] = MSB(c->thousands);  /* thousands separator MSB */
-
 
300
  filebuff[filesize++] = LSB(c->decimal);    /* decimal separator LSB */
-
 
301
  filebuff[filesize++] = MSB(c->decimal);    /* decimal separator MSB */
-
 
302
  filebuff[filesize++] = LSB(c->datesep);    /* date separator LSB */
-
 
303
  filebuff[filesize++] = MSB(c->datesep);    /* date separator MSB */
-
 
304
  filebuff[filesize++] = LSB(c->timesep);    /* time separator LSB */
-
 
305
  filebuff[filesize++] = MSB(c->timesep);    /* time separator MSB */
-
 
306
  filebuff[filesize] = c->currencydecsym; /* currency format (bit 2) */
-
 
307
  filebuff[filesize] <<= 8;
-
 
308
  filebuff[filesize] |= c->currencyspace; /* currency format (bit 1) */
-
 
309
  filebuff[filesize] <<= 8;
240
  filesize += 22;
310
  filebuff[filesize++] |= c->currencypos; /* currency format (bit 0) */
-
 
311
  filebuff[filesize++] = c->currencyprec; /* currency precision */
-
 
312
  filebuff[filesize++] = c->timefmt;      /* time format */
-
 
313
 
241
 
314
  /* write the UCASE subfunction (used for LCASE, too) */
242
  /* write the UCASE subfunction (used for LCASE, too) */
315
  filebuff[subfunction_ptr[1]+0] = DWORDB1(filesize); /* update the    */
-
 
316
  filebuff[subfunction_ptr[1]+1] = DWORDB2(filesize); /* subfunction   */
-
 
317
  filebuff[subfunction_ptr[1]+2] = DWORDB3(filesize); /* pointer with  */
-
 
318
  filebuff[subfunction_ptr[1]+3] = DWORDB4(filesize); /* correct value */
243
  memcpy(filebuff + subfunction_ptr[1], &filesize, sizeof(filesize));
319
  filebuff[subfunction_ptr[2]+0] = DWORDB1(filesize); /* update the    */
-
 
320
  filebuff[subfunction_ptr[2]+1] = DWORDB2(filesize); /* subfunction   */
-
 
321
  filebuff[subfunction_ptr[2]+2] = DWORDB3(filesize); /* pointer with  */
-
 
322
  filebuff[subfunction_ptr[2]+3] = DWORDB4(filesize); /* correct value */
244
  memcpy(filebuff + subfunction_ptr[2], &filesize, sizeof(filesize));
-
 
245
 
323
  /* subfunction header */
246
  /* subfunction header */
324
  memcpy(filebuff + filesize, "\377UCASE  ", 8);
247
  memcpy(filebuff + filesize, "\377UCASE  ", 8);
325
  filesize += 8;
248
  filesize += 8;
326
  /* subfunction size */
249
  /* subfunction size */
327
  filebuff[filesize++] = 128;
250
  filebuff[filesize++] = 128;
328
  filebuff[filesize++] = 0;
251
  filebuff[filesize++] = 0;
329
  /* UCASE table */
252
  /* UCASE table */
330
  for (x = 0; x < 128; x++) {
-
 
331
    filebuff[filesize++] = ucase_437[x];
253
  memcpy(filebuff + filesize, ucase_437, 128);
332
  }
254
  filesize += 128;
333
 
255
 
334
  /* write the FCHAR subfunction (filename terminator table) */
256
  /* write the FCHAR subfunction (filename terminator table) */
335
  filebuff[subfunction_ptr[3]+0] = DWORDB1(filesize); /* update the    */
-
 
336
  filebuff[subfunction_ptr[3]+1] = DWORDB2(filesize); /* subfunction   */
-
 
337
  filebuff[subfunction_ptr[3]+2] = DWORDB3(filesize); /* pointer with  */
-
 
338
  filebuff[subfunction_ptr[3]+3] = DWORDB4(filesize); /* correct value */
257
  memcpy(filebuff + subfunction_ptr[3], &filesize, sizeof(filesize));
-
 
258
 
339
  /* subfunction header */
259
  /* subfunction header */
340
  memcpy(filebuff + filesize, "\377FCHAR  ", 8);
260
  memcpy(filebuff + filesize, "\377FCHAR  ", 8);
341
  filesize += 8;
261
  filesize += 8;
342
  /* subfunction size */
262
  /* subfunction size */
343
  filebuff[filesize++] = 22;
263
  filebuff[filesize++] = 22;
Line 366... Line 286...
366
  filebuff[filesize++] = 61;  /* = */
286
  filebuff[filesize++] = 61;  /* = */
367
  filebuff[filesize++] = 59;  /* ; */
287
  filebuff[filesize++] = 59;  /* ; */
368
  filebuff[filesize++] = 44;  /* , */
288
  filebuff[filesize++] = 44;  /* , */
369
 
289
 
370
  /* write the COLLATE subfunction */
290
  /* write the COLLATE subfunction */
371
  filebuff[subfunction_ptr[4]+0] = DWORDB1(filesize); /* update the    */
-
 
372
  filebuff[subfunction_ptr[4]+1] = DWORDB2(filesize); /* subfunction   */
-
 
373
  filebuff[subfunction_ptr[4]+2] = DWORDB3(filesize); /* pointer with  */
-
 
374
  filebuff[subfunction_ptr[4]+3] = DWORDB4(filesize); /* correct value */
291
  memcpy(filebuff + subfunction_ptr[4], &filesize, sizeof(filesize));
-
 
292
 
375
  /* subfunction header */
293
  /* subfunction header */
376
  memcpy(filebuff + filesize, "\377COLLATE", 8);
294
  memcpy(filebuff + filesize, "\377COLLATE", 8);
377
  filesize += 8;
295
  filesize += 8;
378
  /* subfunction size */
296
  /* subfunction size */
379
  filebuff[filesize++] = LSB(256);
297
  filebuff[filesize++] = LSB(256);
380
  filebuff[filesize++] = MSB(256);
298
  filebuff[filesize++] = MSB(256);
381
  /* collation for standard CP437 */
299
  /* collation for standard CP437 */
382
  for (x = 0; x < 256; x++) {
-
 
383
    filebuff[filesize++] = collate_437[x];
300
  memcpy(filebuff + filesize, collate_437, 256);
384
  }
301
  filesize += 256;
385
 
302
 
386
  /* write the DBCS subfunction */
303
  /* write the DBCS subfunction */
387
  filebuff[subfunction_ptr[5]+0] = DWORDB1(filesize); /* update the    */
-
 
388
  filebuff[subfunction_ptr[5]+1] = DWORDB2(filesize); /* subfunction   */
-
 
389
  filebuff[subfunction_ptr[5]+2] = DWORDB3(filesize); /* pointer with  */
-
 
390
  filebuff[subfunction_ptr[5]+3] = DWORDB4(filesize); /* correct value */
304
  memcpy(filebuff + subfunction_ptr[5], &filesize, sizeof(filesize));
391
  /* subfunction header */
305
  /* subfunction header */
392
  memcpy(filebuff + filesize, "\377DBCS   ", 8);
306
  memcpy(filebuff + filesize, "\377DBCS   ", 8);
393
  filesize += 8;
307
  filesize += 8;
394
  /* subfunction size */
308
  /* subfunction size */
395
  filebuff[filesize++] = 0;
309
  filebuff[filesize++] = 0;
Line 397... Line 311...
397
  /* table terminator (must be there even if no lenght is zero */
311
  /* table terminator (must be there even if no lenght is zero */
398
  filebuff[filesize++] = 0;
312
  filebuff[filesize++] = 0;
399
  filebuff[filesize++] = 0;
313
  filebuff[filesize++] = 0;
400
 
314
 
401
  /* write the YESNO subfunction */
315
  /* write the YESNO subfunction */
402
  filebuff[subfunction_ptr[6]+0] = DWORDB1(filesize); /* update the    */
-
 
403
  filebuff[subfunction_ptr[6]+1] = DWORDB2(filesize); /* subfunction   */
-
 
404
  filebuff[subfunction_ptr[6]+2] = DWORDB3(filesize); /* pointer with  */
-
 
405
  filebuff[subfunction_ptr[6]+3] = DWORDB4(filesize); /* correct value */
316
  memcpy(filebuff + subfunction_ptr[6], &filesize, sizeof(filesize));
406
  memcpy(filebuff + filesize, "\377YESNO  ", 8);
317
  memcpy(filebuff + filesize, "\377YESNO  ", 8);
407
  filesize += 8;
318
  filesize += 8;
408
  filebuff[filesize++] = 4;  /* size (LSB) */
319
  filebuff[filesize] = 4;  /* size (LSB) */
409
  filebuff[filesize++] = 0;  /* size (MSB) */
-
 
410
  filebuff[filesize++] = c->yes;  /* "Yes" letter */
-
 
411
  filebuff[filesize++] = 0;
320
  filesize += 2;
412
  filebuff[filesize++] = c->no;   /* "No" letter */
321
  memcpy(filebuff + filesize, &(c->YESNO), 4);
413
  filebuff[filesize++] = 0;
322
  filesize += 4;
414
 
323
 
415
  /* write the file trailer */
324
  /* write the file trailer */
416
  memcpy(filebuff + filesize, "LOCALCFG", 8);
325
  memcpy(filebuff + filesize, "LOCALCFG", 8);
417
  filesize += 8;
326
  filesize += 8;
418
 
327