Subversion Repositories SvarDOS

Rev

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

Rev Author Line No. Line
363 mateuszvis 1
/*
2
 * chdir
3
 *
4
 * displays the name of or changes the current directory.
5
 *
6
 * CHDIR [drive:][path]
7
 * CD..
8
 *
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.
11
 */
12
 
375 mateuszvis 13
 
372 mateuszvis 14
static int cmd_cd(struct cmd_funcparam *p) {
374 mateuszvis 15
  char *buffptr = p->BUFFER;
16
 
17
  /* CD /? */
387 mateuszvis 18
  if (cmd_ishlp(p)) {
374 mateuszvis 19
    outputnl("Displays the name of or changes the current directory.");
20
    outputnl("");
21
    outputnl("CHDIR [drive:][path]");
22
    outputnl("CHDIR[..]");
23
    outputnl("CD [drive:][path]");
24
    outputnl("CD[..]");
25
    outputnl("");
26
    outputnl(".. Specifies that you want to change to the parent directory.");
27
    outputnl("");
28
    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.");
30
    return(-1);
31
  }
32
 
387 mateuszvis 33
  /* one argument max */
34
  if (p->argc > 1) {
35
    outputnl("Too many parameters");
36
    return(-1);
37
  }
38
 
363 mateuszvis 39
  /* no argument? display current drive and dir ("CWD") */
364 mateuszvis 40
  if (p->argc == 0) {
416 mateuszvis 41
    curpathfordrv(buffptr, 0);
374 mateuszvis 42
    outputnl(buffptr);
43
    return(-1);
363 mateuszvis 44
  }
45
 
46
  /* argument can be either a drive (D:) or a path */
364 mateuszvis 47
  if (p->argc == 1) {
48
    const char *arg = p->argv[0];
49
    unsigned short err = 0;
363 mateuszvis 50
    /* drive (CD B:) */
364 mateuszvis 51
    if ((arg[0] != '\\') && (arg[1] == ':') && (arg[2] == 0)) {
52
      unsigned char drive = arg[0];
363 mateuszvis 53
      if (drive >= 'a') {
375 mateuszvis 54
        drive -= ('a' - 1);
363 mateuszvis 55
      } else {
375 mateuszvis 56
        drive -= ('A' - 1);
363 mateuszvis 57
      }
375 mateuszvis 58
 
416 mateuszvis 59
      err = curpathfordrv(buffptr, drive);
375 mateuszvis 60
      if (err == 0) outputnl(buffptr);
363 mateuszvis 61
    } else { /* path */
62
      _asm {
63
        push dx
64
        push ax
65
        mov ah, 0x3B  /* CHDIR (set current directory) */
364 mateuszvis 66
        mov dx, arg
363 mateuszvis 67
        int 0x21
68
        jnc DONE
69
        mov [err], ax
70
        DONE:
71
        pop ax
72
        pop dx
73
      }
74
    }
369 mateuszvis 75
    if (err != 0) {
76
      outputnl(doserr(err));
77
    }
363 mateuszvis 78
  }
79
 
80
  return(-1);
81
}