Subversion Repositories SvarDOS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
368 mateuszvis 1
/*
2
 * dir
3
 *
4
 * Displays a list of files and subdirectories in a directory.
5
 *
6
 * DIR [drive:][path][filename] [/P] [/W] [/A[:]attributes] [/O[[:]sortorder]] [/S] [/B] [/L]
7
 *
8
 * /P Pauses after each screenful of information.
9
 * /W Uses wide list format.
10
 *
11
 * /A Displays file with specified attributes:
12
 *     D Directories           R Read-only files     H Hidden files
13
 *     A Ready for archiving   S System files        - prefix meaning "not"
14
 *
15
 * /O List files in sorted order:
16
 *     N by name            S by size              E by extension
17
 *     D by date            G group dirs first     - prefix to reverse order
18
 *
19
 * /S Displays files in specified directory and all subdirectories.
20
 * /B Uses bare format (no heading information or summary)
21
 * /L Uses lowercases
22
 */
23
 
24
#define cmd_dir_attr_ro   1
25
#define cmd_dir_attr_hid  2
26
#define cmd_dir_attr_sys  4
27
#define cmd_dir_attr_vol  8
28
#define cmd_dir_attr_dir 16
29
#define cmd_dir_attr_arc 32
30
 
31
 
32
static int cmd_dir(const struct cmd_funcparam *p) {
33
  const char *filespecptr = "*.*";
34
  unsigned short errcode;
35
  _Packed struct DTA {
36
    char reserved[21];
37
    unsigned char attr;
38
    unsigned short time;
39
    unsigned short date;
40
    unsigned long size;
41
    char fname[13];
42
  } *dta = (void *)0x80; /* set DTA to its default location at 80h in PSP */
43
/*
44
 * FileInfoRec (DTA) format:
45
 * offset size desc
46
 *    +0   21  reserved
47
 *  +15h    1  file attr (1=RO 2=Hidden 4=System 8=VOL 16=DIR 32=Archive
48
 *  +16h    2  time: bits 0-4=bi-seconds (0-30), bits 5-10=minutes (0-59), bits 11-15=hour (0-23)
49
 *  +18h    2  date: bits 0-4=day(0-31), bits 5-8=month (1-12), bits 9-15=years since 1980
50
 *  +1ah    4  DWORD file size, in bytes
51
 *  +1eh   13  13-bytes max ASCIIZ filename
52
 */
53
 
54
  errcode = 0;
55
  _asm {
56
    push ax
57
    push cx
58
    push dx
59
    /* query DTA location */
60
    /* mov ah, 0x2f */
61
    /* int 0x21 */ /* DTA address is in ES:BX now */
62
    /* mov dta+2, es */
63
    /* mov dta, bx */
64
    /* set DTA location */
65
    mov ah, 0x1a
66
    mov dx, dta
67
    int 0x21
68
    /* FindFirst */
69
    mov ah, 0x4e
70
    mov dx, filespecptr   /* filespec */
71
    mov cx, 0xff         /* file attr to match: when a bit is clear, files with that attr will NOT be found */
72
    int 0x21
73
    jnc DONE
74
    mov errcode, ax
75
    DONE:
76
    pop dx
77
    pop cx
78
    pop ax
79
  }
80
  if (errcode != 0) return(-1);
81
 
82
  puts(dta->fname);
83
 
84
  NEXTFILE:
85
 
86
  _asm {
87
    push ax
88
    push cx
89
    push dx
90
    mov ah, 0x4f /* FindNext */
91
    mov dx, dta
92
    int 0x21
93
    jnc DONE
94
    mov errcode, ax
95
    DONE:
96
    pop dx
97
    pop cx
98
    pop ax
99
  }
100
 
101
  puts(dta->fname);
102
 
103
  if (errcode == 0) goto NEXTFILE;
104
 
105
  return(-1);
106
}