From 3f4fe6815f1f4aca027578f36c1eb526826939f0 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 28 Sep 2016 09:08:22 -0500 Subject: [PATCH] format was broken in old Linuxen --- os/fmem.c | 39 ++++++++------------------------------- os/format.c | 14 +++++++------- os/format.h | 4 ++-- os/mem.c | 8 ++++---- 4 files changed, 21 insertions(+), 44 deletions(-) diff --git a/os/fmem.c b/os/fmem.c index e4e662cfb..a2cf28a85 100644 --- a/os/fmem.c +++ b/os/fmem.c @@ -30,44 +30,21 @@ static char SccsId[] = "%W% %G%"; - bool format_synch(int sno, int sno0, format_info *fg) { - int (*f_putc)(int, int); + int format_synch(int sno, int sno0, format_info *fg) { const char *s; int n; - if (sno == sno0) { -#if MAY_WRITE + if (sno != sno0) { fflush(GLOBAL_Stream[sno].file); -#endif - return true; - } - f_putc = GLOBAL_Stream[sno0].stream_putc; -#if MAY_WRITE - if (fflush(GLOBAL_Stream[sno].file) == 0) { - s = GLOBAL_Stream[sno].nbuf; n = ftell(GLOBAL_Stream[sno].file); + s = GLOBAL_Stream[sno].nbuf; fwrite(s, n, 1, GLOBAL_Stream[sno0].file); rewind(GLOBAL_Stream[sno].file); - fflush(GLOBAL_Stream[sno0].file); - } else - return false; -#else - s = GLOBAL_Stream[sno].u.mem_string.buf; - n = GLOBAL_Stream[sno].u.mem_string.pos; -#endif -#if MAY_WRITE -#else - while (n--) { - f_putc(sno0, *s++); + fg->lstart = 0; + fg->phys_start = 0; + fg->gapi = 0; } - GLOBAL_Stream[sno].u.mem_string.pos = 0; -#endif - GLOBAL_Stream[sno].linecount = 1; - GLOBAL_Stream[sno].linepos = 0; - GLOBAL_Stream[sno].charcount = 0; - fg->lstart = 0; - fg->phys_start = 0; - fg->gapi = 0; - return true; + fflush(GLOBAL_Stream[sno0].file); + return sno; } bool fill_pads(int sno, int sno0, int total, format_info *fg USES_REGS) diff --git a/os/format.c b/os/format.c index 02c9d7827..6e5517971 100644 --- a/os/format.c +++ b/os/format.c @@ -330,7 +330,7 @@ static void format_clean_up(int sno, int sno0, format_info *finf, const unsigned char *fstr, const Term *targs) { if (sno != sno0) { - format_synch(sno, sno0, finf); + sno = format_synch(sno, sno0, finf); Yap_CloseStream(sno); } if (fstr) { @@ -469,7 +469,7 @@ static Int doformat(volatile Term otail, volatile Term oargs, finfo.phys_start = 0; finfo.lstart = 0; if (true || !(GLOBAL_Stream[sno].status & InMemory_Stream_f)) - sno = Yap_OpenBufWriteStream(PASS_REGS1); + sno = Yap_OpenBufWriteStream(PASS_REGS1); if (sno < 0) { if (!alloc_fstr) fstr = NULL; @@ -479,7 +479,7 @@ static Int doformat(volatile Term otail, volatile Term oargs, format_clean_up(sno, sno0, &finfo, fstr, targs); return false; } - f_putc = GLOBAL_Stream[sno0].stream_wputc; + f_putc = GLOBAL_Stream[sno].stream_wputc; while ((fptr += get_utf8(fptr, -1, &ch)) && ch) { Term t = TermNil; int has_repeats = false; @@ -879,21 +879,21 @@ static Int doformat(volatile Term otail, volatile Term oargs, while (repeats--) { f_putc(sno, (int)'\n'); } - format_synch(sno, sno0, &finfo); + sno = format_synch(sno, sno0, &finfo); break; case 'N': if (!has_repeats) has_repeats = 1; if (GLOBAL_Stream[sno].linepos != 0) { f_putc(sno, '\n'); - format_synch(sno, sno0, &finfo); + sno = format_synch(sno, sno0, &finfo); } if (repeats > 1) { Int i; for (i = 1; i < repeats; i++) f_putc(sno, '\n'); } - format_synch(sno, sno0, &finfo); + sno = format_synch(sno, sno0, &finfo); break; /* padding */ case '|': @@ -971,7 +971,7 @@ static Int doformat(volatile Term otail, volatile Term oargs, } } else { if (ch == '\n') { - format_synch(sno, sno0, &finfo); + sno = format_synch(sno, sno0, &finfo); } f_putc(sno, ch); } diff --git a/os/format.h b/os/format.h index 5333c7839..a5c580978 100644 --- a/os/format.h +++ b/os/format.h @@ -21,5 +21,5 @@ typedef struct format_status { #define FORMAT_COPY_ARGS_ERROR -1 #define FORMAT_COPY_ARGS_OVERFLOW -2 -extern bool format_synch(int sno, int sno0, format_info *fg); -extern bool fill_pads(int sno, int sno0, int total, format_info *fg USES_REGS); \ No newline at end of file +extern int format_synch(int sno, int sno0, format_info *fg); +extern bool fill_pads(int sno, int sno0, int total, format_info *fg USES_REGS); diff --git a/os/mem.c b/os/mem.c index 3aee106d9..2664edf2f 100644 --- a/os/mem.c +++ b/os/mem.c @@ -31,12 +31,12 @@ static char SccsId[] = "%W% %G%"; #include "format.h" - bool format_synch(int sno, int sno0, format_info *fg) { +int format_synch(int sno, int sno0, format_info *fg) { int (*f_putc)(int, int); const char *s; int n; if (sno == sno0) { - return true; + return sno; } f_putc = GLOBAL_Stream[sno0].stream_putc; s = GLOBAL_Stream[sno].u.mem_string.buf; @@ -51,7 +51,7 @@ static char SccsId[] = "%W% %G%"; fg->lstart = 0; fg->phys_start = 0; fg->gapi = 0; - return true; + return sno; } // uses directly the buffer in the memory stream. @@ -377,4 +377,4 @@ void Yap_InitMems(void) { SyncPredFlag); } -#endif \ No newline at end of file +#endif