Subversion Repositories SvarDOS

Rev

Rev 368 | Rev 372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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