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

152 lines
4.8 KiB
C
Raw Normal View History

2016-04-10 14:21:17 +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 "os/YapIOConfig.h"
#include <Yatom.h>
#ifndef _PL_WRITE_
#define EOFCHAR EOF
#endif
/* info on aliases */
typedef struct AliasDescS {
Atom name;
int alias_stream;
} * AliasDesc;
#define MAX_ISO_LATIN1 255
/* parser stack, used to be AuxSp, now is ASP */
#define ParserAuxSp LOCAL_ScannerStack
/* routines in parser.c */
2016-08-05 22:35:50 +01:00
extern VarEntry *Yap_LookupVar(const char *);
extern Term Yap_VarNames(VarEntry *, Term);
extern Term Yap_Variables(VarEntry *, Term);
extern Term Yap_Singletons(VarEntry *, Term);
2016-04-10 14:21:17 +01:00
/* routines in scanner.c */
2016-08-05 22:35:50 +01:00
extern TokEntry *Yap_tokenizer(struct stream_desc *, bool, Term *d);
extern void Yap_clean_tokenizer(TokEntry *, VarEntry *, VarEntry *);
extern char *Yap_AllocScannerMemory(unsigned int);
2016-04-10 14:21:17 +01:00
/* routines in iopreds.c */
2016-08-05 22:35:50 +01:00
extern FILE *Yap_FileDescriptorFromStream(Term);
extern Int Yap_FirstLineInParse(void);
extern int Yap_CheckIOStream(Term, char *);
2016-04-10 14:21:17 +01:00
#if defined(YAPOR) || defined(THREADS)
2016-08-05 22:35:50 +01:00
extern void Yap_LockStream(void *);
extern void Yap_UnLockStream(void *);
2016-04-10 14:21:17 +01:00
#else
#define Yap_LockStream(X)
#define Yap_UnLockStream(X)
#endif
2016-08-05 22:35:50 +01:00
extern Int Yap_GetStreamFd(int);
extern void Yap_CloseStreams(int);
extern void Yap_FlushStreams(void);
extern void Yap_ReleaseStream(int);
extern int Yap_PlGetchar(void);
extern int Yap_PlGetWchar(void);
extern int Yap_PlFGetchar(void);
extern int Yap_GetCharForSIGINT(void);
extern Int Yap_StreamToFileNo(Term);
extern int Yap_OpenStream(FILE *, char *, Term, int);
extern char *Yap_TermToString(Term t, size_t *length, encoding_t encoding,
int flags);
extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length,
encoding_t *encoding, int flags);
extern int Yap_GetFreeStreamD(void);
extern int Yap_GetFreeStreamDForReading(void);
extern Term Yap_WStringToList(wchar_t *);
extern Term Yap_WStringToListOfAtoms(wchar_t *);
extern Atom Yap_LookupWideAtom(const wchar_t *);
2016-04-10 14:21:17 +01:00
/* grow.c */
2016-08-05 22:35:50 +01:00
extern int Yap_growheap_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
extern int Yap_growstack_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
extern int Yap_growtrail_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
2016-04-10 14:21:17 +01:00
2016-08-05 22:35:50 +01:00
extern bool Yap_IsAbsolutePath(const char *p);
extern Atom Yap_TemporaryFile(const char *prefix, int *fd);
extern const char *Yap_AbsoluteFile(const char *spec, char *obuf, bool expand);
2016-04-10 14:21:17 +01:00
typedef enum mem_buf_source {
2016-07-31 15:55:50 +01:00
MEM_BUF_MALLOC = 1,
MEM_BUF_USER = 2
2016-04-10 14:21:17 +01:00
} memBufSource;
2016-08-05 22:35:50 +01:00
extern char *Yap_MemStreamBuf(int sno);
2016-04-10 14:21:17 +01:00
2016-08-05 22:35:50 +01:00
extern X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp,
int prio, Term *bindings_p);
2016-08-05 22:35:50 +01:00
extern Term Yap_StringToNumberTerm(const char *s, encoding_t *encp);
2016-07-31 15:55:50 +01:00
extern int Yap_FormatFloat(Float f, char **s, size_t sz);
2016-08-05 22:35:50 +01:00
extern int Yap_open_buf_read_stream(const char *buf, size_t nchars,
encoding_t *encp, memBufSource src);
2016-07-31 15:55:50 +01:00
extern bool Yap_set_stream_to_buf(struct stream_desc *st, const char *buf,
2016-08-05 22:35:50 +01:00
size_t nchars);
2016-07-31 15:55:50 +01:00
extern int Yap_open_buf_write_stream(encoding_t enc, memBufSource src);
extern Term Yap_AtomToTerm(Atom a, Term opts);
extern FILE *Yap_GetInputStream(Term t, const char *m);
extern FILE *Yap_GetOutputStream(Term t, const char *m);
extern char *Yap_guessFileName(FILE *f, int sno, char *nameb, size_t max);
2016-08-05 22:35:50 +01:00
extern void Yap_plwrite(Term t, struct stream_desc *mywrite, int max_depth,
int flags, int priority);
2016-04-10 14:21:17 +01:00
2016-07-31 15:55:50 +01:00
extern int Yap_CheckSocketStream(Term stream, const char *error);
extern void Yap_init_socks(char *host, long interface_port);
2016-04-10 14:21:17 +01:00
2016-07-31 15:55:50 +01:00
extern uint64_t HashFunction(const unsigned char *);
extern uint64_t WideHashFunction(wchar_t *);
2016-04-10 14:21:17 +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 TermEof;
cs[0] = c;
cs[1] = '\0';
return MkAtomTerm(Yap_LookupMaybeWideAtom(cs));
}
/// UT when yap started
2016-07-31 15:55:50 +01:00
extern uint64_t Yap_StartOfWTimes;
2016-04-10 14:21:17 +01:00
#endif