1 | /*****
2 | ** ** Module Header ******************************************************* **
3 | ** **
4 | ** Modules Revision 3.0 **
5 | ** Providing a flexible user environment **
6 | ** **
7 | ** File: ModuleCmd_Help.c **
8 | ** First Edition: 1991/10/23 **
9 | ** **
10 | ** Authors: John Furlan, jlf@behere.com **
11 | ** Jens Hamisch, jens@Strawberry.COM **
12 | ** **
13 | ** Description: Provides some general help by listing the different **
14 | ** commands. It will also allow for a modulefile to **
15 | ** provide some module-specific help by calling a Tcl **
16 | ** procedure. **
17 | ** **
18 | ** Exports: ModuleCmd_Help **
19 | ** **
20 | ** Notes: **
21 | ** **
22 | ** ************************************************************************ **
23 | ****/
24 |
25 | /** ** Copyright *********************************************************** **
26 | ** **
27 | ** Copyright 1991-1994 by John L. Furlan. **
28 | ** see LICENSE.GPL, which must be provided, for details **
29 | ** **
30 | ** ************************************************************************ **/
31 |
32 | static char Id[] = "@(#)$Id: ModuleCmd_Help.c.src.html,v 1.6 2006/01/18 05:35:11 rkowen Exp $";
33 | static void *UseId[] = { &UseId, Id };
34 |
35 | /** ************************************************************************ **/
36 | /** HEADERS **/
37 | /** ************************************************************************ **/
38 |
39 | #include "modules_def.h"
40 |
41 | /** ************************************************************************ **/
42 | /** LOCAL DATATYPES **/
43 | /** ************************************************************************ **/
44 |
45 | /** not applicable **/
46 |
47 | /** ************************************************************************ **/
48 | /** CONSTANTS **/
49 | /** ************************************************************************ **/
50 |
51 | /** not applicable **/
52 |
53 | /** ************************************************************************ **/
54 | /** MACROS **/
55 | /** ************************************************************************ **/
56 |
57 | /** not applicable **/
58 |
59 | /** ************************************************************************ **/
60 | /** LOCAL DATA **/
61 | /** ************************************************************************ **/
62 |
63 | static char module_name[] = "ModuleCmd_Help.c"; /** File name of this module **/
64 |
65 | #if WITH_DEBUGGING_MODULECMD
66 | static char _proc_ModuleCmd_Help[] = "ModuleCmd_Help";
67 | #endif
68 |
69 | #if WITH_DEBUGGING_MODULECMD || WITH_DEBUGGING_UTIL_1
70 | static char _proc_PerModuleHelp[] = "PerModuleHelp";
71 | #endif
72 |
73 | /** ************************************************************************ **/
74 | /** PROTOTYPES **/
75 | /** ************************************************************************ **/
76 |
77 | static int PerModuleHelp( Tcl_Interp*, int, char*[]);
78 |
79 | /*++++
80 | ** ** Function-Header ***************************************************** **
81 | ** **
82 | ** Function: ModuleCmd_Help **
83 | ** **
84 | ** Description: Execution of the module-command 'help' **
85 | ** Called w/o parameters it will print a list of avail- **
86 | ** able commands. If it is called with a parameter it **
87 | ** will print module specific help. **
88 | ** **
89 | ** First Edition: 1991/10/23 **
90 | ** **
91 | ** Parameters: Tcl_Interp *interp Attached Tcl Interp. **
92 | ** int argc Number of arguments **
93 | ** char *argv[] Argument list **
94 | ** **
95 | ** Result: int TCL_ERROR Failure **
96 | ** TCL_OK Successfull operation **
97 | ** **
98 | ** Attached Globals: **
99 | ** **
100 | ** ************************************************************************ **
101 | ++++*/
102 |
103 | int ModuleCmd_Help( Tcl_Interp *interp,
104 | int argc,
105 | char *argv[])
106 | {
107 | /**
108 | ** General or module specific help wanted. General help is done within
109 | ** here. In case of module specific help we'll call a subroutine to do
110 | ** it ...
111 | **/
112 |
113 | #if WITH_DEBUGGING_MODULECMD
114 | ErrorLogger( NO_ERR_START, LOC, _proc_ModuleCmd_Help, NULL);
115 | #endif
116 |
117 | if( argc > 0)
118 | PerModuleHelp( interp, argc, argv);
119 | else
120 | module_usage(stderr);
121 |
122 | /**
123 | ** Return on success
124 | **/
125 |
126 | #if WITH_DEBUGGING_MODULECMD
127 | ErrorLogger( NO_ERR_START, LOC, _proc_ModuleCmd_Help, NULL);
128 | #endif
129 |
130 | return( TCL_OK);
131 |
132 | } /** End of 'ModuleCmd_Help' **/
133 |
134 | /*++++
135 | ** ** Function-Header ***************************************************** **
136 | ** **
137 | ** Function: PerModuleHelp **
138 | ** **
139 | ** Description: Print module specific help **
140 | ** **
141 | ** First Edition: 1991/10/23 **
142 | ** **
143 | ** Parameters: Tcl_Interp *interp Attached Tcl Interp. **
144 | ** int argc Number of arguments **
145 | ** char *argv[] Argument list **
146 | ** **
147 | ** Result: int TCL_ERROR Failure **
148 | ** TCL_OK Successfull operation **
149 | ** **
150 | ** Attached Globals: g_flags These are set up accordingly before **
151 | ** this function is called in order to **
152 | ** control everything **
153 | ** g_current_module The module which is handled **
154 | ** by the current command **
155 | ** **
156 | ** ************************************************************************ **
157 | ++++*/
158 |
159 | static int PerModuleHelp( Tcl_Interp *interp,
160 | int argc,
161 | char *argv[])
162 | {
163 | Tcl_Interp *help_interp;
164 | Tcl_DString cmdbuf;
165 | int i,
166 | result;
167 | char modulefile[ MOD_BUFSIZE];
168 | char modulename[ MOD_BUFSIZE];
169 |
170 | #if WITH_DEBUGGING_UTIL_1
171 | ErrorLogger( NO_ERR_START, LOC, _proc_PerModuleHelp, NULL);
172 | #endif
173 |
174 | /**
175 | ** Initialize the command buffer
176 | **/
177 |
178 | Tcl_DStringInit( &cmdbuf);
179 | g_flags |= M_HELP;
180 |
181 | /**
182 | ** Handle each passed module file. Create a Tcl interpreter for each
183 | ** module file to be handled
184 | **/
185 |
186 | for(i=0; i<argc; i++) {
187 |
188 | help_interp = Tcl_CreateInterp();
189 | if( TCL_OK != (result = InitializeModuleCommands( help_interp))) {
190 | Tcl_DeleteInterp( help_interp);
191 | result = TCL_ERROR;
192 | break;
193 | }
194 |
195 | /**
196 | ** locate the filename related to the passed module
197 | **/
198 |
199 | if( Locate_ModuleFile( help_interp, argv[i], modulename, modulefile)) {
200 | if( OK != ErrorLogger( ERR_LOCATE, LOC, argv[i], NULL))
201 | continue;
202 | }
203 |
204 | /**
205 | ** Now print the module specific help ...
206 | **/
207 |
208 | g_current_module = modulename;
209 | fprintf( stderr,
210 | "\n----------- Module Specific Help for '%s' %.*s-------\n\n",
211 | g_current_module, (int)(20-strlen( g_current_module)),
212 | "--------------------");
213 | result = CallModuleProcedure( help_interp, &cmdbuf, modulefile,
214 | "ModulesHelp", 1);
215 |
216 | /**
217 | ** If there hasn't been any help ...
218 | **/
219 |
220 | if( result == TCL_ERROR)
221 | fprintf( stderr, "\t*** No Module Specific Help for %s ***\n",
222 | g_current_module);
223 |
224 | /**
225 | ** Finally clear up the Tcl interpreter and handle the next module
226 | **/
227 |
228 | Tcl_DeleteInterp( help_interp);
229 | }
230 |
231 | /**
232 | ** Free the used command buffer and return on success
233 | **/
234 |
235 | g_flags &= ~M_HELP;
236 | Tcl_DStringFree(&cmdbuf);
237 |
238 | return( TCL_OK);
239 |
240 | } /** End of 'PerModuleHelp' **/