Subversion Repositories SvarDOS

Rev

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

Rev 969 Rev 971
Line 20... Line 20...
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
 * DEALINGS IN THE SOFTWARE.
22
 * DEALINGS IN THE SOFTWARE.
23
 */
23
 */
24
 
24
 
25
#include <stdio.h>   /* FILE */
25
#include <i86.h>
26
#include <stdlib.h>  /* NULL */
26
#include <stdlib.h>  /* NULL */
27
#include <string.h>  /* memcmp(), strcpy() */
27
#include <string.h>  /* memcmp(), strcpy() */
28
 
28
 
29
#include "svarlang.h"
29
#include "svarlang.h"
30
 
30
 
Line 43... Line 43...
43
    ptr += ((unsigned short *)ptr)[1] + 4;
43
    ptr += ((unsigned short *)ptr)[1] + 4;
44
  }
44
  }
45
}
45
}
46
 
46
 
47
 
47
 
-
 
48
static unsigned short FOPEN(const char *s) {
-
 
49
  unsigned short fname_seg = FP_SEG(s);
-
 
50
  unsigned short fname_off = FP_OFF(s);
-
 
51
  unsigned short res = 0xffff;
-
 
52
  _asm {
-
 
53
    push dx
-
 
54
    push ds
-
 
55
 
-
 
56
    mov ax, fname_seg
-
 
57
    mov dx, fname_off
-
 
58
    mov ds, ax
-
 
59
    mov ax, 0x3d00  /* open file, read-only (fname at DS:DX) */
-
 
60
    int 0x21
-
 
61
    pop ds
-
 
62
    jc ERR
-
 
63
    mov res, ax
-
 
64
 
-
 
65
    ERR:
-
 
66
    pop dx
-
 
67
  }
-
 
68
 
-
 
69
  return(res);
-
 
70
}
-
 
71
 
-
 
72
 
-
 
73
static void FCLOSE(unsigned short handle) {
-
 
74
  _asm {
-
 
75
    push bx
-
 
76
 
-
 
77
    mov ah, 0x3e
-
 
78
    mov bx, handle
-
 
79
    int 0x21
-
 
80
 
-
 
81
    pop bx
-
 
82
  }
-
 
83
}
-
 
84
 
-
 
85
 
-
 
86
static unsigned short FREAD(unsigned short handle, void *buff, unsigned short bytes) {
-
 
87
  unsigned short buff_seg = FP_SEG(buff);
-
 
88
  unsigned short buff_off = FP_OFF(buff);
-
 
89
  unsigned short res = 0;
-
 
90
 
-
 
91
  _asm {
-
 
92
    push bx
-
 
93
    push cx
-
 
94
    push dx
-
 
95
 
-
 
96
    mov bx, handle
-
 
97
    mov cx, bytes
-
 
98
    mov dx, buff_off
-
 
99
    mov ax, buff_seg
-
 
100
    push ds
-
 
101
    mov ds, ax
-
 
102
    mov ah, 0x3f    /* read cx bytes from file handle bx to DS:DX */
-
 
103
    int 0x21
-
 
104
    pop ds
-
 
105
    jc ERR
-
 
106
 
-
 
107
    mov res, ax
-
 
108
    ERR:
-
 
109
 
-
 
110
    pop dx
-
 
111
    pop cx
-
 
112
    pop bx
-
 
113
  }
-
 
114
 
-
 
115
  return(res);
-
 
116
}
-
 
117
 
-
 
118
 
-
 
119
static void FJUMP(unsigned short handle, unsigned short bytes) {
-
 
120
  _asm {
-
 
121
    push bx
-
 
122
    push cx
-
 
123
    push dx
-
 
124
 
-
 
125
    mov ax, 0x4201  /* move file pointer from cur pos + CX:DX */
-
 
126
    mov bx, handle
-
 
127
    xor cx, cx
-
 
128
    mov dx, bytes
-
 
129
    int 0x21
-
 
130
 
-
 
131
    pop dx
-
 
132
    pop cx
-
 
133
    pop bx
-
 
134
  }
-
 
135
}
-
 
136
 
-
 
137
 
48
int svarlang_load(const char *progname, const char *lang, const char *nlspath) {
138
int svarlang_load(const char *progname, const char *lang, const char *nlspath) {
49
  unsigned short langid;
139
  unsigned short langid;
50
  FILE *fd;
140
  unsigned short fd;
51
  char buff[128];
141
  char buff[128];
52
  unsigned short buff16[2];
142
  unsigned short buff16[2];
53
  unsigned short i;
143
  unsigned short i;
54
 
144
 
55
  if (lang == NULL) return(-1);
145
  if (lang == NULL) return(-1);
Line 71... Line 161...
71
  if ((i > 0) && (buff[i - 1] != '\\')) buff[i++] = '\\';
161
  if ((i > 0) && (buff[i - 1] != '\\')) buff[i++] = '\\';
72
 
162
 
73
  strcpy(buff + i, progname);
163
  strcpy(buff + i, progname);
74
  strcat(buff + i, ".lng");
164
  strcat(buff + i, ".lng");
75
 
165
 
76
  fd = fopen(buff, "rb");
166
  fd = FOPEN(buff);
77
  if (fd == NULL) { /* failed to open file - either abort or try next path */
167
  if (fd == 0xffff) { /* failed to open file - either abort or try next path */
78
    if (*nlspath == 0) return(-2);
168
    if (*nlspath == 0) return(-2);
79
    goto TRYNEXTPATH;
169
    goto TRYNEXTPATH;
80
  }
170
  }
81
 
171
 
82
  /* read hdr, should be "SvL\33" */
172
  /* read hdr, should be "SvL\33" */
83
  if ((fread(buff, 1, 4, fd) != 4) || (memcmp(buff, "SvL\33", 4) != 0)) {
173
  if ((FREAD(fd, buff, 4) != 4) || (memcmp(buff, "SvL\33", 4) != 0)) {
84
    fclose(fd);
174
    FCLOSE(fd);
85
    return(-3);
175
    return(-3);
86
  }
176
  }
87
 
177
 
88
  /* read next lang id in file */
178
  /* read next lang id in file */
89
  while (fread(buff16, 1, 4, fd) == 4) {
179
  while (FREAD(fd, buff16, 4) == 4) {
90
 
180
 
91
    /* is it the lang I am looking for? */
181
    /* is it the lang I am looking for? */
92
    if (buff16[0] != langid) { /* skip to next lang */
182
    if (buff16[0] != langid) { /* skip to next lang */
93
      fseek(fd, buff16[1], SEEK_CUR);
183
      FJUMP(fd, buff16[1]);
94
      continue;
184
      continue;
95
    }
185
    }
96
 
186
 
97
    /* found - but do I have enough memory space? */
187
    /* found - but do I have enough memory space? */
98
    if (buff16[1] >= svarlang_memsz) {
188
    if (buff16[1] >= svarlang_memsz) {
99
      fclose(fd);
189
      FCLOSE(fd);
100
      return(-4);
190
      return(-4);
101
    }
191
    }
102
 
192
 
103
    /* load strings */
193
    /* load strings */
104
    if (fread(svarlang_mem, 1, buff16[1], fd) != buff16[1]) break;
194
    if (FREAD(fd, svarlang_mem, buff16[1]) != buff16[1]) break;
105
    fclose(fd);
195
    FCLOSE(fd);
106
    return(0);
196
    return(0);
107
  }
197
  }
108
 
198
 
109
  fclose(fd);
199
  FCLOSE(fd);
110
  return(-5);
200
  return(-5);
111
}
201
}