/************************************************************************ * * * The SB-Prolog System * * Copyright SUNY at Stony Brook, 1986 * * * ************************************************************************/ /*----------------------------------------------------------------- SB-Prolog is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. No author or distributor accepts responsibility to anyone for the consequences of using it or for whether it serves any particular purpose or works at all, unless he says so in writing. Refer to the SB-Prolog General Public License for full details. Everyone is granted permission to copy, modify and redistribute SB-Prolog, but only under the conditions described in the SB-Prolog General Public License. A copy of this license is supposed to have been given to you along with SB-Prolog so you can know your rights and responsibilities. It should be in a file named COPYING. Among other things, the copyright notice and this notice must be preserved on all copies. ------------------------------------------------------------------ */ #ifndef lint static char rcsid[] = "$Header: io.c 1.3 87/10/24 $"; #endif /* io.c */ /* $Log: io.c,v $ * Revision 1.3 87/10/24 16:01:43 rbk * Fix writeqname() -- managed to delete the need_to_quote=1 in 1st if (duh). * * Revision 1.2 87/10/24 15:40:13 rbk * Fix writeqname() as per S.K.Debray to quote atoms like '1st'. * Cleaned up writeqname() a bit. * */ #include "sim.h" #include "aux.h" writepname(file, name_ptr, length) FILE *file; char *name_ptr; unsigned short length; { int i, slen; char ch; slen = length>80 ? 80 : length; /* trim to 80 characters */ for ( i = 1; i <= slen; ++i ) { ch = *(name_ptr++); putc((ch<' ' ? ' ' : ch), file); /* nonprintables to blanks */ } /* fflush(file); */ } writeqname(file, name_ptr, length) FILE *file; register char *name_ptr; register unsigned short length; { register int i; int need_to_quote, num; need_to_quote = 0; num = (*name_ptr >= '0') && (*name_ptr <= '9'); for (i = 0; i < length; ++i) { /* * quote if name contains spl chars; also see if it has "atom" * characters (after a number). */ if ((*(name_ptr + i) < '0') || (*(name_ptr + i) > '9' && *(name_ptr + i) < 'A') || (*(name_ptr + i) > 'Z' && *(name_ptr + i) < 'a') || (*(name_ptr + i) > 'z')) { need_to_quote = 1; break; } if (num && (((*(name_ptr + i) >= 'A') && (*(name_ptr + i) <= 'Z')) || ((*(name_ptr + i) >= 'a') && (*(name_ptr + i) <= 'z')))) { need_to_quote = 1; break; } } if (need_to_quote) fprintf(file, "'"); for (i = 1; i <= length; ++i) { if (need_to_quote && (*name_ptr == '\'')) fprintf(file, "'"); putc(*(name_ptr++), file); } if (need_to_quote) fprintf(file, "'"); /* fflush(file); */ } printterm(term, car) word term; byte car; { register pw top; unsigned short i, arity1; struct psc_rec *psc_ptr1; ptd: switch((int)(term&3)) { case FREE: nderef(term, ptd); printf("_%x", untag(term)); return; case CS: psc_ptr1 = get_str_psc(term); if (get_etype(psc_ptr1) == T_BUFF) { printf("Buffer_%x", get_name(psc_ptr1)); } else writepname(stdout, get_name(psc_ptr1), get_length(psc_ptr1)); if ( get_arity(psc_ptr1) == 0 ) return; /* constant */ /* structure */ printf("("); arity1 = ( get_arity(psc_ptr1) ); untag(term); for ( i = 1; i <= arity1; i++ ) { printterm(term += 4, CAR); if (i