This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/os/yapio.h

201 lines
5.3 KiB
C
Raw Normal View History

2015-06-18 01:48:44 +01:00
/*************************************************************************
* *
* 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 <stdio.h>
#include <wchar.h>
#include <Yatom.h>
#include "os/YapIOConfig.h"
#ifndef _PL_WRITE_
#define EOFCHAR EOF
#endif
/* info on aliases */
typedef struct AliasDescS {
2015-10-22 00:41:52 +01:00
Atom name;
int alias_stream;
2015-06-18 01:48:44 +01:00
} * AliasDesc;
#define MAX_ISO_LATIN1 255
/* parser stack, used to be AuxSp, now is ASP */
#define ParserAuxSp LOCAL_ScannerStack
/* routines in parser.c */
2015-07-23 01:33:30 +01:00
VarEntry *Yap_LookupVar(const char *);
2015-10-22 00:41:52 +01:00
Term Yap_VarNames(VarEntry *, Term);
Term Yap_Variables(VarEntry *, Term);
Term Yap_Singletons(VarEntry *, Term);
2015-06-18 01:48:44 +01:00
/* routines in scanner.c */
2015-10-22 00:41:52 +01:00
TokEntry *Yap_tokenizer(struct stream_desc *, bool, Term *d);
void Yap_clean_tokenizer(TokEntry *, VarEntry *, VarEntry *);
char *Yap_AllocScannerMemory(unsigned int);
2015-06-18 01:48:44 +01:00
/* routines in iopreds.c */
2015-10-22 00:41:52 +01:00
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 *);
2015-06-18 01:48:44 +01:00
#else
#define Yap_LockStream(X)
#define Yap_UnLockStream(X)
#endif
2015-10-22 00:41:52 +01:00
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
2015-06-18 01:48:44 +01:00
/* grow.c */
2015-10-22 00:41:52 +01:00
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 **);
2015-06-18 01:48:44 +01:00
bool Yap_IsAbsolutePath(const char *p);
2015-10-22 00:41:52 +01:00
Atom Yap_TemporaryFile(const char *prefix, int *fd);
2015-06-18 01:48:44 +01:00
char *Yap_AbsoluteFile(const char *spec, char *tmp);
typedef enum mem_buf_source {
2015-10-22 00:41:52 +01:00
MEM_BUF_CODE = 1,
MEM_BUF_MALLOC = 2,
MEM_BUF_USER = 4
2015-06-18 01:48:44 +01:00
} memBufSource;
2015-10-22 00:41:52 +01:00
char *Yap_MemStreamBuf(int sno);
2015-07-06 12:03:16 +01:00
2015-10-22 00:41:52 +01:00
extern Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp,
int prio, Term *bindings_p);
extern Term Yap_StringToNumberTerm(char *s, encoding_t *encp);
int Yap_FormatFloat(Float f, char **s, size_t sz);
int Yap_open_buf_read_stream(const char *nbuf, size_t nchars, encoding_t *encp,
memBufSource src);
int Yap_open_buf_write_stream(char *nbuf, size_t nchars, encoding_t *encp,
memBufSource src);
2015-06-18 01:48:44 +01:00
Term Yap_ReadFromAtom(Atom a, Term opts);
2015-10-22 00:41:52 +01:00
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);
2015-06-18 01:48:44 +01:00
2015-10-22 00:41:52 +01:00
int Yap_CheckSocketStream(Term stream, const char *error);
2015-06-18 01:48:44 +01:00
void Yap_init_socks(char *host, long interface_port);
#ifdef HAVE_ERRNO_H
#include <errno.h>
#else
extern int errno;
#endif
2015-09-21 23:05:36 +01:00
INLINE_ONLY EXTERN UInt inline HashFunction(const unsigned char *);
2015-06-18 01:48:44 +01:00
INLINE_ONLY EXTERN UInt inline WideHashFunction(wchar_t *);
2015-10-22 00:41:52 +01:00
INLINE_ONLY EXTERN inline UInt HashFunction(const unsigned char *CHP) {
2015-06-18 01:48:44 +01:00
/* djb2 */
UInt hash = 5381;
UInt c;
2015-07-23 01:33:30 +01:00
while ((c = (UInt)(*CHP++)) != '\0') {
2015-06-18 01:48:44 +01:00
/* 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;
*/
}
2015-10-22 00:41:52 +01:00
INLINE_ONLY EXTERN UInt inline WideHashFunction(wchar_t *CHP) {
2015-06-18 01:48:44 +01:00
UInt hash = 5381;
UInt c;
while ((c = *CHP++) != '\0') {
hash = hash * 33 ^ c;
}
return hash;
}
2015-10-22 00:41:52 +01:00
INLINE_ONLY inline EXTERN Term MkCharTerm(Int c);
/**
* MkCharTerm: convert a character into a single atom.
*
* @param c the character code
*
* @return the term.
*/
INLINE_ONLY inline EXTERN Term MkCharTerm(Int c) {
wchar_t cs[2];
if (c < 0)
return MkAtomTerm(AtomEof);
cs[0] = c;
cs[1] = '\0';
return MkAtomTerm(Yap_LookupMaybeWideAtom(cs));
}
2015-06-18 01:48:44 +01:00
#endif