home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
pd3.lzh
/
SBPROLOG2.2
/
SIM
/
io.c
< prev
next >
Wrap
Text File
|
1991-08-10
|
4KB
|
134 lines
/************************************************************************
* *
* 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.
------------------------------------------------------------------ */
/* io.c */
#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;
char *name_ptr;
unsigned short length;
{
int i, need_to_quote;
need_to_quote = 0;
for (i=0; i<length; ++i)
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;
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<arity1 /*-1*/ ) printf(",");
}
printf(")");
/* fflush(stdout); */
return;
case NUM:
if (isinteger(term)) printf("%d", intval(term));
else printf("%f", floatval(term));
return;
case LIST:
untag(term);
if ( car ) printf("[");
printterm(follow(term), CAR);
term = follow(term+4);
ldp: switch((int)(term&3)) {
case FREE:
nderef(term, ldp);
goto vertbar;
case LIST:
printf(",");
printterm(term, CDR);
return;
case CS:
if (isnil(term)) { /* term is the 'nil' constant */
printf("]");
/* fflush(stdout); */
return;
} /* else fall through to the vert bar case */
case NUM:
vertbar:
printf("|");
printterm(term, CAR);
printf("]");
/* fflush(stdout); */
return;
}
}
}