diff --git a/os/CMakeLists.txt b/os/CMakeLists.txt new file mode 100644 index 000000000..1eb860c57 --- /dev/null +++ b/os/CMakeLists.txt @@ -0,0 +1,84 @@ + +set (YAPOS_SOURCES + alias.c + charsio.c + chartypes.c + console.c + files.c + fmemopen.c + format.c + iopreds.c + mem.c + open_memstream.c + pipes.c + readline.c + readterm.c + readutil.c + sockets.c + streams.c + sysbits.c + writeterm.c + ypsocks.c + ypstdio.c + encoding.h + iopreds.h + fmemopen.h + yapio.h + ) + +include_directories (../H ../include . ${GMP_INCLUDE_DIR} ${PROJECT_BINARY_DIR}) + +macro_optional_find_package (Readline ON) +macro_log_feature (READLINE_FOUND "libreadline" + "Readline line editing library" + "http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html") + +if (READLINE_FOUND) + set( CMAKE_REQUIRED_INCLUDES ${READLINE_INCLUDE_DIR} ${CMAKE_REQUIRED_INCLUDES} ) + set( CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${READLINE_LIBRARIES} ) + check_include_files( "stdio.h;readline/readline.h" HAVE_READLINE_READLINE_H ) + check_include_files( "stdio.h;readline/history.h" HAVE_READLINE_HISTORY_H ) + if (HAVE_READLINE_READLINE_H) + SET ( USE_READLINE 1 ) + check_function_exists( add_history HAVE_ADD_HISTORY ) + check_function_exists( rl_begin_undo_group HAVE_RL_BEGIN_UNDO_GROUP) + check_function_exists( rl_clear_pending_input HAVE_RL_CLEAR_PENDING_INPUT) + check_function_exists( rl_discard_argument HAVE_RL_DISCARD_ARGUMENT) + check_function_exists( rl_filename_completion_function HAVE_RL_FILENAME_COMPLETION_FUNCTION) + check_function_exists( rl_free_line_state HAVE_RL_FREE_LINE_STATE ) + check_function_exists( rl_insert_close HAVE_RL_INSERT_CLOSE ) + check_function_exists( rl_reset_after_signal HAVE_RL_RESET_AFTER_SIGNAL ) + check_function_exists( rl_set_keyboard_input_timeout HAVE_RL_SET_KEYBOARD_INPUT_TIMEOUT ) + check_function_exists( rl_set_prompt HAVE_RL_SET_PROMPT) + check_symbol_exists( rl_catch_signals stdio.h;readline/readline.h HAVE_DECL_RL_CATCH_SIGNALS ) + check_symbol_exists( rl_completion_func_t stdio.h;readline/readline.h HAVE_DECL_RL_COMPLETION_FUNC_T ) + check_symbol_exists( rl_done stdio.h;readline/readline.h HAVE_DECL_RL_DONE ) + check_symbol_exists( rl_hook_func_t stdio.h;readline/readline.h HAVE_DECL_RL_HOOK_FUNC_T ) + check_symbol_exists( rl_event_hook stdio.h;readline/readline.h HAVE_DECL_RL_EVENT_HOOK ) + check_symbol_exists( rl_readline_state stdio.h;readline/readline.h HAVE_DECL_RL_READLINE_STATE ) + endif() +endif (READLINE_FOUND) + + +set (POSITION_INDEPENDENT_CODE TRUE) + +add_library (libYAPOs OBJECT + ${YAPOS_SOURCES} ) + +set_target_properties(libYAPOs + PROPERTIES + # RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION} + # SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION} + POSITION_INDEPENDENT_CODE TRUE + OUTPUT_NAME YAPOs + ) + +# target_link_libraries(libYAPOs ${YAP_LIBRARY} m) + +configure_file ("${PROJECT_SOURCE_DIR}/os/YapIOConfig.h.cmake" + "${PROJECT_BINARY_DIR}/os/YapIOConfig.h" ) + + set( READLINE_LIBS ${READLINE_LIBRARIES} PARENT_SCOPE) + + +#set( CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${GMP_LIBRARIES} ) diff --git a/os/YapIOConfig.h b/os/YapIOConfig.h new file mode 100644 index 000000000..1825782cf --- /dev/null +++ b/os/YapIOConfig.h @@ -0,0 +1,99 @@ +/* Define if you have libreadline */ +#ifndef HAVE_LIBREADLINE +#define HAVE_LIBREADLINE YES +#endif + +/* Define to 1 if you have the declaration of `rl_catch_signals ', and to 0 if +you don't. */ +#ifndef HAVE_DECL_RL_CATCH_SIGNALS_ +/* #undef HAVE_DECL_RL_CATCH_SIGNALS */ +#endif + +/* Define to 1 if you have the declaration of `rl_done ', and to 0 if you +don't. */ +#ifndef HAVE_DECL_RL_DONE_ +/* #undef HAVE_DECL_RL_DONE_ */ +#endif + +/* Define to 1 if you have the declaration of `rl_event_hook', and to 0 if you +don't. */ +#ifndef HAVE_DECL_RL_EVENT_HOOK +/* #undef HAVE_DECL_RL_EVENT_HOOK */ +#endif + +/* Define to 1 if you have the declaration of `rl_readline_state', and to 0 if +you don't. */ +#ifndef HAVE_DECL_RL_READLINE_STATE +/* #undef HAVE_DECL_RL_READLINE_STATE */ +#endif + +/* Define to 1 if you have the `rl_begin_undo_group' function. */ +#ifndef HAVE_RL_BEGIN_UNDO_GROUP +#define HAVE_RL_BEGIN_UNDO_GROUP 1 +#endif + +/* Define to 1 if you have the `rl_clear_pending_input' function. */ +#ifndef HAVE_RL_CLEAR_PENDING_INPUT +#define HAVE_RL_CLEAR_PENDING_INPUT 1 +#endif + +/* Define to 1 if the system has the type `rl_completion_func_t'). */ +#ifndef HAVE_RL_COMPLETION_FUNC_T +/* #undef HAVE_RL_COMPLETION_FUNC_T */ +#endif + +/* Define to 1 if the system has the type `rl_completion_func_t'. */ +#ifndef HAVE_RL_COMPLETION_FUNC_T +/* #undef HAVE_RL_COMPLETION_FUNC_T */ +#endif + +/* Define to 1 if you have the `rl_completion_matches' function. */ +#ifndef HAVE_RL_COMPLETION_MATCHES +/* #undef HAVE_RL_COMPLETION_MATCHES */ +#endif + +/* Define to 1 if you have the `rl_discard_argument' function. */ +#ifndef HAVE_RL_DISCARD_ARGUMENT +#define HAVE_RL_DISCARD_ARGUMENT 1 +#endif + +/* Define to 1 if you have the `rl_done' variable. */ +#ifndef HAVE_RL_DONE +#define HAVE_RL_DONE +#endif + +/* Define to 1 if you have the `rl_filename_completion_function' function. */ +#ifndef HAVE_RL_FILENAME_COMPLETION_FUNCTION +#define HAVE_RL_FILENAME_COMPLETION_FUNCTION 1 +#endif + +/* Define to 1 if you have the `rl_free_line_state' function. */ +#ifndef HAVE_RL_FREE_LINE_STATE +#define HAVE_RL_FREE_LINE_STATE 1 +#endif + +/* Define to 1 if the system has the type `rl_hook_func_t'. */ +#ifndef HAVE_RL_HOOK_FUNC_T +/* #undef HAVE_RL_HOOK_FUNC_T */ +#endif + +/* Define to 1 if you have the `rl_insert_close' function. */ +#ifndef HAVE_RL_INSERT_CLOSE +#define HAVE_RL_INSERT_CLOSE 1 +#endif + +/* Define to 1 if you have the `rl_reset_after_signal' function. */ +#ifndef HAVE_RL_RESET_AFTER_SIGNAL +#define HAVE_RL_RESET_AFTER_SIGNAL 1 +#endif + +/* Define to 1 if you have the `rl_set_keyboard_input_timeout' function. */ +#ifndef HAVE_RL_SET_KEYBOARD_INPUT_TIMEOUT +#define HAVE_RL_SET_KEYBOARD_INPUT_TIMEOUT 1 +#endif + +/* Define to 1 if you have the `rl_set_prompt' function. */ +#ifndef HAVE_RL_SET_PROMPT +#define HAVE_RL_SET_PROMPT 1 +#endif + diff --git a/os/YapIOConfig.h.cmake b/os/YapIOConfig.h.cmake new file mode 100644 index 000000000..fa7a00eb6 --- /dev/null +++ b/os/YapIOConfig.h.cmake @@ -0,0 +1,108 @@ +/* Define if you have libreadline */ +#ifndef HAVE_LIBREADLINE +#define HAVE_LIBREADLINE ${USE_READLINE} +#endif + +/* Define to 1 if you have the header file. */ +#ifndef HAVE_READLINE_HISTORY_H +#cmakedefine HAVE_READLINE_HISTORY_H ${HAVE_READLINE_HISTORY_H} +#endif + +/* Define to 1 if you have the header file. */ +#ifndef HAVE_READLINE_READLINE_H +#cmakedefine HAVE_READLINE_READLINE_H ${HAVE_READLINE_READLINE_H} +#endif + +/* Define to 1 if you have the declaration of `rl_catch_signals ', and to 0 if +you don't. */ +#ifndef HAVE_DECL_RL_CATCH_SIGNALS_ +#cmakedefine HAVE_DECL_RL_CATCH_SIGNALS ${HAVE_DECL_RL_CATCH_SIGNALS} +#endif + +/* Define to 1 if you have the declaration of `rl_done ', and to 0 if you +don't. */ +#ifndef HAVE_DECL_RL_DONE_ +#cmakedefine HAVE_DECL_RL_DONE_ ${HAVE_DECL_RL_DONE_} +#endif + +/* Define to 1 if you have the declaration of `rl_event_hook', and to 0 if you +don't. */ +#ifndef HAVE_DECL_RL_EVENT_HOOK +#cmakedefine HAVE_DECL_RL_EVENT_HOOK ${HAVE_DECL_RL_EVENT_HOOK} +#endif + +/* Define to 1 if you have the declaration of `rl_readline_state', and to 0 if +you don't. */ +#ifndef HAVE_DECL_RL_READLINE_STATE +#cmakedefine HAVE_DECL_RL_READLINE_STATE ${HAVE_DECL_RL_READLINE_STATE} +#endif + +/* Define to 1 if you have the `rl_begin_undo_group' function. */ +#ifndef HAVE_RL_BEGIN_UNDO_GROUP +#cmakedefine HAVE_RL_BEGIN_UNDO_GROUP ${HAVE_RL_BEGIN_UNDO_GROUP} +#endif + +/* Define to 1 if you have the `rl_clear_pending_input' function. */ +#ifndef HAVE_RL_CLEAR_PENDING_INPUT +#cmakedefine HAVE_RL_CLEAR_PENDING_INPUT ${HAVE_RL_CLEAR_PENDING_INPUT} +#endif + +/* Define to 1 if the system has the type `rl_completion_func_t'). */ +#ifndef HAVE_RL_COMPLETION_FUNC_T +#cmakedefine HAVE_RL_COMPLETION_FUNC_T ${HAVE_RL_COMPLETION_FUNC_T} +#endif + +/* Define to 1 if the system has the type `rl_completion_func_t'. */ +#ifndef HAVE_RL_COMPLETION_FUNC_T +#cmakedefine HAVE_RL_COMPLETION_FUNC_T ${HAVE_RL_COMPLETION_FUNC_T} +#endif + +/* Define to 1 if you have the `rl_completion_matches' function. */ +#ifndef HAVE_RL_COMPLETION_MATCHES +#cmakedefine HAVE_RL_COMPLETION_MATCHES ${HAVE_RL_COMPLETION_MATCHES} +#endif + +/* Define to 1 if you have the `rl_discard_argument' function. */ +#ifndef HAVE_RL_DISCARD_ARGUMENT +#cmakedefine HAVE_RL_DISCARD_ARGUMENT ${HAVE_RL_DISCARD_ARGUMENT} +#endif + +/* Define to 1 if you have the `rl_done' variable. */ +#ifndef HAVE_RL_DONE +#define HAVE_RL_DONE ${HAVE_RL_DONE} +#endif + +/* Define to 1 if you have the `rl_filename_completion_function' function. */ +#ifndef HAVE_RL_FILENAME_COMPLETION_FUNCTION +#define HAVE_RL_FILENAME_COMPLETION_FUNCTION ${HAVE_RL_FILENAME_COMPLETION_FUNCTION} +#endif + +/* Define to 1 if you have the `rl_free_line_state' function. */ +#ifndef HAVE_RL_FREE_LINE_STATE +#cmakedefine HAVE_RL_FREE_LINE_STATE ${HAVE_RL_FREE_LINE_STATE} +#endif + +/* Define to 1 if the system has the type `rl_hook_func_t'. */ +#ifndef HAVE_RL_HOOK_FUNC_T +#cmakedefine HAVE_RL_HOOK_FUNC_T ${HAVE_RL_HOOK_FUNC_T} +#endif + +/* Define to 1 if you have the `rl_insert_close' function. */ +#ifndef HAVE_RL_INSERT_CLOSE +#cmakedefine HAVE_RL_INSERT_CLOSE ${HAVE_RL_INSERT_CLOSE} +#endif + +/* Define to 1 if you have the `rl_reset_after_signal' function. */ +#ifndef HAVE_RL_RESET_AFTER_SIGNAL +#cmakedefine HAVE_RL_RESET_AFTER_SIGNAL ${HAVE_RL_RESET_AFTER_SIGNAL} +#endif + +/* Define to 1 if you have the `rl_set_keyboard_input_timeout' function. */ +#ifndef HAVE_RL_SET_KEYBOARD_INPUT_TIMEOUT +#cmakedefine HAVE_RL_SET_KEYBOARD_INPUT_TIMEOUT ${HAVE_RL_SET_KEYBOARD_INPUT_TIMEOUT} +#endif + +/* Define to 1 if you have the `rl_set_prompt' function. */ +#ifndef HAVE_RL_SET_PROMPT +#cmakedefine HAVE_RL_SET_PROMPT ${HAVE_RL_SET_PROMPT} +#endif diff --git a/os/yapio.h b/os/yapio.h new file mode 100644 index 000000000..0687fecec --- /dev/null +++ b/os/yapio.h @@ -0,0 +1,217 @@ +/************************************************************************* +* * +* YAP Prolog %W% %G% +* * +* Yap Prolog was developed at NCCUP - Universidade do Porto * +* * +* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2003 * +* * +************************************************************************** +* * +* File: yapio.h * +* Last rev: 22/1/03 * +* mods: * +* comments: Input/Output information * +* * +*************************************************************************/ + +#ifndef YAPIO_H + +#define YAPIO_H 1 + +#ifdef SIMICS +#undef HAVE_LIBREADLINE +#endif + +#include +#include + +#include +#include "os/YapIOConfig.h" + +#ifndef _PL_WRITE_ + +/* Character types for tokenizer and write.c */ + +#define UC 1 /* Upper case */ +#define UL 2 /* Underline */ +#define LC 3 /* Lower case */ +#define NU 4 /* digit */ +#define QT 5 /* single quote */ +#define DC 6 /* double quote */ +#define SY 7 /* Symbol character */ +#define SL 8 /* Solo character */ +#define BK 9 /* Brackets & friends */ +#define BS 10 /* Blank */ +#define EF 11 /* End of File marker */ +#define CC 12 /* comment char % */ + +#define EOFCHAR EOF + +#endif + +/* info on aliases */ +typedef struct AliasDescS { + Atom name; + int alias_stream; +} * AliasDesc; + + +#define MAX_ISO_LATIN1 255 + +/****************** character definition table **************************/ + +#define NUMBER_OF_CHARS 256 +extern char *Yap_chtype; + +#include "inline-only.h" +INLINE_ONLY EXTERN inline int chtype(Int); +int Yap_wide_chtype(Int); + +INLINE_ONLY EXTERN inline int +chtype(Int ch) +{ + if (ch < NUMBER_OF_CHARS) + return Yap_chtype[ch]; + return Yap_wide_chtype(ch); +} + + +/* parser stack, used to be AuxSp, now is ASP */ +#define ParserAuxSp LOCAL_ScannerStack + +/* routines in parser.c */ +VarEntry *Yap_LookupVar(char *); +Term Yap_VarNames(VarEntry *,Term); +Term Yap_Variables(VarEntry *,Term); +Term Yap_Singletons(VarEntry *,Term); + +/* routines in scanner.c */ +TokEntry *Yap_tokenizer( struct stream_desc *, bool, Term *d); +void Yap_clean_tokenizer(TokEntry *, VarEntry *, VarEntry *); +char *Yap_AllocScannerMemory(unsigned int); + +/* routines in iopreds.c */ +FILE *Yap_FileDescriptorFromStream(Term); +Int Yap_FirstLineInParse(void); +int Yap_CheckIOStream(Term, char *); +#if defined(YAPOR) || defined(THREADS) +void Yap_LockStream(void *); +void Yap_UnLockStream(void *); +#else +#define Yap_LockStream(X) +#define Yap_UnLockStream(X) +#endif +Int Yap_GetStreamFd(int); +void Yap_CloseStreams(int); +void Yap_FlushStreams(void); +void Yap_ReleaseStream(int); +void Yap_CloseStream(int); +int Yap_PlGetchar(void); +int Yap_PlGetWchar(void); +int Yap_PlFGetchar(void); +int Yap_GetCharForSIGINT(void); +Int Yap_StreamToFileNo(Term); +int Yap_OpenStream(FILE *,char *,Term,int); +char *Yap_TermToString(Term t, char *s, size_t sz, size_t *length, encoding_t encoding, int flags); +char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length, encoding_t encoding, int flags); +int Yap_GetFreeStreamD(void); +int Yap_GetFreeStreamDForReading(void); + +Term Yap_WStringToList(wchar_t *); +Term Yap_WStringToListOfAtoms(wchar_t *); +Atom Yap_LookupWideAtom( const wchar_t * ); + +#define Quote_illegal_f 0x01 +#define Ignore_ops_f 0x02 +#define Handle_vars_f 0x04 +#define Use_portray_f 0x08 +#define To_heap_f 0x10 +#define Unfold_cyclics_f 0x20 +#define Use_SWI_Stream_f 0x40 +#define BackQuote_String_f 0x80 +#define AttVar_None_f 0x100 +#define AttVar_Dots_f 0x200 +#define AttVar_Portray_f 0x400 +#define Blob_Portray_f 0x800 +#define No_Escapes_f 0x1000 +#define No_Brace_Terms_f 0x2000 +#define Fullstop_f 0x4000 +#define New_Line_f 0x8000 + + + +/* grow.c */ +int Yap_growheap_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **); +int Yap_growstack_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **); +int Yap_growtrail_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **); + +bool Yap_IsAbsolutePath(const char *p); +Atom Yap_TemporaryFile( const char *prefix, int *fd); +char *Yap_AbsoluteFile(const char *spec, char *tmp); + +typedef enum mem_buf_source { + MEM_BUF_CODE=1, + MEM_BUF_MALLOC=2, + MEM_BUF_USER=4 +} memBufSource; + +struct mem_desc *Yap_MemExportStreamPtrs( int sno ); + +extern Term Yap_StringToTerm(const char *s, size_t len, encoding_t enc, int prio, Term *bindings_p); +extern Term Yap_StringToNumberTerm(char *s, encoding_t encp); +int Yap_FormatFloat(Float f, const char *s, size_t sz); +int Yap_open_buf_read_stream(const char *nbuf, size_t nchars, encoding_t enc, memBufSource src); +Term Yap_ReadFromAtom(Atom a, Term opts); +int Yap_open_buf_write_stream(char **nbufp, size_t * szp); +FILE *Yap_GetInputStream(Term t, const char *m); +FILE *Yap_GetOutputStream(Term t,const char *m); +char * Yap_guessFileName(int f, int sno, char *nameb, size_t max); +void Yap_plwrite(Term t, struct stream_desc *mywrite, int max_depth, int flags, int priority); + +int Yap_CheckSocketStream(Term stream, const char * error); +void Yap_init_socks(char *host, long interface_port); + +#ifdef HAVE_ERRNO_H +#include +#else +extern int errno; +#endif + +INLINE_ONLY EXTERN UInt inline HashFunction(unsigned char *); +INLINE_ONLY EXTERN UInt inline WideHashFunction(wchar_t *); + +INLINE_ONLY EXTERN inline UInt +HashFunction(unsigned char *CHP) +{ + /* djb2 */ + UInt hash = 5381; + UInt c; + + while ((c = *CHP++) != '\0') { + /* hash = ((hash << 5) + hash) + c; hash * 33 + c */ + hash = hash * 33 ^ c; + } + return hash; + /* + UInt OUT=0, i = 1; + while(*CHP != '\0') { OUT += (UInt)(*CHP++); } + return OUT; + */ +} + +INLINE_ONLY EXTERN UInt inline +WideHashFunction(wchar_t *CHP) +{ + UInt hash = 5381; + + UInt c; + + while ((c = *CHP++) != '\0') { + hash = hash * 33 ^ c; + } + return hash; +} + +#endif +