1    | /*****
2    |  ** ** Module Header ******************************************************* **
3    |  ** 									     **
4    |  **   Modules Revision 3.0						     **
5    |  **   Providing a flexible user environment				     **
6    |  ** 									     **
7    |  **   File:		cmdAlias.c					     **
8    |  **   First Edition:	1991/10/23					     **
9    |  ** 									     **
10   |  **   Authors:	John Furlan, jlf@behere.com				     **
11   |  **		Jens Hamisch, jens@Strawberry.COM			     **
12   |  ** 									     **
13   |  **   Description:	The Tcl set-alias command			     **
14   |  ** 									     **
15   |  **   Exports:		cmdSetAlias					     **
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   | 
29   | static char Id[] = "@(#)$Id: cmdAlias.c.src.html,v 1.6 2006/01/18 05:35:11 rkowen Exp $";
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[] = "cmdAlias.c";	/** File name of this module **/
61   | #if WITH_DEBUGGING_CALLBACK
62   | static	char	_proc_cmdSetAlias[] = "cmdSetAlias";
63   | #endif
64   | 
65   | /** ************************************************************************ **/
66   | /**				    PROTOTYPES				     **/
67   | /** ************************************************************************ **/
68   | 
69   | /** not applicable **/
70   | 
71   | 
72   | /*++++
73   |  ** ** Function-Header ***************************************************** **
74   |  ** 									     **
75   |  **   Function:		cmdSetAlias					     **
76   |  ** 									     **
77   |  **   Description:	Callback function for (re)setting aliases	     **
78   |  ** 									     **
79   |  **   First Edition:	1991/10/23					     **
80   |  ** 									     **
81   |  **   Parameters:	ClientData	 client_data			     **
82   |  **			Tcl_Interp	*interp		According Tcl interp.**
83   |  **			int		 argc		Number of arguments  **
84   |  **			char		*argv[]		Argument array	     **
85   |  ** 									     **
86   |  **   Result:		int	TCL_OK		Successfull completion	     **
87   |  **				TCL_ERROR	Any error		     **
88   |  ** 									     **
89   |  **   Attached Globals:	g_flags		These are set up accordingly before  **
90   |  **					this function is called in order to  **
91   |  **					control everything		     **
92   |  ** 									     **
93   |  ** ************************************************************************ **
94   |  ++++*/
95   | 
96   | int cmdSetAlias( ClientData	 client_data,
97   | 	  	 Tcl_Interp	*interp,
98   | 	  	 int 		 argc,
99   | 	  	 CONST84 char	*argv[])
100  | {
101  | 
102  | #if WITH_DEBUGGING_CALLBACK
103  |     ErrorLogger( NO_ERR_START, LOC, _proc_cmdSetAlias, NULL);
104  | #endif
105  | 
106  |     /**
107  |      **  Whatis mode?
108  |      **/
109  | 
110  |     if( g_flags & (M_WHATIS | M_HELP)) 
111  |         return( TCL_OK);		/** ------- EXIT PROCEDURE -------> **/
112  | 	
113  |     /**
114  |      **  Parameter check. Valid commands are:
115  |      **
116  |      **     unset-alias <alias>
117  |      **     set-alias <alias> <value>
118  |      **/
119  | 
120  |     if( (!strncmp( argv[0], "un", 2) && (argc != 2)) ||
121  |         (!strncmp( argv[0], "set", 3) && (argc != 3))) {
122  | 	if( OK != ErrorLogger( ERR_USAGE, LOC, argv[0], "variable", NULL))
123  | 	    return( TCL_ERROR);		/** -------- EXIT (FAILURE) -------> **/
124  |     }
125  | 
126  |     /**
127  |      **  Display only mode?
128  |      **/
129  | 
130  |     if( g_flags & M_DISPLAY) {
131  | 	fprintf( stderr, "%s\t ", argv[ 0]);
132  | 	while( --argc)
133  | 	    fprintf( stderr, "%s ", *++argv);
134  | 	fprintf( stderr, "\n");
135  |         return( TCL_OK);		/** ------- EXIT PROCEDURE -------> **/
136  |     }
137  | 
138  |     /**
139  |      **  Switch command
140  |      **/
141  | 
142  |     if( g_flags & M_SWSTATE1) {
143  |         set_marked_entry(markAliasHashTable, (char *) argv[1], M_SWSTATE1);
144  |         return( TCL_OK);		/** ------- EXIT PROCEDURE -------> **/
145  |     } else if( g_flags & M_SWSTATE2) {
146  |         set_marked_entry(markAliasHashTable, (char *) argv[1], M_SWSTATE2);
147  |     } else if( g_flags & M_SWSTATE3) {
148  |         int marked_val;
149  |         if(marked_val = chk_marked_entry(markAliasHashTable,(char *) argv[1])) {
150  |             if( marked_val == M_SWSTATE1)
151  |                 store_hash_value(aliasUnsetHashTable, argv[1], argv[2]);
152  |             else
153  | 		return( TCL_OK);	/** ------- EXIT PROCEDURE -------> **/
154  |       }
155  |     } else if( g_flags & M_REMOVE) {
156  |         store_hash_value( aliasUnsetHashTable, argv[1], argv[2]);
157  |     }
158  | 
159  |     /**
160  |      **  Finally remove or set the alias
161  |      **/
162  | 
163  |     if( *argv[0] == 'u' || (g_flags & M_REMOVE))
164  |         store_hash_value( aliasUnsetHashTable, argv[1], argv[2]);
165  |     else
166  |         store_hash_value( aliasSetHashTable, argv[1], argv[2]);
167  |   
168  | #if WITH_DEBUGGING_CALLBACK
169  |     ErrorLogger( NO_ERR_END, LOC, _proc_cmdSetAlias, NULL);
170  | #endif
171  | 
172  |     return( TCL_OK);
173  | 
174  | } /** End of 'cmdSetAlias' **/