Subversion Repositories SvarDOS

Rev

Rev 538 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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