#include #include #include #include #define stdout XR_MSG_STDOUT /* truncated VERSIONSTAMPPREFIX used to avoid conflicts with mimosamakedo looking for versionstamps. -mdw 12/7/88 */ #define VERSIONSTAMPPREFIX "@(#)mob_versio" typedef void (*InstallFunc)(); static char * XR_getModuleName(); typedef struct LoadStruct { struct LoadStruct *next; char *file_name; InstallFunc load_Func; InstallFunc run_Func; InstallFunc unload_Func; } LoadeeRecord; typedef LoadeeRecord *Loadee; Loadee loadees; void XR_run_command(); char *get_nth_word(); static int silentLoading = 1; int XR_load_command (command) char *command; { /* Currently expects the following procedures in the file: "XR_install_Filename", "XR_run_Filename", and "XR_unload_Filename" where Filename has been stripped of any suffixes or prefixes. */ char *lastchancename; char *file; char *arg, *modulename, *XR_strip(); char func[128]; void XR_install_command(); Loadee new ; int check_load = 0; int nodebugger = 0; int argno; file = get_nth_word(command, 1); modulename = NULL; new = (Loadee)malloc(sizeof(LoadeeRecord)); new->file_name = (char *)malloc(strlen(file)+1); strcpy(new->file_name, file); lastchancename = file; lastchancename = XR_strip(lastchancename); argno = 2; arg = get_nth_word(XR_GetCurrentCommand(), argno++); while (arg[0]) { if (arg[0] == '-') { switch(arg[1]) { case 'q': { check_load = 1; break; } case 'd': { nodebugger = 1; break; } default: { XR_FPrintF (stdout, "Unrecognized load switch: %s. Ignored.\n", arg); break; } } } else { /* does not begin with '-' */ if (modulename) { XR_FPrintF (stdout, "Unrecognized load argument: %s. Ignored.\n", arg); } else { modulename = arg; } } arg = get_nth_word(XR_GetCurrentCommand(), argno++); } cpb_printf("Loading file %s", new->file_name); if (nodebugger) { cpb_printf(" (no debugging).\n"); } else { cpb_printf(".\n"); } if (load_file(new->file_name, NULL, check_load, nodebugger) == NULL) { cpb_printf("No action taken for file '%s'.\n", new->file_name); return 0; } if (! modulename) { cpb_printf("Trying to derive module name from version stamp.\n"); modulename = XR_getModuleName(); }; if (! modulename) { cpb_printf("Deriving module name from filename.\n"); modulename = lastchancename; } cpb_printf("Using module name '%s'.\n", modulename); strcpy(func, "_XR_install_"); strcat(func, modulename); if (((new->load_Func = (InstallFunc)get_sym_val(func)) == NULL) && ((new->load_Func = (InstallFunc)get_sym_val("_XR_install")) == NULL)) { cpb_printf("Could not find 'XR_install' or '%s'.\n", func); } strcpy(func, "_XR_run_"); strcat(func, modulename); if (((new->run_Func = (InstallFunc)get_sym_val(func)) == NULL) && ((new->run_Func = (InstallFunc)get_sym_val("_XR_run")) == NULL)) { cpb_printf("Could not find 'XR_run' or '%s'.\n", func); } strcpy(func, "_XR_unload_"); strcat(func, modulename); new->unload_Func = (InstallFunc)get_sym_val(func); new->next = loadees; loadees = new; if (!(strncmp(command, "loadonly", 8) == 0)) { char *fake; fake = (char *)calloc(strlen(new->file_name)+20, 1); strcat(fake, "fake "); strcat(fake, new->file_name); XR_install_command(fake); } else { cpb_printf("Loaded only--installation proc not called.\n"); } return 1; }; void XR_install_command(command) char *command; { char *file; Loadee loadee = loadees; file = get_nth_word(command, 1); while (loadee != NULL) { if (strcmp(file, loadee->file_name) == 0) { if (loadee->load_Func == NULL) { cpb_printf(" %s has no load function.", file); } else { loadee->load_Func(); XR_VerboseCommit(); }; cpb_printf(" %s has been installed.\n", file); return; }; loadee = loadee->next; }; /* while */ cpb_printf(" %s has not been installed. ", file); } static void request_command(file) char *file; { char *command; Loadee loadee = loadees; while (loadee != NULL) { if (strcmp(file, loadee->file_name) == 0) { XR_FPrintF (stdout, " %s already loaded.\n", file); return; }; loadee = loadee->next; }; /* while */ command = (char *)calloc(strlen(file)+20, 1); strcat(command, "fake_command "); strcat(command, file); XR_load_command(command); } void XR_loadAndRun_command(command) char *command; { char *cmd_rememberer; cmd_rememberer = (char *)malloc(strlen(command) + 1); strcpy(cmd_rememberer, command); if (XR_load_command(command)) XR_run_command(cmd_rememberer); } void XR_run_command(command) char *command; { char *file; Loadee loadee = loadees; file = get_nth_word(command, 1); while (loadee != NULL) { if (strcmp(file, loadee->file_name) == 0) { if (loadee->run_Func == NULL) { cpb_printf(" %s has no function 'run'.\n", file); } else { cpb_printf(" running %s.\n", file); loadee->run_Func(); } return; } loadee = loadee->next; } /* while */ cpb_printf(" %s has not been run.\n", file); } static void unload_command(command) char *command; { char *file; Loadee loadee = loadees; file = get_nth_word(command, 1); while (loadee != NULL) { if (strcmp(file, loadee->file_name) == 0) { if (loadee->unload_Func == NULL) { XR_FPrintF (stdout, " %s has no function 'unload'.\n", file); } else loadee->unload_Func(); return; }; loadee = loadee->next; }; /* while */ cpb_printf(" %s has not been loaded.\n", file); }; static void dbxtoolCommand () { char num[128]; char name[128], filename[128]; int pid; XR_FPrintF (stdout, "No auto-debugger available.\n"); }; /* debugCommand */ verboseloading() { silentLoading = 0; } silentloading() { silentLoading = 1; } typedef (*procpointer)(); static (*install_command_ptr)() = (procpointer)XR_install_command; static (*run_command_ptr)() = (procpointer)XR_run_command; static (*loadAndRun_command_ptr)() = (procpointer)XR_loadAndRun_command; static (*load_command_ptr)() = (procpointer)XR_load_command; static (*unload_command_ptr)() = (procpointer)unload_command; static (*dbxtoolCommand_ptr)() = (procpointer)dbxtoolCommand; static (*verboseloading_ptr)() = (procpointer)verboseloading; static (*silentloading_ptr)() = (procpointer)silentloading; static XR_run() { XR_register("i", &install_command_ptr, "install a previously loaded Cedar module", 0); XR_register("install", &install_command_ptr, "install a previously loaded Cedar module", 0); XR_register("loadandrun", &loadAndRun_command_ptr, "load and then run a Cedar module (takes -d or -q switch after filename)", 0); XR_register("lr", &loadAndRun_command_ptr, "load and then run a Cedar module (takes -d or -q switch after filename)", 0); XR_register("l", &load_command_ptr, "load a Cedar module (takes -d or -q switch after filename)", 0); XR_register("load", &load_command_ptr, "load a Cedar module (takes -d or -q switch after filename)", 0); XR_register("loadonly", &load_command_ptr, "load a Cedar module (takes -d or -q switch after filename)", 0); XR_register("r", &run_command_ptr, "run a previously loaded Cedar module", 0); XR_register("run", &run_command_ptr, "run a previously loaded Cedar module", 0); XR_register("unload", &unload_command_ptr, "unload a previously loaded Cedar module (unimplemented).", 0); XR_register("dbx", &dbxtoolCommand_ptr, "start running a dbxtool pointed at the current cedarboot.", 0); XR_register("debug", &dbxtoolCommand_ptr, "start running a dbxtool pointed at the current cedarboot.", 0); XR_register("silentloading", &silentloading_ptr, "go about the business of dynamic loading quietly.", 0); XR_register("verboseloading", &verboseloading_ptr, "print lots of messages about what is happening during dynamic loading.", 0); } XR_run_cmds() { XR_run(); } cpb_printf(fmt, a, b, c, d, e, f, g, h) { if (! silentLoading) { XR_FPrintF (stdout, fmt, a, b, c, d, e, f, g, h); } } static char * XR_getModuleName() { char *lastblank; char *lastdot; char *addr; char *stamp; if ((addr = (char *)get_sym_val("_versionStamp")) == 0) { cpb_printf("Mimosa version stamp not found.\n"); return 0; } stamp = strdup(addr); if (strncmp(stamp, VERSIONSTAMPPREFIX, strlen(VERSIONSTAMPPREFIX)) != 0) { stamp[strlen(VERSIONSTAMPPREFIX)] = '\0'; cpb_printf("Mimosa version stamp starts with '%s': not in proper form.\n", stamp); return 0; } lastblank = strrchr(stamp, ' ') + 1; lastdot = strrchr(lastblank, '.'); if (lastdot) { *lastdot = '\0'; } cpb_printf("Found name in version stamp. "); return lastblank; }