open-axiom repository from github
/*1Copyright (C) 2007-2014, Gabriel Dos Reis.2All rights reserved.34Redistribution and use in source and binary forms, with or without5modification, are permitted provided that the following conditions are6met:78- Redistributions of source code must retain the above copyright9notice, this list of conditions and the following disclaimer.1011- Redistributions in binary form must reproduce the above copyright12notice, this list of conditions and the following disclaimer in13the documentation and/or other materials provided with the14distribution.1516- Neither the name of The Numerical Algorithms Group Ltd. nor the17names of its contributors may be used to endorse or promote products18derived from this software without specific prior written permission.1920THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS21IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED22TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A23PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER24OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,25EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,26PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR27PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF28LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING29NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS30SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31*/3233#ifndef OPENAXIOM_included34#define OPENAXIOM_included3536#include <vector>37#include <string>3839#include "openaxiom-c-macros.h"4041/* Annotation to request C calling convention */42#ifdef __cplusplus43# define OPENAXIOM_C_CALL extern "C"44#else45# define OPENAXIOM_C_CALL46#endif4748/* Cope with MS-platform oddities. */49#ifdef __WIN32__50# ifdef DLL_EXPORT51# define OPENAXIOM_EXPORT __declspec(dllexport)52# elif defined(DLL_IMPORT)53# define OPENAXIOM_EXPORT __declspec(dllimport)54# endif /* DLL_EXPORT */55# ifndef WIN32_LEAN_AND_MEAN56# define WIN32_LEAN_AND_MEAN57# endif58#endif /* __WIN32__ */59#ifndef OPENAXIOM_EXPORT60# define OPENAXIOM_EXPORT /* nothing */61#endif /* OPENAXIOM_EXPORT */6263#define OPENAXIOM_C_EXPORT OPENAXIOM_C_CALL OPENAXIOM_EXPORT6465#include <stdint.h>6667#if defined(__WIN32__)68# include <windows.h>69#endif70#if defined(HAVE_UNISTD_H)71# include <unistd.h>72#endif7374/* Do we have graphics support? */75#ifdef X_DISPLAY_MISSING76# define OPENAXIOM_HAVE_GRAPHICS 077#else78# define OPENAXIOM_HAVE_GRAPHICS 179#endif8081namespace OpenAxiom {82// A name for the byte datatype.83typedef uint8_t Byte;8485// An opaque datatype86#ifdef __WIN32__87typedef HANDLE Handle;88#else89typedef void* Handle;90#endif9192// Data types for labeling positions and counting items.93using Ordinal = size_t;94using Cardinal = size_t;9596// Byte order of machine word data.97enum class Byteorder {98unknown, little, big99};100101// Datatype for packaging information necessary tolaunch a process.102struct Process {103int argc;104char** argv;105int id;106};107108enum SpawnFlags {109search_path = 0x01,110replace = 0x02,111};112113constexpr SpawnFlags114operator&(SpawnFlags x, SpawnFlags y) {115return SpawnFlags(int(x) & int(y));116}117118constexpr SpawnFlags119operator|(SpawnFlags x, SpawnFlags y) {120return SpawnFlags(int(x) | int(y));121}122123124// Return the address of the byte array object representation of `t'.125template<typename T>126inline Byte* byte_address(T& t) {127return reinterpret_cast<Byte*>(&t);128}129130/* Internal field separator character. */131#if defined(__WIN32__)132# define openaxiom_ifs ';'133#else134# define openaxiom_ifs ':'135#endif136137/* Paths to LaTeX input support file directories.138These paths are relative to system directory. */139#define OPENAXIOM_TEXINPUTS_PATH "/share/texmf/tex"140#define OPENAXIOM_BIBINPUTS_PATH "/share/texmf/tex"141142/* The function sleep() is not available under Windows. Instead, they143have Sleep(); with capital S, please. Furthermore, it does not144take argument in second, but in milliseconds, three order145of magnitude of difference when compared to the Unix world.146We abstract over that difference here. */147148static inline void149openaxiom_sleep(int n)150{151#if defined(__WIN32__)152Sleep(n * 1000);153#else154sleep(n);155#endif156}157158OPENAXIOM_C_EXPORT void oa_allocate_process_argv(Process*, int);159OPENAXIOM_C_EXPORT int oa_spawn(Process*, SpawnFlags);160OPENAXIOM_C_EXPORT const char* oa_concatenate_string(const char*, const char*);161162// ------------163// -- Driver --164// ------------165// A list of drivers for OpenAxiom.166enum class Driver {167unknown, // unknown driver168null, // do nothing169config, // print out configuration information170sman, // start Superman as master process171gui, // start the GUI interface172core, // start the core system as master process173script, // start the core system in script mode.174compiler, // start the core system in compiler mode.175execute, // Execute a command.176translator, // Start the core system in translator mode.177linker // start the core system in linking mode.178};179180// -------------181// -- Runtime --182// -------------183// A list of runtime support systems for OpenAxiom.184enum class Runtime {185unknown, // unknown runtime186gcl, // GCL-based runtime187sbcl, // SBCL-based runtime188clisp, // CLISP-based runtime189ecl, // ECL-based runtime190clozure, // Clozure CL-based runtime191bemol, // Bemol-based runtime192polyml // Poly/ML abstract machine-based runtime193};194195// ---------------196// -- Arguments --197// ---------------198// Command line arguments.199// When non empty, this vector really is of length one more than200// what size() reports, as it is always null-terminated, to comply201// with POSIX-style operating system requirements.202struct Arguments : std::vector<char*> {203explicit Arguments(int n = 0);204int size() const;205void allocate(int);206char* const* data() const;207};208209// -------------210// -- Command --211// -------------212// A description of external command to be executed.213struct Command {214Process core; // arguments for actual executable.215Arguments rt_args; // arguments to the base RT, if any.216const char* root_dir; // path to the OpenAxiom system.217const char* exec_path; // path to the program to execute.218Command();219};220221// ----------------222// -- Filesystem --223// ----------------224// Basic interface to the OpenAxiom filesystem225struct Filesystem {226// Construct the basic filesystem from the OpenAxiom system227// directory. All other directories are derived from the root.228explicit Filesystem(const std::string&);229230// The directory containing the core system231std::string sysdir() const;232233// The directory containing algebra modules234std::string algdir() const;235236// The directory containing database files.237std::string dbdir() const;238239private:240const std::string root;241const std::string alg;242const std::string db;243};244245// Return the path name the specified dabatase file.246std::string database_filepath(const Filesystem&, const std::string&);247248249const char* get_systemdir(int argc, char*[]);250const char* make_path_for(const char*, Driver);251252// Return a pointer the string value associated with an option.253const char* option_value(const Command*, const char*);254255int execute_core(const Command*, Driver);256void build_rts_options(Command*, Driver);257258Driver preprocess_arguments(Command*, int, char**);259260// Return the length of an array literal.261template<typename T, int N>262inline int length(T(&)[N]) {263return N;264}265}266267#endif /* OPENAXIOM_included */268269// Local Variables:270// mode: c++271// End:272273274