Subversion Repositories SvarDOS

Rev

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

Rev 374 Rev 375
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
 
-
 
14
/* display current path drive d (A=1, B=2, etc)
-
 
15
 * returns 0 on success, doserr otherwise */
-
 
16
static unsigned short cmd_cd_curpathfordrv(char *buff, unsigned char d) {
-
 
17
  unsigned short r = 0;
-
 
18
 
-
 
19
  buff[0] = d + 'A' - 1;
-
 
20
  buff[1] = ':';
-
 
21
  buff[2] = '\\';
-
 
22
 
-
 
23
  _asm {
-
 
24
    push si
-
 
25
    push ax
-
 
26
    push dx
-
 
27
    mov ah, 0x47      /* get current directory */
-
 
28
    mov dl, [d]       /* A: = 1, B: = 2, etc */
-
 
29
    mov si, buff      /* append cur dir to buffer */
-
 
30
    add si, 3         /* skip the present drive:\ prefix */
-
 
31
    int 0x21
-
 
32
    jnc DONE
-
 
33
    mov [r], ax       /* copy result from ax */
-
 
34
    DONE:
-
 
35
    pop dx
-
 
36
    pop ax
-
 
37
    pop si
-
 
38
  }
-
 
39
 
-
 
40
  return(r);
-
 
41
}
-
 
42
 
-
 
43
 
13
static int cmd_cd(struct cmd_funcparam *p) {
44
static int cmd_cd(struct cmd_funcparam *p) {
14
  char *buffptr = p->BUFFER;
45
  char *buffptr = p->BUFFER;
15
 
46
 
16
  /* two arguments max */
47
  /* two arguments max */
17
  if (p->argc > 1) {
48
  if (p->argc > 1) {
Line 35... Line 66...
35
    return(-1);
66
    return(-1);
36
  }
67
  }
37
 
68
 
38
  /* no argument? display current drive and dir ("CWD") */
69
  /* no argument? display current drive and dir ("CWD") */
39
  if (p->argc == 0) {
70
  if (p->argc == 0) {
-
 
71
    unsigned char drv = 0;
-
 
72
 
40
    _asm {
73
    _asm {
41
      push ax
74
      push ax
42
      push dx
75
      push dx
43
      push si
76
      push si
44
      mov ah, 0x19  /* get current default drive */
77
      mov ah, 0x19  /* get current default drive */
45
      int 0x21      /* al = drive (00h = A:, 01h = B:, etc) */
78
      int 0x21      /* al = drive (00h = A:, 01h = B:, etc) */
46
      add al, 'A'
-
 
47
      /* print drive to stdout */
79
      inc al        /* convert to 1=A, 2=B, etc */
48
      mov dl, al
80
      mov [drv], al
49
      mov ah, 0x02
-
 
50
      int 0x21
-
 
51
      mov dl, ':'
-
 
52
      int 0x21
-
 
53
      mov dl, '\'
-
 
54
      int 0x21
-
 
55
      /* get current dir */
-
 
56
      mov ah, 0x47
-
 
57
      xor dl, dl       /* select drive (0 = current drive) */
-
 
58
      mov si, buffptr  /* 64-byte buffer for ASCIZ pathname */
-
 
59
      int 0x21
-
 
60
      pop si
-
 
61
      pop dx
-
 
62
      pop ax
-
 
63
    }
81
    }
-
 
82
 
-
 
83
    cmd_cd_curpathfordrv(buffptr, drv);
64
    outputnl(buffptr);
84
    outputnl(buffptr);
-
 
85
 
65
    return(-1);
86
    return(-1);
66
  }
87
  }
67
 
88
 
68
  /* argument can be either a drive (D:) or a path */
89
  /* argument can be either a drive (D:) or a path */
69
  if (p->argc == 1) {
90
  if (p->argc == 1) {
Line 71... Line 92...
71
    unsigned short err = 0;
92
    unsigned short err = 0;
72
    /* drive (CD B:) */
93
    /* drive (CD B:) */
73
    if ((arg[0] != '\\') && (arg[1] == ':') && (arg[2] == 0)) {
94
    if ((arg[0] != '\\') && (arg[1] == ':') && (arg[2] == 0)) {
74
      unsigned char drive = arg[0];
95
      unsigned char drive = arg[0];
75
      if (drive >= 'a') {
96
      if (drive >= 'a') {
76
        drive -= 'a';
97
        drive -= ('a' - 1);
77
      } else {
98
      } else {
78
        drive -= 'A';
99
        drive -= ('A' - 1);
79
      }
100
      }
80
      drive++; /* A: = 1, B: = 2, etc*/
-
 
81
      _asm {
101
 
82
        push si
-
 
83
        push ax
-
 
84
        push dx
-
 
85
        mov ah, 0x47      /* get current directory */
-
 
86
        mov dl, [drive]   /* A: = 1, B: = 2, etc */
102
      err = cmd_cd_curpathfordrv(buffptr, drive);
87
        mov si, buffptr
-
 
88
        int 0x21
-
 
89
        jnc DONE
-
 
90
        mov [err], ax
-
 
91
        DONE:
-
 
92
        pop dx
-
 
93
        pop ax
-
 
94
        pop si
-
 
95
      }
-
 
96
      if (err == 0) printf("%c:\\%s\r\n", drive + 'A' - 1, buffptr);
103
      if (err == 0) outputnl(buffptr);
97
    } else { /* path */
104
    } else { /* path */
98
      _asm {
105
      _asm {
99
        push dx
106
        push dx
100
        push ax
107
        push ax
101
        mov ah, 0x3B  /* CHDIR (set current directory) */
108
        mov ah, 0x3B  /* CHDIR (set current directory) */