Subversion Repositories SvarDOS

Rev

Rev 538 | Rev 990 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 538 Rev 542
Line 106... Line 106...
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.
-
 
112
 * /AHS   -> adds S and H to mandatory attribs ("must")
-
 
113
 * /A-S   -> removes S from allowed attribs ("may")
-
 
114
 * returns non-zero on error. */
-
 
115
static int dir_parse_attr_list(const char *arg, unsigned char *attrfilter_may, unsigned char *attrfilter_must) {
-
 
116
  for (; *arg != 0; arg++) {
-
 
117
    unsigned char curattr;
-
 
118
    char not;
-
 
119
    if (*arg == '-') {
-
 
120
      not = 1;
-
 
121
      arg++;
-
 
122
    } else {
-
 
123
      not = 0;
-
 
124
    }
-
 
125
    switch (*arg) {
-
 
126
      case 'd':
-
 
127
      case 'D':
-
 
128
        curattr = DOS_ATTR_DIR;
-
 
129
        break;
-
 
130
      case 'r':
-
 
131
      case 'R':
-
 
132
        curattr = DOS_ATTR_RO;
-
 
133
        break;
-
 
134
      case 'a':
-
 
135
      case 'A':
-
 
136
        curattr = DOS_ATTR_ARC;
-
 
137
        break;
-
 
138
      case 'h':
-
 
139
      case 'H':
-
 
140
        curattr = DOS_ATTR_HID;
-
 
141
        break;
-
 
142
      case 's':
-
 
143
      case 'S':
-
 
144
        curattr = DOS_ATTR_SYS;
-
 
145
        break;
-
 
146
      default:
-
 
147
        return(-1);
-
 
148
    }
-
 
149
    /* update res bitfield */
-
 
150
    if (not) {
-
 
151
      *attrfilter_may &= ~curattr;
-
 
152
    } else {
-
 
153
      *attrfilter_must |= curattr;
-
 
154
    }
-
 
155
  }
-
 
156
  return(0);
-
 
157
}
-
 
158
 
-
 
159
 
-
 
160
#define DIR_ATTR_DEFAULT (DOS_ATTR_RO | DOS_ATTR_DIR | DOS_ATTR_ARC)
-
 
161
 
111
static enum cmd_result cmd_dir(struct cmd_funcparam *p) {
162
static enum cmd_result cmd_dir(struct cmd_funcparam *p) {
112
  const char *filespecptr = NULL;
163
  const char *filespecptr = NULL;
113
  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 */
114
  unsigned short i;
165
  unsigned short i;
115
  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) */
Line 118... Line 169...
118
  struct nls_patterns *nls = (void *)(p->BUFFER + (p->BUFFERSZ / 2));
169
  struct nls_patterns *nls = (void *)(p->BUFFER + (p->BUFFERSZ / 2));
119
  char *buff2 = p->BUFFER + (p->BUFFERSZ / 2) + sizeof(*nls);
170
  char *buff2 = p->BUFFER + (p->BUFFERSZ / 2) + sizeof(*nls);
120
  unsigned long summary_fcount = 0;
171
  unsigned long summary_fcount = 0;
121
  unsigned long summary_totsz = 0;
172
  unsigned long summary_totsz = 0;
122
  unsigned char drv = 0;
173
  unsigned char drv = 0;
-
 
174
  unsigned char attrfilter_may = DIR_ATTR_DEFAULT;
-
 
175
  unsigned char attrfilter_must = 0;
123
 
176
 
124
  #define DIR_FLAG_PAUSE  1
177
  #define DIR_FLAG_PAUSE  1
125
  #define DIR_FLAG_RECUR  4
178
  #define DIR_FLAG_RECUR  4
126
  #define DIR_FLAG_LCASE  8
179
  #define DIR_FLAG_LCASE  8
127
  unsigned char flags = 0;
180
  unsigned char flags = 0;
Line 157... Line 210...
157
  if (i != 0) nls_outputnl_doserr(i);
210
  if (i != 0) nls_outputnl_doserr(i);
158
 
211
 
159
  /* parse command line */
212
  /* parse command line */
160
  for (i = 0; i < p->argc; i++) {
213
  for (i = 0; i < p->argc; i++) {
161
    if (p->argv[i][0] == '/') {
214
    if (p->argv[i][0] == '/') {
162
      char arg;
215
      const char *arg = p->argv[i] + 1;
163
      char neg = 0;
216
      char neg = 0;
164
      /* detect negations and get actual argument */
217
      /* detect negations and get actual argument */
165
      if (p->argv[i][1] == '-') neg = 1;
218
      if (*arg == '-') {
-
 
219
        neg = 1;
166
      arg = p->argv[i][1 + neg];
220
        arg++;
-
 
221
      }
167
      /* */
222
      /* */
168
      switch (arg) {
223
      switch (*arg) {
169
        case 'a':
224
        case 'a':
170
        case 'A':
225
        case 'A':
-
 
226
          arg++;
-
 
227
          /* preset defaults */
-
 
228
          attrfilter_may = DIR_ATTR_DEFAULT;
-
 
229
          attrfilter_must = 0;
-
 
230
          /* /-A only allowed without further parameters (used to cancel possible previous /Asmth) */
-
 
231
          if (neg) {
-
 
232
            if (*arg != 0) {
-
 
233
              nls_outputnl_err(0, 2); /* invalid switch */
-
 
234
              return(CMD_FAIL);
-
 
235
            }
171
          /* TODO */
236
          } else {
172
          outputnl("/A NOT IMPLEMENTED YET");
237
            /* start with "allow everything" */
-
 
238
            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) {
-
 
240
              nls_outputnl_err(0, 3); /* invalid parameter format */
173
          return(CMD_FAIL);
241
              return(CMD_FAIL);
-
 
242
            }
-
 
243
          }
174
          break;
244
          break;
175
        case 'b':
245
        case 'b':
176
        case 'B':
246
        case 'B':
177
          format = DIR_OUTPUT_BARE;
247
          format = DIR_OUTPUT_BARE;
178
          break;
248
          break;
Line 200... Line 270...
200
        case 'w':
270
        case 'w':
201
        case 'W':
271
        case 'W':
202
          format = DIR_OUTPUT_WIDE;
272
          format = DIR_OUTPUT_WIDE;
203
          break;
273
          break;
204
        default:
274
        default:
205
          outputnl("Invalid switch");
275
          nls_outputnl_err(0, 2); /* invalid switch */
206
          return(CMD_FAIL);
276
          return(CMD_FAIL);
207
      }
277
      }
208
    } else {  /* filespec */
278
    } else {  /* filespec */
209
      if (filespecptr != NULL) {
279
      if (filespecptr != NULL) {
210
        outputnl("Too many parameters");
280
        nls_outputnl_err(0, 4); /* too many parameters */
211
        return(CMD_FAIL);
281
        return(CMD_FAIL);
212
      }
282
      }
213
      filespecptr = p->argv[i];
283
      filespecptr = p->argv[i];
214
    }
284
    }
215
  }
285
  }
Line 254... Line 324...
254
  i = path_appendbkslash_if_dir(p->BUFFER);
324
  i = path_appendbkslash_if_dir(p->BUFFER);
255
 
325
 
256
  /* if ends with a \ then append ????????.??? */
326
  /* if ends with a \ then append ????????.??? */
257
  if (p->BUFFER[i - 1] == '\\') strcat(p->BUFFER, "????????.???");
327
  if (p->BUFFER[i - 1] == '\\') strcat(p->BUFFER, "????????.???");
258
 
328
 
-
 
329
  /* ask DOS for list of files, but only with allowed attribs */
259
  i = findfirst(dta, p->BUFFER, DOS_ATTR_RO | DOS_ATTR_HID | DOS_ATTR_SYS | DOS_ATTR_DIR | DOS_ATTR_ARC);
330
  i = findfirst(dta, p->BUFFER, attrfilter_may);
260
  if (i != 0) {
331
  if (i != 0) {
261
    nls_outputnl_doserr(i);
332
    nls_outputnl_doserr(i);
262
    return(CMD_FAIL);
333
    return(CMD_FAIL);
263
  }
334
  }
264
 
335
 
265
  wcolcount = 0; /* may be used for columns counting with wide mode */
336
  wcolcount = 0; /* may be used for columns counting with wide mode */
266
 
337
 
267
  do {
338
  do {
-
 
339
    /* if mandatory attribs are requested, filter them now */
-
 
340
    if ((attrfilter_must & dta->attr) != attrfilter_must) continue;
-
 
341
 
-
 
342
    /* if file contains attributes that are not allowed -> skip */
-
 
343
    if ((~attrfilter_may & dta->attr) != 0) continue;
-
 
344
 
-
 
345
    /* turn string lcase (/L) */
268
    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... */
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... */
269
 
347
 
270
    summary_fcount++;
348
    summary_fcount++;
271
    if ((dta->attr & DOS_ATTR_DIR) == 0) summary_totsz += dta->size;
349
    if ((dta->attr & DOS_ATTR_DIR) == 0) summary_totsz += dta->size;
272
 
350