Subversion Repositories SvarDOS

Rev

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

Rev 421 Rev 424
Line 53... Line 53...
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
 
-
 
59
/* fills freebytes with free bytes for drv (A=0, B=1, etc)
-
 
60
 * returns DOS ERR code on failure */
-
 
61
static unsigned short cmd_dir_df(unsigned long *freebytes, unsigned char drv) {
-
 
62
  unsigned short res = 0;
-
 
63
  unsigned short sects_per_clust = 0, avail_clusts = 0, bytes_per_sect = 0;
-
 
64
 
-
 
65
  _asm {
-
 
66
    push ax
-
 
67
    push bx
-
 
68
    push cx
-
 
69
    push dx
-
 
70
 
-
 
71
    mov ah, 0x36  /* DOS 2+ -- Get Disk Free Space */
-
 
72
    mov dl, [drv] /* A=1, B=2, etc (0 = DEFAULT DRIVE) */
-
 
73
    inc dl
-
 
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) */
-
 
76
    jne COMPUTEDF
-
 
77
    mov [res], 0x0f /* fill res with DOS error code 15 ("invalid drive") */
-
 
78
    jmp DONE
-
 
79
 
-
 
80
    COMPUTEDF:
-
 
81
    /* freebytes = AX * BX * CX */
-
 
82
    mov [sects_per_clust], ax
-
 
83
    mov [avail_clusts], bx
-
 
84
    mov [bytes_per_sect], cx
-
 
85
 
-
 
86
    DONE:
-
 
87
    pop dx
-
 
88
    pop cx
-
 
89
    pop bx
-
 
90
    pop ax
-
 
91
  }
-
 
92
 
-
 
93
  /* multiple steps to avoid uint16 overflow */
-
 
94
  *freebytes = sects_per_clust;
-
 
95
  *freebytes *= avail_clusts;
-
 
96
  *freebytes *= bytes_per_sect;
-
 
97
 
-
 
98
  return(res);
-
 
99
}
-
 
100
 
-
 
101
 
58
static int cmd_dir(struct cmd_funcparam *p) {
102
static int cmd_dir(struct cmd_funcparam *p) {
59
  const char *filespecptr = NULL;
103
  const char *filespecptr = NULL;
60
  struct DTA *dta = (void *)0x80; /* set DTA to its default location at 80h in PSP */
104
  struct DTA *dta = (void *)0x80; /* set DTA to its default location at 80h in PSP */
61
  unsigned short i;
105
  unsigned short i;
62
  unsigned short availrows;  /* counter of available rows on display (used for /P) */
106
  unsigned short availrows;  /* counter of available rows on display (used for /P) */
63
  unsigned short wcols = screen_getwidth() / WCOLWIDTH; /* number of columns in wide mode */
107
  unsigned short wcols = screen_getwidth() / WCOLWIDTH; /* number of columns in wide mode */
64
  unsigned char wcolcount;
108
  unsigned char wcolcount;
65
  struct nls_patterns *nls = (void *)(p->BUFFER + (BUFFER_SIZE / 3));
109
  struct nls_patterns *nls = (void *)(p->BUFFER + (BUFFER_SIZE / 3));
66
  char *buff2 = p->BUFFER + (BUFFER_SIZE / 3 * 2);
110
  char *buff2 = p->BUFFER + (BUFFER_SIZE / 3 * 2);
-
 
111
  unsigned long summary_fcount = 0;
-
 
112
  unsigned long summary_totsz = 0;
-
 
113
  unsigned char drv = 0;
67
 
114
 
68
  #define DIR_FLAG_PAUSE  1
115
  #define DIR_FLAG_PAUSE  1
69
  #define DIR_FLAG_RECUR  4
116
  #define DIR_FLAG_RECUR  4
70
  #define DIR_FLAG_LCASE  8
117
  #define DIR_FLAG_LCASE  8
71
  unsigned char flags = 0;
118
  unsigned char flags = 0;
Line 175... Line 222...
175
    outputnl(doserr(i));
222
    outputnl(doserr(i));
176
    return(-1);
223
    return(-1);
177
  }
224
  }
178
 
225
 
179
  if (format != DIR_OUTPUT_BARE) {
226
  if (format != DIR_OUTPUT_BARE) {
180
    unsigned char drv = p->BUFFER[0];
227
    drv = p->BUFFER[0];
181
    if (drv >= 'a') {
228
    if (drv >= 'a') {
182
      drv -= 'a';
229
      drv -= 'a';
183
    } else {
230
    } else {
184
      drv -= 'A';
231
      drv -= 'A';
185
    }
232
    }
Line 207... Line 254...
207
  wcolcount = 0; /* may be used for columns counting with wide mode */
254
  wcolcount = 0; /* may be used for columns counting with wide mode */
208
 
255
 
209
  do {
256
  do {
210
    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... */
257
    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... */
211
 
258
 
-
 
259
    summary_fcount++;
-
 
260
    if ((dta->attr & DOS_ATTR_DIR) == 0) summary_totsz += dta->size;
-
 
261
 
212
    switch (format) {
262
    switch (format) {
213
      case DIR_OUTPUT_NORM:
263
      case DIR_OUTPUT_NORM:
214
        /* print fname-space-extension (unless it's "." or "..", then print as-is) */
264
        /* print fname-space-extension (unless it's "." or "..", then print as-is) */
215
        if (dta->fname[0] == '.') {
265
        if (dta->fname[0] == '.') {
216
          output(dta->fname);
266
          output(dta->fname);
Line 269... Line 319...
269
      availrows = screen_getheight();
319
      availrows = screen_getheight();
270
    }
320
    }
271
 
321
 
272
  } while (findnext(dta) == 0);
322
  } while (findnext(dta) == 0);
273
 
323
 
-
 
324
  if (wcolcount != 0) outputnl(""); /* in wide mode make sure to end on a clear row */
-
 
325
 
-
 
326
  /* print out summary (unless bare output mode) */
-
 
327
  if (format != DIR_OUTPUT_BARE) {
-
 
328
    unsigned short alignpos;
-
 
329
    /* x file(s) */
-
 
330
    memset(buff2, ' ', 13); /* 13 is the max len of a 32 bit number with thousand separators (4'000'000'000) */
-
 
331
    i = nls_format_number(buff2 + 13, summary_fcount, nls);
-
 
332
    alignpos = sprintf(buff2 + 13 + i, " %s ", "file(s)");
-
 
333
    output(buff2 + i);
-
 
334
    /* xxxx bytes */
-
 
335
    i = nls_format_number(buff2 + 13, summary_totsz, nls);
-
 
336
    output(buff2 + i);
-
 
337
    output(" ");
-
 
338
    outputnl("bytes");
-
 
339
    /* xxxx bytes free */
-
 
340
    printf("totsz = %lu\r\n", summary_totsz);
-
 
341
    i = cmd_dir_df(&summary_totsz, drv);
274
  if (wcolcount != 0) outputnl("");
342
    if (i != 0) outputnl(doserr(i));
-
 
343
    alignpos += 13 + 13;
-
 
344
    memset(buff2, ' ', alignpos); /* align the freebytes value to same column as totbytes */
-
 
345
    i = nls_format_number(buff2 + alignpos, summary_totsz, nls);
-
 
346
    output(buff2 + i);
-
 
347
    output(" ");
-
 
348
    outputnl("bytes free");
-
 
349
  }
275
 
350
 
276
  return(-1);
351
  return(-1);
277
}
352
}