| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | /*************************************************************************
 | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | *	 YAP Prolog 							 * | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | *	Yap Prolog was developed at NCCUP - Universidade do Porto	 * | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997	 * | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | ************************************************************************** | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | * File:		write.c							 * | 
					
						
							|  |  |  | * Last rev:								 * | 
					
						
							|  |  |  | * mods:									 * | 
					
						
							|  |  |  | * comments:	Writing a Prolog Term					 * | 
					
						
							|  |  |  | *									 * | 
					
						
							|  |  |  | *************************************************************************/ | 
					
						
							|  |  |  | #ifdef SCCS
 | 
					
						
							|  |  |  | static char     SccsId[] = "%W% %G%"; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Yap.h"
 | 
					
						
							|  |  |  | #include "Yatom.h"
 | 
					
						
							|  |  |  | #include "Heap.h"
 | 
					
						
							|  |  |  | #include "yapio.h"
 | 
					
						
							|  |  |  | #if COROUTINING
 | 
					
						
							|  |  |  | #include "attvar.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if HAVE_STRING_H
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #if HAVE_CTYPE_H
 | 
					
						
							|  |  |  | #include <ctype.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* describe the type of the previous term to have been written */ | 
					
						
							|  |  |  | typedef enum { | 
					
						
							|  |  |  |   separator,	/* the previous term was a separator like ',', ')', ... */ | 
					
						
							|  |  |  |   alphanum,	/* the previous term was an atom or number */ | 
					
						
							|  |  |  |   symbol        /* the previous term was a symbol like +, -, *, .... */ | 
					
						
							|  |  |  | } wtype; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static wtype lastw; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-28 14:26:37 +00:00
										 |  |  | typedef  int      (*wrf) (int, wchar_t); | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef struct write_globs { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |   wrf      writewch; | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |   int      Quote_illegal, Ignore_ops, Handle_vars, Use_portray; | 
					
						
							|  |  |  |   int      keep_terms; | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  |   UInt     MaxDepth, MaxList, MaxArgs; | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | } wglbs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | STATIC_PROTO(void wrputn, (Int, wrf)); | 
					
						
							|  |  |  | STATIC_PROTO(void wrputs, (char *, wrf)); | 
					
						
							|  |  |  | STATIC_PROTO(void wrputf, (Float, wrf)); | 
					
						
							| 
									
										
										
										
											2004-02-13 18:39:29 +00:00
										 |  |  | STATIC_PROTO(void wrputref, (CODEADDR, int, wrf)); | 
					
						
							| 
									
										
										
										
											2007-10-02 12:32:46 +00:00
										 |  |  | STATIC_PROTO(int legalAtom, (unsigned char *)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | STATIC_PROTO(int LeftOpToProtect, (Atom, int)); | 
					
						
							|  |  |  | STATIC_PROTO(int RightOpToProtect, (Atom, int)); | 
					
						
							| 
									
										
										
										
											2007-10-02 12:32:46 +00:00
										 |  |  | STATIC_PROTO(wtype AtomIsSymbols, (unsigned char *)); | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | STATIC_PROTO(void putAtom, (Atom, int, wrf)); | 
					
						
							|  |  |  | STATIC_PROTO(void writeTerm, (Term, int, int, int, struct write_globs *)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | #define wrputc(X,WF)	((*WF)(Yap_c_output_stream,X))	/* writes a character */
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void  | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | wrputn(Int n, wrf writewch)	/* writes an integer	 */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	                   | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   char s[256], *s1=s; /* that should be enough for most integers */ | 
					
						
							|  |  |  |   if (n < 0) { | 
					
						
							|  |  |  |     if (lastw == symbol) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc(' ', writewch);   | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     if (lastw == alphanum) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc(' ', writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | #if HAVE_SNPRINTF
 | 
					
						
							|  |  |  | #if SHORT_INTS
 | 
					
						
							|  |  |  |   snprintf(s, 256, "%ld", n); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |   snprintf(s, 256, "%d", n); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #if SHORT_INTS
 | 
					
						
							|  |  |  |   sprintf(s, "%ld", n); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |   sprintf(s, "%d", n); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |   while (*s1) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     wrputc(*s1++, writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   lastw = alphanum; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void  | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | wrputs(char *s, wrf writewch)		/* writes a string	 */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-10-02 12:32:46 +00:00
										 |  |  |   while (*s) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     wrputc(*s++, writewch); | 
					
						
							| 
									
										
										
										
											2007-10-02 12:32:46 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void  | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | wrputws(wchar_t *s, wrf writewch)		/* writes a string	 */ | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   while (*s) | 
					
						
							|  |  |  |     wrputc(*s++, writewch); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void  | 
					
						
							|  |  |  | wrputf(Float f, wrf writewch)		/* writes a float	 */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	                   | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |   char            s[256], *pt = s, ch; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (f < 0) { | 
					
						
							|  |  |  |     if (lastw == symbol) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc(' ', writewch);   | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     if (lastw == alphanum) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc(' ', writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } | 
					
						
							|  |  |  |   lastw = alphanum; | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  |   //  sprintf(s, "%.15g", f);
 | 
					
						
							|  |  |  |   sprintf(s, RepAtom(FloatFormat)->StrOfAE, f); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   while (*pt == ' ') | 
					
						
							|  |  |  |     pt++; | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  |   if (*pt == 'i' || *pt == 'n')  /* inf or nan */ { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     wrputc('(', writewch);     | 
					
						
							|  |  |  |     wrputc('+', writewch);     | 
					
						
							|  |  |  |     wrputs(pt, writewch); | 
					
						
							|  |  |  |     wrputc(')', writewch);     | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  |   } else {     | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     wrputs(pt, writewch); | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   if (*pt == '-') pt++; | 
					
						
							|  |  |  |   while ((ch = *pt) != '\0') { | 
					
						
							|  |  |  |     if (ch < '0' || ch > '9') | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     pt++; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |   wrputs(".0", writewch);     | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void  | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | wrputref(CODEADDR ref, int Quote_illegal, wrf writewch)			/* writes a data base reference */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	                     | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   char            s[256]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |   putAtom(AtomDBRef, Quote_illegal, writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #if SHORT_INTS
 | 
					
						
							| 
									
										
										
										
											2004-02-13 18:39:29 +00:00
										 |  |  |   sprintf(s, "(0x%p,0)", ref); | 
					
						
							| 
									
										
										
										
											2006-05-02 16:39:06 +00:00
										 |  |  | #elif __linux__
 | 
					
						
							| 
									
										
										
										
											2004-02-13 18:39:29 +00:00
										 |  |  |   sprintf(s, "(%p,0)", ref); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2004-02-13 18:39:29 +00:00
										 |  |  |   sprintf(s, "(0x%p,0)", ref); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |   wrputs(s, writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   lastw = alphanum; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int  | 
					
						
							| 
									
										
										
										
											2007-10-02 12:32:46 +00:00
										 |  |  | legalAtom(unsigned char *s)			/* Is this a legal atom ? */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	                   | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-10-02 12:32:46 +00:00
										 |  |  |   wchar_t ch = *s; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   if (ch == '\0') | 
					
						
							|  |  |  |     return(FALSE); | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   if (Yap_chtype[ch] != LC) { | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     if (ch == '[') | 
					
						
							|  |  |  |       return (*++s == ']' && !(*++s)); | 
					
						
							|  |  |  |     else if (ch == '{') | 
					
						
							|  |  |  |       return (*++s == '}' && !(*++s)); | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |     else if (Yap_chtype[ch] == SL) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       return (!*++s); | 
					
						
							|  |  |  |     else if ((ch == ',' || ch == '.') && !s[1]) | 
					
						
							|  |  |  |       return (FALSE); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       while (ch) { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	if (Yap_chtype[ch] != SY) return (FALSE); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	ch = *++s; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     return (TRUE); | 
					
						
							|  |  |  |   } else | 
					
						
							|  |  |  |     while ((ch = *++s) != 0) | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |       if (Yap_chtype[ch] > NU) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	return (FALSE); | 
					
						
							|  |  |  |   return (TRUE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int LeftOpToProtect(Atom at, int p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int op, rp; | 
					
						
							| 
									
										
										
										
											2005-10-21 16:09:03 +00:00
										 |  |  |   OpEntry            *opinfo = Yap_GetOpProp(at); | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   return(opinfo && Yap_IsPrefixOp(opinfo, &op, &rp) ); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int RightOpToProtect(Atom at, int p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int op, lp; | 
					
						
							| 
									
										
										
										
											2005-10-21 16:09:03 +00:00
										 |  |  |   OpEntry            *opinfo = Yap_GetOpProp(at); | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   return(opinfo && Yap_IsPosfixOp(opinfo, &op, &lp) ); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static wtype  | 
					
						
							| 
									
										
										
										
											2007-10-02 12:32:46 +00:00
										 |  |  | AtomIsSymbols(unsigned char *s)		/* Is this atom just formed by symbols ? */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   int ch; | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   if (Yap_chtype[(int)s[0]] == SL && s[1] == '\0') | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     return(separator); | 
					
						
							|  |  |  |   while ((ch = *s++) != '\0') { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |     if (Yap_chtype[ch] != SY) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       return(alphanum); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return(symbol); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void  | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | putAtom(Atom atom, int Quote_illegal, wrf writewch)			/* writes an atom	 */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	                      | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-10-02 12:32:46 +00:00
										 |  |  |   unsigned char           *s = (unsigned char *)RepAtom(atom)->StrOfAE; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   wtype          atom_or_symbol = AtomIsSymbols(s); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-03 19:33:38 +00:00
										 |  |  |   /* #define CRYPT_FOR_STEVE 1*/ | 
					
						
							| 
									
										
										
										
											2002-03-28 18:48:55 +00:00
										 |  |  | #ifdef CRYPT_FOR_STEVE
 | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |   if (Yap_GetValue(Yap_LookupAtom("crypt_atoms")) != TermNil && Yap_GetAProp(atom, OpProperty) == NIL) { | 
					
						
							| 
									
										
										
										
											2002-03-28 18:48:55 +00:00
										 |  |  |     char s[16]; | 
					
						
							|  |  |  |     sprintf(s,"x%x", (CELL)s); | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     wrputs(s, writewch); | 
					
						
							| 
									
										
										
										
											2002-03-28 18:48:55 +00:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |   if (IsWideAtom(atom)) { | 
					
						
							|  |  |  |     wchar_t *ws = (wchar_t *)s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (Quote_illegal) { | 
					
						
							|  |  |  |       wrputc('\'', writewch); | 
					
						
							|  |  |  |       while (*ws) { | 
					
						
							|  |  |  | 	wchar_t ch = *ws++; | 
					
						
							|  |  |  | 	wrputc(ch, writewch); | 
					
						
							|  |  |  | 	if (ch == '\\' && yap_flags[CHARACTER_ESCAPE_FLAG] != CPROLOG_CHARACTER_ESCAPES) | 
					
						
							|  |  |  | 	  wrputc('\\', writewch);	/* be careful about backslashes */ | 
					
						
							|  |  |  | 	else if (ch == '\'') | 
					
						
							|  |  |  | 	  wrputc('\'', writewch);	/* be careful about quotes */ | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       wrputc('\'', writewch); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       wrputws(ws, writewch); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   if (lastw == atom_or_symbol && atom_or_symbol != separator /* solo */) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     wrputc(' ', writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   lastw = atom_or_symbol; | 
					
						
							|  |  |  |   if (!legalAtom(s) && Quote_illegal) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     wrputc('\'', writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     while (*s) { | 
					
						
							| 
									
										
										
										
											2007-10-02 12:32:46 +00:00
										 |  |  |       wchar_t ch = *s++; | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc(ch, writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       if (ch == '\\' && yap_flags[CHARACTER_ESCAPE_FLAG] != CPROLOG_CHARACTER_ESCAPES) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc('\\', writewch);	/* be careful about backslashes */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       else if (ch == '\'') | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc('\'', writewch);	/* be careful about quotes */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     wrputc('\'', writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2007-10-02 12:32:46 +00:00
										 |  |  |     wrputs((char *)s, writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int  | 
					
						
							|  |  |  | IsStringTerm(Term string)	/* checks whether this is a string */ | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (IsVarTerm(string)) return(FALSE); | 
					
						
							|  |  |  |   do { | 
					
						
							|  |  |  |     Term hd; | 
					
						
							|  |  |  |     int ch; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!IsPairTerm(string)) return(FALSE); | 
					
						
							|  |  |  |     hd = HeadOfTerm(string); | 
					
						
							|  |  |  |     if (IsVarTerm(hd)) return(FALSE); | 
					
						
							|  |  |  |     if (!IsIntTerm(hd)) return(FALSE); | 
					
						
							|  |  |  |     ch = IntOfTerm(HeadOfTerm(string)); | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     if ((ch < ' ' || ch > MAX_ISO_LATIN1) && ch != '\n' && ch != '\t') | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       return(FALSE); | 
					
						
							|  |  |  |     string = TailOfTerm(string); | 
					
						
							|  |  |  |     if (IsVarTerm(string)) return(FALSE); | 
					
						
							|  |  |  |   } while (string != TermNil); | 
					
						
							|  |  |  |   return(TRUE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void  | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | putString(Term string, wrf writewch)		/* writes a string	 */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	                      | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |   wrputc('"', writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   while (string != TermNil) { | 
					
						
							|  |  |  |     int ch = IntOfTerm(HeadOfTerm(string)); | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     wrputc(ch, writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     if (ch == '\\' && yap_flags[CHARACTER_ESCAPE_FLAG] != CPROLOG_CHARACTER_ESCAPES) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc('\\', writewch);	/* be careful about backslashes */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     else if (ch == '"') | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc('"', writewch);	/* be careful about quotes */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     string = TailOfTerm(string); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |   wrputc('"', writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   lastw = alphanum; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void  | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | putUnquotedString(Term string, wrf writewch)	/* writes a string	 */ | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	                      | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   while (string != TermNil) { | 
					
						
							|  |  |  |     int ch = IntOfTerm(HeadOfTerm(string)); | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     wrputc(ch, writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     string = TailOfTerm(string); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   lastw = alphanum; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | write_var(CELL *t,  struct write_globs *wglb)  | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   if (lastw == alphanum) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     wrputc(' ', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |   wrputc('_', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   /* make sure we don't get no creepy spaces where they shouldn't be */ | 
					
						
							|  |  |  |   lastw = separator; | 
					
						
							|  |  |  |   if (CellPtr(t) < H0) { | 
					
						
							| 
									
										
										
										
											2007-08-06 14:55:43 +00:00
										 |  |  |     Int vcount = (H0-t)/(sizeof(attvar_record)/sizeof(CELL)); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #if COROUTINING
 | 
					
						
							|  |  |  | #if DEBUG
 | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |     if (Yap_Portray_delays) { | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       exts ext = ExtFromCell(t); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |       Yap_Portray_delays = FALSE; | 
					
						
							| 
									
										
										
										
											2004-06-05 03:37:01 +00:00
										 |  |  |       if (ext == attvars_ext) { | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	attvar_record *attv = (attvar_record *)t; | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	long sl = 0; | 
					
						
							| 
									
										
										
										
											2005-09-09 17:24:39 +00:00
										 |  |  | 	Term l = attv->Atts; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputs("$AT(",wglb->writewch); | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	write_var(t, wglb); | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc(',', wglb->writewch);       | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	  /* garbage collection may be called */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	  sl = Yap_InitSlot((CELL)attv); | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	writeTerm((Term)&(attv->Value), 999, 1, FALSE, wglb); | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc(',', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2005-09-09 17:24:39 +00:00
										 |  |  | 	writeTerm(l, 999, 1, FALSE, wglb); | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	  attv = (attvar_record *)Yap_GetFromSlot(sl); | 
					
						
							|  |  |  | 	  Yap_RecoverSlots(1); | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc(')', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |       Yap_Portray_delays = TRUE; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     wrputc('D', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2007-08-06 14:55:43 +00:00
										 |  |  |     wrputn(vcount,wglb->writewch); | 
					
						
							| 
									
										
										
										
											2006-11-14 11:42:26 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     wrputn(((Int) (t- H0)),wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void  | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | writeTerm(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	                  	/* term to write			 */ | 
					
						
							|  |  |  | 	                  	/* context priority			 */ | 
					
						
							|  |  |  | 	                       | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |   if (wglb->MaxDepth != 0 && depth > wglb->MaxDepth) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     putAtom(Yap_LookupAtom("..."), wglb->Quote_illegal, wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |   if (EX != 0) | 
					
						
							|  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   t = Deref(t); | 
					
						
							|  |  |  |   if (IsVarTerm(t)) { | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |     write_var((CELL *)t, wglb); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } else if (IsIntTerm(t)) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     wrputn((Int) IntOfTerm(t),wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } else if (IsAtomTerm(t)) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |     putAtom(AtomOfTerm(t), wglb->Quote_illegal, wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   } else if (IsPairTerm(t)) { | 
					
						
							|  |  |  |     int             eldepth = 1; | 
					
						
							|  |  |  |     Term ti; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |     if (wglb->Use_portray) { | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       Term targs[1]; | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |       Term old_EX = 0L; | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  |       long sl = 0; | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       targs[0] = t; | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |       Yap_PutValue(AtomPortray, MkAtomTerm(AtomNil)); | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |       if (EX != 0L) old_EX = EX; | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |       sl = Yap_InitSlot(t);       | 
					
						
							|  |  |  |       Yap_execute_goal(Yap_MkApplTerm(FunctorPortray, 1, targs), 0, 1); | 
					
						
							|  |  |  |       t = Yap_GetFromSlot(sl); | 
					
						
							|  |  |  |       Yap_RecoverSlots(1); | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |       if (old_EX != 0L) EX = old_EX; | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |       if (Yap_GetValue(AtomPortray) == MkAtomTerm(AtomTrue)) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (yap_flags[WRITE_QUOTED_STRING_FLAG] && IsStringTerm(t)) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       putString(t, wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc('[', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       lastw = separator; | 
					
						
							|  |  |  |       while (1) { | 
					
						
							|  |  |  | 	int             new_depth = depth + 1; | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	long            sl= 0; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	if (wglb->MaxList && eldepth > wglb->MaxList) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	  putAtom(Yap_LookupAtom("..."), wglb->Quote_illegal, wglb->writewch); | 
					
						
							|  |  |  | 	  wrputc(']', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	  lastw = separator; | 
					
						
							|  |  |  | 	  return; | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	  eldepth++; | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	  /* garbage collection may be called */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	  sl = Yap_InitSlot(t); | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	writeTerm(HeadOfTermCell(t), 999, new_depth, FALSE, wglb); | 
					
						
							|  |  |  | 	if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	  t = Yap_GetFromSlot(sl); | 
					
						
							|  |  |  | 	  Yap_RecoverSlots(1); | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	ti = TailOfTerm(t); | 
					
						
							|  |  |  | 	if (IsVarTerm(ti)) | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	if (!IsPairTerm(ti)) | 
					
						
							|  |  |  | 	  break; | 
					
						
							|  |  |  | 	t = ti; | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc(',', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (ti != MkAtomTerm(AtomNil)) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc('|', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	writeTerm(TailOfTermCell(t), 999, depth + 1, FALSE, wglb); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc(']', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       lastw = separator; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } else {		/* compound term */ | 
					
						
							|  |  |  |     Functor         functor = FunctorOfTerm(t); | 
					
						
							|  |  |  |     int             Arity; | 
					
						
							|  |  |  |     Atom            atom; | 
					
						
							| 
									
										
										
										
											2005-10-21 16:09:03 +00:00
										 |  |  |     OpEntry        *opinfo; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     int             op, lp, rp; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |     if (IsExtensionFunctor(functor)) { | 
					
						
							|  |  |  |       switch((CELL)functor) { | 
					
						
							|  |  |  |       case (CELL)FunctorDouble: | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputf(FloatOfTerm(t),wglb->writewch); | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	return; | 
					
						
							|  |  |  |       case (CELL)FunctorDBRef: | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputref(RefOfTerm(t), wglb->Quote_illegal, wglb->writewch); | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	return; | 
					
						
							|  |  |  |       case (CELL)FunctorLongInt: | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputn(LongIntOfTerm(t),wglb->writewch); | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	return; | 
					
						
							|  |  |  | #ifdef USE_GMP
 | 
					
						
							|  |  |  |       case (CELL)FunctorBigInt: | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  | 	  MP_INT *big = Yap_BigIntOfTerm(t); | 
					
						
							| 
									
										
										
										
											2006-04-28 16:14:05 +00:00
										 |  |  | 	  char *s = (char *)TR; | 
					
						
							|  |  |  | 	  if (s+2+mpz_sizeinbase(big, 10) >= Yap_TrailTop) { | 
					
						
							| 
									
										
										
										
											2006-05-02 16:39:06 +00:00
										 |  |  | 	    s = (char *)H; | 
					
						
							|  |  |  | 	    if (s+2+mpz_sizeinbase(big, 10) >= (char *)ASP) { | 
					
						
							| 
									
										
										
										
											2006-04-28 16:14:05 +00:00
										 |  |  | 	      return; | 
					
						
							|  |  |  | 	    } | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  | 	  } | 
					
						
							| 
									
										
										
										
											2006-04-28 16:14:05 +00:00
										 |  |  | 	  if (!s) | 
					
						
							|  |  |  | 	    return; | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  | 	  if (mpz_sgn(big) < 0) { | 
					
						
							|  |  |  | 	    if (lastw == symbol) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	      wrputc(' ', wglb->writewch);   | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  | 	  } else { | 
					
						
							|  |  |  | 	    if (lastw == alphanum) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	      wrputc(' ', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2006-01-02 02:16:19 +00:00
										 |  |  | 	  } | 
					
						
							|  |  |  | 	  mpz_get_str(s, 10, big); | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	  wrputs(s,wglb->writewch); | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |     Arity = ArityOfFunctor(functor); | 
					
						
							|  |  |  |     atom = NameOfFunctor(functor); | 
					
						
							| 
									
										
										
										
											2005-10-21 16:09:03 +00:00
										 |  |  |     opinfo = Yap_GetOpProp(atom); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | #ifdef SFUNC
 | 
					
						
							|  |  |  |     if (Arity == SFArity) { | 
					
						
							|  |  |  |       int             argno = 1; | 
					
						
							|  |  |  |       CELL           *p = ArgsOfSFTerm(t); | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       putAtom(atom, wglb->Quote_illegal, wglb->writewch); | 
					
						
							|  |  |  |       wrputc('(', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       lastw = separator; | 
					
						
							|  |  |  |       while (*p) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	long sl = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	while (argno < *p) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	  wrputc('_', wglb->writewch), wrputc(',', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	  ++argno; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	*p++; | 
					
						
							|  |  |  | 	lastw = separator; | 
					
						
							|  |  |  | 	/* cannot use the term directly with the SBA */ | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	  /* garbage collection may be called */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	  sl = Yap_InitSlot((CELL)p); | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	writeTerm(Deref(p++), 999, depth + 1, FALSE, wglb); | 
					
						
							|  |  |  | 	if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	  /* garbage collection may be called */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	  p = (CELL *)Yap_GetFromSlot(sl); | 
					
						
							|  |  |  | 	  Yap_RecoverSlots(1); | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	if (*p) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	  wrputc(',', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	argno++; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc(')', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       lastw = separator; | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |     if (wglb->Use_portray) { | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       Term targs[1]; | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |       Term old_EX = 0L; | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  |       long sl = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       targs[0] = t; | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |       Yap_PutValue(AtomPortray, MkAtomTerm(AtomNil)); | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |       if (EX != 0L) old_EX = EX; | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |       sl = Yap_InitSlot(t);       | 
					
						
							|  |  |  |       Yap_execute_goal(Yap_MkApplTerm(FunctorPortray, 1, targs),0, 1); | 
					
						
							|  |  |  |       t = Yap_GetFromSlot(sl); | 
					
						
							|  |  |  |       Yap_RecoverSlots(1); | 
					
						
							| 
									
										
										
										
											2002-05-14 18:24:34 +00:00
										 |  |  |       if (old_EX != 0L) EX = old_EX; | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  |       if (Yap_GetValue(AtomPortray) == MkAtomTerm(AtomTrue) || EX != 0L) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |     if (!wglb->Ignore_ops && | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	Arity == 1 && opinfo && Yap_IsPrefixOp(opinfo, &op, | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 					   &rp) | 
					
						
							|  |  |  | #ifdef DO_NOT_WRITE_PLUS_AND_MINUS_AS_PREFIX
 | 
					
						
							|  |  |  | 	&& | 
					
						
							|  |  |  | 	/* never write '+' and '-' as infix
 | 
					
						
							|  |  |  | 	   operators */ | 
					
						
							|  |  |  | 	( (RepAtom(atom)->StrOfAE[0] != '+' && | 
					
						
							|  |  |  | 	   RepAtom(atom)->StrOfAE[0] != '-') || | 
					
						
							|  |  |  | 	  RepAtom(atom)->StrOfAE[1] ) | 
					
						
							|  |  |  | #endif /* DO_NOT_WRITE_PLUS_AND_MINUS_AS_PREFIX */
 | 
					
						
							|  |  |  | 	) { | 
					
						
							|  |  |  |       Term  tright = ArgOfTerm(1, t); | 
					
						
							|  |  |  |       int            bracket_right = | 
					
						
							|  |  |  | 	!IsVarTerm(tright) && IsAtomTerm(tright) && | 
					
						
							|  |  |  | 	RightOpToProtect(AtomOfTerm(tright), rp); | 
					
						
							|  |  |  |       if (op > p) { | 
					
						
							|  |  |  | 	/* avoid stuff such as \+ (a,b) being written as \+(a,b) */ | 
					
						
							|  |  |  | 	if (lastw != separator && !rinfixarg) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	  wrputc(' ', wglb->writewch); | 
					
						
							|  |  |  | 	wrputc('(', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       putAtom(atom, wglb->Quote_illegal, wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       if (bracket_right) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc('(', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |       writeTerm(ArgOfTermCell(1,t), rp, depth + 1, FALSE, wglb); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       if (bracket_right) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc(')', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (op > p) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc(')', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |     } else if (!wglb->Ignore_ops && | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	       Arity == 1 && opinfo && Yap_IsPosfixOp(opinfo, &op, &lp)) { | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       Term  tleft = ArgOfTerm(1, t); | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  |       long sl = 0; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       int            bracket_left = | 
					
						
							|  |  |  | 	!IsVarTerm(tleft) && IsAtomTerm(tleft) && | 
					
						
							|  |  |  | 	LeftOpToProtect(AtomOfTerm(tleft), lp);  | 
					
						
							|  |  |  |       if (op > p) { | 
					
						
							|  |  |  | 	/* avoid stuff such as \+ (a,b) being written as \+(a,b) */ | 
					
						
							|  |  |  | 	if (lastw != separator && !rinfixarg) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	  wrputc(' ', wglb->writewch); | 
					
						
							|  |  |  | 	wrputc('(', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (bracket_left) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc('(', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |       if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	/* garbage collection may be called */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	sl = Yap_InitSlot(t);       | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |       writeTerm(ArgOfTermCell(1,t), lp, depth + 1, rinfixarg, wglb); | 
					
						
							|  |  |  |       if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	/* garbage collection may be called */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	t = Yap_GetFromSlot(sl); | 
					
						
							|  |  |  | 	Yap_RecoverSlots(1); | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       if (bracket_left) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc(')', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       putAtom(atom, wglb->Quote_illegal, wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       if (op > p) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc(')', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |     } else if (!wglb->Ignore_ops && | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	       Arity == 2 && opinfo && Yap_IsInfixOp(opinfo, &op, &lp, | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 						 &rp) ) { | 
					
						
							|  |  |  |       Term  tleft = ArgOfTerm(1, t); | 
					
						
							|  |  |  |       Term  tright = ArgOfTerm(2, t); | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  |       long sl = 0; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       int   bracket_left = | 
					
						
							|  |  |  | 	!IsVarTerm(tleft) && IsAtomTerm(tleft) && | 
					
						
							|  |  |  | 	LeftOpToProtect(AtomOfTerm(tleft), lp); | 
					
						
							|  |  |  |       int   bracket_right = | 
					
						
							|  |  |  | 	!IsVarTerm(tright) && IsAtomTerm(tright) && | 
					
						
							|  |  |  | 	RightOpToProtect(AtomOfTerm(tright), rp); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (op > p) { | 
					
						
							|  |  |  | 	/* avoid stuff such as \+ (a,b) being written as \+(a,b) */ | 
					
						
							|  |  |  | 	if (lastw != separator && !rinfixarg) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	  wrputc(' ', wglb->writewch); | 
					
						
							|  |  |  | 	wrputc('(', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (bracket_left) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc('(', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |       if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	/* garbage collection may be called */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	sl = Yap_InitSlot(t);       | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |       writeTerm(ArgOfTermCell(1, t), lp, depth + 1, rinfixarg, wglb); | 
					
						
							|  |  |  |       if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	/* garbage collection may be called */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	t = Yap_GetFromSlot(sl); | 
					
						
							|  |  |  | 	Yap_RecoverSlots(1); | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       if (bracket_left) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc(')', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       /* avoid quoting commas */ | 
					
						
							|  |  |  |       if (strcmp(RepAtom(atom)->StrOfAE,",")) | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	putAtom(atom, wglb->Quote_illegal, wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       else { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc(',', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (bracket_right) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc('(', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |       writeTerm(ArgOfTermCell(2, t), rp, depth + 1, TRUE, wglb); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       if (bracket_right) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc(')', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (op > p) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc(')', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |     } else if (wglb->Handle_vars && functor == FunctorVar) { | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       Term ti = ArgOfTerm(1, t); | 
					
						
							|  |  |  |       if (lastw == alphanum) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc(' ', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       } | 
					
						
							|  |  |  |       if (!IsVarTerm(ti) && (IsIntTerm(ti) || IsStringTerm(ti))) { | 
					
						
							|  |  |  | 	if (IsIntTerm(ti)) { | 
					
						
							|  |  |  | 	  Int k = IntOfTerm(ti); | 
					
						
							|  |  |  | 	  if (k == -1)  { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	    wrputc('_', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    lastw = alphanum; | 
					
						
							|  |  |  | 	    return; | 
					
						
							|  |  |  | 	  } else { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	    wrputc((k % 26) + 'A', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    if (k >= 26) { | 
					
						
							|  |  |  | 	      /* make sure we don't get confused about our context */ | 
					
						
							|  |  |  | 	      lastw = separator; | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	      wrputn( k / 26 ,wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	    } else | 
					
						
							|  |  |  | 	      lastw = alphanum; | 
					
						
							|  |  |  | 	  } | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	  putUnquotedString(ti, wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	long sl = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputs("'$VAR'(",wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	  /* garbage collection may be called */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	  sl = Yap_InitSlot(t);       | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	writeTerm(ArgOfTermCell(1,t), 999, depth + 1, FALSE, wglb); | 
					
						
							|  |  |  | 	if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	  /* garbage collection may be called */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	  t = Yap_GetFromSlot(sl); | 
					
						
							|  |  |  | 	  Yap_RecoverSlots(1); | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	wrputc(')', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	lastw = separator; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } else if (functor == FunctorBraces) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc('{', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       lastw = separator; | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |       writeTerm(ArgOfTermCell(1, t), 1200, depth + 1, FALSE, wglb); | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc('}', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       lastw = separator; | 
					
						
							|  |  |  |     } else  if (atom == AtomArray) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  |       long sl = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc('{', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       lastw = separator; | 
					
						
							|  |  |  |       for (op = 1; op <= Arity; ++op) { | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	if (op == wglb->MaxArgs) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	  wrputc('.', wglb->writewch); | 
					
						
							|  |  |  | 	  wrputc('.', wglb->writewch); | 
					
						
							|  |  |  | 	  wrputc('.', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	  break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	  /* garbage collection may be called */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	  sl = Yap_InitSlot(t);       | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	writeTerm(ArgOfTermCell(op, t), 999, depth + 1, FALSE, wglb); | 
					
						
							|  |  |  | 	if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	  /* garbage collection may be called */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	  t = Yap_GetFromSlot(sl); | 
					
						
							|  |  |  | 	  Yap_RecoverSlots(1); | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	if (op != Arity) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	  wrputc(',', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	  lastw = separator; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc('}', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       lastw = separator; | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       putAtom(atom, wglb->Quote_illegal, wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       lastw = separator; | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc('(', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       for (op = 1; op <= Arity; ++op) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	long sl = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	if (op == wglb->MaxArgs) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	  wrputc('.', wglb->writewch); | 
					
						
							|  |  |  | 	  wrputc('.', wglb->writewch); | 
					
						
							|  |  |  | 	  wrputc('.', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  | 	  break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	  /* garbage collection may be called */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	  sl = Yap_InitSlot(t);       | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  | 	writeTerm(ArgOfTermCell(op, t), 999, depth + 1, FALSE, wglb); | 
					
						
							|  |  |  | 	if (wglb->keep_terms) { | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	  /* garbage collection may be called */ | 
					
						
							| 
									
										
										
										
											2002-11-18 18:18:05 +00:00
										 |  |  | 	  t = Yap_GetFromSlot(sl); | 
					
						
							|  |  |  | 	  Yap_RecoverSlots(1); | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	if (op != Arity) { | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  | 	  wrputc(',', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | 	  lastw = separator; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |       wrputc(')', wglb->writewch); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |       lastw = separator; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void  | 
					
						
							| 
									
										
										
										
											2007-01-28 14:26:37 +00:00
										 |  |  | Yap_plwrite(Term t, int (*mywrite) (int, wchar_t), int flags) | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |      /* term to be written			 */ | 
					
						
							|  |  |  |      /* consumer				 */ | 
					
						
							|  |  |  |      /* write options			 */ | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |   struct write_globs wglb; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-27 17:42:03 +00:00
										 |  |  |   wglb.writewch = mywrite; | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  |   lastw = separator; | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |   wglb.Quote_illegal = flags & Quote_illegal_f; | 
					
						
							|  |  |  |   wglb.Handle_vars = flags & Handle_vars_f; | 
					
						
							|  |  |  |   wglb.Use_portray = flags & Use_portray_f; | 
					
						
							|  |  |  |   wglb.MaxDepth = max_depth; | 
					
						
							|  |  |  |   wglb.MaxList = max_list; | 
					
						
							| 
									
										
										
										
											2005-12-05 17:16:12 +00:00
										 |  |  |   wglb.MaxArgs = max_write_args; | 
					
						
							| 
									
										
										
										
											2002-10-17 00:05:29 +00:00
										 |  |  |   /* notice: we must have ASP well set when using portray, otherwise
 | 
					
						
							|  |  |  |      we cannot make recursive Prolog calls */ | 
					
						
							| 
									
										
										
										
											2004-01-29 13:37:10 +00:00
										 |  |  |   wglb.keep_terms = (flags & (Use_portray_f|To_heap_f));  | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |   wglb.Ignore_ops = flags & Ignore_ops_f; | 
					
						
							| 
									
										
										
										
											2004-05-01 03:58:46 +00:00
										 |  |  |   /* protect slots for portray */ | 
					
						
							| 
									
										
										
										
											2002-11-20 20:00:56 +00:00
										 |  |  |   writeTerm(t, 1200, 1, FALSE, &wglb); | 
					
						
							| 
									
										
										
										
											2001-04-09 19:54:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 |