Subversion Repositories SvarDOS

Rev

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

Rev 375 Rev 387
1
/*
1
/*
2
 * chdir
2
 * chdir
3
 *
3
 *
4
 * displays the name of or changes the current directory.
4
 * displays the name of or changes the current directory.
5
 *
5
 *
6
 * CHDIR [drive:][path]
6
 * CHDIR [drive:][path]
7
 * CD..
7
 * CD..
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
 
13
 
14
/* display current path drive d (A=1, B=2, etc)
14
/* display current path drive d (A=1, B=2, etc)
15
 * returns 0 on success, doserr otherwise */
15
 * returns 0 on success, doserr otherwise */
16
static unsigned short cmd_cd_curpathfordrv(char *buff, unsigned char d) {
16
static unsigned short cmd_cd_curpathfordrv(char *buff, unsigned char d) {
17
  unsigned short r = 0;
17
  unsigned short r = 0;
18
 
18
 
19
  buff[0] = d + 'A' - 1;
19
  buff[0] = d + 'A' - 1;
20
  buff[1] = ':';
20
  buff[1] = ':';
21
  buff[2] = '\\';
21
  buff[2] = '\\';
22
 
22
 
23
  _asm {
23
  _asm {
24
    push si
24
    push si
25
    push ax
25
    push ax
26
    push dx
26
    push dx
27
    mov ah, 0x47      /* get current directory */
27
    mov ah, 0x47      /* get current directory */
28
    mov dl, [d]       /* A: = 1, B: = 2, etc */
28
    mov dl, [d]       /* A: = 1, B: = 2, etc */
29
    mov si, buff      /* append cur dir to buffer */
29
    mov si, buff      /* append cur dir to buffer */
30
    add si, 3         /* skip the present drive:\ prefix */
30
    add si, 3         /* skip the present drive:\ prefix */
31
    int 0x21
31
    int 0x21
32
    jnc DONE
32
    jnc DONE
33
    mov [r], ax       /* copy result from ax */
33
    mov [r], ax       /* copy result from ax */
34
    DONE:
34
    DONE:
35
    pop dx
35
    pop dx
36
    pop ax
36
    pop ax
37
    pop si
37
    pop si
38
  }
38
  }
39
 
39
 
40
  return(r);
40
  return(r);
41
}
41
}
42
 
42
 
43
 
43
 
44
static int cmd_cd(struct cmd_funcparam *p) {
44
static int cmd_cd(struct cmd_funcparam *p) {
45
  char *buffptr = p->BUFFER;
45
  char *buffptr = p->BUFFER;
46
 
46
 
47
  /* two arguments max */
-
 
48
  if (p->argc > 1) {
-
 
49
    outputnl("Too many parameters");
-
 
50
    return(-1);
-
 
51
  }
-
 
52
 
-
 
53
  /* CD /? */
47
  /* CD /? */
54
  if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
48
  if (cmd_ishlp(p)) {
55
    outputnl("Displays the name of or changes the current directory.");
49
    outputnl("Displays the name of or changes the current directory.");
56
    outputnl("");
50
    outputnl("");
57
    outputnl("CHDIR [drive:][path]");
51
    outputnl("CHDIR [drive:][path]");
58
    outputnl("CHDIR[..]");
52
    outputnl("CHDIR[..]");
59
    outputnl("CD [drive:][path]");
53
    outputnl("CD [drive:][path]");
60
    outputnl("CD[..]");
54
    outputnl("CD[..]");
61
    outputnl("");
55
    outputnl("");
62
    outputnl(".. Specifies that you want to change to the parent directory.");
56
    outputnl(".. Specifies that you want to change to the parent directory.");
63
    outputnl("");
57
    outputnl("");
64
    outputnl("Type CD drive: to display the current directory in the specified drive.");
58
    outputnl("Type CD drive: to display the current directory in the specified drive.");
65
    outputnl("Type CD without parameters to display the current drive and directory.");
59
    outputnl("Type CD without parameters to display the current drive and directory.");
66
    return(-1);
60
    return(-1);
-
 
61
  }
-
 
62
 
-
 
63
  /* one argument max */
-
 
64
  if (p->argc > 1) {
-
 
65
    outputnl("Too many parameters");
-
 
66
    return(-1);
67
  }
67
  }
68
 
68
 
69
  /* no argument? display current drive and dir ("CWD") */
69
  /* no argument? display current drive and dir ("CWD") */
70
  if (p->argc == 0) {
70
  if (p->argc == 0) {
71
    unsigned char drv = 0;
71
    unsigned char drv = 0;
72
 
72
 
73
    _asm {
73
    _asm {
74
      push ax
74
      push ax
75
      push dx
75
      push dx
76
      push si
76
      push si
77
      mov ah, 0x19  /* get current default drive */
77
      mov ah, 0x19  /* get current default drive */
78
      int 0x21      /* al = drive (00h = A:, 01h = B:, etc) */
78
      int 0x21      /* al = drive (00h = A:, 01h = B:, etc) */
79
      inc al        /* convert to 1=A, 2=B, etc */
79
      inc al        /* convert to 1=A, 2=B, etc */
80
      mov [drv], al
80
      mov [drv], al
81
    }
81
    }
82
 
82
 
83
    cmd_cd_curpathfordrv(buffptr, drv);
83
    cmd_cd_curpathfordrv(buffptr, drv);
84
    outputnl(buffptr);
84
    outputnl(buffptr);
85
 
85
 
86
    return(-1);
86
    return(-1);
87
  }
87
  }
88
 
88
 
89
  /* argument can be either a drive (D:) or a path */
89
  /* argument can be either a drive (D:) or a path */
90
  if (p->argc == 1) {
90
  if (p->argc == 1) {
91
    const char *arg = p->argv[0];
91
    const char *arg = p->argv[0];
92
    unsigned short err = 0;
92
    unsigned short err = 0;
93
    /* drive (CD B:) */
93
    /* drive (CD B:) */
94
    if ((arg[0] != '\\') && (arg[1] == ':') && (arg[2] == 0)) {
94
    if ((arg[0] != '\\') && (arg[1] == ':') && (arg[2] == 0)) {
95
      unsigned char drive = arg[0];
95
      unsigned char drive = arg[0];
96
      if (drive >= 'a') {
96
      if (drive >= 'a') {
97
        drive -= ('a' - 1);
97
        drive -= ('a' - 1);
98
      } else {
98
      } else {
99
        drive -= ('A' - 1);
99
        drive -= ('A' - 1);
100
      }
100
      }
101
 
101
 
102
      err = cmd_cd_curpathfordrv(buffptr, drive);
102
      err = cmd_cd_curpathfordrv(buffptr, drive);
103
      if (err == 0) outputnl(buffptr);
103
      if (err == 0) outputnl(buffptr);
104
    } else { /* path */
104
    } else { /* path */
105
      _asm {
105
      _asm {
106
        push dx
106
        push dx
107
        push ax
107
        push ax
108
        mov ah, 0x3B  /* CHDIR (set current directory) */
108
        mov ah, 0x3B  /* CHDIR (set current directory) */
109
        mov dx, arg
109
        mov dx, arg
110
        int 0x21
110
        int 0x21
111
        jnc DONE
111
        jnc DONE
112
        mov [err], ax
112
        mov [err], ax
113
        DONE:
113
        DONE:
114
        pop ax
114
        pop ax
115
        pop dx
115
        pop dx
116
      }
116
      }
117
    }
117
    }
118
    if (err != 0) {
118
    if (err != 0) {
119
      outputnl(doserr(err));
119
      outputnl(doserr(err));
120
    }
120
    }
121
  }
121
  }
122
 
122
 
123
  return(-1);
123
  return(-1);
124
}
124
}
125
 
125