1
by Alastair McKinstry
Import upstream version 3.2.9c |
1 |
/*****
|
2 |
** ** Module Header ******************************************************* **
|
|
3 |
** **
|
|
4 |
** Modules Revision 3.0 **
|
|
5 |
** Providing a flexible user environment **
|
|
6 |
** **
|
|
7 |
** File: cmdUlvl.c **
|
|
8 |
** First Edition: 1991/10/23 **
|
|
9 |
** **
|
|
10 |
** Authors: Jens Hamisch, jens@Strawberry.COM **
|
|
11 |
** **
|
|
12 |
** Description: The Tcl module-user routine which changes the cur- **
|
|
13 |
** rent user level **
|
|
14 |
** **
|
|
15 |
** Exports: cmdModuleUser **
|
|
16 |
** **
|
|
17 |
** Notes: **
|
|
18 |
** **
|
|
19 |
** ************************************************************************ **
|
|
20 |
****/
|
|
21 |
||
22 |
/** ** Copyright *********************************************************** **
|
|
23 |
** **
|
|
24 |
** Copyright 1991-1994 by John L. Furlan. **
|
|
25 |
** see LICENSE.GPL, which must be provided, for details **
|
|
26 |
** **
|
|
27 |
** ************************************************************************ **/
|
|
28 |
||
1.1.1
by Alastair McKinstry
Import upstream version 3.2.10 |
29 |
static char Id[] = "@(#)$Id: 258acbcbc68eded9ae20ffe9239be82e30c3e49f $"; |
1
by Alastair McKinstry
Import upstream version 3.2.9c |
30 |
static void *UseId[] = { &UseId, Id }; |
31 |
||
32 |
/** ************************************************************************ **/
|
|
33 |
/** HEADERS **/
|
|
34 |
/** ************************************************************************ **/
|
|
35 |
||
36 |
#include "modules_def.h" |
|
37 |
||
38 |
/** ************************************************************************ **/
|
|
39 |
/** LOCAL DATATYPES **/
|
|
40 |
/** ************************************************************************ **/
|
|
41 |
||
42 |
/** not applicable **/
|
|
43 |
||
44 |
/** ************************************************************************ **/
|
|
45 |
/** CONSTANTS **/
|
|
46 |
/** ************************************************************************ **/
|
|
47 |
||
48 |
/** not applicable **/
|
|
49 |
||
50 |
/** ************************************************************************ **/
|
|
51 |
/** MACROS **/
|
|
52 |
/** ************************************************************************ **/
|
|
53 |
||
54 |
/** not applicable **/
|
|
55 |
||
56 |
/** ************************************************************************ **/
|
|
57 |
/** LOCAL DATA **/
|
|
58 |
/** ************************************************************************ **/
|
|
59 |
||
60 |
static char module_name[] = "cmdUlvl.c"; /** File name of this module **/ |
|
61 |
#if WITH_DEBUGGING_CALLBACK
|
|
62 |
static char _proc_cmdModuleUser[] = "cmdModuleUser"; |
|
63 |
#endif
|
|
64 |
#if WITH_DEBUGGING_CALLBACK_1
|
|
65 |
static char _proc_cmdModuleUser_sub[] = "cmdModuleUser_sub"; |
|
66 |
#endif
|
|
67 |
||
68 |
/**
|
|
69 |
** names for the user level
|
|
70 |
**/
|
|
71 |
||
72 |
static char _str_ul_novice[] = "novice"; |
|
73 |
static char _str_ul_advanced[] = "advanced"; |
|
74 |
static char _str_ul_expert[] = "expert"; |
|
75 |
||
76 |
/** ************************************************************************ **/
|
|
77 |
/** PROTOTYPES **/
|
|
78 |
/** ************************************************************************ **/
|
|
79 |
||
80 |
/** not applicable **/
|
|
81 |
||
82 |
||
83 |
/*++++
|
|
84 |
** ** Function-Header ***************************************************** **
|
|
85 |
** **
|
|
86 |
** Function: cmdModuleUser **
|
|
87 |
** **
|
|
88 |
** Description: Callback function for 'info' **
|
|
89 |
** **
|
|
90 |
** First Edition: 1991/10/23 **
|
|
91 |
** **
|
|
92 |
** Parameters: ClientData client_data **
|
|
93 |
** Tcl_Interp *interp According Tcl interp.**
|
|
94 |
** int argc Number of arguments **
|
|
95 |
** char *argv[] Argument array **
|
|
96 |
** **
|
|
97 |
** Result: int TCL_OK Successful completion **
|
|
98 |
** TCL_ERROR Any error **
|
|
99 |
** **
|
|
100 |
** Attached Globals: g_flags These are set up accordingly before **
|
|
101 |
** this function is called in order to **
|
|
102 |
** control everything **
|
|
103 |
** **
|
|
104 |
** ************************************************************************ **
|
|
105 |
++++*/
|
|
106 |
||
107 |
int cmdModuleUser( ClientData client_data, |
|
108 |
Tcl_Interp *interp, |
|
109 |
int argc, |
|
110 |
CONST84 char *argv[]) |
|
111 |
{
|
|
112 |
||
113 |
#if WITH_DEBUGGING_CALLBACK
|
|
114 |
ErrorLogger( NO_ERR_START, LOC, _proc_cmdModuleUser, NULL); |
|
115 |
#endif
|
|
116 |
||
117 |
/**
|
|
118 |
** Whatis mode?
|
|
119 |
**/
|
|
120 |
||
121 |
if( g_flags & (M_WHATIS | M_HELP)) |
|
122 |
return( TCL_OK); /** ------- EXIT PROCEDURE -------> **/ |
|
123 |
||
124 |
/**
|
|
125 |
** Parameter check
|
|
126 |
**/
|
|
127 |
||
128 |
if( argc < 2) { |
|
129 |
if( OK != ErrorLogger( ERR_USAGE, LOC, argv[0], "level ", NULL)) |
|
130 |
return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/ |
|
131 |
}
|
|
132 |
||
133 |
||
134 |
/**
|
|
135 |
** Non-persist mode?
|
|
136 |
**/
|
|
137 |
||
138 |
if (g_flags & M_NONPERSIST) { |
|
139 |
return (TCL_OK); |
|
140 |
}
|
|
141 |
||
142 |
/**
|
|
143 |
** Display mode?
|
|
144 |
**/
|
|
145 |
||
146 |
if( g_flags & M_DISPLAY) { |
|
147 |
fprintf( stderr, "%s\t ", argv[ 0]); |
|
148 |
while( --argc) |
|
149 |
fprintf( stderr, "%s ", *++argv); |
|
150 |
fprintf( stderr, "\n"); |
|
151 |
return( TCL_OK); /** ------- EXIT PROCEDURE -------> **/ |
|
152 |
}
|
|
153 |
||
154 |
/**
|
|
155 |
** Change the user level
|
|
156 |
**/
|
|
157 |
||
158 |
return( cmdModuleUser_sub( (char *) argv[ 1])); |
|
159 |
||
160 |
} /** End of 'cmdModuleUser' **/ |
|
161 |
||
162 |
||
163 |
/*++++
|
|
164 |
** ** Function-Header ***************************************************** **
|
|
165 |
** **
|
|
166 |
** Function: cmdModuleUser_sub **
|
|
167 |
** **
|
|
168 |
** Description: Check the user level passed as argument and set up **
|
|
169 |
** the global user level flag **
|
|
170 |
** **
|
|
171 |
** First Edition: 1991/10/23 **
|
|
172 |
** **
|
|
173 |
** Parameters: char *user_level User level string to be chk. **
|
|
174 |
** **
|
|
175 |
** Result: int TCL_OK Successful completion **
|
|
176 |
** TCL_ERROR Any error **
|
|
177 |
** **
|
|
178 |
** Attached Globals: sw_userlvl Contains the binary coded userlevel **
|
|
179 |
** **
|
|
180 |
** ************************************************************************ **
|
|
181 |
++++*/
|
|
182 |
||
183 |
int cmdModuleUser_sub( char *user_level) |
|
184 |
{
|
|
185 |
char *s; |
|
186 |
int len_arg; |
|
187 |
||
188 |
#if WITH_DEBUGGING_CALLBACK_1
|
|
189 |
ErrorLogger( NO_ERR_START, LOC, _proc_cmdModuleUser_sub, NULL); |
|
190 |
#endif
|
|
191 |
||
192 |
len_arg = strlen( user_level); |
|
193 |
s = user_level; |
|
194 |
while( s && *s) { |
|
195 |
*s = tolower( *s); |
|
196 |
s++; |
|
197 |
}
|
|
198 |
||
199 |
if( !strncmp( user_level, _str_ul_novice, len_arg)) { |
|
200 |
sw_userlvl = UL_NOVICE; |
|
201 |
} else if( !strncmp( user_level, _str_ul_advanced, len_arg)) { |
|
202 |
sw_userlvl = UL_ADVANCED; |
|
203 |
} else if( !strncmp( user_level, _str_ul_expert, len_arg)) { |
|
204 |
sw_userlvl = UL_EXPERT; |
|
205 |
} else { |
|
206 |
if( OK != ErrorLogger( ERR_USERLVL, LOC, user_level, NULL)) |
|
207 |
return( TCL_ERROR); /** ---- EXIT (FAILURE) ---> **/ |
|
208 |
}
|
|
209 |
||
210 |
/**
|
|
211 |
** Success
|
|
212 |
**/
|
|
213 |
||
214 |
#if WITH_DEBUGGING_CALLBACK_1
|
|
215 |
ErrorLogger( NO_ERR_END, LOC, _proc_cmdModuleUser_sub, NULL); |
|
216 |
#endif
|
|
217 |
||
218 |
return( TCL_OK); |
|
219 |
||
220 |
} /** End of 'cmdModuleUser_sub' **/ |