format was broken in old Linuxen
This commit is contained in:
parent
a1ee3b30d3
commit
3f4fe6815f
39
os/fmem.c
39
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)
|
||||
|
14
os/format.c
14
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);
|
||||
}
|
||||
|
@ -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);
|
||||
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);
|
||||
|
8
os/mem.c
8
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
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user