Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 1746 → Rev 1797

/svarcom/trunk/cmd.c
224,6 → 224,31
}
 
 
/* asks DOS to change the current default drive, returns the current drive
* (should be the same as d on success) */
static unsigned char _changedosdrive(unsigned char d);
#pragma aux _changedosdrive = \
"mov ah, 0x0e" /* DOS 1+ - SELECT DRIVE (DL=drive, 00h=A:, 01h=B:, etc) */ \
"int 0x21" \
"mov ah, 0x19" /* DOS 1+ - GET CURRENT DRIVE (drive in al) */ \
"int 0x21" \
parm [dl] \
modify [ah] \
value [al]
 
 
/* asks DOS to del a file, returns 0 on success */
static unsigned short _dosdelfile(const char near *f);
#pragma aux _dosdelfile = \
"mov ah, 0x41" /* delete a file ; DS:DX = filename to delete */ \
"int 0x21" \
"jc DONE" \
"xor ax, ax" \
"DONE:" \
parm [dx] \
value [ax]
 
 
enum cmd_result cmd_process(struct rmod_props far *rmod, unsigned short env_seg, const char *cmdline, void *BUFFER, unsigned short BUFFERSZ, const struct redir_data *redir, unsigned char delstdin) {
const struct CMD_ID *cmdptr;
unsigned short argoffset;
235,24 → 260,13
if ((cmdline[0] != 0) && (cmdline[1] == ':') && ((cmdline[2] == ' ') || (cmdline[2] == 0))) {
if (((cmdline[0] >= 'a') && (cmdline[0] <= 'z')) || ((cmdline[0] >= 'A') && (cmdline[0] <= 'Z'))) {
unsigned char drive = cmdline[0];
unsigned char curdrive = 0;
unsigned char curdrive;
if (drive >= 'a') {
drive -= 'a';
} else {
drive -= 'A';
}
_asm {
push ax
push dx
mov ah, 0x0e /* DOS 1+ - SELECT DEFAULT DRIVE */
mov dl, drive /* DL = new default drive (00h = A:, 01h = B:, etc) */
int 0x21
mov ah, 0x19 /* DOS 1+ - GET CURRENT DRIVE */
int 0x21
mov curdrive, al /* cur drive (0=A, 1=B, etc) */
pop dx
pop ax
}
curdrive = _changedosdrive(drive);
if (curdrive == drive) return(CMD_OK);
nls_outputnl_doserr(0x0f);
return(CMD_FAIL);
282,22 → 296,9
 
/* delete stdin temporary file */
if (delstdin) {
const char *fname = redir->stdinfile;
unsigned short doserr = 0;
_asm {
push ax
push dx
mov ah, 0x41 /* delete a file */
mov dx, fname /* DS:DX - filename to delete */
int 0x21
jnc DONE
mov doserr, ax
DONE:
pop dx
pop ax
}
unsigned short doserr = _dosdelfile(redir->stdinfile);
if (doserr) {
output(fname);
output(redir->stdinfile);
output(": ");
nls_outputnl_doserr(doserr);
}
/svarcom/trunk/command.c
349,34 → 349,14
}
 
 
static void dos_fname2fcb(char far *fcb, const char *cmd) {
unsigned short fcb_seg, fcb_off;
fcb_seg = FP_SEG(fcb);
fcb_off = FP_OFF(fcb);
_asm {
push ax
push bx
push cx
push dx
push es
push si
static void dos_fname2fcb(char far *fcb, const char near *cmd);
#pragma aux dos_fname2fcb = \
"mov ax, 0x2900" /* DOS 1+ - parse filename into FCB (DS:SI=fname, ES:DI=FCB) */ \
"int 0x21" \
parm [es di] [si] \
modify [ax si]
 
mov ax, 0x2900 /* DOS 1+ - parse filename into FCB (DS:SI=fname, ES:DI=FCB) */
mov si, cmd
mov es, fcb_seg
mov di, fcb_off
int 0x21
 
pop si
pop es
pop dx
pop cx
pop bx
pop ax
}
}
 
 
/* parses cmdtail and fills fcb1 and fcb2 with first and second arguments,
* respectively. an FCB is 12 bytes long:
* drive (0=default, 1=A, 2=B, etc)
637,54 → 617,42
 
 
/* wait for user input */
static void cmdline_getinput(unsigned short inpseg, unsigned short inpoff) {
_asm {
push ax
push bx
push cx
push dx
push ds
static void cmdline_getinput(unsigned short inpseg, unsigned short inpoff);
#pragma aux cmdline_getinput = \
"push ds" \
/* set up buffered input to inpseg:inpoff */ \
"push ax" \
"pop ds" \
\
/* is DOSKEY support present? (INT 2Fh, AX=4800h, returns non-zero in AL if present) */ \
"mov ax, 0x4800" \
"int 0x2f" \
\
/* execute either DOS input or DOSKEY */ \
"test al, al" /* al=0 if no DOSKEY present */ \
"jnz DOSKEY" \
\
/* buffered string input */ \
"mov ah, 0x0a" \
"int 0x21" \
"jmp short DONE" \
\
"DOSKEY:" \
"mov ax, 0x4810" \
"int 0x2f" \
\
"DONE:" \
/* terminate command with a CR/LF */ \
"mov ah, 0x02" /* display character in dl */ \
"mov dl, 0x0d" \
"int 0x21" \
"mov dl, 0x0a" \
"int 0x21" \
"pop ds" \
parm [ax] [dx] \
modify [ax dl]
 
/* is DOSKEY support present? (INT 2Fh, AX=4800h, returns non-zero in AL if present) */
mov ax, 0x4800
int 0x2f
mov bl, al /* save doskey status in BL */
 
/* set up buffered input to inpseg:inpoff */
mov ax, inpseg
push ax
pop ds
mov dx, inpoff
 
/* execute either DOS input or DOSKEY */
test bl, bl /* zf set if no DOSKEY present */
jnz DOSKEY
 
mov ah, 0x0a
int 0x21
jmp short DONE
 
DOSKEY:
mov ax, 0x4810
int 0x2f
 
DONE:
/* terminate command with a CR/LF */
mov ah, 0x02 /* display character in dl */
mov dl, 0x0d
int 0x21
mov dl, 0x0a
int 0x21
 
pop ds
pop dx
pop cx
pop bx
pop ax
}
}
 
 
/* fetches a line from batch file and write it to buff (NULL-terminated),
* increments rmod counter and returns 0 on success. */
static int getbatcmd(char *buff, unsigned char buffmaxlen, struct rmod_props far *rmod) {