Subversion Repositories SvarDOS

Compare Revisions

Problem with comparison.

Ignore whitespace Rev HEAD → Rev 374

/svarcom/cmd/cd.c
0,0 → 1,117
/*
* 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(struct cmd_funcparam *p) {
char *buffptr = p->BUFFER;
 
/* two arguments max */
if (p->argc > 1) {
outputnl("Too many parameters");
return(-1);
}
 
/* CD /? */
if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
outputnl("Displays the name of or changes the current directory.");
outputnl("");
outputnl("CHDIR [drive:][path]");
outputnl("CHDIR[..]");
outputnl("CD [drive:][path]");
outputnl("CD[..]");
outputnl("");
outputnl(".. Specifies that you want to change to the parent directory.");
outputnl("");
outputnl("Type CD drive: to display the current directory in the specified drive.");
outputnl("Type CD without parameters to display the current drive and directory.");
return(-1);
}
 
/* no argument? display current drive and dir ("CWD") */
if (p->argc == 0) {
_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
}
outputnl(buffptr);
return(-1);
}
 
/* 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)) {
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, buffptr);
} 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) {
outputnl(doserr(err));
}
}
 
return(-1);
}
/svarcom/cmd/dir.c
0,0 → 1,106
/*
* dir
*
* Displays a list of files and subdirectories in a directory.
*
* DIR [drive:][path][filename] [/P] [/W] [/A[:]attributes] [/O[[:]sortorder]] [/S] [/B] [/L]
*
* /P Pauses after each screenful of information.
* /W Uses wide list format.
*
* /A Displays file with specified attributes:
* D Directories R Read-only files H Hidden files
* A Ready for archiving S System files - prefix meaning "not"
*
* /O List files in sorted order:
* N by name S by size E by extension
* D by date G group dirs first - prefix to reverse order
*
* /S Displays files in specified directory and all subdirectories.
* /B Uses bare format (no heading information or summary)
* /L Uses lowercases
*/
 
#define cmd_dir_attr_ro 1
#define cmd_dir_attr_hid 2
#define cmd_dir_attr_sys 4
#define cmd_dir_attr_vol 8
#define cmd_dir_attr_dir 16
#define cmd_dir_attr_arc 32
 
 
static int cmd_dir(struct cmd_funcparam *p) {
const char *filespecptr = "*.*";
unsigned short errcode;
_Packed struct DTA {
char reserved[21];
unsigned char attr;
unsigned short time;
unsigned short date;
unsigned long size;
char fname[13];
} *dta = (void *)0x80; /* set DTA to its default location at 80h in PSP */
/*
* FileInfoRec (DTA) format:
* offset size desc
* +0 21 reserved
* +15h 1 file attr (1=RO 2=Hidden 4=System 8=VOL 16=DIR 32=Archive
* +16h 2 time: bits 0-4=bi-seconds (0-30), bits 5-10=minutes (0-59), bits 11-15=hour (0-23)
* +18h 2 date: bits 0-4=day(0-31), bits 5-8=month (1-12), bits 9-15=years since 1980
* +1ah 4 DWORD file size, in bytes
* +1eh 13 13-bytes max ASCIIZ filename
*/
 
errcode = 0;
_asm {
push ax
push cx
push dx
/* query DTA location */
/* mov ah, 0x2f */
/* int 0x21 */ /* DTA address is in ES:BX now */
/* mov dta+2, es */
/* mov dta, bx */
/* set DTA location */
mov ah, 0x1a
mov dx, dta
int 0x21
/* FindFirst */
mov ah, 0x4e
mov dx, filespecptr /* filespec */
mov cx, 0xff /* file attr to match: when a bit is clear, files with that attr will NOT be found */
int 0x21
jnc DONE
mov errcode, ax
DONE:
pop dx
pop cx
pop ax
}
if (errcode != 0) return(-1);
 
outputnl(dta->fname);
 
NEXTFILE:
 
_asm {
push ax
push cx
push dx
mov ah, 0x4f /* FindNext */
mov dx, dta
int 0x21
jnc DONE
mov errcode, ax
DONE:
pop dx
pop cx
pop ax
}
 
outputnl(dta->fname);
 
if (errcode == 0) goto NEXTFILE;
 
return(-1);
}
/svarcom/cmd/exit.c
0,0 → 1,18
/*
* exit
*
* Quits the COMMAND.COM program (command interpreter)
*
*/
 
static int cmd_exit(struct cmd_funcparam *p) {
if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
output("EXIT\r\n"
"\r\n"
"Quits the COMMAND.COM program (command interpreter)\r\n"
"\r\n");
} else {
exit(0);
}
return(-1);
}
/svarcom/cmd/path.c
0,0 → 1,67
/*
* path
*
* Displays or sets a search path for executable files.
*/
 
static int cmd_path(struct cmd_funcparam *p) {
char *buff = p->BUFFER;
 
/* no parameter - display current path */
if (p->argc == 0) {
char far *curpath = env_lookup(p->env_seg, "PATH");
if (curpath == NULL) {
outputnl("No Path");
} else {
unsigned short i;
for (i = 0;; i++) {
buff[i] = curpath[i];
if (buff[i] == 0) break;
}
outputnl(buff);
}
return(-1);
}
 
/* more than 1 parameter */
if (p->argc > 1) {
outputnl("Too many parameters");
return(-1);
}
 
/* IF HERE: THERE IS EXACTLY 1 ARGUMENT (argc == 1) */
 
/* help screen (/?) */
if (imatch(p->argv[0], "/?")) {
output("Displays or sets a search path for executable files.\r\n"
"\r\n"
"PATH [[drive:]path[;...]]\r\n"
"PATH ;\r\n"
"\r\n"
"Type PATH ; to clear all search-path settings and direct DOS to search\r\n"
"only in the current directory.\r\n"
"\r\n"
"Type PATH without parameters to display the current path.\r\n");
return(-1);
}
 
/* reset the PATH string (PATH ;) */
if (imatch(p->argv[0], ";")) {
env_dropvar(p->env_seg, "PATH");
return(-1);
}
 
/* otherwise set PATH to whatever is passed on command-line */
{
unsigned short i;
strcpy(buff, "PATH=");
for (i = 0;; i++) {
buff[i + 5] = p->argv[0][i];
if (buff[i + 5] == '\r') break;
}
buff[i + 5] = 0;
env_setvar(p->env_seg, buff);
}
 
return(-1);
}
/svarcom/cmd/prompt.c
0,0 → 1,37
/*
* prompt
*
* Changes the DOS command prompt.
*
*/
 
static int cmd_prompt(struct cmd_funcparam *p) {
if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
output("Changes the DOS command prompt.\r\n"
"\r\n"
"PROMPT [new command prompt specification]\r\n"
"\r\n");
return(-1);
}
 
/* no parameter - restore default prompt path */
if (p->argc == 0) {
env_dropvar(p->env_seg, "PROMPT");
return(-1);
}
 
/* otherwise set PROMPT to whatever is passed on command-line */
{
unsigned short i;
char *buff = p->BUFFER;
strcpy(buff, "PROMPT=");
for (i = 0;; i++) {
buff[i + 7] = p->cmdline[p->argoffset + i];
if (buff[i + 7] == '\r') break;
}
buff[i + 7] = 0;
env_setvar(p->env_seg, buff);
}
 
return(-1);
}
/svarcom/cmd/set.c
0,0 → 1,62
/*
* set [varname[=value]]
*
* value cannot contain any '=' character, but it can contain spaces
* varname can also contain spaces
*/
 
 
static int cmd_set(struct cmd_funcparam *p) {
char far *env = MK_FP(p->env_seg, 0);
char *buff = p->BUFFER;
/* no arguments - display content */
if (p->argc == 0) {
while (*env != 0) {
unsigned short i;
/* copy string to local buff for display */
for (i = 0;; i++) {
buff[i] = *env;
env++;
if (buff[i] == 0) break;
}
outputnl(buff);
}
} else if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
outputnl("TODO: help screen"); /* TODO */
} else { /* set variable (do not rely on argv, SET has its own rules...) */
const char far *ptr;
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) outputnl("Not enough available space within the environment block");
}
return(-1);
 
syntax_err:
 
outputnl("Syntax error");
return(-1);
}