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/packages/swig/android/streamer.cpp
Vitor Santos Costa 9dab200c61 treamer
2017-11-18 08:16:09 +00:00

97 lines
1.8 KiB
C++

//
// Created by vsc on 7/6/17.
//
/* File : example.cxx */
#include "streamer.h"
static AndroidStreamer * streamerInstance = 0;
void setStreamer(AndroidStreamer* streamer) {
streamerInstance = streamer;
}
AndroidStreamer& getStreamer() {
return *streamerInstance;
}
#include <gmpxx.h>
extern "C" {
#include <Yap.h>
#include <YapStreams.h>
#include <VFS.h>
VFS_t andstream;
static std::string buff0;
int n;
static void *
and_open(const char *name, const char *io_mode) {
if (!strcmp(name,"//android/user_output") ||
!strcmp(name,"//android/user_error"))
// we assume object is already open, so there is no need to open it.
return streamerInstance;
else
return NULL;
}
static bool
and_close(int sno) {
return true;
}
static int
and_put(int sno, int ch) {
buff0[n++] = ch;
if (ch=='\n' || n == 128) { buff0[n] = '\0'; streamerInstance->display(buff0); n = 0; }
return ch;
}
static int
and_get(int sno) {
return EOF;
}
static int64_t and_seek(int sno, int64_t where, int how) {
return EOF;
}
static void
and_flush(int sno) {
buff0[n] = '\0';
streamerInstance->display(buff0); n = 0;
}
//
// Created by vsc on 11-07-2017.
//
}
void
AndroidStreamer::bind()
{
buff0 = * new std::string[256];
n = 0;
andstream.name = "//android/user_error";
andstream.vflags = VFS_CAN_WRITE|VFS_HAS_PREFIX;
andstream.prefix = "//android/";
andstream.suffix = NULL;
andstream.open = and_open;
andstream.close = and_close;
andstream.get_char = and_get;
andstream.put_char = and_put;
andstream.flush = and_flush;
andstream.seek = and_seek;
andstream.next = GLOBAL_VFS;
GLOBAL_VFS = &andstream;
// NULL;
Yap_InitStdStream(StdOutStream, Output_Stream_f, NULL, &andstream);
Yap_InitStdStream(StdErrStream, Output_Stream_f, NULL, &andstream);
}