Subversion Repositories SvarDOS

Rev

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

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