Subversion Repositories SvarDOS

Rev

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

Rev 990 Rev 1085
1
/* This file is part of the SvarCOM project and is published under the terms
1
/* This file is part of the SvarCOM project and is published under the terms
2
 * of the MIT license.
2
 * of the MIT license.
3
 *
3
 *
4
 * Copyright (C) 2021-2022 Mateusz Viste
4
 * Copyright (C) 2021-2022 Mateusz Viste
5
 *
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 * and/or sell copies of the Software, and to permit persons to whom the
10
 * and/or sell copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following conditions:
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
12
 *
13
 * The above copyright notice and this permission notice shall be included in
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
14
 * all copies or substantial portions of the Software.
15
 *
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
 * DEALINGS IN THE SOFTWARE.
22
 * DEALINGS IN THE SOFTWARE.
23
 */
23
 */
24
 
24
 
25
/*
25
/*
26
 * dir
26
 * dir
27
 *
27
 *
28
 * Displays a list of files and subdirectories in a directory.
28
 * Displays a list of files and subdirectories in a directory.
29
 *
29
 *
30
 * DIR [drive:][path][filename] [/P] [/W] [/A[:]attributes] [/O[[:]sortorder]] [/S] [/B] [/L]
30
 * DIR [drive:][path][filename] [/P] [/W] [/A[:]attributes] [/O[[:]sortorder]] [/S] [/B] [/L]
31
 *
31
 *
32
 * /P Pauses after each screenful of information.
32
 * /P Pauses after each screenful of information.
33
 * /W Uses wide list format.
33
 * /W Uses wide list format.
34
 *
34
 *
35
 * /A Displays file with specified attributes:
35
 * /A Displays file with specified attributes:
36
 *     D Directories           R Read-only files     H Hidden files
36
 *     D Directories           R Read-only files     H Hidden files
37
 *     A Ready for archiving   S System files        - prefix meaning "not"
37
 *     A Ready for archiving   S System files        - prefix meaning "not"
38
 *
38
 *
39
 * /O List files in sorted order:
39
 * /O List files in sorted order:
40
 *     N by name            S by size              E by extension
40
 *     N by name            S by size              E by extension
41
 *     D by date            G group dirs first     - prefix to reverse order
41
 *     D by date            G group dirs first     - prefix to reverse order
42
 *
42
 *
43
 * /S Displays files in specified directory and all subdirectories.
43
 * /S Displays files in specified directory and all subdirectories.
44
 * /B Uses bare format (no heading information or summary)
44
 * /B Uses bare format (no heading information or summary)
45
 * /L Uses lowercases
45
 * /L Uses lowercases
46
 */
46
 */
47
 
47
 
48
/* NOTE: /A attributes are matched in an exclusive way, ie. only files with
48
/* NOTE: /A attributes are matched in an exclusive way, ie. only files with
49
 *       the specified attributes are matched. This is different from how DOS
49
 *       the specified attributes are matched. This is different from how DOS
50
 *       itself matches attributes hence DIR cannot rely on the attributes
50
 *       itself matches attributes hence DIR cannot rely on the attributes
51
 *       filter within FindFirst.
51
 *       filter within FindFirst.
52
 *
52
 *
53
 * NOTE: Multiple /A are not supported - only the last one is significant.
53
 * NOTE: Multiple /A are not supported - only the last one is significant.
54
 */
54
 */
55
 
55
 
56
#define WCOLWIDTH 15  /* width of a column in wide mode output */
56
#define WCOLWIDTH 15  /* width of a column in wide mode output */
57
 
57
 
58
 
58
 
59
/* fills freebytes with free bytes for drv (A=0, B=1, etc)
59
/* fills freebytes with free bytes for drv (A=0, B=1, etc)
60
 * returns DOS ERR code on failure */
60
 * returns DOS ERR code on failure */
61
static unsigned short cmd_dir_df(unsigned long *freebytes, unsigned char drv) {
61
static unsigned short cmd_dir_df(unsigned long *freebytes, unsigned char drv) {
62
  unsigned short res = 0;
62
  unsigned short res = 0;
63
  unsigned short sects_per_clust = 0, avail_clusts = 0, bytes_per_sect = 0;
63
  unsigned short sects_per_clust = 0, avail_clusts = 0, bytes_per_sect = 0;
64
 
64
 
65
  _asm {
65
  _asm {
66
    push ax
66
    push ax
67
    push bx
67
    push bx
68
    push cx
68
    push cx
69
    push dx
69
    push dx
70
 
70
 
71
    mov ah, 0x36  /* DOS 2+ -- Get Disk Free Space */
71
    mov ah, 0x36  /* DOS 2+ -- Get Disk Free Space */
72
    mov dl, [drv] /* A=1, B=2, etc (0 = DEFAULT DRIVE) */
72
    mov dl, [drv] /* A=1, B=2, etc (0 = DEFAULT DRIVE) */
73
    inc dl
73
    inc dl
74
    int 0x21      /* AX=sects_per_clust, BX=avail_clusts, CX=bytes_per_sect, DX=tot_clusters */
74
    int 0x21      /* AX=sects_per_clust, BX=avail_clusts, CX=bytes_per_sect, DX=tot_clusters */
75
    cmp ax, 0xffff /* AX=0xffff on error (invalid drive) */
75
    cmp ax, 0xffff /* AX=0xffff on error (invalid drive) */
76
    jne COMPUTEDF
76
    jne COMPUTEDF
77
    mov [res], 0x0f /* fill res with DOS error code 15 ("invalid drive") */
77
    mov [res], 0x0f /* fill res with DOS error code 15 ("invalid drive") */
78
    jmp DONE
78
    jmp DONE
79
 
79
 
80
    COMPUTEDF:
80
    COMPUTEDF:
81
    /* freebytes = AX * BX * CX */
81
    /* freebytes = AX * BX * CX */
82
    mov [sects_per_clust], ax
82
    mov [sects_per_clust], ax
83
    mov [avail_clusts], bx
83
    mov [avail_clusts], bx
84
    mov [bytes_per_sect], cx
84
    mov [bytes_per_sect], cx
85
 
85
 
86
    DONE:
86
    DONE:
87
    pop dx
87
    pop dx
88
    pop cx
88
    pop cx
89
    pop bx
89
    pop bx
90
    pop ax
90
    pop ax
91
  }
91
  }
92
 
92
 
93
  /* multiple steps to avoid uint16 overflow */
93
  /* multiple steps to avoid uint16 overflow */
94
  *freebytes = sects_per_clust;
94
  *freebytes = sects_per_clust;
95
  *freebytes *= avail_clusts;
95
  *freebytes *= avail_clusts;
96
  *freebytes *= bytes_per_sect;
96
  *freebytes *= bytes_per_sect;
97
 
97
 
98
  return(res);
98
  return(res);
99
}
99
}
100
 
100
 
101
 
101
 
102
static void dir_pagination(unsigned short *availrows) {
102
static void dir_pagination(unsigned short *availrows) {
103
  *availrows -= 1;
103
  *availrows -= 1;
104
  if (*availrows == 0) {
104
  if (*availrows == 0) {
105
    press_any_key();
105
    press_any_key();
106
    *availrows = screen_getheight() - 1;
106
    *availrows = screen_getheight() - 1;
107
  }
107
  }
108
}
108
}
109
 
109
 
110
 
110
 
111
/* parse an attr list like "Ar-hS" and fill bitfield into attrfilter_may and attrfilter_must.
111
/* parse an attr list like "Ar-hS" and fill bitfield into attrfilter_may and attrfilter_must.
112
 * /AHS   -> adds S and H to mandatory attribs ("must")
112
 * /AHS   -> adds S and H to mandatory attribs ("must")
113
 * /A-S   -> removes S from allowed attribs ("may")
113
 * /A-S   -> removes S from allowed attribs ("may")
114
 * returns non-zero on error. */
114
 * returns non-zero on error. */
115
static int dir_parse_attr_list(const char *arg, unsigned char *attrfilter_may, unsigned char *attrfilter_must) {
115
static int dir_parse_attr_list(const char *arg, unsigned char *attrfilter_may, unsigned char *attrfilter_must) {
116
  for (; *arg != 0; arg++) {
116
  for (; *arg != 0; arg++) {
117
    unsigned char curattr;
117
    unsigned char curattr;
118
    char not;
118
    char not;
119
    if (*arg == '-') {
119
    if (*arg == '-') {
120
      not = 1;
120
      not = 1;
121
      arg++;
121
      arg++;
122
    } else {
122
    } else {
123
      not = 0;
123
      not = 0;
124
    }
124
    }
125
    switch (*arg) {
125
    switch (*arg) {
126
      case 'd':
126
      case 'd':
127
      case 'D':
127
      case 'D':
128
        curattr = DOS_ATTR_DIR;
128
        curattr = DOS_ATTR_DIR;
129
        break;
129
        break;
130
      case 'r':
130
      case 'r':
131
      case 'R':
131
      case 'R':
132
        curattr = DOS_ATTR_RO;
132
        curattr = DOS_ATTR_RO;
133
        break;
133
        break;
134
      case 'a':
134
      case 'a':
135
      case 'A':
135
      case 'A':
136
        curattr = DOS_ATTR_ARC;
136
        curattr = DOS_ATTR_ARC;
137
        break;
137
        break;
138
      case 'h':
138
      case 'h':
139
      case 'H':
139
      case 'H':
140
        curattr = DOS_ATTR_HID;
140
        curattr = DOS_ATTR_HID;
141
        break;
141
        break;
142
      case 's':
142
      case 's':
143
      case 'S':
143
      case 'S':
144
        curattr = DOS_ATTR_SYS;
144
        curattr = DOS_ATTR_SYS;
145
        break;
145
        break;
146
      default:
146
      default:
147
        return(-1);
147
        return(-1);
148
    }
148
    }
149
    /* update res bitfield */
149
    /* update res bitfield */
150
    if (not) {
150
    if (not) {
151
      *attrfilter_may &= ~curattr;
151
      *attrfilter_may &= ~curattr;
152
    } else {
152
    } else {
153
      *attrfilter_must |= curattr;
153
      *attrfilter_must |= curattr;
154
    }
154
    }
155
  }
155
  }
156
  return(0);
156
  return(0);
157
}
157
}
158
 
158
 
159
 
159
 
160
#define DIR_ATTR_DEFAULT (DOS_ATTR_RO | DOS_ATTR_DIR | DOS_ATTR_ARC)
160
#define DIR_ATTR_DEFAULT (DOS_ATTR_RO | DOS_ATTR_DIR | DOS_ATTR_ARC)
161
 
161
 
162
static enum cmd_result cmd_dir(struct cmd_funcparam *p) {
162
static enum cmd_result cmd_dir(struct cmd_funcparam *p) {
163
  const char *filespecptr = NULL;
163
  const char *filespecptr = NULL;
164
  struct DTA *dta = (void *)0x80; /* set DTA to its default location at 80h in PSP */
164
  struct DTA *dta = (void *)0x80; /* set DTA to its default location at 80h in PSP */
165
  unsigned short i;
165
  unsigned short i;
166
  unsigned short availrows;  /* counter of available rows on display (used for /P) */
166
  unsigned short availrows;  /* counter of available rows on display (used for /P) */
167
  unsigned short wcols = screen_getwidth() / WCOLWIDTH; /* number of columns in wide mode */
167
  unsigned short wcols = screen_getwidth() / WCOLWIDTH; /* number of columns in wide mode */
168
  unsigned char wcolcount;
168
  unsigned char wcolcount;
169
  struct nls_patterns *nls = (void *)(p->BUFFER + (p->BUFFERSZ / 2));
169
  struct nls_patterns *nls = (void *)(p->BUFFER + (p->BUFFERSZ / 2));
170
  char *buff2 = p->BUFFER + (p->BUFFERSZ / 2) + sizeof(*nls);
170
  char *buff2 = p->BUFFER + (p->BUFFERSZ / 2) + sizeof(*nls);
171
  unsigned long summary_fcount = 0;
171
  unsigned long summary_fcount = 0;
172
  unsigned long summary_totsz = 0;
172
  unsigned long summary_totsz = 0;
173
  unsigned char drv = 0;
173
  unsigned char drv = 0;
174
  unsigned char attrfilter_may = DIR_ATTR_DEFAULT;
174
  unsigned char attrfilter_may = DIR_ATTR_DEFAULT;
175
  unsigned char attrfilter_must = 0;
175
  unsigned char attrfilter_must = 0;
176
 
176
 
177
  #define DIR_FLAG_PAUSE  1
177
  #define DIR_FLAG_PAUSE  1
178
  #define DIR_FLAG_RECUR  4
178
  #define DIR_FLAG_RECUR  4
179
  #define DIR_FLAG_LCASE  8
179
  #define DIR_FLAG_LCASE  8
180
  unsigned char flags = 0;
180
  unsigned char flags = 0;
181
 
181
 
182
  #define DIR_OUTPUT_NORM 1
182
  #define DIR_OUTPUT_NORM 1
183
  #define DIR_OUTPUT_WIDE 2
183
  #define DIR_OUTPUT_WIDE 2
184
  #define DIR_OUTPUT_BARE 3
184
  #define DIR_OUTPUT_BARE 3
185
  unsigned char format = DIR_OUTPUT_NORM;
185
  unsigned char format = DIR_OUTPUT_NORM;
186
 
186
 
187
  if (cmd_ishlp(p)) {
187
  if (cmd_ishlp(p)) {
188
    nls_outputnl(37,0); /* "Displays a list of files and subdirectories in a directory" */
188
    nls_outputnl(37,0); /* "Displays a list of files and subdirectories in a directory" */
189
    outputnl("");
189
    outputnl("");
190
    nls_outputnl(37,1); /* "DIR [drive:][path][filename] [/P] [/W] [/A[:]attributes] [/O[[:]sortorder]] [/S] [/B] [/L]" */
190
    nls_outputnl(37,1); /* "DIR [drive:][path][filename] [/P] [/W] [/A[:]attributes] [/O[[:]sortorder]] [/S] [/B] [/L]" */
191
    outputnl("");
191
    outputnl("");
192
    nls_outputnl(37,2); /* "/P Pauses after each screenful of information" */
192
    nls_outputnl(37,2); /* "/P Pauses after each screenful of information" */
193
    nls_outputnl(37,3); /* "/W Uses wide list format" */
193
    nls_outputnl(37,3); /* "/W Uses wide list format" */
194
    outputnl("");
194
    outputnl("");
195
    nls_outputnl(37,4); /* "/A Displays files with specified attributes:" */
195
    nls_outputnl(37,4); /* "/A Displays files with specified attributes:" */
196
    nls_outputnl(37,5); /* "    D Directories            R Read-only files        H Hidden files" */
196
    nls_outputnl(37,5); /* "    D Directories            R Read-only files        H Hidden files" */
197
    nls_outputnl(37,6); /* "    A Ready for archiving    S System files           - prefix meaning "not"" */
197
    nls_outputnl(37,6); /* "    A Ready for archiving    S System files           - prefix meaning "not"" */
198
    outputnl("");
198
    outputnl("");
199
    nls_outputnl(37,7); /* "/O List files in sorted order:" */
199
    nls_outputnl(37,7); /* "/O List files in sorted order:" */
200
    nls_outputnl(37,8); /* "    N by name                S by size                E by extension" */
200
    nls_outputnl(37,8); /* "    N by name                S by size                E by extension" */
201
    nls_outputnl(37,9); /* "    D by date                G group dirs first       - prefix to reverse order" */
201
    nls_outputnl(37,9); /* "    D by date                G group dirs first       - prefix to reverse order" */
202
    outputnl("");
202
    outputnl("");
203
    nls_outputnl(37,10); /* "/S Displays files in specified directory and all subdirectories" */
203
    nls_outputnl(37,10); /* "/S Displays files in specified directory and all subdirectories" */
204
    nls_outputnl(37,11); /* "/B Uses bare format (no heading information or summary)" */
204
    nls_outputnl(37,11); /* "/B Uses bare format (no heading information or summary)" */
205
    nls_outputnl(37,12); /* "/L Uses lowercases" */
205
    nls_outputnl(37,12); /* "/L Uses lowercases" */
206
    return(CMD_OK);
206
    return(CMD_OK);
207
  }
207
  }
208
 
208
 
209
  i = nls_getpatterns(nls);
209
  i = nls_getpatterns(nls);
210
  if (i != 0) nls_outputnl_doserr(i);
210
  if (i != 0) nls_outputnl_doserr(i);
211
 
211
 
212
  /* parse command line */
212
  /* parse command line */
213
  for (i = 0; i < p->argc; i++) {
213
  for (i = 0; i < p->argc; i++) {
214
    if (p->argv[i][0] == '/') {
214
    if (p->argv[i][0] == '/') {
215
      const char *arg = p->argv[i] + 1;
215
      const char *arg = p->argv[i] + 1;
216
      char neg = 0;
216
      char neg = 0;
217
      /* detect negations and get actual argument */
217
      /* detect negations and get actual argument */
218
      if (*arg == '-') {
218
      if (*arg == '-') {
219
        neg = 1;
219
        neg = 1;
220
        arg++;
220
        arg++;
221
      }
221
      }
222
      /* */
222
      /* */
223
      switch (*arg) {
223
      switch (*arg) {
224
        case 'a':
224
        case 'a':
225
        case 'A':
225
        case 'A':
226
          arg++;
226
          arg++;
227
          /* preset defaults */
227
          /* preset defaults */
228
          attrfilter_may = DIR_ATTR_DEFAULT;
228
          attrfilter_may = DIR_ATTR_DEFAULT;
229
          attrfilter_must = 0;
229
          attrfilter_must = 0;
230
          /* /-A only allowed without further parameters (used to cancel possible previous /Asmth) */
230
          /* /-A only allowed without further parameters (used to cancel possible previous /Asmth) */
231
          if (neg) {
231
          if (neg) {
232
            if (*arg != 0) {
232
            if (*arg != 0) {
233
              nls_outputnl_err(0, 2); /* invalid switch */
233
              nls_outputnl_err(0, 2); /* invalid switch */
234
              return(CMD_FAIL);
234
              return(CMD_FAIL);
235
            }
235
            }
236
          } else {
236
          } else {
-
 
237
            /* skip colon if present */
-
 
238
            if (*arg == ':') arg++;
237
            /* start with "allow everything" */
239
            /* start with "allow everything" */
238
            attrfilter_may = (DOS_ATTR_ARC | DOS_ATTR_DIR | DOS_ATTR_HID | DOS_ATTR_SYS | DOS_ATTR_RO);
240
            attrfilter_may = (DOS_ATTR_ARC | DOS_ATTR_DIR | DOS_ATTR_HID | DOS_ATTR_SYS | DOS_ATTR_RO);
239
            if (dir_parse_attr_list(arg, &attrfilter_may, &attrfilter_must) != 0) {
241
            if (dir_parse_attr_list(arg, &attrfilter_may, &attrfilter_must) != 0) {
240
              nls_outputnl_err(0, 3); /* invalid parameter format */
242
              nls_outputnl_err(0, 3); /* invalid parameter format */
241
              return(CMD_FAIL);
243
              return(CMD_FAIL);
242
            }
244
            }
243
          }
245
          }
244
          break;
246
          break;
245
        case 'b':
247
        case 'b':
246
        case 'B':
248
        case 'B':
247
          format = DIR_OUTPUT_BARE;
249
          format = DIR_OUTPUT_BARE;
248
          break;
250
          break;
249
        case 'l':
251
        case 'l':
250
        case 'L':
252
        case 'L':
251
          flags |= DIR_FLAG_LCASE;
253
          flags |= DIR_FLAG_LCASE;
252
          break;
254
          break;
253
        case 'o':
255
        case 'o':
254
        case 'O':
256
        case 'O':
255
          /* TODO */
257
          /* TODO */
256
          outputnl("/O NOT IMPLEMENTED YET");
258
          outputnl("/O NOT IMPLEMENTED YET");
257
          return(CMD_FAIL);
259
          return(CMD_FAIL);
258
          break;
260
          break;
259
        case 'p':
261
        case 'p':
260
        case 'P':
262
        case 'P':
261
          flags |= DIR_FLAG_PAUSE;
263
          flags |= DIR_FLAG_PAUSE;
262
          if (neg) flags &= (0xff ^ DIR_FLAG_PAUSE);
264
          if (neg) flags &= (0xff ^ DIR_FLAG_PAUSE);
263
          break;
265
          break;
264
        case 's':
266
        case 's':
265
        case 'S':
267
        case 'S':
266
          /* TODO */
268
          /* TODO */
267
          outputnl("/S NOT IMPLEMENTED YET");
269
          outputnl("/S NOT IMPLEMENTED YET");
268
          return(CMD_FAIL);
270
          return(CMD_FAIL);
269
          break;
271
          break;
270
        case 'w':
272
        case 'w':
271
        case 'W':
273
        case 'W':
272
          format = DIR_OUTPUT_WIDE;
274
          format = DIR_OUTPUT_WIDE;
273
          break;
275
          break;
274
        default:
276
        default:
275
          nls_outputnl_err(0, 2); /* invalid switch */
277
          nls_outputnl_err(0, 2); /* invalid switch */
276
          return(CMD_FAIL);
278
          return(CMD_FAIL);
277
      }
279
      }
278
    } else {  /* filespec */
280
    } else {  /* filespec */
279
      if (filespecptr != NULL) {
281
      if (filespecptr != NULL) {
280
        nls_outputnl_err(0, 4); /* too many parameters */
282
        nls_outputnl_err(0, 4); /* too many parameters */
281
        return(CMD_FAIL);
283
        return(CMD_FAIL);
282
      }
284
      }
283
      filespecptr = p->argv[i];
285
      filespecptr = p->argv[i];
284
    }
286
    }
285
  }
287
  }
286
 
288
 
287
  if (filespecptr == NULL) filespecptr = ".";
289
  if (filespecptr == NULL) filespecptr = ".";
288
 
290
 
289
  availrows = screen_getheight() - 2;
291
  availrows = screen_getheight() - 2;
290
 
292
 
291
  /* special case: "DIR drive:" (truename() fails on "C:" under MS-DOS 6.0) */
293
  /* special case: "DIR drive:" (truename() fails on "C:" under MS-DOS 6.0) */
292
  if ((filespecptr[0] != 0) && (filespecptr[1] == ':') && (filespecptr[2] == 0)) {
294
  if ((filespecptr[0] != 0) && (filespecptr[1] == ':') && (filespecptr[2] == 0)) {
293
    if ((filespecptr[0] >= 'a') && (filespecptr[0] <= 'z')) {
295
    if ((filespecptr[0] >= 'a') && (filespecptr[0] <= 'z')) {
294
      p->BUFFER[0] = filespecptr[0] - ('a' - 1);
296
      p->BUFFER[0] = filespecptr[0] - ('a' - 1);
295
    } else {
297
    } else {
296
      p->BUFFER[0] = filespecptr[0] - ('A' - 1);
298
      p->BUFFER[0] = filespecptr[0] - ('A' - 1);
297
    }
299
    }
298
    i = curpathfordrv(p->BUFFER, p->BUFFER[0]);
300
    i = curpathfordrv(p->BUFFER, p->BUFFER[0]);
299
  } else {
301
  } else {
300
    i = file_truename(filespecptr, p->BUFFER);
302
    i = file_truename(filespecptr, p->BUFFER);
301
  }
303
  }
302
  if (i != 0) {
304
  if (i != 0) {
303
    nls_outputnl_doserr(i);
305
    nls_outputnl_doserr(i);
304
    return(CMD_FAIL);
306
    return(CMD_FAIL);
305
  }
307
  }
306
 
308
 
307
  if (format != DIR_OUTPUT_BARE) {
309
  if (format != DIR_OUTPUT_BARE) {
308
    drv = p->BUFFER[0];
310
    drv = p->BUFFER[0];
309
    if (drv >= 'a') {
311
    if (drv >= 'a') {
310
      drv -= 'a';
312
      drv -= 'a';
311
    } else {
313
    } else {
312
      drv -= 'A';
314
      drv -= 'A';
313
    }
315
    }
314
    cmd_vol_internal(drv, buff2);
316
    cmd_vol_internal(drv, buff2);
315
    sprintf(buff2, svarlang_str(37,20)/*"Directory of %s"*/, p->BUFFER);
317
    sprintf(buff2, svarlang_str(37,20)/*"Directory of %s"*/, p->BUFFER);
316
    /* trim at first '?', if any */
318
    /* trim at first '?', if any */
317
    for (i = 0; buff2[i] != 0; i++) if (buff2[i] == '?') buff2[i] = 0;
319
    for (i = 0; buff2[i] != 0; i++) if (buff2[i] == '?') buff2[i] = 0;
318
    outputnl(buff2);
320
    outputnl(buff2);
319
    outputnl("");
321
    outputnl("");
320
    availrows -= 3;
322
    availrows -= 3;
321
  }
323
  }
322
 
324
 
323
  /* if dir: append a backslash (also get its len) */
325
  /* if dir: append a backslash (also get its len) */
324
  i = path_appendbkslash_if_dir(p->BUFFER);
326
  i = path_appendbkslash_if_dir(p->BUFFER);
325
 
327
 
326
  /* if ends with a \ then append ????????.??? */
328
  /* if ends with a \ then append ????????.??? */
327
  if (p->BUFFER[i - 1] == '\\') strcat(p->BUFFER, "????????.???");
329
  if (p->BUFFER[i - 1] == '\\') strcat(p->BUFFER, "????????.???");
328
 
330
 
329
  /* ask DOS for list of files, but only with allowed attribs */
331
  /* ask DOS for list of files, but only with allowed attribs */
330
  i = findfirst(dta, p->BUFFER, attrfilter_may);
332
  i = findfirst(dta, p->BUFFER, attrfilter_may);
331
  if (i != 0) {
333
  if (i != 0) {
332
    nls_outputnl_doserr(i);
334
    nls_outputnl_doserr(i);
333
    return(CMD_FAIL);
335
    return(CMD_FAIL);
334
  }
336
  }
335
 
337
 
336
  wcolcount = 0; /* may be used for columns counting with wide mode */
338
  wcolcount = 0; /* may be used for columns counting with wide mode */
337
 
339
 
338
  do {
340
  do {
339
    /* if mandatory attribs are requested, filter them now */
341
    /* if mandatory attribs are requested, filter them now */
340
    if ((attrfilter_must & dta->attr) != attrfilter_must) continue;
342
    if ((attrfilter_must & dta->attr) != attrfilter_must) continue;
341
 
343
 
342
    /* if file contains attributes that are not allowed -> skip */
344
    /* if file contains attributes that are not allowed -> skip */
343
    if ((~attrfilter_may & dta->attr) != 0) continue;
345
    if ((~attrfilter_may & dta->attr) != 0) continue;
344
 
346
 
345
    /* turn string lcase (/L) */
347
    /* turn string lcase (/L) */
346
    if (flags & DIR_FLAG_LCASE) _strlwr(dta->fname); /* OpenWatcom extension, probably does not care about NLS so results may be odd with non-A-Z characters... */
348
    if (flags & DIR_FLAG_LCASE) _strlwr(dta->fname); /* OpenWatcom extension, probably does not care about NLS so results may be odd with non-A-Z characters... */
347
 
349
 
348
    summary_fcount++;
350
    summary_fcount++;
349
    if ((dta->attr & DOS_ATTR_DIR) == 0) summary_totsz += dta->size;
351
    if ((dta->attr & DOS_ATTR_DIR) == 0) summary_totsz += dta->size;
350
 
352
 
351
    switch (format) {
353
    switch (format) {
352
      case DIR_OUTPUT_NORM:
354
      case DIR_OUTPUT_NORM:
353
        /* print fname-space-extension (unless it's "." or "..", then print as-is) */
355
        /* print fname-space-extension (unless it's "." or "..", then print as-is) */
354
        if (dta->fname[0] == '.') {
356
        if (dta->fname[0] == '.') {
355
          output(dta->fname);
357
          output(dta->fname);
356
          i = strlen(dta->fname);
358
          i = strlen(dta->fname);
357
          while (i++ < 12) output(" ");
359
          while (i++ < 12) output(" ");
358
        } else {
360
        } else {
359
          file_fname2fcb(buff2, dta->fname);
361
          file_fname2fcb(buff2, dta->fname);
360
          memmove(buff2 + 9, buff2 + 8, 4);
362
          memmove(buff2 + 9, buff2 + 8, 4);
361
          buff2[8] = ' ';
363
          buff2[8] = ' ';
362
          output(buff2);
364
          output(buff2);
363
        }
365
        }
364
        output(" ");
366
        output(" ");
365
        /* either <DIR> or right aligned 10-chars byte size */
367
        /* either <DIR> or right aligned 10-chars byte size */
366
        memset(buff2, ' ', 10);
368
        memset(buff2, ' ', 10);
367
        if (dta->attr & DOS_ATTR_DIR) {
369
        if (dta->attr & DOS_ATTR_DIR) {
368
          strcpy(buff2 + 10, svarlang_str(37,21));
370
          strcpy(buff2 + 10, svarlang_str(37,21));
369
        } else {
371
        } else {
370
          _ultoa(dta->size, buff2 + 10, 10); /* OpenWatcom extension */
372
          _ultoa(dta->size, buff2 + 10, 10); /* OpenWatcom extension */
371
        }
373
        }
372
        output(buff2 + strlen(buff2) - 10);
374
        output(buff2 + strlen(buff2) - 10);
373
        /* two spaces and NLS DATE */
375
        /* two spaces and NLS DATE */
374
        buff2[0] = ' ';
376
        buff2[0] = ' ';
375
        buff2[1] = ' ';
377
        buff2[1] = ' ';
376
        nls_format_date(buff2 + 2, dta->date_yr + 1980, dta->date_mo, dta->date_dy, nls);
378
        nls_format_date(buff2 + 2, dta->date_yr + 1980, dta->date_mo, dta->date_dy, nls);
377
        output(buff2);
379
        output(buff2);
378
 
380
 
379
        /* one space and NLS TIME */
381
        /* one space and NLS TIME */
380
        nls_format_time(buff2 + 1, dta->time_hour, dta->time_min, 0xff, nls);
382
        nls_format_time(buff2 + 1, dta->time_hour, dta->time_min, 0xff, nls);
381
        outputnl(buff2);
383
        outputnl(buff2);
382
        break;
384
        break;
383
 
385
 
384
      case DIR_OUTPUT_WIDE: /* display in columns of 12 chars per item */
386
      case DIR_OUTPUT_WIDE: /* display in columns of 12 chars per item */
385
        i = strlen(dta->fname);
387
        i = strlen(dta->fname);
386
        if (dta->attr & DOS_ATTR_DIR) {
388
        if (dta->attr & DOS_ATTR_DIR) {
387
          i += 2;
389
          i += 2;
388
          output("[");
390
          output("[");
389
          output(dta->fname);
391
          output(dta->fname);
390
          output("]");
392
          output("]");
391
        } else {
393
        } else {
392
          output(dta->fname);
394
          output(dta->fname);
393
        }
395
        }
394
        while (i++ < WCOLWIDTH) output(" ");
396
        while (i++ < WCOLWIDTH) output(" ");
395
        if (++wcolcount == wcols) {
397
        if (++wcolcount == wcols) {
396
          wcolcount = 0;
398
          wcolcount = 0;
397
          outputnl("");
399
          outputnl("");
398
        } else {
400
        } else {
399
          availrows++; /* wide mode is the only one that does not write one line per file */
401
          availrows++; /* wide mode is the only one that does not write one line per file */
400
        }
402
        }
401
        break;
403
        break;
402
 
404
 
403
      case DIR_OUTPUT_BARE:
405
      case DIR_OUTPUT_BARE:
404
        outputnl(dta->fname);
406
        outputnl(dta->fname);
405
        break;
407
        break;
406
    }
408
    }
407
 
409
 
408
    if (flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
410
    if (flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
409
 
411
 
410
  } while (findnext(dta) == 0);
412
  } while (findnext(dta) == 0);
411
 
413
 
412
  if (wcolcount != 0) {
414
  if (wcolcount != 0) {
413
    outputnl(""); /* in wide mode make sure to end on a clear row */
415
    outputnl(""); /* in wide mode make sure to end on a clear row */
414
    if (flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
416
    if (flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
415
  }
417
  }
416
 
418
 
417
  /* print out summary (unless bare output mode) */
419
  /* print out summary (unless bare output mode) */
418
  if (format != DIR_OUTPUT_BARE) {
420
  if (format != DIR_OUTPUT_BARE) {
419
    unsigned short alignpos;
421
    unsigned short alignpos;
420
    /* x file(s) */
422
    /* x file(s) */
421
    memset(buff2, ' ', 13); /* 13 is the max len of a 32 bit number with thousand separators (4'000'000'000) */
423
    memset(buff2, ' ', 13); /* 13 is the max len of a 32 bit number with thousand separators (4'000'000'000) */
422
    i = nls_format_number(buff2 + 13, summary_fcount, nls);
424
    i = nls_format_number(buff2 + 13, summary_fcount, nls);
423
    alignpos = sprintf(buff2 + 13 + i, " %s ", svarlang_str(37,22)/*"file(s)"*/);
425
    alignpos = sprintf(buff2 + 13 + i, " %s ", svarlang_str(37,22)/*"file(s)"*/);
424
    output(buff2 + i);
426
    output(buff2 + i);
425
    /* xxxx bytes */
427
    /* xxxx bytes */
426
    i = nls_format_number(buff2 + 13, summary_totsz, nls);
428
    i = nls_format_number(buff2 + 13, summary_totsz, nls);
427
    output(buff2 + i);
429
    output(buff2 + i);
428
    output(" ");
430
    output(" ");
429
    nls_outputnl(37,23); /* "bytes" */
431
    nls_outputnl(37,23); /* "bytes" */
430
    if (flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
432
    if (flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
431
    /* xxxx bytes free */
433
    /* xxxx bytes free */
432
    i = cmd_dir_df(&summary_totsz, drv);
434
    i = cmd_dir_df(&summary_totsz, drv);
433
    if (i != 0) nls_outputnl_doserr(i);
435
    if (i != 0) nls_outputnl_doserr(i);
434
    alignpos += 13 + 13;
436
    alignpos += 13 + 13;
435
    memset(buff2, ' ', alignpos); /* align the freebytes value to same column as totbytes */
437
    memset(buff2, ' ', alignpos); /* align the freebytes value to same column as totbytes */
436
    i = nls_format_number(buff2 + alignpos, summary_totsz, nls);
438
    i = nls_format_number(buff2 + alignpos, summary_totsz, nls);
437
    output(buff2 + i);
439
    output(buff2 + i);
438
    output(" ");
440
    output(" ");
439
    nls_outputnl(37,24); /* "bytes free" */
441
    nls_outputnl(37,24); /* "bytes free" */
440
    if (flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
442
    if (flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
441
  }
443
  }
442
 
444
 
443
  return(CMD_OK);
445
  return(CMD_OK);
444
}
446
}
445
 
447