/svarcom/cmd/cd.c |
---|
0,0 → 1,99 |
/* |
* chdir |
* |
* displays the name of or changes the current directory. |
* |
* CHDIR [drive:][path] |
* CD.. |
* |
* Type CD drive: to display the current directory in the specified drive. |
* Type CD without parameters to display the current drive and directory. |
*/ |
static int cmd_cd(const struct cmd_funcparam *p) { |
/* two arguments max */ |
if (p->argc > 1) { |
puts("Too many parameters"); |
} |
/* no argument? display current drive and dir ("CWD") */ |
if (p->argc == 0) { |
char buff[64]; |
char *buffptr = buff; |
_asm { |
push ax |
push dx |
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 |
} |
puts(buff); |
} |
/* argument can be either a drive (D:) or a path */ |
if (p->argc == 1) { |
const char *arg = p->argv[0]; |
unsigned short err = 0; |
/* drive (CD B:) */ |
if ((arg[0] != '\\') && (arg[1] == ':') && (arg[2] == 0)) { |
char buff[64]; |
char *buffptr = buff; |
unsigned char drive = arg[0]; |
if (drive >= 'a') { |
drive -= 'a'; |
} else { |
drive -= 'A'; |
} |
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, buff); |
} else { /* path */ |
_asm { |
push dx |
push ax |
mov ah, 0x3B /* CHDIR (set current directory) */ |
mov dx, arg |
int 0x21 |
jnc DONE |
mov [err], ax |
DONE: |
pop ax |
pop dx |
} |
} |
if (err != 0) puts(doserr(err)); |
} |
return(-1); |
} |
/svarcom/cmd/exit.c |
---|
0,0 → 1,18 |
/* |
* exit |
* |
* Quits the COMMAND.COM program (command interpreter) |
* |
*/ |
static int cmd_exit(const struct cmd_funcparam *p) { |
if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) { |
puts("EXIT"); |
puts(""); |
puts("Quits the COMMAND.COM program (command interpreter)"); |
puts(""); |
} else { |
exit(0); |
} |
return(-1); |
} |
/svarcom/cmd/set.c |
---|
0,0 → 1,64 |
/* |
* set [varname[=value]] |
* |
* value cannot contain any '=' character, but it can contain spaces |
* varname can also contain spaces |
*/ |
#include "env.h" |
static int cmd_set(const struct cmd_funcparam *p) { |
char far *env = MK_FP(p->env_seg, 0); |
char buff[256]; |
int i; |
/* no arguments - display content */ |
if (p->argc == 0) { |
while (*env != 0) { |
/* copy string to local buff for display */ |
for (i = 0;; i++) { |
buff[i] = *env; |
env++; |
if (buff[i] == 0) break; |
} |
puts(buff); |
} |
} else if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) { |
puts("TODO: help screen"); /* TODO */ |
} else { /* set variable (do not rely on argv, SET has its own rules...) */ |
const char far *ptr; |
char buff[256]; |
unsigned short i; |
/* locate the first space */ |
for (ptr = p->cmdline; *ptr != ' '; ptr++); |
/* now locate the first non-space: that's where the variable name begins */ |
for (; *ptr == ' '; ptr++); |
/* copy variable to buff and switch it upercase */ |
i = 0; |
for (; *ptr != '='; ptr++) { |
if (*ptr == '\r') goto syntax_err; |
buff[i] = *ptr; |
if ((buff[i] >= 'a') && (buff[i] <= 'z')) buff[i] -= ('a' - 'A'); |
i++; |
} |
/* copy value now */ |
while (*ptr != '\r') { |
buff[i++] = *ptr; |
ptr++; |
} |
/* terminate buff */ |
buff[i] = 0; |
/* commit variable to environment */ |
i = env_setvar(p->env_seg, buff); |
if (i == ENV_INVSYNT) goto syntax_err; |
if (i == ENV_NOTENOM) puts("Not enough available space within the environment block"); |
} |
return(-1); |
syntax_err: |
puts("Syntax error"); |
return(-1); |
} |