/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* $Header: b3scr.c,v 1.4 85/08/22 16:58:54 timo Exp $ */ /* B input/output handling */ #include "b.h" #include "b0fea.h" #include "b1mem.h" #include "b1obj.h" #include "b0con.h" /*for CLEAR_EOF*/ #include "b2nod.h" #include "b2syn.h" #include "b2par.h" #include "b3scr.h" #include "b3err.h" #include "b3fil.h" #include "b3typ.h" #include "b3env.h" #include "b3sem.h" #include "b3int.h" #ifdef SETJMP #include #endif Visible bool interactive; Visible bool rd_interactive; Visible value iname= Vnil; /* input name */ Visible bool filtered= No; Visible bool outeractive; #ifdef SETJMP Visible bool awaiting_input= No; Visible jmp_buf read_interrupt; #endif Visible bool at_nwl= Yes; /*Yes if currently at the start of an output line*/ Hidden bool woa, wnwl; /*was outeractive, was at_nwl */ Hidden bool last_was_text= No; /*Yes if last value written was a text*/ Visible bool Eof; FILE *ofile= stdout; FILE *ifile; /* input file */ FILE *sv_ifile; /* copy of ifile for restoring after reading unit */ /******************************* Output *******************************/ #ifndef INTEGRATION Hidden Procedure putch(c) char c; { if (still_ok) { putc(c, ofile); if (c == '\n') at_nwl= Yes; else at_nwl= No; } } #else Hidden int ocol; /* Current output column */ Hidden Procedure putch(c) char c; { if (still_ok) { putc(c, ofile); if (c == '\n') { at_nwl= Yes; ocol= 0; } else { if (at_nwl) { ocol= 0; at_nwl= No;} ++ocol; } } } #endif Visible Procedure newline() { putch('\n'); fflush(stdout); } Hidden Procedure line() { if (!at_nwl) newline(); } Visible Procedure wri_space() { putch(' '); } Visible Procedure writ(v) value v; { wri(v, Yes, Yes, No); fflush(stdout); } #define Putch_sp() {if (!perm) putch(' ');} Hidden int intsize(v) value v; { value s= size(v); int len=0; if (large(s)) error(MESS(3800, "value too big to output")); else len= intval(s); release(s); return len; } Hidden bool lwt; Visible Procedure wri(v, coll, outer, perm) value v; bool coll, outer, perm; { if (outer && !at_nwl && (!Is_text(v) || !last_was_text) && (!Is_compound(v) || !coll)) putch(' '); lwt= No; if (Is_number(v)) { if (perm) printnum(ofile, v); else { string cp= convnum(v); while(*cp && still_ok) putch(*cp++); } } else if (Is_text(v)) { #ifndef INTEGRATION wrtext(putch, v, outer ? '\0' : '"'); #else value ch; char c; int k, len= Length(v); #define QUOTE '"' if (!outer) putch(QUOTE); for (k=0; k