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. --- configure | 18 +++++----- configure.ac | 2 +- configure.ac.pamphlet | 2 +- src/ChangeLog | 15 ++++++++ src/Makefile.in | 2 +- src/Makefile.pamphlet | 2 +- src/driver/main.c | 37 +++++++++++++++++-- src/driver/utils.c | 94 +++++++++++++++++++++++++----------------------- src/driver/utils.h | 10 +++--- src/include/open-axiom.h | 12 +++++++ src/lib/cfuns-c.c | 18 ++++++++++ src/sman/sman.c | 16 ++++----- 12 files changed, 153 insertions(+), 75 deletions(-) diff --git a/configure b/configure index 246dbe60..504389eb 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.63 for OpenAxiom 1.4.0-2009-10-13. +# Generated by GNU Autoconf 2.63 for OpenAxiom 1.4.0-2009-10-25. # # Report bugs to . # @@ -745,8 +745,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='OpenAxiom' PACKAGE_TARNAME='openaxiom' -PACKAGE_VERSION='1.4.0-2009-10-13' -PACKAGE_STRING='OpenAxiom 1.4.0-2009-10-13' +PACKAGE_VERSION='1.4.0-2009-10-25' +PACKAGE_STRING='OpenAxiom 1.4.0-2009-10-25' PACKAGE_BUGREPORT='open-axiom-bugs@lists.sf.net' ac_unique_file="src/Makefile.pamphlet" @@ -1509,7 +1509,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures OpenAxiom 1.4.0-2009-10-13 to adapt to many kinds of systems. +\`configure' configures OpenAxiom 1.4.0-2009-10-25 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1579,7 +1579,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of OpenAxiom 1.4.0-2009-10-13:";; + short | recursive ) echo "Configuration of OpenAxiom 1.4.0-2009-10-25:";; esac cat <<\_ACEOF @@ -1685,7 +1685,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -OpenAxiom configure 1.4.0-2009-10-13 +OpenAxiom configure 1.4.0-2009-10-25 generated by GNU Autoconf 2.63 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -1699,7 +1699,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by OpenAxiom $as_me 1.4.0-2009-10-13, which was +It was created by OpenAxiom $as_me 1.4.0-2009-10-25, which was generated by GNU Autoconf 2.63. Invocation command line was $ $0 $@ @@ -21124,7 +21124,7 @@ exec 6>&1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by OpenAxiom $as_me 1.4.0-2009-10-13, which was +This file was extended by OpenAxiom $as_me 1.4.0-2009-10-25, which was generated by GNU Autoconf 2.63. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -21187,7 +21187,7 @@ Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_version="\\ -OpenAxiom config.status 1.4.0-2009-10-13 +OpenAxiom config.status 1.4.0-2009-10-25 configured by $0, generated by GNU Autoconf 2.63, with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/configure.ac b/configure.ac index 5d22e5e4..5d1b74f1 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ sinclude(config/open-axiom.m4) sinclude(config/aclocal.m4) -AC_INIT([OpenAxiom], [1.4.0-2009-10-13], +AC_INIT([OpenAxiom], [1.4.0-2009-10-25], [open-axiom-bugs@lists.sf.net]) AC_CONFIG_AUX_DIR(config) diff --git a/configure.ac.pamphlet b/configure.ac.pamphlet index 0a4d74df..fa50c83c 100644 --- a/configure.ac.pamphlet +++ b/configure.ac.pamphlet @@ -1167,7 +1167,7 @@ information: <>= sinclude(config/open-axiom.m4) sinclude(config/aclocal.m4) -AC_INIT([OpenAxiom], [1.4.0-2009-10-13], +AC_INIT([OpenAxiom], [1.4.0-2009-10-25], [open-axiom-bugs@lists.sf.net]) @ diff --git a/src/ChangeLog b/src/ChangeLog index cf07ee90..636a99ba 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2009-10-25 Gabriel Dos Reis + + * 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. + 2009-10-24 Gabriel Dos Reis * lib/cfuns-c.c (oa_spawn): New. diff --git a/src/Makefile.in b/src/Makefile.in index f65eb8b8..420b1c8f 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -16,7 +16,7 @@ stamp: @axiom_src_all@ all-driver -rm -f stamp $(STAMP) stamp -all-driver: +all-driver: all-lib @cd driver && $(MAKE) $@ all-clef: all-lib diff --git a/src/Makefile.pamphlet b/src/Makefile.pamphlet index d3a90eb9..806d8375 100644 --- a/src/Makefile.pamphlet +++ b/src/Makefile.pamphlet @@ -263,7 +263,7 @@ stamp: @axiom_src_all@ all-driver -rm -f stamp $(STAMP) stamp -all-driver: +all-driver: all-lib @cd driver && $(MAKE) $@ <> 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 */ diff --git a/src/include/open-axiom.h b/src/include/open-axiom.h index df814476..67f378d7 100644 --- a/src/include/open-axiom.h +++ b/src/include/open-axiom.h @@ -101,6 +101,17 @@ typedef enum openaxiom_spawn_flags { /* Return the address of the data buffer `BUF'. */ #define oa_buffer_address(BUF) ((openaxiom_byte*)&BUF[0]) +/* Internal field separator character. */ +#ifdef __WIN32__ +# define openaxiom_ifs ';' +#else +# define openaxiom_ifs ':' +#endif + +/* Paths to LaTeX input support file directories. + These paths are relative to system directory. */ +#define OPENAXIOM_TEXINPUTS_PATH "/share/tex" +#define OPENAXIOM_BIBINPUTS_PATH "/share/tex" /* The function sleep() is not available under Windows. Instead, they have Sleep(); with capital S, please. Furthermore, it does not @@ -121,6 +132,7 @@ openaxiom_sleep(int n) OPENAXIOM_EXPORT void oa_allocate_process_argv(openaxiom_process*, int); OPENAXIOM_EXPORT int oa_spawn(openaxiom_process*, openaxiom_spawn_flags); +OPENAXIOM_EXPORT const char* oa_concatenate_string(const char*, const char*); #ifdef __cplusplus } diff --git a/src/lib/cfuns-c.c b/src/lib/cfuns-c.c index 97d85d15..42dce2ed 100644 --- a/src/lib/cfuns-c.c +++ b/src/lib/cfuns-c.c @@ -526,6 +526,24 @@ oa_getpid(void) #endif } +/* Concatenate two strings and return a pointer to the + newly allocate resulting string. */ +OPENAXIOM_EXPORT const char* +oa_concatenate_string(const char* lhs, const char* rhs) +{ + if (lhs == NULL) + return rhs; + else if (rhs == NULL) + return lhs; + else { + const int lhs_length = strlen(lhs); + char* result = (char*) malloc(lhs_length + strlen(rhs) + 1); + strcpy(result, lhs); + strcpy(result + lhs_length, rhs); + return result; + } +} + /* Return the value of an environment variable. */ OPENAXIOM_EXPORT char* oa_getenv(const char* var) diff --git a/src/sman/sman.c b/src/sman/sman.c index b4d73dd8..948a748a 100644 --- a/src/sman/sman.c +++ b/src/sman/sman.c @@ -209,8 +209,8 @@ process_arguments(openaxiom_command* command, int argc,char ** argv) argv[other++] = argv[arg]; } - command->core_argv = argv; - command->core_argc = other; + command->core.argv = argv; + command->core.argc = other; /* If there were no X libraries * at build-time, we proceed to @@ -251,10 +251,10 @@ process_options(openaxiom_command* command, int argc, char **argv) set_up_defaults(); process_arguments(command, argc, argv); /* Complain about command line arguments unknown to Superman. */ - if (command->core_argc > 0) { + if (command->core.argc > 0) { int i; - for (i = 0; i < command->core_argc; ++i) - fprintf(stderr,"command line error: %s\n", command->core_argv[i]); + for (i = 0; i < command->core.argc; ++i) + fprintf(stderr,"command line error: %s\n", command->core.argv[i]); exit(-1); } } @@ -527,10 +527,10 @@ fork_Axiom(openaxiom_command* cmd) } /* Tell the Core that it is being invoked in server mode. */ - openaxiom_allocate_command_argv(cmd, 2); - cmd->core_argv[0] = + oa_allocate_process_argv(&cmd->core, 2); + cmd->core.argv[0] = openaxiom_make_path_for(cmd->root_dir, openaxiom_core_driver); - cmd->core_argv[1] = "--role=server"; + cmd->core.argv[1] = "--role=server"; openaxiom_execute_core(cmd, openaxiom_core_driver); } } -- cgit v1.2.3