IO patches

simplify error handling
use get and inject
use wide support in OS
be stricter in checkin streams and arguments
This commit is contained in:
Vítor Santos Costa
2015-10-08 02:23:45 +01:00
parent b788dc131d
commit b3cc23ce64
30 changed files with 1224 additions and 1381 deletions

View File

@@ -1,4 +1,3 @@
/*************************************************************************
* *
* YAP Prolog *
@@ -54,14 +53,18 @@ static char SccsId[] = "%W% %G%";
static Int p_change_type_of_char(USES_REGS1);
static Int p_type_of_char(USES_REGS1);
Term Yap_StringToNumberTerm(char *s, encoding_t enc) {
Term Yap_StringToNumberTerm(char *s, encoding_t *encp) {
CACHE_REGS
int sno;
Term t;
sno = Yap_open_buf_read_stream(s, strlen(s), enc, MEM_BUF_USER);
sno = Yap_open_buf_read_stream(s, strlen(s), encp, MEM_BUF_USER);
if (sno < 0)
return FALSE;
GLOBAL_Stream[sno].encoding = enc;
if (encp)
GLOBAL_Stream[sno].encoding = *encp;
else
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
UNLOCK(GLOBAL_Stream[sno].streamlock);
while (*s && isblank(*s++))
;
@@ -162,25 +165,6 @@ void Yap_SetDefaultEncoding(encoding_t new_encoding) {
LOCAL_encoding = new_encoding;
}
encoding_t Yap_InitialEncoding(void) {
char *s = getenv("LANG");
size_t sz;
/* if we don't have a LANG then just use ISO_LATIN1 */
if (s == NULL)
s = getenv("LC_CTYPE");
if (s == NULL)
return ENC_ISO_UTF8;
sz = strlen(s);
if (sz >= 5) {
if (s[sz - 5] == 'U' && s[sz - 4] == 'T' && s[sz - 3] == 'F' &&
s[sz - 2] == '-' && s[sz - 1] == '8') {
return ENC_ISO_UTF8;
}
}
return ENC_ISO_UTF8;
}
static Int get_default_encoding(USES_REGS1) {
Term out = MkIntegerTerm(Yap_DefaultEncoding());
return Yap_unify(ARG1, out);