~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
/*****
 ** ** Module Header ******************************************************* **
 ** 									     **
 **   Modules Revision 3.0						     **
 **   Providing a flexible user environment				     **
 ** 									     **
 **   File:		cmdAlias.c					     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Authors:	John Furlan, jlf@behere.com				     **
 **		Jens Hamisch, jens@Strawberry.COM			     **
 ** 									     **
 **   Description:	The Tcl set-alias command			     **
 ** 									     **
 **   Exports:		cmdSetAlias					     **
 ** 									     **
 **   Notes:								     **
 ** 									     **
 ** ************************************************************************ **
 ****/

/** ** Copyright *********************************************************** **
 ** 									     **
 ** Copyright 1991-1994 by John L. Furlan.                      	     **
 ** see LICENSE.GPL, which must be provided, for details		     **
 ** 									     ** 
 ** ************************************************************************ **/

static char Id[] = "@(#)$Id: cmdAlias.c,v 1.4.22.1 2010/11/11 18:23:18 rkowen Exp $";
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[] = "cmdAlias.c";	/** File name of this module **/
#if WITH_DEBUGGING_CALLBACK
static	char	_proc_cmdSetAlias[] = "cmdSetAlias";
#endif

/** ************************************************************************ **/
/**				    PROTOTYPES				     **/
/** ************************************************************************ **/

/** not applicable **/


/*++++
 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		cmdSetAlias					     **
 ** 									     **
 **   Description:	Callback function for (re)setting aliases	     **
 ** 									     **
 **   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 cmdSetAlias( ClientData	 client_data,
	  	 Tcl_Interp	*interp,
	  	 int 		 argc,
	  	 CONST84 char	*argv[])
{

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

    /**
     **  Whatis mode?
     **/

    if( g_flags & (M_WHATIS | M_HELP)) 
        return( TCL_OK);		/** ------- EXIT PROCEDURE -------> **/
	
    /**
     **  Parameter check. Valid commands are:
     **
     **     unset-alias <alias>
     **     set-alias <alias> <value>
     **/

    if( (!strncmp( argv[0], "un", 2) && (argc != 2)) ||
        (!strncmp( argv[0], "set", 3) && (argc != 3))) {
	if( OK != ErrorLogger( ERR_USAGE, LOC, argv[0], "variable", NULL))
	    return( TCL_ERROR);		/** -------- EXIT (FAILURE) -------> **/
    }

    /**
     **  Display only 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 -------> **/
    }

    /**
     **  Switch command
     **/

    if( g_flags & M_SWSTATE1) {
        set_marked_entry(markAliasHashTable, (char *) argv[1], M_SWSTATE1);
        return( TCL_OK);		/** ------- EXIT PROCEDURE -------> **/
    } else if( g_flags & M_SWSTATE2) {
        set_marked_entry(markAliasHashTable, (char *) argv[1], M_SWSTATE2);
    } else if( g_flags & M_SWSTATE3) {
        int marked_val;
        if(marked_val = chk_marked_entry(markAliasHashTable,(char *) argv[1])) {
            if( marked_val == M_SWSTATE1)
                store_hash_value(aliasUnsetHashTable, argv[1], argv[2]);
            else
		return( TCL_OK);	/** ------- EXIT PROCEDURE -------> **/
      }
    } else if( g_flags & M_REMOVE) {
        store_hash_value( aliasUnsetHashTable, argv[1], argv[2]);
    }

    /**
     **  Finally remove or set the alias
     **/

    if( *argv[0] == 'u' || (g_flags & M_REMOVE))
        store_hash_value( aliasUnsetHashTable, argv[1], argv[2]);
    else
        store_hash_value( aliasSetHashTable, argv[1], argv[2]);
  
#if WITH_DEBUGGING_CALLBACK
    ErrorLogger( NO_ERR_END, LOC, _proc_cmdSetAlias, NULL);
#endif

    return( TCL_OK);

} /** End of 'cmdSetAlias' **/