improve char conversion

This commit is contained in:
Vítor Santos Costa 2013-12-05 11:20:57 +00:00
parent ba07371328
commit b3608c6a83
5 changed files with 23 additions and 21 deletions

View File

@ -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); Int sz = (3+src[1])*sizeof(CELL);
CELL *dest; CELL *dest;
char *ptr = src+2; int chr;
/* use a special list to store the blobs */ /* use a special list to store the blobs */
cglobs->cint.cpc = cglobs->cint.icpc; cglobs->cint.cpc = cglobs->cint.icpc;
/* if (IsFloatTerm(t)) { /* if (IsFloatTerm(t)) {

View File

@ -592,6 +592,8 @@ ShowOp (char *f, struct PSEUDO *cpc)
Yap_DebugPlWrite(MkAtomTerm(AtomLONGINT)); Yap_DebugPlWrite(MkAtomTerm(AtomLONGINT));
} else if (fun == FunctorDouble) { } else if (fun == FunctorDouble) {
Yap_DebugPlWrite(MkAtomTerm(AtomDOUBLE)); Yap_DebugPlWrite(MkAtomTerm(AtomDOUBLE));
} else if (fun == FunctorString) {
Yap_DebugPlWrite(MkAtomTerm(AtomSTRING));
} }
} else { } else {
Yap_DebugPlWrite (MkAtomTerm(NameOfFunctor(fun))); Yap_DebugPlWrite (MkAtomTerm(NameOfFunctor(fun)));

View File

@ -25,7 +25,7 @@
#include <string.h> #include <string.h>
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; } 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; break;
case YAP_CHAR: 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 ); Term t = init_tstring( PASS_REGS1 );
char *cp = s, *buf; unsigned char *cp = s;
char *buf;
LOCAL_TERM_ERROR( 2*(lim-s) ); LOCAL_TERM_ERROR( 2*(lim-s) );
buf = buf_from_tstring(H); 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; out->val.t = t;
} }
} }
return out->val.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; break;
} }
case YAP_CHAR: case YAP_CHAR:
{ char *s = s0, *lim = s + strnlen(s, max); { unsigned char *s = s0, *lim = s + strnlen(s0, max);
char *cp = s; unsigned char *cp = s;
char w[2]; char w[2];
w[1] = '\0'; w[1] = '\0';
@ -683,8 +685,8 @@ write_codes( void *s0, seq_tv_t *out, encoding_t enc, int minimal USES_REGS)
break; break;
} }
case YAP_CHAR: case YAP_CHAR:
{ char *s = s0, *lim = s + strnlen(s, max); { unsigned char *s = s0, *lim = s + strnlen(s0, max);
char *cp = s; unsigned char *cp = s;
LOCAL_TERM_ERROR( 2*(lim-s) ); LOCAL_TERM_ERROR( 2*(lim-s) );
while (cp < lim) { 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; l1 = l-l0;
slice(l0, l, buf, outv+1, enc PASS_REGS); slice(l0, l, buf, outv+1, enc PASS_REGS);
return buf1; return buf0;
} else /* if (outv[1].val.t) */ { } else /* if (outv[1].val.t) */ {
buf1 = read_Text( buf, outv, &enc1, &minimal1 PASS_REGS ); buf1 = read_Text( buf, outv, &enc1, &minimal1 PASS_REGS );
l1 = write_length( buf1, 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) if (cmp_Text( advance_Text(buf, l0, enc), buf1, l1, enc, enc1) == 0)
return NULL; return NULL;
slice(0, l0, buf, outv, enc PASS_REGS); slice(0, l0, buf, outv, enc PASS_REGS);
return buf0; return buf1;
} }
} }
} }

View File

@ -174,21 +174,18 @@ wrpututf8(const char *s, struct write_globs *wglb) /* writes an integer */
IOSTREAM *stream = wglb->stream; IOSTREAM *stream = wglb->stream;
int chr;
char *ptr = (char *)s;
if (wglb->Write_strings) if (wglb->Write_strings)
wrputc('`', stream); wrputc('`', stream);
else else
wrputc('"', stream); wrputc('"', stream);
if (stream->encoding == ENC_UTF8) { do {
wrputs( s, stream); ptr = utf8_get_char(ptr, &chr);
} else { if (chr == '\0') break;
int chr; wrputc(chr, stream);
char *ptr = (char *)s; } while (TRUE);
do {
ptr = utf8_get_char(ptr, &chr);
if (chr == '\0') break;
wrputc(chr, stream);
} while (TRUE);
}
if (wglb->Write_strings) if (wglb->Write_strings)
wrputc('`', stream); wrputc('`', stream);
else else

@ -1 +1 @@
Subproject commit f60caaf8b2134b6a64e4923b2a471cdcd8026c2f Subproject commit 5a72fe49e5a5c651a890a388eb967b83da8e2c52