Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 436 → Rev 437

/svarcom/trunk/cmd/pause.c
29,7 → 29,7
 
static int cmd_pause(struct cmd_funcparam *p) {
if (cmd_ishlp(p)) {
outputnl("Suspends processing of a batch program");
nls_outputnl(15, 0);
outputnl("\r\nPAUSE");
return(-1);
}
/svarcom/trunk/command.c
307,6 → 307,9
 
if (*echostatus != 0) outputnl(""); /* terminate the previous command with a CR/LF */
 
/* (re)load translation strings if needed */
nls_langreload(BUFFER, *rmod_envseg);
 
SKIP_NEWLINE:
 
/* print shell prompt (only if ECHO is enabled) */
/svarcom/trunk/helpers.c
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);
}
/svarcom/trunk/helpers.h
34,8 → 34,13
/* outputs a NULL-terminated string to stdout */
void output_internal(const char *s, unsigned short nl);
 
/* outputs a NULL-terminated NLS string to stdout */
void nls_output_internal(unsigned short id, unsigned short nl);
 
#define output(x) output_internal(x, 0)
#define outputnl(x) output_internal(x, 1)
#define nls_output(x,y) nls_output_internal((x << 8) | y, 0)
#define nls_outputnl(x,y) nls_output_internal((x << 8) | y, 1)
 
/*
* FileInfoRec (DTA) format:
167,4 → 172,7
* returns length of result */
unsigned short nls_format_number(char *s, unsigned long num, const struct nls_patterns *p);
 
/* reload nls ressources from svarcom.lng into langblock */
void nls_langreload(char *buff, unsigned short env);
 
#endif
/svarcom/trunk/tlumacz/tlumacz.c
29,9 → 29,7
#include <stdlib.h>
#include <string.h>
 
#include "msgid.h"
 
 
/* read a single line from fd and fills it into dst, returns line length
* ending CR/LF is trimmed, as well as any trailing spaces */
static unsigned short readl(char *dst, size_t dstsz, FILE *fd) {
201,7 → 199,9
puts("ERROR: FAILED TO OPEN OR CREATE DEFAULT.LNG");
break;
}
fwrite(buff, 1, sz, fd2);
fwrite(id, 1, 2, fd2); /* lang block id */
fwrite(&sz, 1, 2, fd2); /* lang block size */
fwrite(buff, 1, sz, fd2); /* langblock content (strings) */
fclose(fd2);
}
}
/svarcom/trunk/todo.txt
11,7 → 11,6
BEFORE NEXT RELEASE:
 
pipes redirections
support for translations (single binary file in %NLSPATH%)
basic BAT support (without workflow controls, FOR loops etc)
wmake clean does not work under SvarCOM
 
18,6 → 17,8
 
AT SOME LATER TIME:
 
translations should be cached in rmod-owned memory
if translations reloading fails, do not retry after every command
stdin redirection: command < file.txt
DIR: /A
DIR: %DIRCMD% support