-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmdChdir.c
101 lines (80 loc) · 3.16 KB
/
cmdChdir.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*****
** ** Module Header ******************************************************* **
** **
** File: cmdChdir.c **
** First Edition: 2009-06-27 **
** **
** Authors: Gerrit Renker **
** R.K. Owen, <[email protected]> or <[email protected]> **
** **
** Description: Implements a "chdir" command to set the working **
** directory upon module load/switch. **
** **
** Exports: cmdChDir **
** **
** Attached Globals: g_flags These are set up accordingly before **
** this function is called in order to **
** control everything **
** change_dir Communicates the target directory. **
** ************************************************************************ **
****/
static char Id[] = "@(#)$Id$";
static void *UseId[] = { &UseId, Id };
/** ************************************************************************ **/
/** HEADERS **/
/** ************************************************************************ **/
#include "modules_def.h"
/** ************************************************************************ **/
/** LOCAL DATATYPES **/
/** ************************************************************************ **/
char *change_dir = NULL;
/** ************************************************************************ **/
/** CONSTANTS **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** MACROS **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** LOCAL DATA **/
/** ************************************************************************ **/
static char module_name[] = __FILE__;
/** ************************************************************************ **/
/** PROTOTYPES **/
/** ************************************************************************ **/
/** not applicable **/
int cmdChDir(
ClientData client_data,
Tcl_Interp * interp,
int objc,
Tcl_Obj * CONST84 objv[]
) {
char *dir; /** directory name **/
if (g_flags & ~(M_LOAD | M_SWSTATE2 | M_SUBCMD))
return TCL_OK;
if (objc != 2) {
if (OK != ErrorLogger(ERR_USAGE, LOC, Tcl_GetString(objv[0]),
" directory", NULL))
return (TCL_ERROR); /** ------ EXIT (FAILURE) -----> **/
}
if (g_flags & M_NONPERSIST)
return TCL_OK;
if (g_flags & M_DISPLAY) {
fprintf(stderr, "%s\t%s\n", Tcl_GetString(objv[0]),
Tcl_GetString(objv[1]));
return TCL_OK;
}
/* check for directory existence */
/* It is not an error if we can not ... */
dir = Tcl_GetString(objv[1]);
if (!is_("dir",dir)) {
ErrorLogger(ERR_CHDIR, LOC, dir, g_current_module, NULL);
return (TCL_OK); /** ------ EXIT PROCEDURE -----> **/
}
/* The actual work happens here */
if (change_dir != NULL)
null_free((void *) &change_dir);
change_dir = stringer(NULL, 0, dir, NULL);
return TCL_OK;
}