Subversion Repositories SvarDOS

Rev

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

Rev 363 Rev 364
Line 8... Line 8...
8
 *
8
 *
9
 * Type CD drive: to display the current directory in the specified drive.
9
 * Type CD drive: to display the current directory in the specified drive.
10
 * Type CD without parameters to display the current drive and directory.
10
 * Type CD without parameters to display the current drive and directory.
11
 */
11
 */
12
 
12
 
13
static int cmd_cd(int argc, char const **argv) {
13
static int cmd_cd(const struct cmd_funcparam *p) {
14
  /* two arguments max */
14
  /* two arguments max */
15
  if (argc > 2) {
15
  if (p->argc > 1) {
16
    puts("Too many parameters");
16
    puts("Too many parameters");
17
  }
17
  }
18
 
18
 
19
  /* no argument? display current drive and dir ("CWD") */
19
  /* no argument? display current drive and dir ("CWD") */
20
  if (argc == 1) {
20
  if (p->argc == 0) {
21
    char buff[64];
21
    char buff[64];
22
    char *buffptr = buff;
22
    char *buffptr = buff;
23
    _asm {
23
    _asm {
24
      push ax
24
      push ax
25
      push dx
25
      push dx
Line 38... Line 38...
38
      /* get current dir */
38
      /* get current dir */
39
      mov ah, 0x47
39
      mov ah, 0x47
40
      xor dl, dl       /* select drive (0 = current drive) */
40
      xor dl, dl       /* select drive (0 = current drive) */
41
      mov si, buffptr  /* 64-byte buffer for ASCIZ pathname */
41
      mov si, buffptr  /* 64-byte buffer for ASCIZ pathname */
42
      int 0x21
42
      int 0x21
43
      pop ax
-
 
44
      pop dx
-
 
45
      pop si
43
      pop si
-
 
44
      pop dx
-
 
45
      pop ax
46
    }
46
    }
47
    puts(buff);
47
    puts(buff);
48
  }
48
  }
49
 
49
 
50
  /* argument can be either a drive (D:) or a path */
50
  /* argument can be either a drive (D:) or a path */
51
  if (argc == 2) {
51
  if (p->argc == 1) {
-
 
52
    const char *arg = p->argv[0];
-
 
53
    unsigned short err = 0;
52
    /* drive (CD B:) */
54
    /* drive (CD B:) */
53
    if ((argv[1][0] != '\\') && (argv[1][1] == ':') && (argv[1][2] == 0)) {
55
    if ((arg[0] != '\\') && (arg[1] == ':') && (arg[2] == 0)) {
54
      char buff[64];
56
      char buff[64];
55
      char *buffptr = buff;
57
      char *buffptr = buff;
56
      unsigned char drive = argv[1][0];
58
      unsigned char drive = arg[0];
57
      unsigned short err = 0;
-
 
58
      if (drive >= 'a') {
59
      if (drive >= 'a') {
59
        drive -= 'a';
60
        drive -= 'a';
60
      } else {
61
      } else {
61
        drive -= 'A';
62
        drive -= 'A';
62
      }
63
      }
Line 74... Line 75...
74
        DONE:
75
        DONE:
75
        pop dx
76
        pop dx
76
        pop ax
77
        pop ax
77
        pop si
78
        pop si
78
      }
79
      }
79
      if (err != 0) {
-
 
80
        if (err != 0) puts(doserr(err));
-
 
81
      } else {
-
 
82
        printf("%c:\\%s\r\n", drive + 'A' - 1, buff);
80
      if (err == 0) printf("%c:\\%s\r\n", drive + 'A' - 1, buff);
83
      }
-
 
84
    } else { /* path */
81
    } else { /* path */
85
      char const *dir = argv[1];
-
 
86
      unsigned short err = 0;
-
 
87
      _asm {
82
      _asm {
88
        push dx
83
        push dx
89
        push ax
84
        push ax
90
        mov ah, 0x3B  /* CHDIR (set current directory) */
85
        mov ah, 0x3B  /* CHDIR (set current directory) */
91
        mov dx, dir
86
        mov dx, arg
92
        int 0x21
87
        int 0x21
93
        jnc DONE
88
        jnc DONE
94
        mov [err], ax
89
        mov [err], ax
95
        DONE:
90
        DONE:
96
        pop ax
91
        pop ax
97
        pop dx
92
        pop dx
98
      }
93
      }
99
      if (err != 0) puts(doserr(err));
-
 
100
    }
94
    }
-
 
95
    if (err != 0) puts(doserr(err));
101
  }
96
  }
102
 
97
 
103
  return(-1);
98
  return(-1);
104
}
99
}