signed wchar
This commit is contained in:
parent
4d3d9c408d
commit
71f0076ed6
25
os/format.c
25
os/format.c
@ -233,10 +233,10 @@ output is directed to the stream used by format/2.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
#include "Yatom.h"
|
|
||||||
#include "YapHeap.h"
|
#include "YapHeap.h"
|
||||||
#include "yapio.h"
|
|
||||||
#include "YapText.h"
|
#include "YapText.h"
|
||||||
|
#include "Yatom.h"
|
||||||
|
#include "yapio.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#if HAVE_UNISTD_H
|
#if HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -257,8 +257,8 @@ output is directed to the stream used by format/2.
|
|||||||
#define S_ISDIR(x) (((x)&_S_IFDIR) == _S_IFDIR)
|
#define S_ISDIR(x) (((x)&_S_IFDIR) == _S_IFDIR)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#include "iopreds.h"
|
|
||||||
#include "eval.h"
|
#include "eval.h"
|
||||||
|
#include "iopreds.h"
|
||||||
|
|
||||||
#define FORMAT_MAX_SIZE 1024
|
#define FORMAT_MAX_SIZE 1024
|
||||||
|
|
||||||
@ -618,7 +618,8 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
goto do_type_atom_error;
|
goto do_type_atom_error;
|
||||||
yhandle_t sl = Yap_StartSlots();
|
yhandle_t sl = Yap_StartSlots();
|
||||||
// stream is already locked.
|
// stream is already locked.
|
||||||
Yap_plwrite(t, GLOBAL_Stream + sno, 0, Handle_vars_f | To_heap_f, GLOBAL_MaxPriority);
|
Yap_plwrite(t, GLOBAL_Stream + sno, 0, Handle_vars_f | To_heap_f,
|
||||||
|
GLOBAL_MaxPriority);
|
||||||
Yap_CloseSlots(sl);
|
Yap_CloseSlots(sl);
|
||||||
break;
|
break;
|
||||||
case 'c': {
|
case 'c': {
|
||||||
@ -810,8 +811,8 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
char *pt, *res;
|
char *pt, *res;
|
||||||
|
|
||||||
tmpbase = tmp1;
|
tmpbase = tmp1;
|
||||||
while (!(res = Yap_gmp_to_string(t, tmpbase, TMP_STRING_SIZE,
|
while (!(
|
||||||
radix))) {
|
res = Yap_gmp_to_string(t, tmpbase, TMP_STRING_SIZE, radix))) {
|
||||||
if (tmpbase == tmp1) {
|
if (tmpbase == tmp1) {
|
||||||
tmpbase = NULL;
|
tmpbase = NULL;
|
||||||
} else {
|
} else {
|
||||||
@ -871,7 +872,8 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
t = targs[targ++];
|
t = targs[targ++];
|
||||||
yhandle_t sl = Yap_StartSlots();
|
yhandle_t sl = Yap_StartSlots();
|
||||||
Yap_plwrite(t, GLOBAL_Stream + sno, 0,
|
Yap_plwrite(t, GLOBAL_Stream + sno, 0,
|
||||||
Quote_illegal_f | Ignore_ops_f | To_heap_f, GLOBAL_MaxPriority);
|
Quote_illegal_f | Ignore_ops_f | To_heap_f,
|
||||||
|
GLOBAL_MaxPriority);
|
||||||
Yap_CloseSlots(sl);
|
Yap_CloseSlots(sl);
|
||||||
break;
|
break;
|
||||||
case '@':
|
case '@':
|
||||||
@ -910,7 +912,8 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
{
|
{
|
||||||
Int sl = Yap_InitSlot(args);
|
Int sl = Yap_InitSlot(args);
|
||||||
Yap_plwrite(t, GLOBAL_Stream + sno, 0,
|
Yap_plwrite(t, GLOBAL_Stream + sno, 0,
|
||||||
Handle_vars_f | Use_portray_f | To_heap_f, GLOBAL_MaxPriority);
|
Handle_vars_f | Use_portray_f | To_heap_f,
|
||||||
|
GLOBAL_MaxPriority);
|
||||||
args = Yap_GetFromSlot(sl);
|
args = Yap_GetFromSlot(sl);
|
||||||
Yap_CloseSlots(sl);
|
Yap_CloseSlots(sl);
|
||||||
}
|
}
|
||||||
@ -936,7 +939,8 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
t = targs[targ++];
|
t = targs[targ++];
|
||||||
yhandle_t sl0 = Yap_StartSlots();
|
yhandle_t sl0 = Yap_StartSlots();
|
||||||
Yap_plwrite(t, GLOBAL_Stream + sno, 0,
|
Yap_plwrite(t, GLOBAL_Stream + sno, 0,
|
||||||
Handle_vars_f | Quote_illegal_f | To_heap_f, GLOBAL_MaxPriority);
|
Handle_vars_f | Quote_illegal_f | To_heap_f,
|
||||||
|
GLOBAL_MaxPriority);
|
||||||
Yap_CloseSlots(sl0);
|
Yap_CloseSlots(sl0);
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
@ -1022,8 +1026,7 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
else
|
else
|
||||||
finfo.pad_entries[finfo.padders].filler = fptr[-2];
|
finfo.pad_entries[finfo.padders].filler = fptr[-2];
|
||||||
finfo.padders++;
|
finfo.padders++;
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
do_instantiation_error:
|
do_instantiation_error:
|
||||||
LOCAL_Error_TYPE = INSTANTIATION_ERROR;
|
LOCAL_Error_TYPE = INSTANTIATION_ERROR;
|
||||||
goto do_default_error;
|
goto do_default_error;
|
||||||
|
293
os/getw.h
293
os/getw.h
@ -24,12 +24,12 @@ static int GETW(int sno) {
|
|||||||
case ENC_ISO_ANSI: {
|
case ENC_ISO_ANSI: {
|
||||||
char buf[8];
|
char buf[8];
|
||||||
int out;
|
int out;
|
||||||
int wch;
|
wchar_t wch;
|
||||||
mbstate_t mbstate;
|
mbstate_t mbstate;
|
||||||
|
|
||||||
memset((void *)&(mbstate), 0, sizeof(mbstate_t));
|
memset((void *)&(mbstate), 0, sizeof(mbstate_t));
|
||||||
buf[0] = ch;
|
buf[0] = ch;
|
||||||
int n=1;
|
int n = 1;
|
||||||
while ((out = mbrtowc(&wch, buf, 1, &(mbstate))) != 1) {
|
while ((out = mbrtowc(&wch, buf, 1, &(mbstate))) != 1) {
|
||||||
int ch = buf[0] = GETC();
|
int ch = buf[0] = GETC();
|
||||||
n++;
|
n++;
|
||||||
@ -38,166 +38,169 @@ static int GETW(int sno) {
|
|||||||
}
|
}
|
||||||
return post_process_read_wchar(wch, n, st);
|
return post_process_read_wchar(wch, n, st);
|
||||||
}
|
}
|
||||||
// UTF-8 works o 8 bits.
|
// UTF-8 works o 8 bits.
|
||||||
case ENC_ISO_UTF8: {
|
case ENC_ISO_UTF8: {
|
||||||
int wch;
|
int wch;
|
||||||
unsigned char buf[8];
|
unsigned char buf[8];
|
||||||
|
|
||||||
if (ch < 0x80) {
|
if (ch < 0x80) {
|
||||||
return post_process_read_wchar(ch, 1, st);
|
return post_process_read_wchar(ch, 1, st);
|
||||||
}
|
}
|
||||||
// if ((ch - 0xc2) > (0xf4-0xc2)) return UTF8PROC_ERROR_INVALIDUTF8;
|
// if ((ch - 0xc2) > (0xf4-0xc2)) return UTF8PROC_ERROR_INVALIDUTF8;
|
||||||
if (ch < 0xe0) { // 2-byte sequence
|
if (ch < 0xe0) { // 2-byte sequence
|
||||||
// Must have valid continuation character
|
// Must have valid continuation character
|
||||||
int c1 = buf[0] = GETC();
|
int c1 = buf[0] = GETC();
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
// if (!utf_cont(*str)) return UTF8PROC_ERROR_INVALIDUTF8;
|
// if (!utf_cont(*str)) return UTF8PROC_ERROR_INVALIDUTF8;
|
||||||
wch = ((ch & 0x1f)<<6) | (c1 & 0x3f);
|
wch = ((ch & 0x1f) << 6) | (c1 & 0x3f);
|
||||||
return post_process_read_wchar(wch, 2, st);
|
return post_process_read_wchar(wch, 2, st);
|
||||||
}
|
}
|
||||||
if (ch < 0xf0) { // 3-byte sequence
|
if (ch < 0xf0) { // 3-byte sequence
|
||||||
//if ((str + 1 >= end) || !utf_cont(*str) || !utf_cont(str[1]))
|
// if ((str + 1 >= end) || !utf_cont(*str) || !utf_cont(str[1]))
|
||||||
// return UTF8PROC_ERROR_INVALIDUTF8;
|
// return UTF8PROC_ERROR_INVALIDUTF8;
|
||||||
// Check for surrogate chars
|
// Check for surrogate chars
|
||||||
//if (ch == 0xed && *str > 0x9f)
|
// if (ch == 0xed && *str > 0x9f)
|
||||||
// return UTF8PROC_ERROR_INVALIDUTF8;
|
// return UTF8PROC_ERROR_INVALIDUTF8;
|
||||||
int c1 = GETC();
|
|
||||||
if (c1 == -1)
|
|
||||||
return post_process_weof(st);
|
|
||||||
int c2 = GETC();
|
|
||||||
if (c2 == -1)
|
|
||||||
return post_process_weof(st);
|
|
||||||
wch = ((ch & 0xf)<<12) | ((c1 & 0x3f)<<6) | (c2 & 0x3f);
|
|
||||||
return post_process_read_wchar(wch, 3, st);
|
|
||||||
} else {
|
|
||||||
int c1 = GETC();
|
|
||||||
if (c1 == -1)
|
|
||||||
return post_process_weof(st);
|
|
||||||
int c2 = GETC();
|
|
||||||
if (c2 == -1)
|
|
||||||
return post_process_weof(st);
|
|
||||||
int c3 = GETC();
|
|
||||||
if (c3 == -1)
|
|
||||||
return post_process_weof(st);
|
|
||||||
wch = ((ch & 7)<<18) | ((c1 & 0x3f)<<12) | ((c2 & 0x3f)<<6) | (c3 & 0x3f);
|
|
||||||
return post_process_read_wchar(wch, 4, st);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case ENC_UTF16_LE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
|
||||||
// little-endian: start with big shot
|
|
||||||
{
|
|
||||||
int wch;
|
|
||||||
int c1 = GETC();
|
int c1 = GETC();
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = (c1 << 8) + ch;
|
int c2 = GETC();
|
||||||
if (wch >= 0xd800 && wch < 0xdc00) {
|
if (c2 == -1)
|
||||||
int c2 = GETC();
|
return post_process_weof(st);
|
||||||
if (c2 == -1)
|
wch = ((ch & 0xf) << 12) | ((c1 & 0x3f) << 6) | (c2 & 0x3f);
|
||||||
return post_process_weof(st);
|
return post_process_read_wchar(wch, 3, st);
|
||||||
int c3 = GETC();
|
} else {
|
||||||
if (c3 == -1)
|
|
||||||
return post_process_weof(st);
|
|
||||||
wch = wch + (((c3 << 8) + c2)<<wch) + SURROGATE_OFFSET;
|
|
||||||
return post_process_read_wchar(wch, 4, st);
|
|
||||||
}
|
|
||||||
return post_process_read_wchar(wch, 2, st);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
case ENC_UTF16_BE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
|
||||||
// little-endian: start with big shot
|
|
||||||
{
|
|
||||||
int wch;
|
|
||||||
int c1 = GETC();
|
int c1 = GETC();
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = (c1) + (ch<<8);
|
int c2 = GETC();
|
||||||
if (wch >= 0xd800 && wch < 0xdc00) {
|
if (c2 == -1)
|
||||||
int c3 = GETC();
|
return post_process_weof(st);
|
||||||
if (c3 == -1)
|
int c3 = GETC();
|
||||||
return post_process_weof(st);
|
if (c3 == -1)
|
||||||
int c2 = GETC();
|
return post_process_weof(st);
|
||||||
if (c2 == -1)
|
wch = ((ch & 7) << 18) | ((c1 & 0x3f) << 12) | ((c2 & 0x3f) << 6) |
|
||||||
return post_process_weof(st);
|
(c3 & 0x3f);
|
||||||
wch = (((c3 << 8) + c2) << 10) + wch + SURROGATE_OFFSET;
|
return post_process_read_wchar(wch, 4, st);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case ENC_UTF16_LE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
||||||
|
// little-endian: start with big shot
|
||||||
|
{
|
||||||
|
int wch;
|
||||||
|
int c1 = GETC();
|
||||||
|
if (c1 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
wch = (c1 << 8) + ch;
|
||||||
|
if (wch >= 0xd800 && wch < 0xdc00) {
|
||||||
|
int c2 = GETC();
|
||||||
|
if (c2 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
int c3 = GETC();
|
||||||
|
if (c3 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
wch = wch + (((c3 << 8) + c2) << wch) + SURROGATE_OFFSET;
|
||||||
return post_process_read_wchar(wch, 4, st);
|
return post_process_read_wchar(wch, 4, st);
|
||||||
}
|
}
|
||||||
return post_process_read_wchar(wch, 2, st);
|
return post_process_read_wchar(wch, 2, st);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case ENC_UTF16_BE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
||||||
|
// little-endian: start with big shot
|
||||||
|
{
|
||||||
|
int wch;
|
||||||
|
int c1 = GETC();
|
||||||
|
if (c1 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
wch = (c1) + (ch << 8);
|
||||||
|
if (wch >= 0xd800 && wch < 0xdc00) {
|
||||||
|
int c3 = GETC();
|
||||||
|
if (c3 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
int c2 = GETC();
|
||||||
|
if (c2 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
wch = (((c3 << 8) + c2) << 10) + wch + SURROGATE_OFFSET;
|
||||||
|
return post_process_read_wchar(wch, 4, st);
|
||||||
|
}
|
||||||
|
return post_process_read_wchar(wch, 2, st);
|
||||||
|
}
|
||||||
|
|
||||||
case ENC_UCS2_BE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
case ENC_UCS2_BE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
||||||
// little-endian: start with big shot
|
// little-endian: start with big shot
|
||||||
{
|
{
|
||||||
int wch;
|
int wch;
|
||||||
int c1 = GETC();
|
|
||||||
if (c1 == -1)
|
|
||||||
return post_process_weof(st);
|
|
||||||
wch = (c1) + (ch<<8);
|
|
||||||
return post_process_read_wchar(wch, 2, st);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
case ENC_UCS2_LE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
|
||||||
// little-endian: start with big shot
|
|
||||||
{
|
|
||||||
int wch;
|
|
||||||
int c1 = GETC();
|
|
||||||
if (c1 == -1)
|
|
||||||
return post_process_weof(st);
|
|
||||||
wch = (c1 << 8) + ch;
|
|
||||||
|
|
||||||
return post_process_read_wchar(wch, 2, st);
|
|
||||||
}
|
|
||||||
|
|
||||||
case ENC_ISO_UTF32_BE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
|
||||||
// little-endian: start with big shot
|
|
||||||
{
|
|
||||||
int wch = ch;
|
|
||||||
{
|
|
||||||
int c1 = GETC();
|
int c1 = GETC();
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = wch + c1;
|
wch = (c1) + (ch << 8);
|
||||||
|
return post_process_read_wchar(wch, 2, st);
|
||||||
}
|
}
|
||||||
{
|
|
||||||
|
case ENC_UCS2_LE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
||||||
|
// little-endian: start with big shot
|
||||||
|
{
|
||||||
|
int wch;
|
||||||
int c1 = GETC();
|
int c1 = GETC();
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = (wch << 8 )+c1;
|
wch = (c1 << 8) + ch;
|
||||||
|
|
||||||
|
return post_process_read_wchar(wch, 2, st);
|
||||||
}
|
}
|
||||||
{
|
|
||||||
int c1 = GETC();
|
case ENC_ISO_UTF32_BE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
||||||
if (c1 == -1)
|
// little-endian: start with big shot
|
||||||
return post_process_weof(st);
|
{
|
||||||
wch = (wch << 8) +c1;
|
int wch = ch;
|
||||||
}
|
{
|
||||||
return post_process_read_wchar(wch, 4, st);
|
int c1 = GETC();
|
||||||
}
|
if (c1 == -1)
|
||||||
case ENC_ISO_UTF32_LE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
return post_process_weof(st);
|
||||||
// little-endian: start with big shot
|
wch = wch + c1;
|
||||||
{
|
}
|
||||||
int wch = ch;
|
{
|
||||||
{
|
int c1 = GETC();
|
||||||
int c1 = GETC();
|
if (c1 == -1)
|
||||||
if (c1 == -1)
|
return post_process_weof(st);
|
||||||
return post_process_weof(st);
|
wch = (wch << 8) + c1;
|
||||||
wch += c1<<8;
|
}
|
||||||
|
{
|
||||||
|
int c1 = GETC();
|
||||||
|
if (c1 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
wch = (wch << 8) + c1;
|
||||||
|
}
|
||||||
|
return post_process_read_wchar(wch, 4, st);
|
||||||
}
|
}
|
||||||
{
|
case ENC_ISO_UTF32_LE: // check http://unicode.org/faq/utf_bom.html#utf16-3
|
||||||
int c1 = GETC();
|
// little-endian: start with big shot
|
||||||
if (c1 == -1)
|
{
|
||||||
return post_process_weof(st);
|
int wch = ch;
|
||||||
wch += c1<<16;
|
{
|
||||||
|
int c1 = GETC();
|
||||||
|
if (c1 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
wch += c1 << 8;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int c1 = GETC();
|
||||||
|
if (c1 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
wch += c1 << 16;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int c1 = GETC();
|
||||||
|
if (c1 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
wch += c1 << 24;
|
||||||
|
}
|
||||||
|
return post_process_read_wchar(wch, 4, st);
|
||||||
}
|
}
|
||||||
{
|
default:
|
||||||
int c1 = GETC();
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, MkIntTerm(st->encoding),
|
||||||
if (c1 == -1)
|
"Bad Encoding\n");
|
||||||
return post_process_weof(st);
|
return -1;
|
||||||
wch += c1<<24;
|
|
||||||
}
|
|
||||||
return post_process_read_wchar(wch, 4, st);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2086
os/iopreds.c
2086
os/iopreds.c
File diff suppressed because it is too large
Load Diff
21
os/iopreds.h
21
os/iopreds.h
@ -18,9 +18,9 @@ static char SccsId[] = "%W% %G%";
|
|||||||
#define HAVE_SOCKET 1
|
#define HAVE_SOCKET 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "Yap.h"
|
|
||||||
#include "Atoms.h"
|
#include "Atoms.h"
|
||||||
|
#include "Yap.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file defines main data-structure for stream management,
|
* This file defines main data-structure for stream management,
|
||||||
@ -206,12 +206,17 @@ typedef struct stream_desc {
|
|||||||
#if defined(YAPOR) || defined(THREADS)
|
#if defined(YAPOR) || defined(THREADS)
|
||||||
lockvar streamlock; /* protect stream access */
|
lockvar streamlock; /* protect stream access */
|
||||||
#endif
|
#endif
|
||||||
int (*stream_putc)(int, int); /** function the stream uses for writing a single octet */
|
int (*stream_putc)(
|
||||||
int (*stream_wputc)(int, int); /** function the stream uses for writing a character */
|
int, int); /** function the stream uses for writing a single octet */
|
||||||
int (*stream_getc)(int); /** function the stream uses for reading an octet. */
|
int (*stream_wputc)(
|
||||||
int (*stream_wgetc)(int); /** function the stream uses for reading a character. */
|
int, wchar_t); /** function the stream uses for writing a character */
|
||||||
|
int (*stream_getc)(int); /** function the stream uses for reading an octet. */
|
||||||
|
int (*stream_wgetc)(
|
||||||
|
int); /** function the stream uses for reading a character. */
|
||||||
|
|
||||||
int (*stream_wgetc_for_read)(int); /* function the stream uses for parser. It may be different from above if the ISO character conversion is on */
|
int (*stream_wgetc_for_read)(
|
||||||
|
int); /* function the stream uses for parser. It may be different
|
||||||
|
from above if the ISO character conversion is on */
|
||||||
encoding_t encoding; /** current encoding for stream */
|
encoding_t encoding; /** current encoding for stream */
|
||||||
} StreamDesc;
|
} StreamDesc;
|
||||||
|
|
||||||
@ -270,7 +275,7 @@ void Yap_ConsolePipeOps(StreamDesc *st);
|
|||||||
void Yap_SocketOps(StreamDesc *st);
|
void Yap_SocketOps(StreamDesc *st);
|
||||||
void Yap_ConsoleSocketOps(StreamDesc *st);
|
void Yap_ConsoleSocketOps(StreamDesc *st);
|
||||||
bool Yap_ReadlineOps(StreamDesc *st);
|
bool Yap_ReadlineOps(StreamDesc *st);
|
||||||
int Yap_OpenBufWriteStream(USES_REGS1);
|
int Yap_OpenBufWriteStream(USES_REGS1);
|
||||||
void Yap_ConsoleOps(StreamDesc *s, bool recursive);
|
void Yap_ConsoleOps(StreamDesc *s, bool recursive);
|
||||||
|
|
||||||
void Yap_InitRandomPreds(void);
|
void Yap_InitRandomPreds(void);
|
||||||
|
322
os/mem.c
322
os/mem.c
@ -8,7 +8,7 @@
|
|||||||
* *
|
* *
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
* *
|
* *
|
||||||
* File: sockets.c *
|
* File: sockets.c *
|
||||||
* Last rev: 5/2/88 *
|
* Last rev: 5/2/88 *
|
||||||
* mods: *
|
* mods: *
|
||||||
* comments: Input/Output C implemented predicates *
|
* comments: Input/Output C implemented predicates *
|
||||||
@ -24,8 +24,8 @@ static char SccsId[] = "%W% %G%";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
#include "Yatom.h"
|
|
||||||
#include "YapHeap.h"
|
#include "YapHeap.h"
|
||||||
|
#include "Yatom.h"
|
||||||
#include "yapio.h"
|
#include "yapio.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#if HAVE_UNISTD_H
|
#if HAVE_UNISTD_H
|
||||||
@ -44,7 +44,7 @@ static char SccsId[] = "%W% %G%";
|
|||||||
#endif
|
#endif
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#ifndef S_ISDIR
|
#ifndef S_ISDIR
|
||||||
#define S_ISDIR(x) (((x)&_S_IFDIR)==_S_IFDIR)
|
#define S_ISDIR(x) (((x)&_S_IFDIR) == _S_IFDIR)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#include "iopreds.h"
|
#include "iopreds.h"
|
||||||
@ -52,7 +52,12 @@ static char SccsId[] = "%W% %G%";
|
|||||||
#include "fmemopen.h"
|
#include "fmemopen.h"
|
||||||
#define HAVE_FMEMOPEN 1
|
#define HAVE_FMEMOPEN 1
|
||||||
#define HAVE_OPEN_MEMSTREAM 1
|
#define HAVE_OPEN_MEMSTREAM 1
|
||||||
FILE * open_memstream (char **buf, size_t *len);
|
FILE *open_memstream(char **buf, size_t *len);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __ANDROID__
|
||||||
|
#undef HAVE_FMEMOPEN
|
||||||
|
#undef HAVE_OPEN_MEMSTREAM
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAVE_FMEMOPEN
|
#if HAVE_FMEMOPEN
|
||||||
@ -70,44 +75,38 @@ FILE * open_memstream (char **buf, size_t *len);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !MAY_READ
|
#if !MAY_READ
|
||||||
static int MemGetc( int);
|
static int MemGetc(int);
|
||||||
|
|
||||||
/* read from memory */
|
/* read from memory */
|
||||||
static int
|
static int MemGetc(int sno) {
|
||||||
MemGetc(int sno)
|
register StreamDesc *s = &GLOBAL_Stream[sno];
|
||||||
{
|
Int ch;
|
||||||
register StreamDesc *s = &GLOBAL_Stream[sno];
|
int spos;
|
||||||
Int ch;
|
|
||||||
int spos;
|
|
||||||
|
|
||||||
spos = s->u.mem_string.pos;
|
spos = s->u.mem_string.pos;
|
||||||
if (spos == s->u.mem_string.max_size) {
|
if (spos == s->u.mem_string.max_size) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else {
|
||||||
else {
|
ch = s->u.mem_string.buf[spos];
|
||||||
ch = s->u.mem_string.buf[spos];
|
s->u.mem_string.pos = ++spos;
|
||||||
s->u.mem_string.pos = ++spos;
|
}
|
||||||
}
|
return ch;
|
||||||
return ch;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !MAY_WRITE
|
#if !MAY_WRITE
|
||||||
static int MemPutc( int, int);
|
static int MemPutc(int, int);
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
static int
|
static int MemPutc(int sno, int ch) {
|
||||||
MemPutc(int sno, int ch)
|
|
||||||
{
|
|
||||||
StreamDesc *s = &GLOBAL_Stream[sno];
|
StreamDesc *s = &GLOBAL_Stream[sno];
|
||||||
#if MAC || _MSC_VER
|
#if MAC || _MSC_VER
|
||||||
if (ch == 10)
|
if (ch == 10) {
|
||||||
{
|
ch = '\n';
|
||||||
ch = '\n';
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
s->u.mem_string.buf[s->u.mem_string.pos++] = ch;
|
s->u.mem_string.buf[s->u.mem_string.pos++] = ch;
|
||||||
if (s->u.mem_string.pos >= s->u.mem_string.max_size -8) {
|
if (s->u.mem_string.pos >= s->u.mem_string.max_size - 8) {
|
||||||
int old_src = s->u.mem_string.src, new_src;
|
int old_src = s->u.mem_string.src, new_src;
|
||||||
|
|
||||||
/* oops, we have reached an overflow */
|
/* oops, we have reached an overflow */
|
||||||
@ -115,52 +114,53 @@ MemPutc(int sno, int ch)
|
|||||||
char *newbuf;
|
char *newbuf;
|
||||||
|
|
||||||
if (old_src == MEM_BUF_CODE &&
|
if (old_src == MEM_BUF_CODE &&
|
||||||
(newbuf = Yap_AllocAtomSpace(new_max_size*sizeof(char))) != NULL) {
|
(newbuf = Yap_AllocAtomSpace(new_max_size * sizeof(char))) != NULL) {
|
||||||
new_src = MEM_BUF_CODE;
|
new_src = MEM_BUF_CODE;
|
||||||
#if HAVE_MEMMOVE
|
#if HAVE_MEMMOVE
|
||||||
memmove((void *)newbuf, (void *)s->u.mem_string.buf, (size_t)((s->u.mem_string.pos)*sizeof(char)));
|
memmove((void *)newbuf, (void *)s->u.mem_string.buf,
|
||||||
|
(size_t)((s->u.mem_string.pos) * sizeof(char)));
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
Int n = s->u.mem_string.pos;
|
Int n = s->u.mem_string.pos;
|
||||||
char *to = newbuf;
|
char *to = newbuf;
|
||||||
char *from = s->u.mem_string.buf;
|
char *from = s->u.mem_string.buf;
|
||||||
while (n-- >= 0) {
|
while (n-- >= 0) {
|
||||||
*to++ = *from++;
|
*to++ = *from++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
Yap_FreeAtomSpace(s->u.mem_string.buf);
|
Yap_FreeAtomSpace(s->u.mem_string.buf);
|
||||||
#if !HAVE_SYSTEM_MALLOC
|
#if !HAVE_SYSTEM_MALLOC
|
||||||
} else if ((newbuf = (ADDR)realloc(s->u.mem_string.buf, new_max_size*sizeof(char))) != NULL) {
|
} else if ((newbuf = (ADDR)realloc(s->u.mem_string.buf,
|
||||||
|
new_max_size * sizeof(char))) != NULL) {
|
||||||
new_src = MEM_BUF_MALLOC;
|
new_src = MEM_BUF_MALLOC;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
if (GLOBAL_Stream[sno].u.mem_string.error_handler) {
|
if (GLOBAL_Stream[sno].u.mem_string.error_handler) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
LOCAL_Error_Size = new_max_size*sizeof(char);
|
LOCAL_Error_Size = new_max_size * sizeof(char);
|
||||||
save_machine_regs();
|
save_machine_regs();
|
||||||
longjmp(*(jmp_buf *)GLOBAL_Stream[sno].u.mem_string.error_handler,1);
|
longjmp(*(jmp_buf *)GLOBAL_Stream[sno].u.mem_string.error_handler, 1);
|
||||||
} else {
|
} else {
|
||||||
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "YAP could not grow heap for writing to string");
|
Yap_Error(RESOURCE_ERROR_HEAP, TermNil,
|
||||||
|
"YAP could not grow heap for writing to string");
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (old_src == MEM_BUF_CODE) {
|
if (old_src == MEM_BUF_CODE) {
|
||||||
}
|
}
|
||||||
s->u.mem_string.buf = newbuf;
|
s->u.mem_string.buf = newbuf;
|
||||||
s->u.mem_string.max_size = new_max_size;
|
s->u.mem_string.max_size = new_max_size;
|
||||||
s->u.mem_string.src = new_src;
|
s->u.mem_string.src = new_src;
|
||||||
}
|
}
|
||||||
count_output_char(ch,s);
|
count_output_char(ch, s);
|
||||||
return ((int) ch);
|
return ((int)ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int Yap_open_buf_read_stream(const char *nbuf, size_t nchars, encoding_t *encp,
|
||||||
int
|
memBufSource src) {
|
||||||
Yap_open_buf_read_stream(const char *nbuf, size_t nchars, encoding_t *encp, memBufSource src)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int sno;
|
int sno;
|
||||||
StreamDesc *st;
|
StreamDesc *st;
|
||||||
@ -170,23 +170,23 @@ MemPutc(int sno, int ch)
|
|||||||
|
|
||||||
sno = GetFreeStreamD();
|
sno = GetFreeStreamD();
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return (PlIOError (RESOURCE_ERROR_MAX_STREAMS,TermNil, "new stream not available for open_mem_read_stream/1"));
|
return (PlIOError(RESOURCE_ERROR_MAX_STREAMS, TermNil,
|
||||||
st = GLOBAL_Stream+sno;
|
"new stream not available for open_mem_read_stream/1"));
|
||||||
|
st = GLOBAL_Stream + sno;
|
||||||
if (encp)
|
if (encp)
|
||||||
encoding = *encp;
|
encoding = *encp;
|
||||||
else
|
else
|
||||||
encoding = LOCAL_encoding;
|
encoding = LOCAL_encoding;
|
||||||
#if MAY_READ
|
#if MAY_READ
|
||||||
// like any file stream.
|
// like any file stream.
|
||||||
f = fmemopen( (void *)nbuf, nchars, "r");
|
f = fmemopen((void *)nbuf, nchars, "r");
|
||||||
flags = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f;
|
flags = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f;
|
||||||
#else
|
#else
|
||||||
f = NULL;
|
f = NULL;
|
||||||
flags = Input_Stream_f | InMemory_Stream_f;
|
flags = Input_Stream_f | InMemory_Stream_f;
|
||||||
#endif
|
#endif
|
||||||
Yap_initStream(sno, f, NULL, TermNil,
|
Yap_initStream(sno, f, NULL, TermNil, encoding, flags, AtomRead);
|
||||||
encoding, flags, AtomRead);
|
// like any file stream.
|
||||||
// like any file stream.
|
|
||||||
#if !MAY_READ
|
#if !MAY_READ
|
||||||
/* currently these streams are not seekable */
|
/* currently these streams are not seekable */
|
||||||
st->status = Input_Stream_f | InMemory_Stream_f;
|
st->status = Input_Stream_f | InMemory_Stream_f;
|
||||||
@ -196,13 +196,13 @@ MemPutc(int sno, int ch)
|
|||||||
st->u.mem_string.error_handler = NULL;
|
st->u.mem_string.error_handler = NULL;
|
||||||
st->u.mem_string.src = src;
|
st->u.mem_string.src = src;
|
||||||
#endif
|
#endif
|
||||||
Yap_MemOps( st );
|
Yap_MemOps(st);
|
||||||
UNLOCK(st->streamlock);
|
UNLOCK(st->streamlock);
|
||||||
return sno;
|
return sno;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int
|
||||||
open_mem_read_stream (USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */
|
open_mem_read_stream(USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */
|
||||||
{
|
{
|
||||||
Term t, ti;
|
Term t, ti;
|
||||||
int sno;
|
int sno;
|
||||||
@ -222,10 +222,10 @@ open_mem_read_stream (USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */
|
|||||||
ti = TailOfTerm(ti);
|
ti = TailOfTerm(ti);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while ((nbuf = (char *)Yap_AllocAtomSpace((sl+1)*sizeof(char))) == NULL) {
|
while ((nbuf = (char *)Yap_AllocAtomSpace((sl + 1) * sizeof(char))) == NULL) {
|
||||||
if (!Yap_growheap(FALSE, (sl+1)*sizeof(char), NULL)) {
|
if (!Yap_growheap(FALSE, (sl + 1) * sizeof(char), NULL)) {
|
||||||
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage);
|
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage);
|
||||||
return(FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ti = Deref(ARG1);
|
ti = Deref(ARG1);
|
||||||
@ -244,83 +244,81 @@ open_mem_read_stream (USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */
|
|||||||
}
|
}
|
||||||
nbuf[nchars] = '\0';
|
nbuf[nchars] = '\0';
|
||||||
sno = Yap_open_buf_read_stream(nbuf, nchars, &LOCAL_encoding, MEM_BUF_CODE);
|
sno = Yap_open_buf_read_stream(nbuf, nchars, &LOCAL_encoding, MEM_BUF_CODE);
|
||||||
t = Yap_MkStream (sno);
|
t = Yap_MkStream(sno);
|
||||||
return (Yap_unify (ARG2, t));
|
return (Yap_unify(ARG2, t));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int Yap_open_buf_write_stream(char *buf, size_t nchars, encoding_t *encp,
|
||||||
Yap_open_buf_write_stream(char *buf, size_t nchars, encoding_t *encp, memBufSource sr)
|
memBufSource sr) {
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int sno;
|
int sno;
|
||||||
StreamDesc *st;
|
StreamDesc *st;
|
||||||
|
|
||||||
|
sno = GetFreeStreamD();
|
||||||
sno = GetFreeStreamD();
|
if (sno < 0)
|
||||||
if (sno < 0)
|
return -1;
|
||||||
return -1;
|
st = GLOBAL_Stream + sno;
|
||||||
st = GLOBAL_Stream+sno;
|
st->status = Output_Stream_f | InMemory_Stream_f;
|
||||||
st->status = Output_Stream_f | InMemory_Stream_f;
|
if (!buf) {
|
||||||
if (!buf) {
|
if (!nchars) {
|
||||||
if (!nchars) {
|
nchars = Yap_page_size;
|
||||||
nchars = Yap_page_size;
|
|
||||||
}
|
|
||||||
buf = malloc( nchars );
|
|
||||||
st->status |= FreeOnClose_Stream_f;
|
|
||||||
}
|
}
|
||||||
st->nbuf = buf;
|
buf = malloc(nchars);
|
||||||
if(!st->nbuf) {
|
st->status |= FreeOnClose_Stream_f;
|
||||||
return -1;
|
}
|
||||||
}
|
st->nbuf = buf;
|
||||||
st->nsize = nchars;
|
if (!st->nbuf) {
|
||||||
st->linepos = 0;
|
return -1;
|
||||||
st->charcount = 0;
|
}
|
||||||
st->linecount = 1;
|
st->nsize = nchars;
|
||||||
if (encp)
|
st->linepos = 0;
|
||||||
st->encoding = *encp;
|
st->charcount = 0;
|
||||||
else
|
st->linecount = 1;
|
||||||
st->encoding = LOCAL_encoding;
|
if (encp)
|
||||||
Yap_DefaultStreamOps( st );
|
st->encoding = *encp;
|
||||||
|
else
|
||||||
|
st->encoding = LOCAL_encoding;
|
||||||
|
Yap_DefaultStreamOps(st);
|
||||||
#if MAY_WRITE
|
#if MAY_WRITE
|
||||||
st->file = open_memstream(&st->nbuf, &st->nsize);
|
st->file = open_memstream(&st->nbuf, &st->nsize);
|
||||||
st->status |= Seekable_Stream_f;
|
st->status |= Seekable_Stream_f;
|
||||||
#else
|
#else
|
||||||
st->u.mem_string.pos = 0;
|
st->u.mem_string.pos = 0;
|
||||||
st->u.mem_string.buf = st->nbuf;
|
st->u.mem_string.buf = st->nbuf;
|
||||||
st->u.mem_string.max_size = nchars;
|
st->u.mem_string.max_size = nchars;
|
||||||
#endif
|
#endif
|
||||||
Yap_MemOps( st );
|
Yap_MemOps(st);
|
||||||
UNLOCK(st->streamlock);
|
UNLOCK(st->streamlock);
|
||||||
return sno;
|
return sno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int Yap_OpenBufWriteStream(USES_REGS1) {
|
||||||
Yap_OpenBufWriteStream( USES_REGS1 )
|
|
||||||
{
|
|
||||||
char *nbuf;
|
char *nbuf;
|
||||||
size_t sz = Yap_page_size;
|
size_t sz = Yap_page_size;
|
||||||
|
|
||||||
|
while ((nbuf = (char *)Yap_AllocAtomSpace(Yap_page_size * sizeof(char))) ==
|
||||||
while ((nbuf = (char *)Yap_AllocAtomSpace(Yap_page_size*sizeof(char))) == NULL) {
|
NULL) {
|
||||||
if (!Yap_growheap(FALSE, Yap_page_size*sizeof(char), NULL)) {
|
if (!Yap_growheap(FALSE, Yap_page_size * sizeof(char), NULL)) {
|
||||||
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage);
|
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Yap_open_buf_write_stream(nbuf, sz, &GLOBAL_Stream[LOCAL_c_output_stream].encoding, 0);
|
return Yap_open_buf_write_stream(
|
||||||
|
nbuf, sz, &GLOBAL_Stream[LOCAL_c_output_stream].encoding, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int
|
||||||
open_mem_write_stream (USES_REGS1) /* $open_mem_write_stream(-Stream) */
|
open_mem_write_stream(USES_REGS1) /* $open_mem_write_stream(-Stream) */
|
||||||
{
|
{
|
||||||
Term t;
|
Term t;
|
||||||
int sno;
|
int sno;
|
||||||
|
|
||||||
sno = Yap_OpenBufWriteStream( PASS_REGS1 );
|
sno = Yap_OpenBufWriteStream(PASS_REGS1);
|
||||||
if (sno == -1)
|
if (sno == -1)
|
||||||
return (PlIOError (SYSTEM_ERROR_INTERNAL,TermNil, "new stream not available for open_mem_read_stream/1"));
|
return (PlIOError(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
t = Yap_MkStream (sno);
|
"new stream not available for open_mem_read_stream/1"));
|
||||||
return (Yap_unify (ARG1, t));
|
t = Yap_MkStream(sno);
|
||||||
|
return (Yap_unify(ARG1, t));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -331,14 +329,11 @@ open_mem_write_stream (USES_REGS1) /* $open_mem_write_stream(-Stream) */
|
|||||||
* @return temporary buffer, discarded by close and may be moved away
|
* @return temporary buffer, discarded by close and may be moved away
|
||||||
* by other writes..
|
* by other writes..
|
||||||
*/
|
*/
|
||||||
char *
|
char *Yap_MemExportStreamPtr(int sno) {
|
||||||
Yap_MemExportStreamPtr( int sno )
|
|
||||||
{
|
|
||||||
#if MAY_WRITE
|
#if MAY_WRITE
|
||||||
char *s;
|
char *s;
|
||||||
if (fflush(GLOBAL_Stream[sno].file) == 0)
|
if (fflush(GLOBAL_Stream[sno].file) == 0) {
|
||||||
{
|
s = GLOBAL_Stream[sno].nbuf;
|
||||||
s = GLOBAL_Stream[sno].nbuf;
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -347,11 +342,10 @@ Yap_MemExportStreamPtr( int sno )
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Int peek_mem_write_stream(
|
||||||
static Int
|
USES_REGS1) { /* '$peek_mem_write_stream'(+GLOBAL_Stream,?S0,?S) */
|
||||||
peek_mem_write_stream ( USES_REGS1 )
|
Int sno =
|
||||||
{ /* '$peek_mem_write_stream'(+GLOBAL_Stream,?S0,?S) */
|
Yap_CheckStream(ARG1, (Output_Stream_f | InMemory_Stream_f), "close/2");
|
||||||
Int sno = Yap_CheckStream (ARG1, (Output_Stream_f | InMemory_Stream_f), "close/2");
|
|
||||||
Int i;
|
Int i;
|
||||||
Term tf = ARG2;
|
Term tf = ARG2;
|
||||||
CELL *HI;
|
CELL *HI;
|
||||||
@ -359,27 +353,27 @@ peek_mem_write_stream ( USES_REGS1 )
|
|||||||
|
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
restart:
|
restart:
|
||||||
HI = HR;
|
HI = HR;
|
||||||
#if MAY_WRITE
|
#if MAY_WRITE
|
||||||
if (fflush(GLOBAL_Stream[sno].file) == 0) {
|
if (fflush(GLOBAL_Stream[sno].file) == 0) {
|
||||||
ptr = GLOBAL_Stream[sno].nbuf;
|
ptr = GLOBAL_Stream[sno].nbuf;
|
||||||
i = GLOBAL_Stream[sno].nsize;
|
i = GLOBAL_Stream[sno].nsize;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
ptr = GLOBAL_Stream[sno].u.mem_string.buf;
|
ptr = GLOBAL_Stream[sno].u.mem_string.buf;
|
||||||
i = GLOBAL_Stream[sno].u.mem_string.pos;
|
i = GLOBAL_Stream[sno].u.mem_string.pos;
|
||||||
#endif
|
#endif
|
||||||
while (i > 0) {
|
while (i > 0) {
|
||||||
--i;
|
--i;
|
||||||
tf = MkPairTerm(MkIntTerm(ptr[i]),tf);
|
tf = MkPairTerm(MkIntTerm(ptr[i]), tf);
|
||||||
if (HR + 1024 >= ASP) {
|
if (HR + 1024 >= ASP) {
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
HR = HI;
|
HR = HI;
|
||||||
if (!Yap_gcl((ASP-HI)*sizeof(CELL), 3, ENV, Yap_gcP()) ) {
|
if (!Yap_gcl((ASP - HI) * sizeof(CELL), 3, ENV, Yap_gcP())) {
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
||||||
return(FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
i = GLOBAL_Stream[sno].u.mem_string.pos;
|
i = GLOBAL_Stream[sno].u.mem_string.pos;
|
||||||
tf = ARG2;
|
tf = ARG2;
|
||||||
@ -388,16 +382,14 @@ peek_mem_write_stream ( USES_REGS1 )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return (Yap_unify(ARG3,tf));
|
return (Yap_unify(ARG3, tf));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Yap_MemOps(StreamDesc *st) {
|
||||||
Yap_MemOps( StreamDesc *st )
|
|
||||||
{
|
|
||||||
#if MAY_WRITE
|
#if MAY_WRITE
|
||||||
st->stream_putc = FilePutc;
|
st->stream_putc = FilePutc;
|
||||||
#else
|
#else
|
||||||
st->stream_putc = MemPutc;
|
st->stream_putc = MemPutc;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MAY_READ
|
#if MAY_READ
|
||||||
@ -407,44 +399,42 @@ void
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Yap_CloseMemoryStream( int sno )
|
bool Yap_CloseMemoryStream(int sno) {
|
||||||
{
|
if (!(GLOBAL_Stream[sno].status & Output_Stream_f)) {
|
||||||
if (!(GLOBAL_Stream[sno].status & Output_Stream_f) ) {
|
|
||||||
#if MAY_WRITE
|
#if MAY_WRITE
|
||||||
fclose(GLOBAL_Stream[sno].file);
|
fclose(GLOBAL_Stream[sno].file);
|
||||||
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
|
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
|
||||||
free( GLOBAL_Stream[sno].nbuf );
|
free(GLOBAL_Stream[sno].nbuf);
|
||||||
#else
|
#else
|
||||||
if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_CODE)
|
if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_CODE)
|
||||||
Yap_FreeAtomSpace(GLOBAL_Stream[sno].u.mem_string.buf);
|
Yap_FreeAtomSpace(GLOBAL_Stream[sno].u.mem_string.buf);
|
||||||
else if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_MALLOC) {
|
else if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_MALLOC) {
|
||||||
free(GLOBAL_Stream[sno].u.mem_string.buf);
|
free(GLOBAL_Stream[sno].u.mem_string.buf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#if MAY_READ
|
#if MAY_READ
|
||||||
fclose(GLOBAL_Stream[sno].file);
|
fclose(GLOBAL_Stream[sno].file);
|
||||||
Yap_FreeAtomSpace(GLOBAL_Stream[sno].nbuf);
|
Yap_FreeAtomSpace(GLOBAL_Stream[sno].nbuf);
|
||||||
#else
|
#else
|
||||||
if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_CODE)
|
if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_CODE)
|
||||||
Yap_FreeAtomSpace(GLOBAL_Stream[sno].u.mem_string.buf);
|
Yap_FreeAtomSpace(GLOBAL_Stream[sno].u.mem_string.buf);
|
||||||
else if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_MALLOC) {
|
else if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_MALLOC) {
|
||||||
free(GLOBAL_Stream[sno].u.mem_string.buf);
|
free(GLOBAL_Stream[sno].u.mem_string.buf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void Yap_InitMems(void) {
|
||||||
Yap_InitMems( void )
|
CACHE_REGS
|
||||||
{
|
|
||||||
CACHE_REGS
|
|
||||||
Term cm = CurrentModule;
|
Term cm = CurrentModule;
|
||||||
CurrentModule = CHARSIO_MODULE;
|
CurrentModule = CHARSIO_MODULE;
|
||||||
Yap_InitCPred ("open_mem_read_stream", 2, open_mem_read_stream, SyncPredFlag);
|
Yap_InitCPred("open_mem_read_stream", 2, open_mem_read_stream, SyncPredFlag);
|
||||||
Yap_InitCPred ("open_mem_write_stream", 1, open_mem_write_stream, SyncPredFlag);
|
Yap_InitCPred("open_mem_write_stream", 1, open_mem_write_stream,
|
||||||
Yap_InitCPred ("peek_mem_write_stream", 3, peek_mem_write_stream, SyncPredFlag);
|
SyncPredFlag);
|
||||||
|
Yap_InitCPred("peek_mem_write_stream", 3, peek_mem_write_stream,
|
||||||
|
SyncPredFlag);
|
||||||
CurrentModule = cm;
|
CurrentModule = cm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,6 +635,7 @@ static Term
|
|||||||
do_glob(const char *spec, bool glob_vs_wordexp) {
|
do_glob(const char *spec, bool glob_vs_wordexp) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
char u[YAP_FILENAME_MAX + 1];
|
char u[YAP_FILENAME_MAX + 1];
|
||||||
|
char *espec = u;
|
||||||
if (spec == NULL) {
|
if (spec == NULL) {
|
||||||
return TermNil;
|
return TermNil;
|
||||||
}
|
}
|
||||||
@ -642,7 +643,6 @@ static Term
|
|||||||
{
|
{
|
||||||
WIN32_FIND_DATA find;
|
WIN32_FIND_DATA find;
|
||||||
HANDLE hFind;
|
HANDLE hFind;
|
||||||
const char *espec;
|
|
||||||
CELL *dest;
|
CELL *dest;
|
||||||
Term tf;
|
Term tf;
|
||||||
|
|
||||||
@ -673,7 +673,6 @@ static Term
|
|||||||
return tf;
|
return tf;
|
||||||
}
|
}
|
||||||
#elif HAVE_WORDEXP || HAVE_GLOB
|
#elif HAVE_WORDEXP || HAVE_GLOB
|
||||||
char *espec = u;
|
|
||||||
strncpy(espec, spec, sizeof(u));
|
strncpy(espec, spec, sizeof(u));
|
||||||
/* Expand the string for the program to run. */
|
/* Expand the string for the program to run. */
|
||||||
size_t pathcount;
|
size_t pathcount;
|
||||||
|
863
os/ypsocks.c
863
os/ypsocks.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user