-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmdUlvl.c
196 lines (168 loc) · 5.93 KB
/
cmdUlvl.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*****
** ** Module Header ******************************************************* **
** **
** Modules Revision 3.0 **
** Providing a flexible user environment **
** **
** File: cmdUlvl.c **
** First Edition: 1991/10/23 **
** **
** Authors: Jens Hamisch, jens@Strawberry.COM **
** R.K. Owen, <rk@owen.sj.ca.us> or <rkowen@nersc.gov> **
** **
** Description: The Tcl module-user routine which changes the cur- **
** rent user level **
** **
** Exports: cmdModuleUser **
** **
** Notes: **
** **
** ************************************************************************ **
****/
/** ** Copyright *********************************************************** **
** **
** Copyright 1991-1994 by John L. Furlan. **
** see LICENSE.GPL, which must be provided, for details **
** **
** ************************************************************************ **/
static char Id[] = "@(#)$Id$";
static void *UseId[] = { &UseId, Id };
/** ************************************************************************ **/
/** HEADERS **/
/** ************************************************************************ **/
#include "modules_def.h"
/** ************************************************************************ **/
/** LOCAL DATATYPES **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** CONSTANTS **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** MACROS **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** LOCAL DATA **/
/** ************************************************************************ **/
static char module_name[] = __FILE__;
/**
** names for the user level
**/
static char _str_ul_novice[] = "novice";
static char _str_ul_advanced[] = "advanced";
static char _str_ul_expert[] = "expert";
/** ************************************************************************ **/
/** PROTOTYPES **/
/** ************************************************************************ **/
/** not applicable **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: cmdModuleUser **
** **
** Description: Callback function for 'info' **
** **
** First Edition: 1991/10/23 **
** **
** Parameters: ClientData client_data **
** Tcl_Interp *interp According Tcl interp.**
** int objc Number of arguments **
** Tcl_Obj *objv[] Argument array **
** **
** Result: int TCL_OK Successful completion **
** TCL_ERROR Any error **
** **
** Attached Globals: g_flags These are set up accordingly before **
** this function is called in order to **
** control everything **
** **
** ************************************************************************ **
++++*/
int cmdModuleUser(
ClientData client_data,
Tcl_Interp * interp,
int objc,
Tcl_Obj * CONST84 objv[]
) {
/**
** Whatis mode?
**/
if (g_flags & (M_WHATIS | M_HELP))
return (TCL_OK); /** ------- EXIT PROCEDURE -------> **/
/**
** Parameter check
**/
if (objc < 2) {
if (OK !=
ErrorLogger(ERR_USAGE, LOC, Tcl_GetString(objv[0]),
"level ", NULL))
return (TCL_ERROR);
/** -------- EXIT (FAILURE) -------> **/
}
/**
** Non-persist mode?
**/
if (g_flags & M_NONPERSIST) {
return (TCL_OK);
}
/**
** Display mode?
**/
if (g_flags & M_DISPLAY) {
fprintf(stderr, "%s\t ", Tcl_GetString(*objv++));
while (--objc)
fprintf(stderr, "%s ", Tcl_GetString(*objv++));
fprintf(stderr, "\n");
return (TCL_OK); /** ------- EXIT PROCEDURE -------> **/
}
/**
** Change the user level
**/
return (cmdModuleUser_sub((char *)Tcl_GetString(objv[1])));
} /** End of 'cmdModuleUser' **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: cmdModuleUser_sub **
** **
** Description: Check the user level passed as argument and set up **
** the global user level flag **
** **
** First Edition: 1991/10/23 **
** **
** Parameters: char *user_level User level string to be chk. **
** **
** Result: int TCL_OK Successful completion **
** TCL_ERROR Any error **
** **
** Attached Globals: sw_userlvl Contains the binary coded userlevel **
** **
** ************************************************************************ **
++++*/
int cmdModuleUser_sub( char *user_level)
{
char *s;
int len_arg;
len_arg = strlen( user_level);
s = user_level;
while( s && *s) {
*s = tolower( *s);
s++;
}
if( !strncmp( user_level, _str_ul_novice, len_arg)) {
sw_userlvl = UL_NOVICE;
} else if( !strncmp( user_level, _str_ul_advanced, len_arg)) {
sw_userlvl = UL_ADVANCED;
} else if( !strncmp( user_level, _str_ul_expert, len_arg)) {
sw_userlvl = UL_EXPERT;
} else {
if( OK != ErrorLogger( ERR_USERLVL, LOC, user_level, NULL))
return( TCL_ERROR); /** ---- EXIT (FAILURE) ---> **/
}
/**
** Success
**/
return( TCL_OK);
} /** End of 'cmdModuleUser_sub' **/