Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 395 → Rev 396

/svarcom/cmd/dir.c
21,14 → 21,51
* /L Uses lowercases
*/
 
/* NOTE: /A attributes are matched in an exclusive way, ie. only files with
* the specified attributes are matched. This is different from how DOS
* itself matches attributes hence DIR cannot rely on the attributes
* filter within FindFirst.
*
* NOTE: Multiple /A are not supported - only the last one is significant.
*/
 
static int cmd_dir(struct cmd_funcparam *p) {
const char *filespecptr = NULL;
struct DTA *dta = (void *)0x80; /* set DTA to its default location at 80h in PSP */
int i;
unsigned short availrows; /* counter of available rows on display (used for /P) */
#define DIR_FLAG_PAUSE 1
#define DIR_FLAG_WIDE 2
#define DIR_FLAG_RECUR 4
#define DIR_FLAG_BARE 8
#define DIR_FLAG_LCASE 16
unsigned char flags = 0;
// unsigned char attribs_show = 0; /* show only files with ALL these attribs */
// unsigned char attribs_hide = 0; /* hide files with ANY of these attribs */
 
if (cmd_ishlp(p)) {
outputnl("Displays a list of files and subdirectories in a directory.");
outputnl("\r\nTHIS COMMAND IS NOT FULLY IMPLEMENTED YET");
outputnl("Displays a list of files and subdirectories in a directory");
outputnl("");
outputnl("DIR [drive:][path][filename] [/P] [/W] [/A[:]attributes] [/O[[:]sortorder]] [/S] [/B] [/L]");
outputnl("");
outputnl("/P Pauses after each screenful of information");
outputnl("/W Uses wide list format");
outputnl("");
outputnl("/A Displays files with specified attributes:");
outputnl(" D Directories R Read-only files H Hidden files");
outputnl(" A Ready for archiving S System files - prefix meaning \"not\"");
outputnl("");
outputnl("/O List files in sorted order:");
outputnl(" N by name S by size E by extension");
outputnl(" D by date G group dirs first - prefix to reverse order");
outputnl("");
outputnl("/S Displays files in specified directory and all subdirectories");
outputnl("/B Uses bare format (no heading information or summary)");
outputnl("/L Uses lowercases");
 
/* TODO FIXME REMOVE THIS ONCE ALL IMPLEMENTED */
outputnl("\r\n*** THIS COMMAND IS NOT FULLY IMPLEMENTED YET ***");
 
return(-1);
}
 
35,7 → 72,24
/* parse command line */
for (i = 0; i < p->argc; i++) {
if (p->argv[i][0] == '/') {
switch (p->argv[i][1]) {
char arg;
char neg = 0;
/* detect negations and get actual argument */
if (p->argv[i][1] == '-') neg = 1;
arg = p->argv[i][1 + neg];
/* */
switch (arg) {
case 'a':
case 'A':
/* TODO */
outputnl("/A NOT IMPLEMENTED YET");
return(-1);
break;
case 'p':
case 'P':
flags |= DIR_FLAG_PAUSE;
if (neg) flags &= (0xff ^ DIR_FLAG_PAUSE);
break;
default:
outputnl("Invalid switch");
return(-1);
59,9 → 113,21
 
if (findfirst(dta, p->BUFFER, DOS_ATTR_RO | DOS_ATTR_HID | DOS_ATTR_SYS | DOS_ATTR_DIR | DOS_ATTR_ARC) != 0) return(-1);
 
availrows = screen_getheight();
 
outputnl(dta->fname);
availrows--;
 
while (findnext(dta) == 0) outputnl(dta->fname);
while (findnext(dta) == 0) {
outputnl(dta->fname);
if (flags & DIR_FLAG_PAUSE) {
availrows--;
if (availrows < 2) {
press_any_key();
availrows = screen_getheight();
}
}
}
 
return(-1);
}
/svarcom/helpers.c
3,6 → 3,8
* Copyright (C) 2021 Mateusz Viste
*/
 
#include <i86.h> /* MK_FP() */
 
#include "helpers.h"
 
/* case-insensitive comparison of strings, returns non-zero on equality */
169,3 → 171,40
}
return(res);
}
 
 
/* returns screen's width (in columns) */
unsigned short screen_getwidth(void) {
/* BIOS 0040:004A = word containing screen width in text columns */
unsigned short far *scrw = MK_FP(0x40, 0x4a);
return(*scrw);
}
 
 
/* returns screen's height (in rows) */
unsigned short screen_getheight(void) {
/* BIOS 0040:0084 = byte containing maximum valid row value (EGA ONLY) */
unsigned char far *scrh = MK_FP(0x40, 0x84);
if (*scrh == 0) return(25); /* pre-EGA adapter */
return(*scrh + 1);
}
 
 
/* displays the "Press any key to continue" msg and waits for a keypress */
void press_any_key(void) {
output("Press any key to continue...");
_asm {
mov ah, 0x08 /* no echo console input */
int 0x21 /* pressed key in AL now (0 for extended keys) */
test al, al
jnz DONE
int 0x21 /* executed ah=8 again to read the rest of extended key */
DONE:
/* output CR/LF */
mov ah, 0x02
mov dl, 0x0D
int 0x21
mov dl, 0x0A
int 0x21
}
}
/svarcom/helpers.h
57,4 → 57,13
/* returns DOS attributes of file, or -1 on error */
int file_getattr(const char *fname);
 
/* returns screen's width (in columns) */
unsigned short screen_getwidth(void);
 
/* returns screen's height (in rows) */
unsigned short screen_getheight(void);
 
/* displays the "Press any key to continue" msg and waits for a keypress */
void press_any_key(void);
 
#endif