Subversion Repositories SvarDOS

Rev

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

Rev 390 Rev 393
1
/*
1
/*
2
 * dir
2
 * dir
3
 *
3
 *
4
 * Displays a list of files and subdirectories in a directory.
4
 * Displays a list of files and subdirectories in a directory.
5
 *
5
 *
6
 * DIR [drive:][path][filename] [/P] [/W] [/A[:]attributes] [/O[[:]sortorder]] [/S] [/B] [/L]
6
 * DIR [drive:][path][filename] [/P] [/W] [/A[:]attributes] [/O[[:]sortorder]] [/S] [/B] [/L]
7
 *
7
 *
8
 * /P Pauses after each screenful of information.
8
 * /P Pauses after each screenful of information.
9
 * /W Uses wide list format.
9
 * /W Uses wide list format.
10
 *
10
 *
11
 * /A Displays file with specified attributes:
11
 * /A Displays file with specified attributes:
12
 *     D Directories           R Read-only files     H Hidden files
12
 *     D Directories           R Read-only files     H Hidden files
13
 *     A Ready for archiving   S System files        - prefix meaning "not"
13
 *     A Ready for archiving   S System files        - prefix meaning "not"
14
 *
14
 *
15
 * /O List files in sorted order:
15
 * /O List files in sorted order:
16
 *     N by name            S by size              E by extension
16
 *     N by name            S by size              E by extension
17
 *     D by date            G group dirs first     - prefix to reverse order
17
 *     D by date            G group dirs first     - prefix to reverse order
18
 *
18
 *
19
 * /S Displays files in specified directory and all subdirectories.
19
 * /S Displays files in specified directory and all subdirectories.
20
 * /B Uses bare format (no heading information or summary)
20
 * /B Uses bare format (no heading information or summary)
21
 * /L Uses lowercases
21
 * /L Uses lowercases
22
 */
22
 */
23
 
23
 
24
static int cmd_dir(struct cmd_funcparam *p) {
24
static int cmd_dir(struct cmd_funcparam *p) {
25
  const char *filespecptr = "*.*";
25
  const char *filespecptr = NULL;
26
  struct DTA *dta = (void *)0x80; /* set DTA to its default location at 80h in PSP */
26
  struct DTA *dta = (void *)0x80; /* set DTA to its default location at 80h in PSP */
-
 
27
  int i;
27
 
28
 
28
  if (cmd_ishlp(p)) {
29
  if (cmd_ishlp(p)) {
29
    outputnl("Displays a list of files and subdirectories in a directory.");
30
    outputnl("Displays a list of files and subdirectories in a directory.");
30
    outputnl("\r\nTHIS COMMAND IS NOT FULLY IMPLEMENTED YET");
31
    outputnl("\r\nTHIS COMMAND IS NOT FULLY IMPLEMENTED YET");
31
    return(-1);
32
    return(-1);
32
  }
33
  }
33
 
34
 
-
 
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
  }
-
 
51
 
-
 
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
 
34
  if (findfirst(dta, filespecptr, DOS_ATTR_RO | DOS_ATTR_HID | DOS_ATTR_SYS | DOS_ATTR_DIR | DOS_ATTR_ARC) != 0) return(-1);
60
  if (findfirst(dta, p->BUFFER, DOS_ATTR_RO | DOS_ATTR_HID | DOS_ATTR_SYS | DOS_ATTR_DIR | DOS_ATTR_ARC) != 0) return(-1);
35
 
61
 
36
  outputnl(dta->fname);
62
  outputnl(dta->fname);
37
 
63
 
38
  while (findnext(dta) == 0) outputnl(dta->fname);
64
  while (findnext(dta) == 0) outputnl(dta->fname);
39
 
65
 
40
  return(-1);
66
  return(-1);
41
}
67
}
42
 
68