diff options
author | dos-reis <gdr@axiomatics.org> | 2008-01-05 08:57:06 +0000 |
---|---|---|
committer | dos-reis <gdr@axiomatics.org> | 2008-01-05 08:57:06 +0000 |
commit | 3545eca90d734224e7a468251ac686e1ca41d910 (patch) | |
tree | 5bcf2cd44f29efeace31a299ec57cc8709aac66a /src | |
parent | 915b5b3272b0babc886c1c3c0605c9977cd36feb (diff) | |
download | open-axiom-3545eca90d734224e7a468251ac686e1ca41d910.tar.gz |
2008-01-05 Gabriel Dos Reis <gdr@cs.tamu.edu>
* configure.ac.pamphlet: For mingw host, default $prefix to
C:/Program Files/OpenAxiom.
Don't instantiate src/script/axiom.
Instantiate src/driver/Makefile. Tidy.
* Makefile.pamphlet: Tidy.
* config/axiom-c-macros.h.in: Update.
src/
2008-01-05 Gabriel Dos Reis <gdr@cs.tamu.edu>
* scripts/axiom.in: Remove.
* driver: New directory.
* driver/main.c: New. Now implement driver as native
application.
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 7 | ||||
-rw-r--r-- | src/Makefile.in | 7 | ||||
-rw-r--r-- | src/Makefile.pamphlet | 7 | ||||
-rw-r--r-- | src/driver/Makefile.in | 69 | ||||
-rw-r--r-- | src/driver/main.c | 220 | ||||
-rw-r--r-- | src/scripts/axiom.in | 192 |
6 files changed, 306 insertions, 196 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index e69de29b..55e167f6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -0,0 +1,7 @@ +2008-01-05 Gabriel Dos Reis <gdr@cs.tamu.edu> + + * scripts/axiom.in: Remove. + * driver: New directory. + * driver/main.c: New. Now implement driver as native + application. + diff --git a/src/Makefile.in b/src/Makefile.in index bc2835dd..4ba18c17 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -5,17 +5,20 @@ subdir = src/ SUBDIRS = @axiom_src_subdirs@ -.PHONY: all all-ax all-src all-clef all-sman +.PHONY: all all-ax all-src all-clef all-sman all-driver all: all-ax all-ax all-src: stamp @echo finished $(builddir) -stamp: @axiom_src_all@ +stamp: @axiom_src_all@ all-driver -rm -f stamp $(STAMP) stamp +all-driver: + @cd driver && $(MAKE) $@ + all-clef: all-lib @$(mkinstalldirs) $(axiom_target_bindir) cd clef && ${MAKE} diff --git a/src/Makefile.pamphlet b/src/Makefile.pamphlet index 06029371..f2f86358 100644 --- a/src/Makefile.pamphlet +++ b/src/Makefile.pamphlet @@ -246,17 +246,20 @@ subdir = src/ SUBDIRS = @axiom_src_subdirs@ -.PHONY: all all-ax all-src all-clef all-sman +.PHONY: all all-ax all-src all-clef all-sman all-driver all: all-ax all-ax all-src: stamp @echo finished $(builddir) -stamp: @axiom_src_all@ +stamp: @axiom_src_all@ all-driver -rm -f stamp $(STAMP) stamp +all-driver: + @cd driver && $(MAKE) $@ + <<clefdir>> <<smandir>> <<hyperdir>> diff --git a/src/driver/Makefile.in b/src/driver/Makefile.in new file mode 100644 index 00000000..0a1ba801 --- /dev/null +++ b/src/driver/Makefile.in @@ -0,0 +1,69 @@ +# Copyright (C) 2007, Gabriel Dos Reis. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# - Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# - Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# +# - Neither the name of The Numerical Algorithms Group Ltd. nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +bin_PROGRAMS = axiom$(EXEEXT) + +axiom_SOURCES = main.c + +axiom_objects = $(axiom_SOURCES:.c=.lo) + +.PHONY: all all-ax all-driver + +all: all-ax + +all-ax all-driver: stamp + +stamp: $(bin_PROGRAMS) + -rm -f stamp + $(STAMP) stamp + +.SUFFIXES: +.SUFFIXES: .c .h .lo .$(OBJEXT) +.PRECIOUS: %.lo %.obj + +%.lo: %.c + $(COMPILE) ${CCF} -o $@ \ + -DOPENAXIOM_ROOT_DIRECTORY="\"$(open_axiom_installdir)\"" \ + $(axiom_includes) $< + +axiom$(EXEEXT): $(axiom_objects) + $(LINK) -o $@ $< + +mostlyclean-local: + @rm -f $(axiom_objects) + @rm -f *~ core + +clean-local: mostlyclean-local + @rm -f $(bin_PROGRAMS) + +distclean-local: clean-local + diff --git a/src/driver/main.c b/src/driver/main.c new file mode 100644 index 00000000..12e8434a --- /dev/null +++ b/src/driver/main.c @@ -0,0 +1,220 @@ +/* + Copyright (C) 2008, Gabriel Dos Reis. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + - Neither the name of The Numerical ALgorithms Group Ltd. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* This program is a driver for the OpenAxiom core executable. + It pretends to be the OpenAxiom interpreter when, in fact, the actual + work is done by the Core Executable. It also occasionally masquerades + as the seesion manager. */ + + +#include "axiom-c-macros.h" +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <stdio.h> +#if HAVE_UNISTD_H +# include <unistd.h> +#endif +#ifdef __WIN32__ +# include <windows.h> +#endif + +/* The basename of the file holding the OpenAxiom core executable. */ +#define OPENAXIOM_CORE_EXECUTABLE \ + "AXIOMsys" OPENAXIOM_EXEEXT + +/* The basename of the file holding the session manager executable. */ +#define OPENAXIOM_SMAN_EXECUTABLE \ + "sman" OPENAXIOM_EXEEXT + +/* Path to the OpenAxiom executable core, relative to + OPENAXIOM_ROOT_DIRECTORY, or to the system root directory as specified + on command line. */ +#define OPENAXIOM_CORE_PATH \ + "/bin/" OPENAXIOM_CORE_EXECUTABLE + +/* Path to the session manager, relative to OPENAXIOM_ROOT_DIRECTORY, + or to the system root directory as specified on command line. */ +#define OPENAXIOM_SMAN_PATH \ + "/bin/" OPENAXIOM_SMAN_EXECUTABLE + +/* Return a path to the running system, either as specified on command + line through --system=, or as specified at configuration time. */ +static const char* +get_systemdir(int argc, char* argv[]) +{ + int i; + + /* Root directory specified on command line takes precedence + over location specified at configuration time. */ + for (i = 1; i < argc; ++i) + if (strcmp("--", argv[i]) == 0) + break; + else if (strncmp("--system=", argv[i], sizeof("--system=") - 1) == 0) { + return argv[i] + sizeof ("--system=") - 1; + } + + /* Command line did not change the system location to use. + Return what was computed at configuration time. */ + return OPENAXIOM_ROOT_DIRECTORY; +} + + +#define OPENAXIOM_GLOBAL_ENV "AXIOM" + +/* Publish the system exec prefix for use by sub-processes. */ +static void +publish_systemdir(const char* dir) +{ +#ifdef __WIN32__ + if (SetEnvironmentVariable(OPENAXIOM_GLOBAL_ENV, dir) == 0) { + perror("SetEnvironmentVariable"); + abort(); + } +#else /* __WIN32__ */ + const int env_length = sizeof (OPENAXIOM_GLOBAL_ENV) + + 1 /* room for '=' */ + + strlen(dir); + char* env = (char*) malloc (env_length); + strcpy(env, OPENAXIOM_GLOBAL_ENV); + env[sizeof OPENAXIOM_GLOBAL_ENV - 1] = '='; + strcpy(env + sizeof(OPENAXIOM_GLOBAL_ENV), dir); + if (putenv(env) != 0) abort(); +#endif /* __WIN32__ */ +} + + +/* Return a path for PROG specified as a relative path to PREFIX. */ +static const char* +make_path_for(const char* prefix, const char* prog) +{ + const int prefix_length = strlen(prefix); + char* execpath = (char*) malloc(prefix_length + strlen(prog) + 1); + strcpy(execpath, prefix); + strcpy(execpath + prefix_length, prog); + return execpath; +} + + +int +main(int argc, char* argv[]) +{ + const char* root_dir = get_systemdir(argc, argv); + const char* execpath = + make_path_for(root_dir, + OPENAXIOM_USE_SMAN ? + OPENAXIOM_SMAN_PATH : OPENAXIOM_CORE_PATH); +#ifdef __WIN32__ + char* command_line; + int cur = strlen(argv[0]); + int command_line_length = 0; + int i; + PROCESS_INFORMATION procInfo; + STARTUPINFO startupInfo = { 0 }; + DWORD status; /* Exit code for this program masqueraded as + the child created below. */ + + command_line_length += cur; + for (i = 1; i < argc; ++i) + command_line_length += 1 /* blank char as separator */ + + strlen(argv[i]); /* room for each argument */ + + /* Don't forget room for the doubledash string. */ + command_line_length += sizeof("--") - 1; + + command_line = (char*) malloc(command_line_length + 1); + + strcpy(command_line, argv[0]); + command_line[++cur] = ' '; + + /* Now start arguments to the core executable. */ + command_line[++cur] = '-'; + command_line[++cur] = '-'; + + /* Concatenate the arguments into a single string. */ + for (i = 1; i < argc; ++i) { + const int arg_length = strlen(argv[i]); + command_line[++cur] = ' '; + /* Note that strcpy will terminate `command_line' with a NUL + character, and since the next iteration will write the + blank precisely where the NUL character is, the whole command + line string will be a proper C-style string when the loop + normally exits. */ + strcpy(command_line + cur, argv[i]); + cur += arg_length; + } + + publish_systemdir(root_dir); + if(CreateProcess(/* lpApplicationName */ execpath, + /* lpCommandLine */ command_line, + /* lpProcessAttributes */ NULL, + /* lpThreadAttributes */ NULL, + /* bInheritHandles */ TRUE, + /* dwCreationFlags */ 0, + /* lpEnvironment */ NULL, + /* lpCurrentDirectory */ NULL, + /* lpstartupInfo */ &startupInfo, + /* lpProcessInformation */ &procInfo) == 0) { + fprintf(stderr, GetLastError()); + abort(); + } + WaitForSingleObject(procInfo.hProcess, INFINITE); + GetExitCodeProcess(procInfo.hProcess, &status); + CloseHandle(procInfo.hThread); + CloseHandle(procInfo.hProcess); + return status; + +#else /* __WIN32__ */ + int i; + char** args = (char**) malloc(sizeof (char*) * (argc + 2)); + publish_systemdir(root_dir); + + /* Pretend that we are still running the OpenAxiom driver, even if + it is actually the session manager or the core executable running. + We don't want to expose implementation details to users. */ + args[0] = argv[0]; + /* If we are running the core executable, we need to insert a + doubledash to indicate beginning of arguments. The session manager + does not need that temporary necessary obfuscation, and will + be confused. */ + if (!OPENAXIOM_USE_SMAN) + args[1] = "--"; + for (i = 1; i < argc; ++i) + args[i + !OPENAXIOM_USE_SMAN] = argv[i]; + args[argc + !OPENAXIOM_USE_SMAN] = NULL; + + execv(execpath, args); + perror(strerror(errno)); + return -1; +#endif /* __WIN32__ */ +} diff --git a/src/scripts/axiom.in b/src/scripts/axiom.in deleted file mode 100644 index 1fda6803..00000000 --- a/src/scripts/axiom.in +++ /dev/null @@ -1,192 +0,0 @@ -#!/bin/sh - -# Start everything for OpenAxiom. -# -# axiom -# [-ht |-noht] whether to use HyperDoc -# [-gr |-nogr] whether to use Graphics -# [-clef |-noclef] whether to use Clef -# [-nag |-nonag] whether to use NAG -# [-iw |-noiw] start in interpreter window -# [-ihere|-noihere] start an interpreter buffer in the original window -# [-nox] don't use X Windows -# [-go |-nogo] whether to start system -# [-ws wsname] use named workspace -# [-list] list workspaces only -# [-grprog fname] use named program for Graphics -# [-nagprog fname] use named program for Nag -# [-htprog fname] use named program for HyperDoc -# [-clefprog fname] use named program for Clef -# [-sessionprog fname] use named program for session -# [-clientprog fname] use named program for spadclient -# [-h] show usage -# -# - -## Where The OpenAxiom system resides -prefix=@prefix@ -exec_prefix=@exec_prefix@ -AXIOM=@open_axiom_installdir@ -export AXIOM - -## We adjust the value of PATH here because, currently, some OpenAxiom -## programs are called from the executing shell, and relying on the -## fact that the executables are reachable from the PATH. -PATH=$AXIOM/bin:$PATH - -## If the system is built without Superman support, there is -## no point in trying to forcefully use Superman -use_sman=@axiom_use_sman@ - - -MALLOCTYPE=3.1 -export MALLOCTYPE - -# NAGMAN needs to know the hostname -HOST=`hostname` -export HOST - -# 0. Basic utilities - -ciao() { - echo "Goodbye." - exit 1 -} - -needsubopt () { - echo "The $1 option requires an argument." - ciao -} - - -showuse() { -echo "axiom" -echo " [-ht |-noht] whether to use HyperDoc" -echo " [-gr |-nogr] whether to use Graphics" -echo " [-clef |-noclef] whether to use Clef" -echo " [-nag |-nonag] whether to use NAG" -echo " [-iw |-noiw] start in interpreter window" -echo " [-ihere|-noihere] start an interpreter buffer in the original window." -echo " [-nox] don't use X Windows" -echo " [-go |-nogo] whether to start system" -echo " [-ws wsname] use named workspace" -echo " [-list] list workspaces only" -#echo " [-grprog fname] use named program for Graphics" -#echo " [-nagprog fname] use named program for Nag" -#echo " [-htprog fname] use named program for HyperDoc" -#echo " [-clefprog fname] use named program for Clef" -#echo " [-sessionprog fname] use named program for session" -#echo " [-clientprog fname] use named program for spadclient" -echo " [-h] show usage" -} - -# 1. Ensure the environment is set. - -# Just process '-h' - -if [ "$*" = "-h" ] ; then - showuse -fi - -if [ "$AXIOMXLROOT" = "" ] ; then -AXIOMXLROOT=${AXIOM}/compiler -fi -export AXIOMXLROOT -PATH=$AXIOMXLROOT/bin:${PATH} -export PATH - - - -if [ ! -d "$AXIOM" ] ; then - echo "The directory for OpenAxiom, $AXIOM, does not exist." - ciao -fi - -# Name the workspace directories. -rootwsdir=$AXIOM/bin - -# 2. Process command line arguments. - -# Defaults for command-line arguments. -list=no -go=yes -wsname=AXIOMsys - -otheropts="" - -while [ "$*" != "" ] ; do - - case $1 in - -list) list=yes - go=no;; - -go) go=yes ;; - -nogo) go=no ;; - - -ws) - if [ "$2" = "" ] ; then needsubopt "$1" ; fi - shift - wsname="$1" - ;; - - -nagprog|-grprog|-htprog|-clefprog|-sessionprog|-clientprog|-paste|-rm|-rv) - if [ "$2" = "" ] ; then needsubopt "$1" ; fi - otheropts="$otheropts $1 $2" - shift - ;; - -clef|-noclef|-gr|-nogr|-ht|-noht|-iw|-noiw|-ihere|-noihere|-nox|-nag|-nonag) - otheropts="$otheropts $1" - ;; - - -h) - go=no - ;; - - - *) echo "Unknown option: $1" - echo "To use a specific workspace use, e.g.: spad -ws $1" - ciao - ;; - esac - - shift -done - -# 3. List the available workspaces, if asked - -listwspaces() -{ - echo "$1" - ls -l $2 | grep "sys$" - echo "" -} - -if [ $list = yes ] ; then - listwspaces "AXIOM workspaces in \$AXIOM/bin = $rootwsdir: " $rootwsdir -fi - -# 5. Try to ensure a suitable workspace on this host. - -if [ `expr $wsname : '.*/.*'` = 0 ] ; then - serverws=$rootwsdir/$wsname -else - serverws=$wsname -fi - -if [ ! -f $serverws ] ; then - showuse - ciao -fi - -# 6. Start processes - -if [ $go = no ] ; then - echo "Would now start the processes." - echo exec $AXIOM/bin/sman $otheropts -ws $serverws - exit 0 -fi - -if [ $use_sman = "yes" ]; then - exec $AXIOM/bin/sman $otheropts -ws $serverws -else - exec $serverws -fi |