Subversion Repositories SvarDOS

Rev

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

Rev Author Line No. Line
368 mateuszvis 1
/*
2
 * dir
3
 *
4
 * Displays a list of files and subdirectories in a directory.
5
 *
6
 * DIR [drive:][path][filename] [/P] [/W] [/A[:]attributes] [/O[[:]sortorder]] [/S] [/B] [/L]
7
 *
8
 * /P Pauses after each screenful of information.
9
 * /W Uses wide list format.
10
 *
11
 * /A Displays file with specified attributes:
12
 *     D Directories           R Read-only files     H Hidden files
13
 *     A Ready for archiving   S System files        - prefix meaning "not"
14
 *
15
 * /O List files in sorted order:
16
 *     N by name            S by size              E by extension
17
 *     D by date            G group dirs first     - prefix to reverse order
18
 *
19
 * /S Displays files in specified directory and all subdirectories.
20
 * /B Uses bare format (no heading information or summary)
21
 * /L Uses lowercases
22
 */
23
 
372 mateuszvis 24
static int cmd_dir(struct cmd_funcparam *p) {
393 mateuszvis 25
  const char *filespecptr = NULL;
388 mateuszvis 26
  struct DTA *dta = (void *)0x80; /* set DTA to its default location at 80h in PSP */
393 mateuszvis 27
  int i;
368 mateuszvis 28
 
390 mateuszvis 29
  if (cmd_ishlp(p)) {
30
    outputnl("Displays a list of files and subdirectories in a directory.");
31
    outputnl("\r\nTHIS COMMAND IS NOT FULLY IMPLEMENTED YET");
32
    return(-1);
33
  }
34
 
393 mateuszvis 35
  /* parse command line */
36
  for (i = 0; i < p->argc; i++) {
37
    if (p->argv[i][0] == '/') {
38
      switch (p->argv[i][1]) {
39
        default:
40
          outputnl("Invalid switch");
41
          return(-1);
42
      }
43
    } else {  /* filespec */
44
      if (filespecptr != NULL) {
45
        outputnl("Too many parameters");
46
        return(-1);
47
      }
48
      filespecptr = p->argv[i];
49
    }
50
  }
368 mateuszvis 51
 
393 mateuszvis 52
  if (filespecptr == NULL) filespecptr = ".";
53
 
54
  file_truename(filespecptr, p->BUFFER);
55
 
56
  /* if dir then append \????????.??? */
57
  i = file_getattr(p->BUFFER);
58
  if ((i > 0) && (i & DOS_ATTR_DIR)) strcat(p->BUFFER, "\\????????.???");
59
 
60
  if (findfirst(dta, p->BUFFER, DOS_ATTR_RO | DOS_ATTR_HID | DOS_ATTR_SYS | DOS_ATTR_DIR | DOS_ATTR_ARC) != 0) return(-1);
61
 
369 mateuszvis 62
  outputnl(dta->fname);
368 mateuszvis 63
 
388 mateuszvis 64
  while (findnext(dta) == 0) outputnl(dta->fname);
368 mateuszvis 65
 
66
  return(-1);
67
}