~ubuntu-branches/ubuntu/utopic/modules/utopic-proposed

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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*****
 ** ** 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			     **
 ** 									     **
 **   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: 258acbcbc68eded9ae20ffe9239be82e30c3e49f $";
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[] = "cmdUlvl.c";	/** File name of this module **/
#if WITH_DEBUGGING_CALLBACK
static	char	_proc_cmdModuleUser[] = "cmdModuleUser";
#endif
#if WITH_DEBUGGING_CALLBACK_1
static	char	_proc_cmdModuleUser_sub[] = "cmdModuleUser_sub";
#endif

/**
 **  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		 argc		Number of arguments  **
 **			char		*argv[]		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		 argc,
	      		CONST84 char	*argv[])
{

#if WITH_DEBUGGING_CALLBACK
    ErrorLogger( NO_ERR_START, LOC, _proc_cmdModuleUser, NULL);
#endif

    /**
     **  Whatis mode?
     **/

    if( g_flags & (M_WHATIS | M_HELP))
        return( TCL_OK);		/** ------- EXIT PROCEDURE -------> **/
	
    /**
     **  Parameter check
     **/

    if( argc < 2) {
	if( OK != ErrorLogger( ERR_USAGE, LOC, argv[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 ", argv[ 0]);
	while( --argc)
	    fprintf( stderr, "%s ", *++argv);
	fprintf( stderr, "\n");
        return( TCL_OK);		/** ------- EXIT PROCEDURE -------> **/
    }
	
    /**
     **  Change the user level
     **/

    return( cmdModuleUser_sub( (char *) argv[ 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;

#if WITH_DEBUGGING_CALLBACK_1
    ErrorLogger( NO_ERR_START, LOC, _proc_cmdModuleUser_sub, NULL);
#endif

    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
     **/

#if WITH_DEBUGGING_CALLBACK_1
    ErrorLogger( NO_ERR_END, LOC, _proc_cmdModuleUser_sub, NULL);
#endif

    return( TCL_OK);

} /** End of 'cmdModuleUser_sub' **/