Subversion Repositories SvarDOS

Rev

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

Rev 364 Rev 369
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(const struct cmd_funcparam *p) {
13
static int cmd_cd(const struct cmd_funcparam *p) {
14
  /* two arguments max */
14
  /* two arguments max */
15
  if (p->argc > 1) {
15
  if (p->argc > 1) {
16
    puts("Too many parameters");
16
    outputnl("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 (p->argc == 0) {
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
26
      push si
26
      push si
27
      mov ah, 0x19  /* get current default drive */
27
      mov ah, 0x19  /* get current default drive */
28
      int 0x21      /* al = drive (00h = A:, 01h = B:, etc) */
28
      int 0x21      /* al = drive (00h = A:, 01h = B:, etc) */
29
      add al, 'A'
29
      add al, 'A'
30
      /* print drive to stdout */
30
      /* print drive to stdout */
31
      mov dl, al
31
      mov dl, al
32
      mov ah, 0x02
32
      mov ah, 0x02
33
      int 0x21
33
      int 0x21
34
      mov dl, ':'
34
      mov dl, ':'
35
      int 0x21
35
      int 0x21
36
      mov dl, '\'
36
      mov dl, '\'
37
      int 0x21
37
      int 0x21
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 si
43
      pop si
44
      pop dx
44
      pop dx
45
      pop ax
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 (p->argc == 1) {
51
  if (p->argc == 1) {
52
    const char *arg = p->argv[0];
52
    const char *arg = p->argv[0];
53
    unsigned short err = 0;
53
    unsigned short err = 0;
54
    /* drive (CD B:) */
54
    /* drive (CD B:) */
55
    if ((arg[0] != '\\') && (arg[1] == ':') && (arg[2] == 0)) {
55
    if ((arg[0] != '\\') && (arg[1] == ':') && (arg[2] == 0)) {
56
      char buff[64];
56
      char buff[64];
57
      char *buffptr = buff;
57
      char *buffptr = buff;
58
      unsigned char drive = arg[0];
58
      unsigned char drive = arg[0];
59
      if (drive >= 'a') {
59
      if (drive >= 'a') {
60
        drive -= 'a';
60
        drive -= 'a';
61
      } else {
61
      } else {
62
        drive -= 'A';
62
        drive -= 'A';
63
      }
63
      }
64
      drive++; /* A: = 1, B: = 2, etc*/
64
      drive++; /* A: = 1, B: = 2, etc*/
65
      _asm {
65
      _asm {
66
        push si
66
        push si
67
        push ax
67
        push ax
68
        push dx
68
        push dx
69
        mov ah, 0x47      /* get current directory */
69
        mov ah, 0x47      /* get current directory */
70
        mov dl, [drive]   /* A: = 1, B: = 2, etc */
70
        mov dl, [drive]   /* A: = 1, B: = 2, etc */
71
        mov si, buffptr
71
        mov si, buffptr
72
        int 0x21
72
        int 0x21
73
        jnc DONE
73
        jnc DONE
74
        mov [err], ax
74
        mov [err], ax
75
        DONE:
75
        DONE:
76
        pop dx
76
        pop dx
77
        pop ax
77
        pop ax
78
        pop si
78
        pop si
79
      }
79
      }
80
      if (err == 0) printf("%c:\\%s\r\n", drive + 'A' - 1, buff);
80
      if (err == 0) printf("%c:\\%s\r\n", drive + 'A' - 1, buff);
81
    } else { /* path */
81
    } else { /* path */
82
      _asm {
82
      _asm {
83
        push dx
83
        push dx
84
        push ax
84
        push ax
85
        mov ah, 0x3B  /* CHDIR (set current directory) */
85
        mov ah, 0x3B  /* CHDIR (set current directory) */
86
        mov dx, arg
86
        mov dx, arg
87
        int 0x21
87
        int 0x21
88
        jnc DONE
88
        jnc DONE
89
        mov [err], ax
89
        mov [err], ax
90
        DONE:
90
        DONE:
91
        pop ax
91
        pop ax
92
        pop dx
92
        pop dx
93
      }
93
      }
94
    }
94
    }
-
 
95
    if (err != 0) {
95
    if (err != 0) puts(doserr(err));
96
      outputnl(doserr(err));
-
 
97
    }
96
  }
98
  }
97
 
99
 
98
  return(-1);
100
  return(-1);
99
}
101
}
100
 
102