Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 374 → Rev 375

/svarcom/cmd/cd.c
10,6 → 10,37
* Type CD without parameters to display the current drive and directory.
*/
 
 
/* display current path drive d (A=1, B=2, etc)
* returns 0 on success, doserr otherwise */
static unsigned short cmd_cd_curpathfordrv(char *buff, unsigned char d) {
unsigned short r = 0;
 
buff[0] = d + 'A' - 1;
buff[1] = ':';
buff[2] = '\\';
 
_asm {
push si
push ax
push dx
mov ah, 0x47 /* get current directory */
mov dl, [d] /* A: = 1, B: = 2, etc */
mov si, buff /* append cur dir to buffer */
add si, 3 /* skip the present drive:\ prefix */
int 0x21
jnc DONE
mov [r], ax /* copy result from ax */
DONE:
pop dx
pop ax
pop si
}
 
return(r);
}
 
 
static int cmd_cd(struct cmd_funcparam *p) {
char *buffptr = p->BUFFER;
 
37,6 → 68,8
 
/* no argument? display current drive and dir ("CWD") */
if (p->argc == 0) {
unsigned char drv = 0;
 
_asm {
push ax
push dx
43,25 → 76,13
push si
mov ah, 0x19 /* get current default drive */
int 0x21 /* al = drive (00h = A:, 01h = B:, etc) */
add al, 'A'
/* print drive to stdout */
mov dl, al
mov ah, 0x02
int 0x21
mov dl, ':'
int 0x21
mov dl, '\'
int 0x21
/* get current dir */
mov ah, 0x47
xor dl, dl /* select drive (0 = current drive) */
mov si, buffptr /* 64-byte buffer for ASCIZ pathname */
int 0x21
pop si
pop dx
pop ax
inc al /* convert to 1=A, 2=B, etc */
mov [drv], al
}
 
cmd_cd_curpathfordrv(buffptr, drv);
outputnl(buffptr);
 
return(-1);
}
 
73,27 → 94,13
if ((arg[0] != '\\') && (arg[1] == ':') && (arg[2] == 0)) {
unsigned char drive = arg[0];
if (drive >= 'a') {
drive -= 'a';
drive -= ('a' - 1);
} else {
drive -= 'A';
drive -= ('A' - 1);
}
drive++; /* A: = 1, B: = 2, etc*/
_asm {
push si
push ax
push dx
mov ah, 0x47 /* get current directory */
mov dl, [drive] /* A: = 1, B: = 2, etc */
mov si, buffptr
int 0x21
jnc DONE
mov [err], ax
DONE:
pop dx
pop ax
pop si
}
if (err == 0) printf("%c:\\%s\r\n", drive + 'A' - 1, buffptr);
 
err = cmd_cd_curpathfordrv(buffptr, drive);
if (err == 0) outputnl(buffptr);
} else { /* path */
_asm {
push dx