From b3608c6a832077875eb917fd016f65784f5690e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Thu, 5 Dec 2013 11:20:57 +0000 Subject: [PATCH] improve char conversion --- C/compiler.c | 1 + C/computils.c | 2 ++ C/strings.c | 20 +++++++++++--------- C/write.c | 19 ++++++++----------- packages/real | 2 +- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/C/compiler.c b/C/compiler.c index 8e32eed54..17b9ca358 100644 --- a/C/compiler.c +++ b/C/compiler.c @@ -693,6 +693,7 @@ c_arg(Int argno, Term t, unsigned int arity, unsigned int level, compiler_struct Int sz = (3+src[1])*sizeof(CELL); CELL *dest; + char *ptr = src+2; int chr; /* use a special list to store the blobs */ cglobs->cint.cpc = cglobs->cint.icpc; /* if (IsFloatTerm(t)) { diff --git a/C/computils.c b/C/computils.c index 02b93ebe1..6c9b7e22f 100644 --- a/C/computils.c +++ b/C/computils.c @@ -592,6 +592,8 @@ ShowOp (char *f, struct PSEUDO *cpc) Yap_DebugPlWrite(MkAtomTerm(AtomLONGINT)); } else if (fun == FunctorDouble) { Yap_DebugPlWrite(MkAtomTerm(AtomDOUBLE)); + } else if (fun == FunctorString) { + Yap_DebugPlWrite(MkAtomTerm(AtomSTRING)); } } else { Yap_DebugPlWrite (MkAtomTerm(NameOfFunctor(fun))); diff --git a/C/strings.c b/C/strings.c index 1386413be..1dd6c3a8a 100644 --- a/C/strings.c +++ b/C/strings.c @@ -25,7 +25,7 @@ #include -static inline char *get_char(char *p, int *c) { *c = *p; return p+1; } +static inline unsigned char *get_char(unsigned char *p, int *c) { *c = *p; return p+1; } static inline wchar_t *get_wchar(wchar_t *p, int *c) { *c = *p; return p+1; } @@ -527,9 +527,10 @@ write_strings( void *s0, seq_tv_t *out, encoding_t enc, int minimal USES_REGS) } break; case YAP_CHAR: - { char *s = s0, *lim = s + (max = strnlen(s, max)); + { unsigned char *s = s0, *lim = s + (max = strnlen(s0, max)); Term t = init_tstring( PASS_REGS1 ); - char *cp = s, *buf; + unsigned char *cp = s; + char *buf; LOCAL_TERM_ERROR( 2*(lim-s) ); buf = buf_from_tstring(H); @@ -569,6 +570,7 @@ write_strings( void *s0, seq_tv_t *out, encoding_t enc, int minimal USES_REGS) out->val.t = t; } } + return out->val.t; } @@ -602,8 +604,8 @@ write_atoms( void *s0, seq_tv_t *out, encoding_t enc, int minimal USES_REGS) break; } case YAP_CHAR: - { char *s = s0, *lim = s + strnlen(s, max); - char *cp = s; + { unsigned char *s = s0, *lim = s + strnlen(s0, max); + unsigned char *cp = s; char w[2]; w[1] = '\0'; @@ -683,8 +685,8 @@ write_codes( void *s0, seq_tv_t *out, encoding_t enc, int minimal USES_REGS) break; } case YAP_CHAR: - { char *s = s0, *lim = s + strnlen(s, max); - char *cp = s; + { unsigned char *s = s0, *lim = s + strnlen(s0, max); + unsigned char *cp = s; LOCAL_TERM_ERROR( 2*(lim-s) ); while (cp < lim) { @@ -1280,7 +1282,7 @@ Yap_Splice_Text( int n, size_t cuts[], seq_tv_t *inp, seq_tv_t outv[] USES_REGS l1 = l-l0; slice(l0, l, buf, outv+1, enc PASS_REGS); - return buf1; + return buf0; } else /* if (outv[1].val.t) */ { buf1 = read_Text( buf, outv, &enc1, &minimal1 PASS_REGS ); l1 = write_length( buf1, outv, enc1, minimal1 PASS_REGS); @@ -1288,7 +1290,7 @@ Yap_Splice_Text( int n, size_t cuts[], seq_tv_t *inp, seq_tv_t outv[] USES_REGS if (cmp_Text( advance_Text(buf, l0, enc), buf1, l1, enc, enc1) == 0) return NULL; slice(0, l0, buf, outv, enc PASS_REGS); - return buf0; + return buf1; } } } diff --git a/C/write.c b/C/write.c index 074f6fbe5..b46a7e39e 100644 --- a/C/write.c +++ b/C/write.c @@ -174,21 +174,18 @@ wrpututf8(const char *s, struct write_globs *wglb) /* writes an integer */ IOSTREAM *stream = wglb->stream; + int chr; + char *ptr = (char *)s; + if (wglb->Write_strings) wrputc('`', stream); else wrputc('"', stream); - if (stream->encoding == ENC_UTF8) { - wrputs( s, stream); - } else { - int chr; - char *ptr = (char *)s; - do { - ptr = utf8_get_char(ptr, &chr); - if (chr == '\0') break; - wrputc(chr, stream); - } while (TRUE); - } + do { + ptr = utf8_get_char(ptr, &chr); + if (chr == '\0') break; + wrputc(chr, stream); + } while (TRUE); if (wglb->Write_strings) wrputc('`', stream); else diff --git a/packages/real b/packages/real index f60caaf8b..5a72fe49e 160000 --- a/packages/real +++ b/packages/real @@ -1 +1 @@ -Subproject commit f60caaf8b2134b6a64e4923b2a471cdcd8026c2f +Subproject commit 5a72fe49e5a5c651a890a388eb967b83da8e2c52