4 * $Id: lane.c,v 1.21 1995/11/15 08:27:11 carnil Exp $
23 /* Type definitions */
25 /* Local function prototypes */
26 static void main_init1(void);
27 static void main_release(void);
28 static void parse_args(int argc, char **argv);
29 static void usage(void);
30 static int dump_handler(const Event_t *event, void *funcdata);
31 static int exit_handler(const Event_t *event, void *funcdata);
34 static const char *rcsid = "$Id: lane.c,v 1.21 1995/11/15 08:27:11 carnil Exp $";
35 const Unit_t main_unit = {
43 static const char *progname;
44 char *var_file = NULL;
48 /* Initialization for data that needs other units */
52 set_var_str(&main_unit, "version", rcsid);
53 add_event_handler(CE_DUMP, &dump_handler, "dump_handler", NULL);
54 add_event_handler(CE_EXIT, &exit_handler, "exit_handler", NULL);
55 Debug_unit(&main_unit, "Initialized.");
62 mem_free(&main_unit, var_file);
69 main(int argc, char **argv)
75 /* Debugging facility */
76 dump_type = DT_STDERR;
79 /* Call phase 0 initializers */
80 Debug_unit(&main_unit, "Calling phase 0 initializers");
81 FOR_ALL_UNITS(units) {
82 if ((*units)->init0 != NULL) {
83 Debug_unit(&main_unit, "Initializing %s", (*units)->name);
84 (*((*units)->init0))();
88 /* Get flags from command line */
89 parse_args(argc, argv);
91 /* Call phase 1 initializers */
92 Debug_unit(&main_unit, "Calling phase 1 initializers");
93 FOR_ALL_UNITS(units) {
94 if ((*units)->init1 != NULL) {
95 Debug_unit(&main_unit, "Initializing %s", (*units)->name);
96 (*((*units)->init1))();
102 while (!do_restart) {
103 event = event_get_next();
104 if (dispatch_handlers(event) == 1) {
107 switch (event->type) {
124 mem_free(&main_unit, event);
127 Debug_unit(&main_unit, "Releasing %d units", num_units);
128 FOR_ALL_UNITS_REV(units) {
129 if ((*units)->release != NULL) {
130 Debug_unit(&main_unit, "Releasing %s", (*units)->name);
131 (*((*units)->release))();
138 /* Process CE_DUMP events */
140 dump_handler(const Event_t *event, void *funcdata)
142 const Unit_t **units;
144 mem_free(&main_unit, event);
145 FOR_ALL_UNITS(units) {
146 if ((*units)->dump != NULL) {
147 Debug_unit(&main_unit, "Dumping %s", (*units)->name);
148 (*((*units)->dump))();
154 /* Process CE_EXIT events */
156 exit_handler(const Event_t *event, void *funcdata)
158 const Unit_t **units;
160 mem_free(&main_unit, event);
161 Debug_unit(&main_unit, "Releasing %d units", num_units);
162 FOR_ALL_UNITS_REV(units) {
163 if ((*units)->release != NULL) {
164 Debug_unit(&main_unit, "Releasing %s", (*units)->name);
165 (*((*units)->release))();
172 parse_args(int argc, char **argv)
175 const Unit_t *unit, **units;
179 i = getopt(argc, argv, "d:m:f:");
182 if (strcmp(optarg, "all") == 0) {
183 FOR_ALL_UNITS(units) {
184 set_var_bool(*units, "debug", BL_TRUE);
187 unit = find_unit(optarg);
189 set_var_bool(unit, "debug", BL_TRUE);
191 dump_printf(EL_ERROR, "Unknown module name: %s", optarg);
197 if (strcmp(optarg, "all") == 0) {
198 FOR_ALL_UNITS(units) {
199 set_var_bool(*units, "memdebug", BL_TRUE);
202 unit = find_unit(optarg);
204 set_var_bool(unit, "memdebug", BL_TRUE);
206 dump_printf(EL_ERROR, "Unknown module name: %s", optarg);
212 var_file = mem_alloc(&main_unit, strlen(optarg)+1);
213 strcpy(var_file, optarg);
214 dump_printf(EL_NOTE, "Configuration file: %s\n", var_file);
223 if (argc != optind) usage();
225 var_file = mem_alloc(&main_unit, strlen(DEFAULT_CFG_FILE)+1);
226 strcpy(var_file, DEFAULT_CFG_FILE);
227 dump_printf(EL_NOTE, "Configuration file: %s\n", var_file);
234 dump_printf(EL_ERROR, "Usage:");
235 dump_printf(EL_ERROR, "%s [-d module]... [-m module]...[-f conf_file]", progname);