Subversion Repositories SvarDOS

Rev

Rev 2204 | Rev 2206 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
421 mateuszvis 1
/* This file is part of the SvarCOM project and is published under the terms
2
 * of the MIT license.
3
 *
1716 mateusz.vi 4
 * Copyright (C) 2021-2024 Mateusz Viste
421 mateuszvis 5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
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
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
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,
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
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
22
 * DEALINGS IN THE SOFTWARE.
23
 */
24
 
368 mateuszvis 25
/*
26
 * dir
27
 *
28
 * Displays a list of files and subdirectories in a directory.
29
 *
30
 * DIR [drive:][path][filename] [/P] [/W] [/A[:]attributes] [/O[[:]sortorder]] [/S] [/B] [/L]
31
 *
32
 * /P Pauses after each screenful of information.
33
 * /W Uses wide list format.
34
 *
35
 * /A Displays file with specified attributes:
36
 *     D Directories           R Read-only files     H Hidden files
37
 *     A Ready for archiving   S System files        - prefix meaning "not"
38
 *
39
 * /O List files in sorted order:
40
 *     N by name            S by size              E by extension
41
 *     D by date            G group dirs first     - prefix to reverse order
42
 *
43
 * /S Displays files in specified directory and all subdirectories.
44
 * /B Uses bare format (no heading information or summary)
45
 * /L Uses lowercases
2189 mateusz.vi 46
 *
47
 * about /S - recursive DIR on specified (or current) path and subdirectories:
48
 * prerequisite: some sort of mechanism that works as a stack pile of DTAs
49
 *
50
 * /S logic:
51
 * 1. do a FindFirst on current directory
52
 * 2. do FindNext calls in a loop, if a DIR entry is encountered, remember its
53
 *    name and put a copy of the current DTA on stack, then continue the
54
 *    listing without further interruption
55
 * 3. if a new DIR was discovered, do a FindFirst on it and jmp to 2.
56
 *    if no DIR found, then go to 4.
57
 * 4. look on the stack for a DTA.
58
 *    if any found, pop it and jmp to 2.
59
 *    otherwise job is done, exit.
368 mateuszvis 60
 */
61
 
396 mateuszvis 62
/* NOTE: /A attributes are matched in an exclusive way, ie. only files with
63
 *       the specified attributes are matched. This is different from how DOS
64
 *       itself matches attributes hence DIR cannot rely on the attributes
65
 *       filter within FindFirst.
66
 *
67
 * NOTE: Multiple /A are not supported - only the last one is significant.
68
 */
69
 
420 mateuszvis 70
 
1991 mateusz.vi 71
/* width of a column in wide mode output: 15 chars is the MINIMUM because
72
 * directories are enclosed in [BRACKETS] and they may have an extension, too.
73
 * Hence "[12345678.123]" is the longest we can get. Plus a delimiter space. */
74
#define WCOLWIDTH 15
424 mateuszvis 75
 
1991 mateusz.vi 76
 
1716 mateusz.vi 77
/* a "tiny" DTA is a DTA that is stripped from bytes that are not needed for
78
 * DIR operations */
79
_Packed struct TINYDTA {
80
/*  char reserved[21];
81
  unsigned char attr; */
82
  unsigned short time_sec2:5;
83
  unsigned short time_min:6;
84
  unsigned short time_hour:5;
85
  unsigned short date_dy:5;
86
  unsigned short date_mo:4;
87
  unsigned short date_yr:7;
88
  unsigned long size;
89
/*  char fname[13]; */
90
  char fname[12];
91
};
92
 
93
 
424 mateuszvis 94
/* fills freebytes with free bytes for drv (A=0, B=1, etc)
95
 * returns DOS ERR code on failure */
96
static unsigned short cmd_dir_df(unsigned long *freebytes, unsigned char drv) {
97
  unsigned short res = 0;
98
  unsigned short sects_per_clust = 0, avail_clusts = 0, bytes_per_sect = 0;
99
 
100
  _asm {
101
    push ax
102
    push bx
103
    push cx
104
    push dx
105
 
106
    mov ah, 0x36  /* DOS 2+ -- Get Disk Free Space */
107
    mov dl, [drv] /* A=1, B=2, etc (0 = DEFAULT DRIVE) */
108
    inc dl
109
    int 0x21      /* AX=sects_per_clust, BX=avail_clusts, CX=bytes_per_sect, DX=tot_clusters */
110
    cmp ax, 0xffff /* AX=0xffff on error (invalid drive) */
111
    jne COMPUTEDF
112
    mov [res], 0x0f /* fill res with DOS error code 15 ("invalid drive") */
113
    jmp DONE
114
 
115
    COMPUTEDF:
116
    /* freebytes = AX * BX * CX */
117
    mov [sects_per_clust], ax
118
    mov [avail_clusts], bx
119
    mov [bytes_per_sect], cx
120
 
121
    DONE:
122
    pop dx
123
    pop cx
124
    pop bx
125
    pop ax
126
  }
127
 
128
  /* multiple steps to avoid uint16 overflow */
129
  *freebytes = sects_per_clust;
130
  *freebytes *= avail_clusts;
131
  *freebytes *= bytes_per_sect;
132
 
133
  return(res);
134
}
135
 
136
 
528 mateuszvis 137
static void dir_pagination(unsigned short *availrows) {
138
  *availrows -= 1;
139
  if (*availrows == 0) {
140
    press_any_key();
141
    *availrows = screen_getheight() - 1;
142
  }
143
}
144
 
145
 
2204 mateusz.vi 146
/* print the "Directory of C:\ABC\.... string using a buffer with possible
147
 * file pattern garbage trailing */
148
static void dir_print_dirof(const char *p, unsigned short *availrows, unsigned char pagination) {
149
  unsigned char t, lastbkslash;
150
  char buff[2] = {0, 0};
151
  const char *dirof = svarlang_str(37,20); /* Directory of % */
152
 
2205 mateusz.vi 153
  outputnl("");
154
  if (pagination) dir_pagination(availrows);
155
 
2204 mateusz.vi 156
  /* print string until % */
157
  while ((*dirof != 0) && (*dirof != '%')) {
158
    *buff = *dirof;
159
    output(buff);
160
    dirof++;
161
  }
162
 
163
  if (*dirof != '%') return;
164
  dirof++;
165
 
166
  /* find the last backslash of path */
167
  lastbkslash = 0;
168
  for (t = 0; p[t] != 0; t++) {
169
    if (p[t] == '\\') lastbkslash = t;
170
  }
171
  if (lastbkslash == 0) return;
172
 
173
  /* print path until last bkslash */
174
  do {
175
    *buff = *p;
176
    output(buff);
177
    p++;
178
  } while (lastbkslash-- != 0);
179
 
180
  /* print the rest of the dirof string */
181
  while (*dirof != 0) {
182
    *buff = *dirof;
183
    output(buff);
184
    dirof++;
185
  }
186
 
187
  outputnl("");
188
  if (pagination) dir_pagination(availrows);
189
  outputnl("");
190
  if (pagination) dir_pagination(availrows);
191
}
192
 
193
 
2193 mateusz.vi 194
/* add a new dirname to path, C:\XXX\*.EXE + YYY -> C:\XXX\YYY\*.EXE */
195
static void path_add(char *path, const char *dirname) {
2196 mateusz.vi 196
  short i, ostatni = -1;
2198 mateusz.vi 197
  //printf("path_add(%s,%s) -> ", path, dirname);
2193 mateusz.vi 198
  /* find the last backslash */
199
  for (i = 0; path[i] != 0; i++) {
200
    if (path[i] == '\\') ostatni = i;
201
  }
202
  /* abort on error */
203
  if (ostatni == -1) return;
204
  /* do the trick */
2196 mateusz.vi 205
  /* move ending to the right */
206
  memcpy_rtl(path + ostatni + strlen(dirname) + 1, path + ostatni, strlen(path + ostatni) + 1);
207
  /* fill in the space with dirname */
208
  memcpy_ltr(path + ostatni + 1, dirname, strlen(dirname));
2198 mateusz.vi 209
  //printf("'%s'\n", path);
2193 mateusz.vi 210
}
211
 
212
 
213
/* take back last dir from path, C:\XXX\YYY\*.EXE -> C:\XXX\*.EXE */
214
static void path_back(char *path) {
215
  short i, ostatni = -1, przedostatni = -1;
2198 mateusz.vi 216
  //printf("path_back(%s) -> ", path);
2193 mateusz.vi 217
  /* find the two last backslashes */
218
  for (i = 0; path[i] != 0; i++) {
219
    if (path[i] == '\\') {
220
      przedostatni = ostatni;
221
      ostatni = i;
222
    }
223
  }
224
  /* abort on error */
225
  if (przedostatni == -1) return;
226
  /* do the trick */
2196 mateusz.vi 227
  memcpy_ltr(path + przedostatni, path + ostatni, 1 + i - ostatni);
2198 mateusz.vi 228
  //printf("'%s'\n", path);
2193 mateusz.vi 229
}
230
 
231
 
542 mateuszvis 232
/* parse an attr list like "Ar-hS" and fill bitfield into attrfilter_may and attrfilter_must.
233
 * /AHS   -> adds S and H to mandatory attribs ("must")
234
 * /A-S   -> removes S from allowed attribs ("may")
235
 * returns non-zero on error. */
236
static int dir_parse_attr_list(const char *arg, unsigned char *attrfilter_may, unsigned char *attrfilter_must) {
237
  for (; *arg != 0; arg++) {
238
    unsigned char curattr;
239
    char not;
240
    if (*arg == '-') {
241
      not = 1;
242
      arg++;
243
    } else {
244
      not = 0;
245
    }
246
    switch (*arg) {
247
      case 'd':
248
      case 'D':
249
        curattr = DOS_ATTR_DIR;
250
        break;
251
      case 'r':
252
      case 'R':
253
        curattr = DOS_ATTR_RO;
254
        break;
255
      case 'a':
256
      case 'A':
257
        curattr = DOS_ATTR_ARC;
258
        break;
259
      case 'h':
260
      case 'H':
261
        curattr = DOS_ATTR_HID;
262
        break;
263
      case 's':
264
      case 'S':
265
        curattr = DOS_ATTR_SYS;
266
        break;
267
      default:
268
        return(-1);
269
    }
270
    /* update res bitfield */
271
    if (not) {
272
      *attrfilter_may &= ~curattr;
273
    } else {
274
      *attrfilter_must |= curattr;
275
    }
276
  }
277
  return(0);
278
}
279
 
280
 
1716 mateusz.vi 281
/* compare attributes in a DTA node to mandatory and optional attributes. returns 1 on match, 0 otherwise */
282
static int filter_attribs(const struct DTA *dta, unsigned char attrfilter_must, unsigned char attrfilter_may) {
283
  /* if mandatory attribs are requested, filter them now */
284
  if ((attrfilter_must & dta->attr) != attrfilter_must) return(0);
285
 
286
  /* if file contains attributes that are not allowed -> skip */
287
  if ((~attrfilter_may & dta->attr) != 0) return(0);
288
 
289
  return(1);
290
}
291
 
292
 
1719 mateusz.vi 293
static struct {
294
  struct TINYDTA far *dtabuf_root;
295
  char order[8]; /* GNESD values (ucase = lower first ; lcase = higher first) */
1739 mateusz.vi 296
  unsigned char sortownia[256]; /* collation table (used for NLS-aware sorts) */
1719 mateusz.vi 297
} glob_sortcmp_dat;
1716 mateusz.vi 298
 
1719 mateusz.vi 299
 
300
/* translates an order string like "GNE-S" into values fed into the order[]
301
 * table of glob_sortcmp_dat. returns 0 on success, non-zero otherwise. */
1724 mateusz.vi 302
static int dir_process_order_directive(const char *ordstring) {
1719 mateusz.vi 303
  const char *gnesd = "gnesd"; /* must be lower case */
304
  int ordi, orderi = 0, i;
305
 
306
  /* tabula rasa */
307
  glob_sortcmp_dat.order[0] = 0;
308
 
1721 mateusz.vi 309
  /* /O alone is a short hand for /OGN */
310
  if (*ordstring == 0) {
311
    glob_sortcmp_dat.order[0] = 'G';
312
    glob_sortcmp_dat.order[1] = 'N';
313
    glob_sortcmp_dat.order[2] = 0;
314
  }
315
 
1726 mateusz.vi 316
  /* stupid MSDOS compatibility ("DIR /O:GNE") */
317
  if (*ordstring == ':') ordstring++;
318
 
1719 mateusz.vi 319
  /* parsing */
320
  for (ordi = 0; ordstring[ordi] != 0; ordi++) {
321
    if (ordstring[ordi] == '-') {
322
      if ((ordstring[ordi + 1] == '-') || (ordstring[ordi + 1] == 0)) return(-1);
323
      continue;
324
    }
325
    if (orderi == sizeof(glob_sortcmp_dat.order)) return(-1);
326
 
327
    for (i = 0; gnesd[i] != 0; i++) {
328
      if ((ordstring[ordi] | 32) == gnesd[i]) { /* | 32 is lcase-ing the char */
329
        if ((ordi > 0) && (ordstring[ordi - 1] == '-')) {
330
          glob_sortcmp_dat.order[orderi] = gnesd[i];
331
        } else {
332
          glob_sortcmp_dat.order[orderi] = gnesd[i] ^ 32;
333
        }
334
        orderi++;
335
        break;
336
      }
337
    }
338
    if (gnesd[i] == 0) return(-1);
339
  }
340
 
341
  return(0);
342
}
343
 
344
 
345
static int sortcmp(const void *dtaid1, const void *dtaid2) {
346
  struct TINYDTA far *dta1 = &(glob_sortcmp_dat.dtabuf_root[*((unsigned short *)dtaid1)]);
347
  struct TINYDTA far *dta2 = &(glob_sortcmp_dat.dtabuf_root[*((unsigned short *)dtaid2)]);
348
  char *ordconf = glob_sortcmp_dat.order;
349
 
350
  /* debug stuff
351
  {
352
    int i;
353
    printf("%lu vs %lu | ", dta1->size, dta2->size);
354
    for (i = 0; dta1->fname[i] != 0; i++) printf("%c", dta1->fname[i]);
355
    printf(" vs ");
356
    for (i = 0; dta2->fname[i] != 0; i++) printf("%c", dta2->fname[i]);
357
    printf("\n");
358
  } */
359
 
360
  for (;;) {
361
    int r = -1;
362
    if (*ordconf & 32) r = 1;
363
 
364
    switch (*ordconf | 32) {
365
      case 'g': /* sort by type (directories first, then files) */
366
        if ((dta1->time_sec2 & DOS_ATTR_DIR) > (dta2->time_sec2 & DOS_ATTR_DIR)) return(0 - r);
367
        if ((dta1->time_sec2 & DOS_ATTR_DIR) < (dta2->time_sec2 & DOS_ATTR_DIR)) return(r);
368
        break;
369
      case ' ': /* default (last resort) sort: by name */
370
      case 'e': /* sort by extension */
371
      case 'n': /* sort by filename */
372
      {
373
        const char far *f1 = dta1->fname;
374
        const char far *f2 = dta2->fname;
375
        int i, limit = 12;
376
        /* special handling for '.' and '..' entries */
377
        if ((f1[0] == '.') && (f2[0] != '.')) return(0 - r);
378
        if ((f2[0] == '.') && (f1[0] != '.')) return(r);
379
 
380
        if ((*ordconf | 32) == 'e') {
381
          /* fast-forward to extension or end of filename */
382
          while ((*f1 != 0) && (*f1 != '.')) f1++;
383
          while ((*f2 != 0) && (*f2 != '.')) f2++;
384
          limit = 4; /* TINYDTA structs are not nul-terminated */
385
        }
386
        /* cmp */
387
        for (i = 0; i < limit; i++) {
1739 mateusz.vi 388
          if ((glob_sortcmp_dat.sortownia[(unsigned char)(*f1)]) < (glob_sortcmp_dat.sortownia[(unsigned char)(*f2)])) return(0 - r);
389
          if ((glob_sortcmp_dat.sortownia[(unsigned char)(*f1)]) > (glob_sortcmp_dat.sortownia[(unsigned char)(*f2)])) return(r);
1719 mateusz.vi 390
          if (*f1 == 0) break;
391
          f1++;
392
          f2++;
393
        }
394
      }
395
        break;
396
      case 's': /* sort by size */
397
        if (dta1->size > dta2->size) return(r);
398
        if (dta1->size < dta2->size) return(0 - r);
399
        break;
400
      case 'd': /* sort by date */
401
        if (dta1->date_yr < dta2->date_yr) return(0 - r);
402
        if (dta1->date_yr > dta2->date_yr) return(r);
403
        if (dta1->date_mo < dta2->date_mo) return(0 - r);
404
        if (dta1->date_mo > dta2->date_mo) return(r);
405
        if (dta1->date_dy < dta2->date_dy) return(0 - r);
406
        if (dta1->date_dy > dta2->date_dy) return(r);
407
        if (dta1->time_hour < dta2->time_hour) return(0 - r);
408
        if (dta1->time_hour > dta2->time_hour) return(r);
409
        if (dta1->time_min < dta2->time_min) return(0 - r);
410
        if (dta1->time_min > dta2->time_min) return(r);
411
        break;
412
    }
413
 
414
    if (*ordconf == 0) break;
415
    ordconf++;
416
  }
417
 
418
  return(0);
419
}
420
 
421
 
542 mateuszvis 422
#define DIR_ATTR_DEFAULT (DOS_ATTR_RO | DOS_ATTR_DIR | DOS_ATTR_ARC)
423
 
1724 mateusz.vi 424
struct dirrequest {
425
  unsigned char attrfilter_may;
426
  unsigned char attrfilter_must;
427
  const char *filespecptr;
420 mateuszvis 428
 
396 mateuszvis 429
  #define DIR_FLAG_PAUSE  1
430
  #define DIR_FLAG_RECUR  4
420 mateuszvis 431
  #define DIR_FLAG_LCASE  8
1719 mateusz.vi 432
  #define DIR_FLAG_SORT  16
1724 mateusz.vi 433
  unsigned char flags;
368 mateuszvis 434
 
420 mateuszvis 435
  #define DIR_OUTPUT_NORM 1
436
  #define DIR_OUTPUT_WIDE 2
437
  #define DIR_OUTPUT_BARE 3
1724 mateusz.vi 438
  unsigned char format;
439
};
420 mateuszvis 440
 
1719 mateusz.vi 441
 
1724 mateusz.vi 442
static int dir_parse_cmdline(struct dirrequest *req, const char **argv) {
443
  for (; *argv != NULL; argv++) {
444
    if (*argv[0] == '/') {
445
      const char *arg = *argv + 1;
396 mateuszvis 446
      char neg = 0;
447
      /* detect negations and get actual argument */
542 mateuszvis 448
      if (*arg == '-') {
449
        neg = 1;
450
        arg++;
451
      }
396 mateuszvis 452
      /* */
542 mateuszvis 453
      switch (*arg) {
396 mateuszvis 454
        case 'a':
455
        case 'A':
542 mateuszvis 456
          arg++;
457
          /* preset defaults */
1724 mateusz.vi 458
          req->attrfilter_may = DIR_ATTR_DEFAULT;
459
          req->attrfilter_must = 0;
542 mateuszvis 460
          /* /-A only allowed without further parameters (used to cancel possible previous /Asmth) */
461
          if (neg) {
462
            if (*arg != 0) {
463
              nls_outputnl_err(0, 2); /* invalid switch */
1724 mateusz.vi 464
              return(-1);
542 mateuszvis 465
            }
466
          } else {
1085 mateusz.vi 467
            /* skip colon if present */
468
            if (*arg == ':') arg++;
542 mateuszvis 469
            /* start with "allow everything" */
1724 mateusz.vi 470
            req->attrfilter_may = (DOS_ATTR_ARC | DOS_ATTR_DIR | DOS_ATTR_HID | DOS_ATTR_SYS | DOS_ATTR_RO);
471
            if (dir_parse_attr_list(arg, &(req->attrfilter_may), &(req->attrfilter_must)) != 0) {
542 mateuszvis 472
              nls_outputnl_err(0, 3); /* invalid parameter format */
1724 mateusz.vi 473
              return(-1);
542 mateuszvis 474
            }
475
          }
396 mateuszvis 476
          break;
399 mateuszvis 477
        case 'b':
478
        case 'B':
1724 mateusz.vi 479
          req->format = DIR_OUTPUT_BARE;
399 mateuszvis 480
          break;
421 mateuszvis 481
        case 'l':
482
        case 'L':
1724 mateusz.vi 483
          req->flags |= DIR_FLAG_LCASE;
420 mateuszvis 484
          break;
421 mateuszvis 485
        case 'o':
486
        case 'O':
1720 mateusz.vi 487
          if (neg) {
1724 mateusz.vi 488
            req->flags &= (0xff ^ DIR_FLAG_SORT);
1720 mateusz.vi 489
            break;
490
          }
1724 mateusz.vi 491
          if (dir_process_order_directive(arg+1) != 0) {
1719 mateusz.vi 492
            nls_output_err(0, 3); /* invalid parameter format */
493
            output(": ");
494
            outputnl(arg);
1724 mateusz.vi 495
            return(-1);
1719 mateusz.vi 496
          }
1724 mateusz.vi 497
          req->flags |= DIR_FLAG_SORT;
421 mateuszvis 498
          break;
396 mateuszvis 499
        case 'p':
500
        case 'P':
1724 mateusz.vi 501
          req->flags |= DIR_FLAG_PAUSE;
502
          if (neg) req->flags &= (0xff ^ DIR_FLAG_PAUSE);
396 mateuszvis 503
          break;
421 mateuszvis 504
        case 's':
505
        case 'S':
2193 mateusz.vi 506
          req->flags |= DIR_FLAG_RECUR;
420 mateuszvis 507
          break;
421 mateuszvis 508
        case 'w':
509
        case 'W':
1724 mateusz.vi 510
          req->format = DIR_OUTPUT_WIDE;
421 mateuszvis 511
          break;
393 mateuszvis 512
        default:
542 mateuszvis 513
          nls_outputnl_err(0, 2); /* invalid switch */
1724 mateusz.vi 514
          return(-1);
393 mateuszvis 515
      }
516
    } else {  /* filespec */
1724 mateusz.vi 517
      if (req->filespecptr != NULL) {
542 mateuszvis 518
        nls_outputnl_err(0, 4); /* too many parameters */
1724 mateusz.vi 519
        return(-1);
393 mateuszvis 520
      }
1724 mateusz.vi 521
      req->filespecptr = *argv;
393 mateuszvis 522
    }
523
  }
368 mateuszvis 524
 
1724 mateusz.vi 525
  return(0);
526
}
393 mateuszvis 527
 
1724 mateusz.vi 528
 
2201 mateusz.vi 529
static void dir_print_summary_files(char *buff64, unsigned short uint32maxlen, unsigned long summary_totsz, unsigned long summary_fcount, unsigned short *availrows, unsigned char flags, const struct nls_patterns *nls) {
530
  unsigned short i;
531
  /* x file(s) (maximum of files in a FAT-32 directory is 65'535) */
532
  memset(buff64, ' ', 8);
533
  i = nls_format_number(buff64 + 8, summary_fcount, nls);
534
  sprintf(buff64 + 8 + i, " %s ", svarlang_str(37,22)/*"file(s)"*/);
535
  output(buff64 + i);
536
  /* xxxx bytes */
537
  memset(buff64, ' ', 14);
538
  i = nls_format_number(buff64 + uint32maxlen, summary_totsz, nls);
539
  output(buff64 + i + 1);
540
  output(" ");
541
  nls_outputnl(37,23); /* "bytes" */
542
  if (flags & DIR_FLAG_PAUSE) dir_pagination(availrows);
543
}
544
 
545
 
2193 mateusz.vi 546
#define MAX_SORTABLE_FILES 8192
547
 
1724 mateusz.vi 548
static enum cmd_result cmd_dir(struct cmd_funcparam *p) {
549
  struct DTA *dta = (void *)0x80; /* set DTA to its default location at 80h in PSP */
550
  struct TINYDTA far *dtabuf = NULL; /* used to buffer results when sorting is enabled */
551
  unsigned short dtabufcount = 0;
552
  unsigned short i;
553
  unsigned short availrows;  /* counter of available rows on display (used for /P) */
554
  unsigned short screenw = screen_getwidth();
555
  unsigned short wcols = screenw / WCOLWIDTH; /* number of columns in wide mode */
556
  unsigned char wcolcount;
557
  struct {
558
    struct nls_patterns nls;
559
    char buff64[64];
560
    char path[128];
2193 mateusz.vi 561
    struct DTA dtastack[64]; /* used for /S, max number of subdirs in DOS5 is 42 (A/B/C/...) */
562
    unsigned char dtastacklen;
563
    unsigned short orderidx[MAX_SORTABLE_FILES / sizeof(struct TINYDTA)];
564
  } *buf;
2201 mateusz.vi 565
  unsigned long summary_recurs_fcount = 0; /* used for /s global summary */
566
  unsigned long summary_recurs_totsz = 0;  /* used for /s global summary */
567
  unsigned long summary_fcount;
568
  unsigned long summary_totsz;
1724 mateusz.vi 569
  unsigned char drv = 0;
570
  struct dirrequest req;
2201 mateusz.vi 571
  unsigned short summary_alignpos = strlen(svarlang_str(37,22)) + 2;
2200 mateusz.vi 572
  unsigned short uint32maxlen = 14; /* 13 is the max len of a 32 bit number with thousand separators (4'000'000'000) */
573
  if (screenw < 80) uint32maxlen = 10;
1724 mateusz.vi 574
 
575
  if (cmd_ishlp(p)) {
576
    nls_outputnl(37,0); /* "Displays a list of files and subdirectories in a directory" */
577
    outputnl("");
578
    nls_outputnl(37,1); /* "DIR [drive:][path][filename] [/P] [/W] [/A[:]attributes] [/O[[:]sortorder]] [/S] [/B] [/L]" */
579
    outputnl("");
580
    nls_outputnl(37,2); /* "/P Pauses after each screenful of information" */
581
    nls_outputnl(37,3); /* "/W Uses wide list format" */
582
    outputnl("");
583
    nls_outputnl(37,4); /* "/A Displays files with specified attributes:" */
584
    nls_outputnl(37,5); /* "    D Directories            R Read-only files        H Hidden files" */
585
    nls_outputnl(37,6); /* "    A Ready for archiving    S System files           - prefix meaning "not"" */
586
    outputnl("");
587
    nls_outputnl(37,7); /* "/O List files in sorted order:" */
588
    nls_outputnl(37,8); /* "    N by name                S by size                E by extension" */
589
    nls_outputnl(37,9); /* "    D by date                G group dirs first       - prefix to reverse order" */
590
    outputnl("");
591
    nls_outputnl(37,10); /* "/S Displays files in specified directory and all subdirectories" */
592
    nls_outputnl(37,11); /* "/B Uses bare format (no heading information or summary)" */
593
    nls_outputnl(37,12); /* "/L Uses lowercases" */
2205 mateusz.vi 594
    goto GAMEOVER;
1724 mateusz.vi 595
  }
596
 
2193 mateusz.vi 597
  /* allocate buf */
598
  buf = calloc(sizeof(*buf), 1);
599
  if (buf == NULL) {
600
    nls_output_err(255, 8); /* insufficient memory */
2205 mateusz.vi 601
    goto GAMEOVER;
2193 mateusz.vi 602
  }
603
 
1739 mateusz.vi 604
  /* zero out glob_sortcmp_dat and init the collation table */
605
  bzero(&glob_sortcmp_dat, sizeof(glob_sortcmp_dat));
606
  for (i = 0; i < 256; i++) {
607
    glob_sortcmp_dat.sortownia[i] = i;
608
    /* sorting should be case-insensitive */
1740 mateusz.vi 609
    if ((i >= 'A') && (i <= 'Z')) glob_sortcmp_dat.sortownia[i] |= 32;
1739 mateusz.vi 610
  }
611
 
1743 mateusz.vi 612
  /* try to replace (or complement) my naive collation table with an NLS-aware
1744 mateusz.vi 613
   * version provided by the kernel (or NLSFUNC)
1745 mateusz.vi 614
   * see https://github.com/SvarDOS/bugz/issues/68 for some thoughts */
615
  {
1743 mateusz.vi 616
    _Packed struct nlsseqtab {
617
      unsigned char id;
618
      unsigned short taboff;
619
      unsigned short tabseg;
620
    } collat;
621
    void *colptr = &collat;
622
    unsigned char errflag = 1;
623
    _asm {
624
      push ax
625
      push bx
626
      push cx
627
      push dx
628
      push di
629
      push es
630
 
631
      mov ax, 0x6506  /* DOS 3.3+ - Get collating sequence table */
632
      mov bx, 0xffff  /* code page, FFFFh = "current" */
633
      mov cx, 5       /* size of buffer at ES:DI */
634
      mov dx, 0xffff  /* country id, FFFFh = "current" */
635
      push ds
636
      pop es          /* ES:DI = address of buffer for the 5-bytes struct */
637
      mov di, colptr
638
      int 0x21
639
      jc FAIL
640
      xor al, al
641
      mov errflag, al
642
      FAIL:
643
 
644
      pop es
645
      pop di
646
      pop dx
647
      pop cx
648
      pop bx
649
      pop ax
650
    }
651
 
652
    if ((errflag == 0) && (collat.id == 6)) {
653
      unsigned char far *ptr = MK_FP(collat.tabseg, collat.taboff);
654
      unsigned short count = *(unsigned short far *)ptr;
1745 mateusz.vi 655
#ifdef DIR_DUMPNLSCOLLATE
656
      printf("NLS AT %04X:%04X (%u elements)\n", collat.tabseg, collat.taboff, count);
657
#endif
1743 mateusz.vi 658
      if (count <= 256) { /* you never know */
659
        ptr += 2; /* skip the count header */
660
        for (i = 0; i < count; i++) {
661
          glob_sortcmp_dat.sortownia[i] = ptr[i];
1745 mateusz.vi 662
#ifdef DIR_DUMPNLSCOLLATE
663
          printf(" %03u", ptr[i]);
664
          if ((i & 15) == 15) {
665
            printf("\n");
666
            fflush(stdout);
667
          }
668
#endif
1743 mateusz.vi 669
        }
670
      }
671
    }
672
  }
673
 
1724 mateusz.vi 674
  i = nls_getpatterns(&(buf->nls));
675
  if (i != 0) nls_outputnl_doserr(i);
676
 
677
  /* disable usage of thousands separator on narrow screens */
678
  if (screenw < 80) buf->nls.thousep[0] = 0;
679
 
1725 mateusz.vi 680
  /*** PARSING COMMAND LINE STARTS *******************************************/
681
 
682
  /* init req with some defaults */
683
  bzero(&req, sizeof(req));
684
  req.attrfilter_may = DIR_ATTR_DEFAULT;
685
  req.format = DIR_OUTPUT_NORM;
686
 
687
  /* process DIRCMD first (so it can be overidden by user's cmdline) */
688
  {
689
  const char far *dircmd = env_lookup_val(p->env_seg, "DIRCMD");
690
  if (dircmd != NULL) {
691
    const char *argvptrs[32];
692
    cmd_explode(buf->buff64, dircmd, argvptrs);
693
    if ((dir_parse_cmdline(&req, argvptrs) != 0) || (req.filespecptr != NULL)) {
694
      nls_output(255, 10);/* bad environment */
695
      output(" - ");
696
      outputnl("DIRCMD");
2205 mateusz.vi 697
      goto GAMEOVER;
1725 mateusz.vi 698
    }
699
  }
700
  }
701
 
702
  /* parse user's command line */
2205 mateusz.vi 703
  if (dir_parse_cmdline(&req, p->argv) != 0) goto GAMEOVER;
1724 mateusz.vi 704
 
2193 mateusz.vi 705
  /*** PARSING COMMAND LINE DONE *********************************************/
706
 
1725 mateusz.vi 707
  /* if no filespec provided, then it's about the current directory */
708
  if (req.filespecptr == NULL) req.filespecptr = ".";
709
 
2202 mateusz.vi 710
  availrows = screen_getheight() - 1;
528 mateuszvis 711
 
417 mateuszvis 712
  /* special case: "DIR drive:" (truename() fails on "C:" under MS-DOS 6.0) */
1724 mateusz.vi 713
  if ((req.filespecptr[0] != 0) && (req.filespecptr[1] == ':') && (req.filespecptr[2] == 0)) {
714
    if ((req.filespecptr[0] >= 'a') && (req.filespecptr[0] <= 'z')) {
715
      buf->path[0] = req.filespecptr[0] - ('a' - 1);
417 mateuszvis 716
    } else {
1724 mateusz.vi 717
      buf->path[0] = req.filespecptr[0] - ('A' - 1);
399 mateuszvis 718
    }
1717 mateusz.vi 719
    i = curpathfordrv(buf->path, buf->path[0]);
417 mateuszvis 720
  } else {
1724 mateusz.vi 721
    i = file_truename(req.filespecptr, buf->path);
399 mateuszvis 722
  }
417 mateuszvis 723
  if (i != 0) {
538 mateuszvis 724
    nls_outputnl_doserr(i);
2205 mateusz.vi 725
    goto GAMEOVER;
417 mateuszvis 726
  }
393 mateuszvis 727
 
2198 mateusz.vi 728
  /* volume label and serial */
1724 mateusz.vi 729
  if (req.format != DIR_OUTPUT_BARE) {
1717 mateusz.vi 730
    drv = buf->path[0];
399 mateuszvis 731
    if (drv >= 'a') {
732
      drv -= 'a';
733
    } else {
734
      drv -= 'A';
735
    }
1717 mateusz.vi 736
    cmd_vol_internal(drv, buf->buff64);
2202 mateusz.vi 737
    availrows -= 2;
2198 mateusz.vi 738
  }
739
 
740
  NEXT_ITER: /* re-entry point for /S recursing */
741
 
2201 mateusz.vi 742
  summary_fcount = 0;
743
  summary_totsz = 0;
744
 
2203 mateusz.vi 745
  /* if dir: append a backslash (also get its len) */
746
  i = path_appendbkslash_if_dir(buf->path);
747
 
748
  /* if ends with a \ then append ????????.??? */
749
  if (buf->path[i - 1] == '\\') strcat(buf->path, "????????.???");
750
 
751
  /* ask DOS for list of files, but only with allowed attribs */
752
  i = findfirst(dta, buf->path, req.attrfilter_may);
753
 
754
  /* print "directory of" unless /B or /S mode with no match */
755
  if ((req.format != DIR_OUTPUT_BARE) && (((req.flags & DIR_FLAG_RECUR) == 0) || (i == 0))) {
2204 mateusz.vi 756
    dir_print_dirof(buf->path, &availrows, req.flags & DIR_FLAG_PAUSE);
399 mateuszvis 757
  }
758
 
2203 mateusz.vi 759
  /* if no file match then abort */
417 mateuszvis 760
  if (i != 0) {
2197 mateusz.vi 761
    if (req.flags & DIR_FLAG_RECUR) goto CHECK_RECURS;
538 mateuszvis 762
    nls_outputnl_doserr(i);
2205 mateusz.vi 763
    goto GAMEOVER;
417 mateuszvis 764
  }
765
 
1716 mateusz.vi 766
  /* if sorting is involved, then let's buffer all results (and sort them) */
1724 mateusz.vi 767
  if (req.flags & DIR_FLAG_SORT) {
1716 mateusz.vi 768
    /* allocate a memory buffer - try several sizes until one succeeds */
2194 mateusz.vi 769
    unsigned short max_dta_bufcount;
770
 
771
    /* compute the amount of DTAs I can buffer */
772
    for (max_dta_bufcount = MAX_SORTABLE_FILES; max_dta_bufcount != 0; max_dta_bufcount /= 2) {
773
      dtabuf = _fmalloc(max_dta_bufcount * sizeof(struct TINYDTA));
1716 mateusz.vi 774
      if (dtabuf != NULL) break;
775
    }
2194 mateusz.vi 776
    /* printf("max_dta_bufcount = %u\n", max_dta_bufcount); */
1716 mateusz.vi 777
 
778
    if (dtabuf == NULL) {
779
      nls_outputnl_doserr(8); /* out of memory */
2205 mateusz.vi 780
      goto GAMEOVER;
1716 mateusz.vi 781
    }
782
 
783
    /* remember the address so I can free it afterwards */
1719 mateusz.vi 784
    glob_sortcmp_dat.dtabuf_root = dtabuf;
1716 mateusz.vi 785
 
786
    do {
787
      /* filter out files with uninteresting attributes */
1724 mateusz.vi 788
      if (filter_attribs(dta, req.attrfilter_must, req.attrfilter_may) == 0) continue;
1716 mateusz.vi 789
 
1719 mateusz.vi 790
      /* normalize "size" of directories to zero because kernel returns garbage
791
       * sizes for directories which might confuse the sorting routine later */
792
      if (dta->attr & DOS_ATTR_DIR) dta->size = 0;
793
 
1716 mateusz.vi 794
      _fmemcpy(&(dtabuf[dtabufcount]), ((char *)dta) + 22, sizeof(struct TINYDTA));
795
 
796
      /* save attribs in sec field, otherwise zero it (this field is not
797
       * displayed and dropping the attr field saves 2 bytes per entry) */
798
      dtabuf[dtabufcount++].time_sec2 = (dta->attr & 31);
799
 
800
      /* do I have any space left? */
801
      if (dtabufcount == max_dta_bufcount) {
1719 mateusz.vi 802
        //TODO some kind of user notification might be nice here
1716 mateusz.vi 803
        //outputnl("TOO MANY ENTRIES FOR SORTING! LIST IS UNSORTED");
804
        break;
805
      }
806
 
807
    } while (findnext(dta) == 0);
808
 
1742 mateusz.vi 809
    /* no match? kein gluck! (this can happen when filtering attribs with /A:xxx
810
     * because while findfirst() succeeds, all entries can be rejected) */
811
    if (dtabufcount == 0) {
812
      nls_outputnl_doserr(2); /* "File not found" */
2205 mateusz.vi 813
      goto GAMEOVER;
1742 mateusz.vi 814
    }
815
 
1716 mateusz.vi 816
    /* sort the list - the tricky part is that my array is a far address while
1719 mateusz.vi 817
     * qsort works only with near pointers, so I have to use an ugly (and
818
     * global) auxiliary table */
819
    for (i = 0; i < dtabufcount; i++) buf->orderidx[i] = i;
820
    qsort(buf->orderidx, dtabufcount, 2, &sortcmp);
1716 mateusz.vi 821
 
1719 mateusz.vi 822
    /* preload first entry (last from orderidx, since entries are sorted in reverse) */
1716 mateusz.vi 823
    dtabufcount--;
1719 mateusz.vi 824
    _fmemcpy(((unsigned char *)dta) + 22, &(dtabuf[buf->orderidx[dtabufcount]]), sizeof(struct TINYDTA));
825
    dta->attr = dtabuf[buf->orderidx[dtabufcount]].time_sec2; /* restore attr from the abused time_sec2 field */
1716 mateusz.vi 826
  }
827
 
420 mateuszvis 828
  wcolcount = 0; /* may be used for columns counting with wide mode */
396 mateuszvis 829
 
1716 mateusz.vi 830
  for (;;) {
542 mateuszvis 831
 
1716 mateusz.vi 832
    /* filter out attributes (skip if entry comes from buffer, then it was already veted) */
1741 mateusz.vi 833
    if (filter_attribs(dta, req.attrfilter_must, req.attrfilter_may) == 0) goto NEXT_ENTRY;
542 mateuszvis 834
 
835
    /* turn string lcase (/L) */
1724 mateusz.vi 836
    if (req.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... */
368 mateuszvis 837
 
424 mateuszvis 838
    summary_fcount++;
839
    if ((dta->attr & DOS_ATTR_DIR) == 0) summary_totsz += dta->size;
840
 
1724 mateusz.vi 841
    switch (req.format) {
420 mateuszvis 842
      case DIR_OUTPUT_NORM:
843
        /* print fname-space-extension (unless it's "." or "..", then print as-is) */
844
        if (dta->fname[0] == '.') {
845
          output(dta->fname);
846
          i = strlen(dta->fname);
847
          while (i++ < 12) output(" ");
848
        } else {
1717 mateusz.vi 849
          file_fname2fcb(buf->buff64, dta->fname);
850
          memmove(buf->buff64 + 9, buf->buff64 + 8, 4);
851
          buf->buff64[8] = ' ';
852
          output(buf->buff64);
420 mateuszvis 853
        }
854
        output(" ");
1960 mateusz.vi 855
        /* either <DIR> or right aligned 13 or 10 chars byte size, depending
856
         * on the presence of a thousands delimiter (max 2'000'000'000) */
857
        {
858
          unsigned short szlen = 10 + (strlen(buf->nls.thousep) * 3);
859
          memset(buf->buff64, ' ', 16);
860
          if (dta->attr & DOS_ATTR_DIR) {
861
            strcpy(buf->buff64 + szlen, svarlang_str(37,21));
862
          } else {
863
            nls_format_number(buf->buff64 + 12, dta->size, &(buf->nls));
864
          }
865
          output(buf->buff64 + strlen(buf->buff64) - szlen);
420 mateuszvis 866
        }
1960 mateusz.vi 867
        /* one spaces and NLS DATE */
1717 mateusz.vi 868
        buf->buff64[0] = ' ';
1141 mateusz.vi 869
        if (screenw >= 80) {
1960 mateusz.vi 870
          nls_format_date(buf->buff64 + 1, dta->date_yr + 1980, dta->date_mo, dta->date_dy, &(buf->nls));
1141 mateusz.vi 871
        } else {
1960 mateusz.vi 872
          nls_format_date(buf->buff64 + 1, (dta->date_yr + 80) % 100, dta->date_mo, dta->date_dy, &(buf->nls));
1141 mateusz.vi 873
        }
1717 mateusz.vi 874
        output(buf->buff64);
420 mateuszvis 875
 
876
        /* one space and NLS TIME */
1717 mateusz.vi 877
        nls_format_time(buf->buff64 + 1, dta->time_hour, dta->time_min, 0xff, &(buf->nls));
878
        outputnl(buf->buff64);
420 mateuszvis 879
        break;
880
 
881
      case DIR_OUTPUT_WIDE: /* display in columns of 12 chars per item */
882
        i = strlen(dta->fname);
883
        if (dta->attr & DOS_ATTR_DIR) {
884
          i += 2;
885
          output("[");
886
          output(dta->fname);
887
          output("]");
888
        } else {
889
          output(dta->fname);
890
        }
891
        while (i++ < WCOLWIDTH) output(" ");
892
        if (++wcolcount == wcols) {
893
          wcolcount = 0;
894
          outputnl("");
528 mateuszvis 895
        } else {
896
          availrows++; /* wide mode is the only one that does not write one line per file */
420 mateuszvis 897
        }
898
        break;
899
 
900
      case DIR_OUTPUT_BARE:
901
        outputnl(dta->fname);
902
        break;
396 mateuszvis 903
    }
368 mateuszvis 904
 
1724 mateusz.vi 905
    if (req.flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
420 mateuszvis 906
 
1741 mateusz.vi 907
    NEXT_ENTRY:
1716 mateusz.vi 908
    /* take next entry, either from buf or disk */
909
    if (dtabufcount > 0) {
910
      dtabufcount--;
1719 mateusz.vi 911
      _fmemcpy(((unsigned char *)dta) + 22, &(dtabuf[buf->orderidx[dtabufcount]]), sizeof(struct TINYDTA));
912
      dta->attr = dtabuf[buf->orderidx[dtabufcount]].time_sec2; /* restore attr from the abused time_sec2 field */
1716 mateusz.vi 913
    } else {
914
      if (findnext(dta) != 0) break;
915
    }
420 mateuszvis 916
 
1716 mateusz.vi 917
  }
918
 
528 mateuszvis 919
  if (wcolcount != 0) {
920
    outputnl(""); /* in wide mode make sure to end on a clear row */
1724 mateusz.vi 921
    if (req.flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
528 mateuszvis 922
  }
420 mateuszvis 923
 
424 mateuszvis 924
  /* print out summary (unless bare output mode) */
1724 mateusz.vi 925
  if (req.format != DIR_OUTPUT_BARE) {
2201 mateusz.vi 926
    dir_print_summary_files(buf->buff64, uint32maxlen, summary_totsz, summary_fcount, &availrows, req.flags, &(buf->nls));
424 mateuszvis 927
  }
928
 
2201 mateusz.vi 929
  /* update global counters in case /s is used */
930
  summary_recurs_fcount += summary_fcount;
931
  summary_recurs_totsz += summary_totsz;
932
 
2193 mateusz.vi 933
  /* /S processing */
2197 mateusz.vi 934
  CHECK_RECURS:
935
  /* if /S then look for a subdir */
936
  if (req.flags & DIR_FLAG_RECUR) {
937
    /* do the findfirst on *.* instead of reusing the user filter */
938
    char *s;
939
    char backup[4];
2200 mateusz.vi 940
    //printf("orig path='%s' new=", buf->path);
2197 mateusz.vi 941
    for (s = buf->path; *s != 0; s++);
942
    for (; s[-1] != '\\'; s--);
943
    memcpy_ltr(backup, s, 4);
944
    memcpy_ltr(s, "*.*", 4);
2200 mateusz.vi 945
    //printf("'%s'\n", buf->path);
2197 mateusz.vi 946
    if (findfirst(dta, buf->path, DOS_ATTR_DIR) == 0) {
947
      memcpy_ltr(s, backup, 4);
948
      for (;;) {
949
        if ((dta->fname[0] != '.') && (dta->attr & DOS_ATTR_DIR)) break;
950
        if (findnext(dta) != 0) goto NOSUBDIR;
951
      }
2200 mateusz.vi 952
      //printf("GOT DIR (/S): '%s'\n", dta->fname);
2197 mateusz.vi 953
      /* add dir to path and redo scan */
954
      memcpy_ltr(&(buf->dtastack[buf->dtastacklen]), dta, sizeof(struct DTA));
955
      buf->dtastacklen++;
956
      path_add(buf->path, dta->fname);
957
      goto NEXT_ITER;
958
    }
959
    memcpy_ltr(s, backup, 4);
2193 mateusz.vi 960
  }
2197 mateusz.vi 961
  NOSUBDIR:
962
 
2193 mateusz.vi 963
  while (buf->dtastacklen > 0) {
964
    /* rewind path one directory back, pop the next dta and do a FindNext */
965
    path_back(buf->path);
966
    buf->dtastacklen--;
967
    TRYNEXTENTRY:
968
    if (findnext(&(buf->dtastack[buf->dtastacklen])) != 0) continue;
969
    if ((buf->dtastack[buf->dtastacklen].attr & DOS_ATTR_DIR) == 0) goto TRYNEXTENTRY;
2200 mateusz.vi 970
    if (buf->dtastack[buf->dtastacklen].fname[0] == '.') goto TRYNEXTENTRY;
2193 mateusz.vi 971
    /* something found -> add dir to path and redo scan */
972
    path_add(buf->path, buf->dtastack[buf->dtastacklen].fname);
973
    goto NEXT_ITER;
974
  }
975
 
2200 mateusz.vi 976
  /* print out disk space available (unless bare output mode) */
977
  if (req.format != DIR_OUTPUT_BARE) {
2201 mateusz.vi 978
    /* if /s mode then print also global stats */
979
    if (req.flags & DIR_FLAG_RECUR) {
2205 mateusz.vi 980
      if (summary_recurs_fcount == 0) {
981
        file_truename(req.filespecptr, buf->path);
982
        dir_print_dirof(buf->path, &availrows, req.flags & DIR_FLAG_PAUSE);
983
        nls_outputnl_doserr(2); /* "File not found" */
984
        goto GAMEOVER;
985
      } else {
986
        outputnl("");
987
        if (req.flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
988
        nls_outputnl(37,25); /* Total files listed: */
989
        if (req.flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
990
        dir_print_summary_files(buf->buff64, uint32maxlen, summary_recurs_totsz, summary_recurs_fcount, &availrows, req.flags, &(buf->nls));
991
      }
2201 mateusz.vi 992
    }
2200 mateusz.vi 993
    /* xxxx bytes free */
994
    i = cmd_dir_df(&summary_totsz, drv);
995
    if (i != 0) nls_outputnl_doserr(i);
996
    memset(buf->buff64, ' ', summary_alignpos + 8 + uint32maxlen); /* align the freebytes value to same column as totbytes */
997
    i = nls_format_number(buf->buff64 + summary_alignpos + 8 + uint32maxlen, summary_totsz, &(buf->nls));
998
    output(buf->buff64 + i + 1);
999
    output(" ");
1000
    nls_outputnl(37,24); /* "bytes free" */
1001
    if (req.flags & DIR_FLAG_PAUSE) dir_pagination(&availrows);
1002
  }
1003
 
2205 mateusz.vi 1004
  GAMEOVER:
1005
 
1716 mateusz.vi 1006
  /* free the buffer memory (if used) */
1719 mateusz.vi 1007
  if (glob_sortcmp_dat.dtabuf_root != NULL) _ffree(glob_sortcmp_dat.dtabuf_root);
1716 mateusz.vi 1008
 
2193 mateusz.vi 1009
  free(buf);
533 mateuszvis 1010
  return(CMD_OK);
368 mateuszvis 1011
}