Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 547 → Rev 548

/svarcom/trunk/command.c
63,26 → 63,50
/* check RMOD signature (would be overwritten in case of stack overflow */
static char msg[] = "!! MEMORY CORRUPTION ## DETECTED !!";
unsigned short far *rmodsig = MK_FP(rmodseg, 0x100 + 6);
unsigned char far *rmod = MK_FP(rmodseg, 0);
 
if (*rmodsig != 0x2019) {
msg[22] = '1';
outputnl(msg);
printf("rmodseg = %04X ; *rmodsig = %04X\r\n", rmodseg, *rmodsig);
return(1);
goto FAIL;
}
 
/* check last BUFFER byte */
if (BUFFER[sizeof(BUFFER) - 1] != 0xC7) {
msg[22] = '2';
outputnl(msg);
return(2);
goto FAIL;
}
 
/* check last cmdlinebuf byte */
if (cmdlinebuf[CMDLINE_MAXLEN] != 0xC7) {
msg[22] = '3';
outputnl(msg);
return(3);
goto FAIL;
}
/* all good */
 
/* check rmod exec buf */
if (rmod[RMOD_OFFSET_EXECPROG + 127] != 0) {
msg[22] = '4';
goto FAIL;
}
 
/* check rmod exec stdin buf */
if (rmod[RMOD_OFFSET_STDINFILE + 127] != 0) {
msg[22] = '5';
goto FAIL;
}
 
/* check rmod exec stdout buf */
if (rmod[RMOD_OFFSET_STDOUTFILE + 127] != 0) {
msg[22] = '6';
goto FAIL;
}
 
/* else all good */
return(0);
 
/* error handling */
FAIL:
outputnl(msg);
return(1);
}
 
 
421,8 → 445,7
/* special handling of batch files */
if ((ext != NULL) && (imatch(ext, "bat"))) {
/* copy truename of the bat file to rmod buff */
for (i = 0; cmdfile[i] != 0; i++) rmod->batfile[i] = cmdfile[i];
rmod->batfile[i] = 0;
_fstrcpy(rmod->batfile, cmdfile);
 
/* explode args of the bat file and store them in rmod buff */
cmd_explode(buff, cmdline, NULL);
437,28 → 460,21
}
 
/* copy full filename to execute, along with redirected files (if any) */
for (i = 0; cmdfile[i] != 0; i++) rmod_execprog[i] = cmdfile[i];
rmod_execprog[i++] = 0;
_fstrcpy(rmod_execprog, cmdfile);
 
/* copy stdin file if a redirection is needed */
if (redir->stdinfile) {
unsigned short far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDINFILE);
unsigned short t;
*farptr = i;
for (t = 0;; t++) {
rmod_execprog[i++] = redir->stdinfile[t];
if (redir->stdinfile[t] == 0) break;
}
char far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDINFILE);
_fstrcpy(farptr, redir->stdinfile);
}
 
/* same for stdout file */
if (redir->stdoutfile) {
unsigned short far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTFILE);
unsigned short t;
*farptr = i;
for (t = 0;; t++) {
rmod_execprog[i++] = redir->stdoutfile[t];
if (redir->stdoutfile[t] == 0) break;
}
char far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTFILE);
unsigned short far *farptr16 = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTAPP);
_fstrcpy(farptr, redir->stdoutfile);
/* openflag */
farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTAPP);
*farptr = redir->stdout_openflag;
*farptr16 = redir->stdout_openflag;
}
 
/* copy cmdtail to rmod's PSP and compute its len */
/svarcom/trunk/rmod.asm
45,25 → 45,24
; +0Ah 4 address of an FCB to be placed at PSP:006c
EXEC_PARAM_REC db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; +5Ch
 
; Program to execute, preset by SvarCOM (128 bytes, ASCIIZ) ; +6Ah
EXECPROG dd 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
; Program to execute, preset by SvarCOM (128 bytes, ASCIIZ)
EXECPROG: times 128 db 0 ; +6Ah
 
; offset within EXECPROG for out and in filenames in case stdin or stdout
; needs to be redirected (0xffff=no redirection)
REDIR_OUTFIL dw 0xffff ; +EAh
REDIR_INFIL dw 0xffff ; +ECh
REDIR_OUTAPPEND dw 0 ; +EEh
; File where stdin and stdout should be redirected (0 = no redirection)
REDIR_INFIL: times 128 db 0 ; +EAh
REDIR_OUTFIL: times 128 db 0 ; +16Ah
REDIR_OUTAPPEND: dw 0 ; +1EAh
 
; CTRL+BREAK (int 23h) handler
; According to the TechHelp! Manual: "If you want to abort (exit to the parent
; process), then set the carry flag and return via a FAR RET. This causes DOS
; to perform normal cleanup and exit to the parent." (otherwise use iret)
BREAK_HANDLER: ; +F0h
BREAK_HANDLER: ; +1ECh
stc
retf
 
 
skipsig: ; +F2h
skipsig: ; +1EEh
 
; set up CS=DS=SS and point SP to my private stack buffer
mov ax, cs
223,16 → 222,15
; ----------------------------------------------------------------------------
; redirect stdout if REDIR_OUTFIL points to something
REDIR_INOUTFILE_IF_REQUIRED:
mov si, [REDIR_OUTFIL]
cmp si, 0xffff
cmp [REDIR_OUTFIL], byte 0
je NO_STDOUT_REDIR
add si, EXECPROG ; si=output file
mov si, REDIR_OUTFIL ; si = output file
mov ax, 0x6c00 ; Extended Open/Create
mov bx, 1 ; access mode (0=read, 1=write, 2=r+w)
xor cx, cx ; file attribs when(if) file is created (0=normal)
mov dx, [REDIR_OUTAPPEND] ; action if file exist (0x11=open, 0x12=truncate)
int 0x21 ; ax=handle on success (CF clear)
mov [REDIR_OUTFIL], word 0xffff
mov [REDIR_OUTFIL], byte 0
jc NO_STDOUT_REDIR ; TODO: abort with an error message instead
 
; jump to end of file if flag was 0x11 (required for >> redirections)
249,7 → 247,7
; duplicate current stdout so I can revert it later
push ax ; save my file handle in stack
mov ah, 0x45 ; duplicate file handle BX
mov bx, 1 ; 1=stdout
mov bx, 1 ; 1 = stdout
int 0x21 ; ax=new (duplicated) file handle
mov [OLD_STDOUT], ax ; save the old handle in memory
 
265,13 → 263,12
NO_STDOUT_REDIR:
 
; *** redirect stdin if REDIR_INFIL points to something ***
mov dx, [REDIR_INFIL]
cmp dx, 0xffff
cmp [REDIR_INFIL], byte 0
je NO_STDIN_REDIR
add dx, EXECPROG ; ds:dx=file
mov dx, REDIR_INFIL ; dx:dx = file
mov ax, 0x3d00 ; open file for read
int 0x21 ; ax=handle on success (CF clear)
mov [REDIR_INFIL], word 0xffff
mov [REDIR_INFIL], byte 0
jc NO_STDIN_REDIR ; TODO: abort with an error message instead
 
; duplicate current stdin so I can revert it later
/svarcom/trunk/rmodinit.h
50,11 → 50,11
#define RMOD_OFFSET_LEXITCODE (0x100 + 0x5B)
#define RMOD_OFFSET_EXECPARAM (0x100 + 0x5C)
#define RMOD_OFFSET_EXECPROG (0x100 + 0x6A)
#define RMOD_OFFSET_STDOUTFILE (0x100 + 0xEA)
#define RMOD_OFFSET_STDINFILE (0x100 + 0xEC)
#define RMOD_OFFSET_STDOUTAPP (0x100 + 0xEE)
#define RMOD_OFFSET_BRKHANDLER (0x100 + 0xF0)
#define RMOD_OFFSET_ROUTINE (0x100 + 0xF2)
#define RMOD_OFFSET_STDINFILE (0x100 + 0xEA)
#define RMOD_OFFSET_STDOUTFILE (0x100 + 0x16A)
#define RMOD_OFFSET_STDOUTAPP (0x100 + 0x1EA)
#define RMOD_OFFSET_BRKHANDLER (0x100 + 0x1EC)
#define RMOD_OFFSET_ROUTINE (0x100 + 0x1EE)
 
struct rmod_props far *rmod_install(unsigned short envsize, unsigned char *rmodcore, unsigned short rmodcore_len);
struct rmod_props far *rmod_find(unsigned short rmodcore_len);