Subversion Repositories SvarDOS

Rev

Rev 538 | 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
 *
989 mateusz.vi 4
 * Copyright (C) 2021-2022 Mateusz Viste
421 mateuszvis 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
 
533 mateuszvis 38
static enum cmd_result cmd_cd(struct cmd_funcparam *p) {
374 mateuszvis 39
  char *buffptr = p->BUFFER;
40
 
41
  /* CD /? */
387 mateuszvis 42
  if (cmd_ishlp(p)) {
989 mateusz.vi 43
    nls_outputnl(12,0); /* "Displays the name of or changes the current directory." */
374 mateuszvis 44
    outputnl("");
989 mateusz.vi 45
    nls_outputnl(12,1); /* "CHDIR [drive:][path]" */
46
    nls_outputnl(12,2); /* "CHDIR[..]" */
47
    nls_outputnl(12,3); /* "CD [drive:][path]" */
48
    nls_outputnl(12,4); /* "CD[..]" */
374 mateuszvis 49
    outputnl("");
989 mateusz.vi 50
    nls_outputnl(12,5); /* ".. Specifies that you want to change to the parent directory." */
374 mateuszvis 51
    outputnl("");
989 mateusz.vi 52
    nls_outputnl(12,6); /* "Type CD drive: to display the current directory in the specified drive." */
53
    nls_outputnl(12,7); /* "Type CD without parameters to display the current drive and directory." */
533 mateuszvis 54
    return(CMD_OK);
374 mateuszvis 55
  }
56
 
387 mateuszvis 57
  /* one argument max */
58
  if (p->argc > 1) {
989 mateusz.vi 59
    nls_outputnl(0,4); /* "Too many parameters" */
533 mateuszvis 60
    return(CMD_FAIL);
387 mateuszvis 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);
533 mateuszvis 67
    return(CMD_OK);
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) {
538 mateuszvis 100
      nls_outputnl_doserr(err);
533 mateuszvis 101
      return(CMD_FAIL);
369 mateuszvis 102
    }
363 mateuszvis 103
  }
104
 
533 mateuszvis 105
  return(CMD_OK);
363 mateuszvis 106
}