From e23e15aa5c1a1e476fb022edaefe95f5fbe9c97e Mon Sep 17 00:00:00 2001 From: dos-reis Date: Sun, 25 Oct 2009 19:01:37 +0000 Subject: * lib/cfuns-c.c (oa_concatenate_string): Define. * include/open-axiom.h (openaxiom_ifs): New. (OPENAXIOM_TEXINPUTS_PATH): Likewise. (OPENAXIOM_BIBINPUTS_PATH): Likewise. * driver/main.c (augment_variable): New. (upgrade_environment): Likewise. Call publish_systemdir. (main): Call it instead of publish_systemdir. Handle 'spawn' driver. * driver/utils.h (openaxiom_execute_driver): New kind of driver. * driver/utils.c (openaxiom_preprocess_arguments): Tidy. (openaxiom_execute_core): Likewise. * sman/sman.c (process_arguments): Likewise. (process_options): Likewise. --- src/driver/main.c | 37 +++++++++++++++++++-- src/driver/utils.c | 94 ++++++++++++++++++++++++++++-------------------------- src/driver/utils.h | 10 +++--- 3 files changed, 87 insertions(+), 54 deletions(-) (limited to 'src/driver') diff --git a/src/driver/main.c b/src/driver/main.c index a943a95f..15e27d8b 100644 --- a/src/driver/main.c +++ b/src/driver/main.c @@ -58,6 +58,33 @@ publish_systemdir(const char* dir) } } +static void +augment_variable(const char* name, const char* value) { + const char* oldval = oa_getenv(name); + const int value_length = strlen(value); + const int oldval_length = oldval == 0 ? 0 : strlen(oldval); + const int newval_length = value_length + 1 + oldval_length; + char* newval = (char*) malloc(newval_length + 1); + + strcpy(newval,value); + if (oldval != 0) { + newval[value_length] = openaxiom_ifs; + strcpy(newval + value_length + 1, oldval); + } + + if (!oa_setenv(name, newval)) + perror("oa_augment_environment_variable"); +} + +static void +upgrade_environment(const char* sysdir) { + augment_variable("TEXINPUTS", + oa_concatenate_string(sysdir, OPENAXIOM_TEXINPUTS_PATH)); + augment_variable("BIBINPUTS", + oa_concatenate_string(sysdir, OPENAXIOM_BIBINPUTS_PATH)); + publish_systemdir(sysdir); +} + int main(int argc, char* argv[]) @@ -65,17 +92,22 @@ main(int argc, char* argv[]) openaxiom_command command = { }; openaxiom_driver driver = openaxiom_preprocess_arguments(&command, argc, argv); + upgrade_environment(command.root_dir); - putenv("LC_ALL=C"); - setlocale(LC_ALL, ""); switch (driver) { case openaxiom_null_driver: return 0; /* Bye. */ case openaxiom_core_driver: case openaxiom_script_driver: case openaxiom_compiler_driver: + putenv("LC_ALL=C"); + setlocale(LC_ALL, ""); return openaxiom_execute_core(&command, driver); + case openaxiom_execute_driver: + return oa_spawn(&command.core, + openaxiom_spawn_search_path | openaxiom_spawn_replace); + case openaxiom_sman_driver: break; @@ -87,7 +119,6 @@ main(int argc, char* argv[]) /* Should not happen on MS platforms. */ abort(); #else /* __WIN32__ */ - publish_systemdir(command.root_dir); execv(openaxiom_make_path_for(command.root_dir, openaxiom_sman_driver), argv); perror(strerror(errno)); diff --git a/src/driver/utils.c b/src/driver/utils.c index 1653641f..b3ba56e9 100644 --- a/src/driver/utils.c +++ b/src/driver/utils.c @@ -31,12 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "openaxiom-c-macros.h" #include #include #include -#include "utils.h" #include +#include "utils.h" /* The basename of the file holding the OpenAxiom core executable. */ #define OPENAXIOM_CORE_EXECUTABLE \ @@ -122,6 +121,7 @@ openaxiom_build_rts_options(openaxiom_command* command, { switch (driver) { case openaxiom_sman_driver: + case openaxiom_execute_driver: case openaxiom_unknown_driver: break; @@ -230,21 +230,27 @@ openaxiom_preprocess_arguments(openaxiom_command* command, driver = openaxiom_core_driver; else if (strcmp(argv[i], "--server") == 0) driver = openaxiom_sman_driver; + else if (strcmp(argv[i], "--execute") == 0) { + driver = openaxiom_execute_driver; + break; + } + else if (strcmp(argv[i], "--help") == 0) { + print_usage(); + driver = openaxiom_null_driver; + break; + } + else if (strcmp(argv[i], "--version") == 0) { + print_version(); + driver = openaxiom_null_driver; + break; + } else { + /* Apparently we will invoke the Core system; we need to + pass on this option. */ if (strcmp(argv[i], "--script") == 0) driver = openaxiom_script_driver; else if(strcmp(argv[i], "--compile") == 0) driver = openaxiom_compiler_driver; - else if (strcmp(argv[i], "--help") == 0) { - print_usage(); - driver = openaxiom_null_driver; - break; - } - else if (strcmp(argv[i], "--version") == 0) { - print_version(); - driver = openaxiom_null_driver; - break; - } else { if (argv[i][0] == '-') /* Maybe option for the driver. */ @@ -259,23 +265,31 @@ openaxiom_preprocess_arguments(openaxiom_command* command, /* Save it for the core executable. */ argv[other++] = argv[i]; } - command->core_argc = other; - command->core_argv = argv; + + /* Determine argument vector. */ + if (driver == openaxiom_execute_driver) { + command->core.argc = argc - i - 1; + command->core.argv = argv + i + 1; + } + else { + command->core.argc = other; + command->core.argv = argv; + } if (driver != openaxiom_null_driver) { - /* If we have a file but not instructed to compiler, assume + /* If we have a file but not instructed to compile, assume we are asked to interpret a script. */ if (files > 0) switch (driver) { case openaxiom_unknown_driver: case openaxiom_sman_driver: - command->core_argc += 1; - command->core_argv = + command->core.argc += 1; + command->core.argv = (char**) malloc((other + 2) * sizeof(char*)); - command->core_argv[0] = argv[0]; - command->core_argv[1] = "--script"; + command->core.argv[0] = argv[0]; + command->core.argv[1] = "--script"; for (i = 0; i < other; ++i) - command->core_argv[2 + i] = argv[1 + i]; + command->core.argv[2 + i] = argv[1 + i]; driver = openaxiom_script_driver; break; default: @@ -284,7 +298,7 @@ openaxiom_preprocess_arguments(openaxiom_command* command, } else if (driver == openaxiom_unknown_driver) driver = OPENAXIOM_DEFAULT_DRIVER; - command->core_argv[command->core_argc] = NULL; + command->core.argv[command->core.argc] = NULL; openaxiom_build_rts_options(command, driver); } @@ -305,7 +319,7 @@ openaxiom_execute_core(const openaxiom_command* command, openaxiom_make_path_for(command->root_dir, driver); #ifdef __WIN32__ char* command_line; - int cur = strlen(command->core_argv[0]); + int cur = strlen(command->core.argv[0]); int command_line_length = 0; int i; PROCESS_INFORMATION procInfo; @@ -322,13 +336,13 @@ openaxiom_execute_core(const openaxiom_command* command, /* Don't forget room for the doubledash string. */ command_line_length += sizeof("--") - 1; /* And arguments to the actual command. */ - for (i = 1; i < command->core_argc; ++i) - command_line_length += 1 + 2 + strlen(command->core_argv[i]); + for (i = 1; i < command->core.argc; ++i) + command_line_length += 1 + 2 + strlen(command->core.argv[i]); /* Now, build the actual command line. This is done by concatenating the arguments into a single string. */ command_line = (char*) malloc(command_line_length + 1); - strcpy(command_line, command->core_argv[0]); + strcpy(command_line, command->core.argv[0]); for (i = 0; i < command->rt_argc; ++i) { const int arg_length = strlen(command->rt_argv[i]); command_line[cur++] = ' '; @@ -340,11 +354,11 @@ openaxiom_execute_core(const openaxiom_command* command, command_line[cur++] = ' '; command_line[cur++] = '-'; /* start arguments to the core executable. */ command_line[cur++] = '-'; - for (i = 1; i < command->core_argc; ++i) { - const int arg_length = strlen(command->core_argv[i]); + for (i = 1; i < command->core.argc; ++i) { + const int arg_length = strlen(command->core.argv[i]); command_line[cur++] = ' '; command_line[cur++] = '"'; - strcpy(command_line + cur, command->core_argv[i]); + strcpy(command_line + cur, command->core.argv[i]); cur += arg_length; command_line[cur++] = '"'; } @@ -372,44 +386,34 @@ openaxiom_execute_core(const openaxiom_command* command, #else /* __WIN32__ */ int i; char** args = (char**) - malloc(sizeof (char*) * (command->rt_argc + command->core_argc + 2)); + malloc(sizeof (char*) * (command->rt_argc + command->core.argc + 2)); /* GCL has this oddity that it wants to believe that argv[0] has something to tell about what GCL's own runtime is. Silly. */ if (OPENAXIOM_BASE_RTS == openaxiom_gcl_runtime) args[0] = ""; else - args[0] = command->core_argv[0]; + args[0] = command->core.argv[0]; /* Now, make sure we copy whatever arguments are required by the runtime system. */ for (i = 0; i < command->rt_argc; ++i) args[i + 1] = command->rt_argv[i]; - if (command->core_argc > 1) { + if (command->core.argc > 1) { /* We do have arguments from the command line. We want to differentiate this from the base runtime system arguments. We do this by inserting a doubledash to indicate beginning of arguments. */ args[command->rt_argc + 1] = "--"; /* Then, copy over the arguments received from the command line. */ - for (i = 1; i < command->core_argc; ++i) - args[command->rt_argc + i + 1] = command->core_argv[i]; - args[command->rt_argc + command->core_argc + 1] = NULL; + for (i = 1; i < command->core.argc; ++i) + args[command->rt_argc + i + 1] = command->core.argv[i]; + args[command->rt_argc + command->core.argc + 1] = NULL; } else - args[command->rt_argc + command->core_argc] = NULL; + args[command->rt_argc + command->core.argc] = NULL; execv(execpath, args); perror(strerror(errno)); return -1; #endif /* __WIN32__ */ } - - -/* Allocate a vector for ARGC command line arguments. */ -void -openaxiom_allocate_command_argv(openaxiom_command* cmd, int argc) -{ - cmd->core_argc = argc; - cmd->core_argv = (char**) malloc((1 + argc) * sizeof (char*)); - cmd->core_argv[argc] = NULL; -} diff --git a/src/driver/utils.h b/src/driver/utils.h index 3f706a88..89aa81aa 100644 --- a/src/driver/utils.h +++ b/src/driver/utils.h @@ -34,7 +34,7 @@ #ifndef OPENAXIOM_UTILS_INCLUDED #define OPENAXIOM_UTILS_INCLUDED -#include "openaxiom-c-macros.h" +#include "open-axiom.h" #if HAVE_UNISTD_H # include #endif @@ -49,7 +49,8 @@ typedef enum openaxiom_driver { openaxiom_sman_driver, /* start Superman as master process */ openaxiom_core_driver, /* start the core system as master process */ openaxiom_script_driver, /* start the core system in script mode. */ - openaxiom_compiler_driver /* start the core system in compiler mode. */ + openaxiom_compiler_driver, /* start the core system in compiler mode. */ + openaxiom_execute_driver /* Execute a command. */ } openaxiom_driver; /* A list of runtime support systems for OpenAxiom. */ @@ -64,8 +65,7 @@ typedef enum openaxiom_runtime { /* A description of external command to be executed. */ typedef struct openaxiom_command { - char** core_argv; /* arguments for the actual executable. */ - int core_argc; /* number of such arguments. */ + openaxiom_process core; /* arguments for actual executable. */ char** rt_argv; /* arguments to the base RT, if any. */ int rt_argc; /* number of such arguments. */ const char* root_dir; /* path to the OpenAxiom system. */ @@ -80,6 +80,4 @@ void openaxiom_build_rts_options(openaxiom_command*, openaxiom_driver); openaxiom_driver openaxiom_preprocess_arguments(openaxiom_command*, int, char**); -void openaxiom_allocate_command_argv(openaxiom_command*, int); - #endif /* OPENAXIOM_UTILS_INCLUDED */ -- cgit v1.2.3