Subversion Repositories SvarDOS

Rev

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

Rev 416 Rev 421
-
 
1
/* This file is part of the SvarCOM project and is published under the terms
-
 
2
 * of the MIT license.
-
 
3
 *
-
 
4
 * Copyright (C) 2021 Mateusz Viste
-
 
5
 *
-
 
6
 * Permission is hereby granted, free of charge, to any person obtaining a
-
 
7
 * copy of this software and associated documentation files (the "Software"),
-
 
8
 * to deal in the Software without restriction, including without limitation
-
 
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
-
 
10
 * and/or sell copies of the Software, and to permit persons to whom the
-
 
11
 * Software is furnished to do so, subject to the following conditions:
-
 
12
 *
-
 
13
 * The above copyright notice and this permission notice shall be included in
-
 
14
 * all copies or substantial portions of the Software.
-
 
15
 *
-
 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-
 
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-
 
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-
 
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-
 
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-
 
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-
 
22
 * DEALINGS IN THE SOFTWARE.
-
 
23
 */
-
 
24
 
1
/*
25
/*
2
 * chdir
26
 * chdir
3
 *
27
 *
4
 * displays the name of or changes the current directory.
28
 * displays the name of or changes the current directory.
5
 *
29
 *
6
 * CHDIR [drive:][path]
30
 * CHDIR [drive:][path]
7
 * CD..
31
 * CD..
8
 *
32
 *
9
 * Type CD drive: to display the current directory in the specified drive.
33
 * Type CD drive: to display the current directory in the specified drive.
10
 * Type CD without parameters to display the current drive and directory.
34
 * Type CD without parameters to display the current drive and directory.
11
 */
35
 */
12
 
36
 
13
 
37
 
14
static int cmd_cd(struct cmd_funcparam *p) {
38
static int cmd_cd(struct cmd_funcparam *p) {
15
  char *buffptr = p->BUFFER;
39
  char *buffptr = p->BUFFER;
16
 
40
 
17
  /* CD /? */
41
  /* CD /? */
18
  if (cmd_ishlp(p)) {
42
  if (cmd_ishlp(p)) {
19
    outputnl("Displays the name of or changes the current directory.");
43
    outputnl("Displays the name of or changes the current directory.");
20
    outputnl("");
44
    outputnl("");
21
    outputnl("CHDIR [drive:][path]");
45
    outputnl("CHDIR [drive:][path]");
22
    outputnl("CHDIR[..]");
46
    outputnl("CHDIR[..]");
23
    outputnl("CD [drive:][path]");
47
    outputnl("CD [drive:][path]");
24
    outputnl("CD[..]");
48
    outputnl("CD[..]");
25
    outputnl("");
49
    outputnl("");
26
    outputnl(".. Specifies that you want to change to the parent directory.");
50
    outputnl(".. Specifies that you want to change to the parent directory.");
27
    outputnl("");
51
    outputnl("");
28
    outputnl("Type CD drive: to display the current directory in the specified drive.");
52
    outputnl("Type CD drive: to display the current directory in the specified drive.");
29
    outputnl("Type CD without parameters to display the current drive and directory.");
53
    outputnl("Type CD without parameters to display the current drive and directory.");
30
    return(-1);
54
    return(-1);
31
  }
55
  }
32
 
56
 
33
  /* one argument max */
57
  /* one argument max */
34
  if (p->argc > 1) {
58
  if (p->argc > 1) {
35
    outputnl("Too many parameters");
59
    outputnl("Too many parameters");
36
    return(-1);
60
    return(-1);
37
  }
61
  }
38
 
62
 
39
  /* no argument? display current drive and dir ("CWD") */
63
  /* no argument? display current drive and dir ("CWD") */
40
  if (p->argc == 0) {
64
  if (p->argc == 0) {
41
    curpathfordrv(buffptr, 0);
65
    curpathfordrv(buffptr, 0);
42
    outputnl(buffptr);
66
    outputnl(buffptr);
43
    return(-1);
67
    return(-1);
44
  }
68
  }
45
 
69
 
46
  /* argument can be either a drive (D:) or a path */
70
  /* argument can be either a drive (D:) or a path */
47
  if (p->argc == 1) {
71
  if (p->argc == 1) {
48
    const char *arg = p->argv[0];
72
    const char *arg = p->argv[0];
49
    unsigned short err = 0;
73
    unsigned short err = 0;
50
    /* drive (CD B:) */
74
    /* drive (CD B:) */
51
    if ((arg[0] != '\\') && (arg[1] == ':') && (arg[2] == 0)) {
75
    if ((arg[0] != '\\') && (arg[1] == ':') && (arg[2] == 0)) {
52
      unsigned char drive = arg[0];
76
      unsigned char drive = arg[0];
53
      if (drive >= 'a') {
77
      if (drive >= 'a') {
54
        drive -= ('a' - 1);
78
        drive -= ('a' - 1);
55
      } else {
79
      } else {
56
        drive -= ('A' - 1);
80
        drive -= ('A' - 1);
57
      }
81
      }
58
 
82
 
59
      err = curpathfordrv(buffptr, drive);
83
      err = curpathfordrv(buffptr, drive);
60
      if (err == 0) outputnl(buffptr);
84
      if (err == 0) outputnl(buffptr);
61
    } else { /* path */
85
    } else { /* path */
62
      _asm {
86
      _asm {
63
        push dx
87
        push dx
64
        push ax
88
        push ax
65
        mov ah, 0x3B  /* CHDIR (set current directory) */
89
        mov ah, 0x3B  /* CHDIR (set current directory) */
66
        mov dx, arg
90
        mov dx, arg
67
        int 0x21
91
        int 0x21
68
        jnc DONE
92
        jnc DONE
69
        mov [err], ax
93
        mov [err], ax
70
        DONE:
94
        DONE:
71
        pop ax
95
        pop ax
72
        pop dx
96
        pop dx
73
      }
97
      }
74
    }
98
    }
75
    if (err != 0) {
99
    if (err != 0) {
76
      outputnl(doserr(err));
100
      outputnl(doserr(err));
77
    }
101
    }
78
  }
102
  }
79
 
103
 
80
  return(-1);
104
  return(-1);
81
}
105
}
82
 
106