29,7 → 29,12 |
|
#include <i86.h> /* MK_FP() */ |
#include <stdio.h> /* sprintf() */ |
#include <string.h> /* memcpy() */ |
|
#include "deflang.h" |
|
#include "env.h" |
|
#include "helpers.h" |
|
|
87,6 → 92,25 |
} |
|
|
void nls_output_internal(unsigned short id, unsigned short nl) { |
const char *ptr = langblock + 4; /* first 4 bytes are lang id and lang len */ |
const char *NOTFOUND = "NLS_STRING_NOT_FOUND"; |
/* find the string id in langblock memory */ |
for (;;) { |
if (((unsigned short *)ptr)[0] == id) { |
ptr += 3; |
break; |
} |
if (ptr[2] == 0) { |
ptr = NOTFOUND; |
break; |
} |
ptr += ptr[2] + 3; |
} |
output_internal(ptr, nl); |
} |
|
|
/* find first matching files using a FindFirst DOS call |
* returns 0 on success or a DOS err code on failure */ |
unsigned short findfirst(struct DTA *dta, const char *pattern, unsigned short attr) { |
226,7 → 250,7 |
|
/* displays the "Press any key to continue" msg and waits for a keypress */ |
void press_any_key(void) { |
output("Press any key to continue..."); |
nls_output(15, 1); /* Press any key to continue... */ |
_asm { |
mov ah, 0x08 /* no echo console input */ |
int 0x21 /* pressed key in AL now (0 for extended keys) */ |
541,3 → 565,157 |
|
return(sl); |
} |
|
|
/* reload nls ressources from svarcom.lng into langblock */ |
void nls_langreload(char *buff, unsigned short env) { |
unsigned short i; |
const char far *nlspath; |
char *langblockptr = langblock; |
unsigned short lang; |
unsigned short errcode = 0; |
|
/* look up the LANG env variable, upcase it and copy to lang */ |
nlspath = env_lookup_val(env, "LANG"); |
if ((nlspath == NULL) || (nlspath[0] == 0)) return; |
buff[0] = nlspath[0]; |
buff[1] = nlspath[1]; |
buff[2] = 0; |
|
if (buff[0] >= 'a') buff[0] -= 'a' - 'A'; |
if (buff[1] >= 'a') buff[1] -= 'a' - 'A'; |
memcpy(&lang, buff, 2); |
|
/* check if there is need to reload at all */ |
if (((unsigned short *)langblock)[0] == lang) return; |
|
/* printf("NLS RELOAD (curlang=%04X ; toload=%04X\r\n", ((unsigned short *)langblock)[0], lang); */ |
|
nlspath = env_lookup_val(env, "NLSPATH"); |
if ((nlspath == NULL) || (nlspath[0] == 0)) return; |
|
/* copy NLSPATH(far) to buff */ |
for (i = 0; nlspath[i] != 0; i++) buff[i] = nlspath[i]; |
|
/* terminate with a bkslash, if not already the case */ |
if (buff[i - 1] != '\\') buff[i++] = '\\'; |
|
/* append "svarcom.lng" */ |
strcpy(buff + i, "SVARCOM.LNG"); |
|
/* copy file content to langblock */ |
_asm { |
push ax |
push bx |
push cx |
push dx |
push si |
push di |
|
/* make sure ES=DS and clear DF (will be useful for string matching) */ |
push ds |
pop es |
cld |
|
/* preset SI to buff */ |
mov si, buff |
|
/* Open File */ |
mov bx, 0xffff /* bx holds the file handle (0xffff = not set) */ |
mov ax, 0x3d00 /* DOS 2+ -- Open File for read */ |
mov dx, si /* fname */ |
int 0x21 /* cf set on error, otherwise handle in AX */ |
jnc OPENOK |
jmp FAIL |
OPENOK: |
mov bx, ax /* save file handle to bx */ |
|
/* read hdr */ |
mov ah, 0x3f /* DOS 2+ -- Read from File via Handle in BX */ |
mov cx, 4 /* read 4 bytes */ |
mov dx, si |
int 0x21 |
jnc READHDROK |
jmp FAIL |
|
READHDROK: |
|
cmp ax, cx /* hdr must be 4 bytes long (SvL\x1b) */ |
jne FAIL |
/* check that sig is Svl\x1b */ |
mov di, si |
cld /* scasw must inc DI */ |
mov ax, 'vS' |
scasw /* cmp ax, ES:[DI] and DI += 2*/ |
jne FAIL |
mov ax, 0x1B4C |
scasw /* cmp ax, ES:[DI] and DI += 2*/ |
jne FAIL |
|
READLANGID: |
/* read lang id */ |
mov ah, 0x3f /* Read from File via Handle in BX */ |
/* mov bx, [i] already set */ |
mov cx, 4 |
mov dx, si |
int 0x21 |
jc FAIL |
cmp ax, cx |
jne FAIL |
/* is this the LANG I am looking for? */ |
mov ax, [lang] |
mov di, si |
scasw /* cmp ax, ES:[DI] and DI += 2*/ |
je LOADSTRINGS |
/* skip to next lang */ |
mov ax, 0x4201 /* move file pointer CX:DX bytes forward */ |
/* mov bx, [i] file handle */ |
xor cx, cx |
mov dx, [di] |
int 0x21 |
jc FAIL |
jmp READLANGID |
|
LOADSTRINGS: |
|
/* copy langid and langlen to langblockptr */ |
mov di, langblockptr |
mov ax, [si] |
stosw /* mov [di], ax and di += 2 */ |
mov ax, [si+2] |
stosw |
/* read strings (buff+2 bytes) into langblock */ |
mov ah, 0x3f /* Read from File via Handle in BX */ |
mov cx, [si+2] |
mov dx, di |
int 0x21 |
jnc DONE |
|
/* on error make sure to zero out langblock's header */ |
xor cx, cx |
mov [di], cx /* langblock id*/ |
mov [di + 2], cx /* langblock len */ |
mov [di + 4], cx /* 1st string id */ |
mov [di + 6], cx /* 1st string len */ |
|
/* cleanup and quit */ |
FAIL: |
mov [errcode], ax |
DONE: |
/* close file handle if set */ |
cmp bx, 0xffff |
je FNOTOPEN |
mov ah, 0x3e /* DOS 2+ -- Close a File Handle (Handle in BX) */ |
int 0x21 |
FNOTOPEN: |
|
pop di |
pop si |
pop dx |
pop cx |
pop bx |
pop ax |
} |
|
if (errcode != 0) printf("AX=%04x\r\n", errcode); |
} |