Subversion Repositories SvarDOS

Rev

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

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