01: /*
02: * CdCmd.java
03: *
04: * This file contains the Jacl implementation of the built-in Tcl "cd"
05: * command.
06: *
07: * Copyright (c) 1997 Sun Microsystems, Inc.
08: *
09: * See the file "license.terms" for information on usage and
10: * redistribution of this file, and for a DISCLAIMER OF ALL
11: * WARRANTIES.
12: *
13: * RCS: @(#) $Id: CdCmd.java,v 1.2 1999/05/08 23:53:08 dejong Exp $
14: *
15: */
16:
17: package tcl.lang;
18:
19: import java.io.*;
20:
21: // This class implements the built-in "cd" command in Tcl.
22:
23: class CdCmd implements Command {
24:
25: /*
26: *-----------------------------------------------------------------------------
27: *
28: * cmdProc --
29: *
30: * This procedure is invoked to process the "cd" Tcl command.
31: * See the user documentation for details on what it does.
32: *
33: * Results:
34: * None.
35: *
36: * Side effects:
37: * See the user documentation.
38: *
39: *-----------------------------------------------------------------------------
40: */
41:
42: public void cmdProc(Interp interp, // Current interp to eval the file cmd.
43: TclObject argv[]) // Args passed to the file command.
44: throws TclException {
45: String dirName;
46:
47: if (argv.length > 2) {
48: throw new TclNumArgsException(interp, 1, argv, "?dirName?");
49: }
50:
51: if (argv.length == 1) {
52: dirName = "~";
53: } else {
54: dirName = argv[1].toString();
55: }
56: if ((JACL.PLATFORM == JACL.PLATFORM_WINDOWS)
57: && (dirName.length() == 2)
58: && (dirName.charAt(1) == ':')) {
59: dirName = dirName + "/";
60: }
61:
62: // Set the interp's working dir.
63:
64: interp.setWorkingDir(dirName);
65: }
66:
67: } // end CdCmd class
|