Subversion Repositories SvarDOS

Rev

Rev 416 | Rev 533 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
421 mateuszvis 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
 
363 mateuszvis 25
/*
26
 * chdir
27
 *
28
 * displays the name of or changes the current directory.
29
 *
30
 * CHDIR [drive:][path]
31
 * CD..
32
 *
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.
35
 */
36
 
375 mateuszvis 37
 
372 mateuszvis 38
static int cmd_cd(struct cmd_funcparam *p) {
374 mateuszvis 39
  char *buffptr = p->BUFFER;
40
 
41
  /* CD /? */
387 mateuszvis 42
  if (cmd_ishlp(p)) {
374 mateuszvis 43
    outputnl("Displays the name of or changes the current directory.");
44
    outputnl("");
45
    outputnl("CHDIR [drive:][path]");
46
    outputnl("CHDIR[..]");
47
    outputnl("CD [drive:][path]");
48
    outputnl("CD[..]");
49
    outputnl("");
50
    outputnl(".. Specifies that you want to change to the parent directory.");
51
    outputnl("");
52
    outputnl("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.");
54
    return(-1);
55
  }
56
 
387 mateuszvis 57
  /* one argument max */
58
  if (p->argc > 1) {
59
    outputnl("Too many parameters");
60
    return(-1);
61
  }
62
 
363 mateuszvis 63
  /* no argument? display current drive and dir ("CWD") */
364 mateuszvis 64
  if (p->argc == 0) {
416 mateuszvis 65
    curpathfordrv(buffptr, 0);
374 mateuszvis 66
    outputnl(buffptr);
67
    return(-1);
363 mateuszvis 68
  }
69
 
70
  /* argument can be either a drive (D:) or a path */
364 mateuszvis 71
  if (p->argc == 1) {
72
    const char *arg = p->argv[0];
73
    unsigned short err = 0;
363 mateuszvis 74
    /* drive (CD B:) */
364 mateuszvis 75
    if ((arg[0] != '\\') && (arg[1] == ':') && (arg[2] == 0)) {
76
      unsigned char drive = arg[0];
363 mateuszvis 77
      if (drive >= 'a') {
375 mateuszvis 78
        drive -= ('a' - 1);
363 mateuszvis 79
      } else {
375 mateuszvis 80
        drive -= ('A' - 1);
363 mateuszvis 81
      }
375 mateuszvis 82
 
416 mateuszvis 83
      err = curpathfordrv(buffptr, drive);
375 mateuszvis 84
      if (err == 0) outputnl(buffptr);
363 mateuszvis 85
    } else { /* path */
86
      _asm {
87
        push dx
88
        push ax
89
        mov ah, 0x3B  /* CHDIR (set current directory) */
364 mateuszvis 90
        mov dx, arg
363 mateuszvis 91
        int 0x21
92
        jnc DONE
93
        mov [err], ax
94
        DONE:
95
        pop ax
96
        pop dx
97
      }
98
    }
369 mateuszvis 99
    if (err != 0) {
100
      outputnl(doserr(err));
101
    }
363 mateuszvis 102
  }
103
 
104
  return(-1);
105
}