Wild Life  2.30
 All Data Structures Files Functions Variables Typedefs Macros
print.c
Go to the documentation of this file.
1 
6 /* Copyright 1991 Digital Equipment Corporation.
7 ** All Rights Reserved.
8 *****************************************************************/
9 
10 #include "defs.h"
11 
19 
21 
23 
24 char *no_name="pointer";
25 char *name="symbol";
26 // char *buffer;
28 
30 
31 /* Used to distinguish listings from other writes */
32 static long listing_flag;
33 
34 /* Used to list function bodies in a nice way */
35 /* Only valid if listing_flag==TRUE */
36 static long func_flag;
37 
38 /* Precedence of the comma and colon operators (or 0 if none exists) */
39 #define COMMA_PREC ((commasym->op_data)?(commasym->op_data->precedence):0)
40 #define COLON_PREC ((colonsym->op_data)?(colonsym->op_data->precedence):0)
41 
42 
43 
52 void init_print()
53 {
54  (void)snprintf(seg_format,PRINT_POWER+4,"%%0%ldd",PRINT_POWER);
55 }
56 
64 {
65  string tmp1,tmp2;
66  char g,len; // ,leading_a;
67 
68  g= ++gen_sym_counter;
69  len=2;
70  strcpy(tmp2,"");
71  do {
72  g--;
73  /* Prefix one character to tmp2: */
74  (void)snprintf(tmp1,2,"%c",g%26+'A');
75  strcat(tmp1,tmp2);
76  strcpy(tmp2,tmp1);
77  g=g/26;
78  len++;
79  } while (g>0 && len<STRLEN);
80  if (len>=STRLEN)
81  perr("Variable name too long -- the universe has ceased to exist.");
82 
83  strcpy(tmp1,"_");
84  strcat(tmp1,tmp2);
85 
86  return heap_copy_string(tmp1);
87 }
88 
100 {
101  GENERIC name_loc;
102 
103  do name_loc=(GENERIC)heap_nice_name();
104  while (find(STRCMP,(char *)name_loc,var_tree));
105 
106  return name_loc;
107 }
108 
118 long str_to_int(char *s)
119 {
120  long v=0;
121  char c;
122 
123  c=(*s);
124  if (c==0)
125  v= -1;
126  else {
127  while (DIGIT(c)) {
128  v=v*10+(c-'0');
129  s++;
130  c=(*s);
131  }
132  if (c!=0) v= -1;
133  }
134 
135  return v;
136 }
137 
147 void print_bin(long b)
148 {
149  long p;
150 
151  for (p=INT_SIZE;p--;p>0)
152  {
153  fprintf(outfile,(b&1?"X":" "));
154  b = b>>1;
155  }
156 }
157 
167 void print_code(FILE *s,ptr_int_list c)
168 {
169  outfile=s;
170 
171  if (c==NOT_CODED)
172  fprintf(outfile," (not coded) ");
173  else {
174  fprintf(outfile," [");
175  while (c) {
176  print_bin((long)c->value_1);
177  c=c->next;
178  }
179  fprintf(outfile,"]");
180  }
181 }
182 
192 void print_operator_kind(FILE *s,long kind)
193 {
194  switch (kind) {
195  case xf:
196  fprintf(s,"xf");
197  break;
198  case fx:
199  fprintf(s,"fx");
200  break;
201  case yf:
202  fprintf(s,"yf");
203  break;
204  case fy:
205  fprintf(s,"fy");
206  break;
207  case xfx:
208  fprintf(s,"xfx");
209  break;
210  case xfy:
211  fprintf(s,"xfy");
212  break;
213  case yfx:
214  fprintf(s,"yfx");
215  break;
216  default:
217  fprintf(s,"illegal");
218  break;
219  }
220 }
221 
234 {
235  ptr_node n;
236 
237  if (p) {
238  deref_ptr(p);
239  n=find(INTCMP,(char *)p,pointer_names);
240  if (n==NULL) {
241  (void)heap_insert(INTCMP,(char *)p,&pointer_names,(GENERIC)NULL);
242  go_through(p);
243  }
244  else
245  n->data=(GENERIC)no_name;
246  }
247 }
248 
259 {
260  if (t) {
261  if (t->left) {
262  go_through_tree(t->left);
263  }
265  if (t->right) {
267  }
268  }
269 
270 }
271 
283 {
284  if (t->attr_list)
286 
287  /*
288  if(r=t->resid)
289  while(r) {
290  if(r->goal->pending)
291  go_through(r->goal->aaaa_1);
292  r=r->next;
293  } */
294 }
295 
308 void insert_variables(ptr_node vars,long force)
309 {
310  ptr_psi_term p;
311  ptr_node n;
312 
313  if(vars) {
314  insert_variables(vars->right,force);
315  p=(ptr_psi_term )vars->data;
316  deref_ptr(p);
317  n=find(INTCMP,(char *)p,pointer_names);
318  if (n)
319  if (n->data || force)
320  n->data=(GENERIC)vars->key;
321  insert_variables(vars->left,force);
322  }
323 }
324 
335 {
336  ptr_psi_term v;
337 
338  if(n) {
340  v=(ptr_psi_term )n->data;
341  deref_ptr(v);
342  (void)heap_insert(INTCMP,(char *)v,&printed_pointers,(GENERIC)n->key);
344  }
345 }
346 
374 void prettyf_inner(char *s,long q,char c)
375 {
376  char *sb=buffer;
377 
378  if (indent) {
379  while (*sb) sb++;
380  if (q) { *sb = c; sb++; }
381  while (*s) {
382  if (q && *s==c) { *sb = *s; sb++; }
383  *sb = *s; sb++; s++;
384  }
385  if (q) { *sb = c; sb++; }
386  *sb=0;
387  }
388  else {
389  if (q) (void)putc(c,outfile);
390  while (*s) {
391  if (q && *s==c) { (void)putc(*s,outfile); }
392  (void)putc(*s,outfile);
393  s++;
394  }
395  if (q) (void)putc(c,outfile);
396  }
397 }
398 
406 long starts_nonlower(char *s)
407 {
408  return (*s && !LOWER(s[0]));
409 }
410 
418 long has_non_alpha(char *s)
419 {
420  while (*s) {
421  if (!ISALPHA(*s)) return TRUE;
422  s++;
423  }
424  return FALSE;
425 }
426 
434 long all_symbol(char *s)
435 {
436  while (*s) {
437  if (!SYMBOL(*s)) return FALSE;
438  s++;
439  }
440  return TRUE;
441 }
442 
450 long is_integer(char *s)
451 {
452  if (!*s) return FALSE;
453  if (*s=='-') s++;
454  while (*s) {
455  if (!DIGIT(*s)) return FALSE;
456  s++;
457  }
458  return TRUE;
459 }
460 
470 long no_quote(char *s)
471 {
472  if (!s[0]) return FALSE;
473 
474  if (s[0]=='%') return FALSE;
475  if (SINGLE(s[0]) && s[1]==0) return TRUE;
476  if (s[0]=='_' && s[1]==0) return FALSE;
477  if (all_symbol(s)) return TRUE;
478 
479  if (!LOWER(s[0])) return FALSE;
480  s++;
481  while (*s) {
482  if (!ISALPHA(*s)) return FALSE;
483  s++;
484  }
485  return TRUE;
486 }
487 
496 void prettyf(char *s)
497 {
498  prettyf_inner(s,FALSE,'\'');
499 }
500 
508 {
509  prettyf_inner((char *)s,const_quote,'"');
510 }
511 
529 void prettyf_quote(char *s)
530 {
531  prettyf_inner(s, const_quote && !no_quote(s), '\'');
532 }
533 /*
534  !is_integer(s) &&
535  (starts_nonlower(s) || has_non_alpha(s)) &&
536  ((int)strlen(s)>1
537  ? !all_symbol(s):
538  ((int)strlen(s)==1
539  ? (s[0]==' ' || s[0]=='_' || UPPER(s[0]) || DIGIT(s[0]))
540  : TRUE
541  )
542  ),
543  '\'');
544 */
545 
554 void end_tab()
555 {
556  if (indent) {
557  indx->str=(char *)heap_alloc(strlen(buffer)+1);
558  strcpy(indx->str,buffer);
559  indx++;
560  *buffer=0;
561  }
562 }
563 
574 {
575  end_tab();
576  indx->tab=t;
577 }
578 
588 {
589  (*t)=HEAP_ALLOC(tab_brk);
590  (*t)->broken=FALSE;
591  (*t)->printed=FALSE;
592  (*t)->column=0;
593 }
594 
595 
608 long strpos(long pos, char *str)
609 {
610  while (*str) {
611  if (str[0]=='\n') pos=0; else pos++;
612  str++;
613  }
614  return pos;
615 }
616 
627 {
628  ptr_item i;
629  long done=FALSE;
630  long pos;
631  ptr_tab_brk worst,root;
632  long w;
633 
634  while(!done) {
635 
636  pos=0;
637  done=TRUE;
638 
639  w= -1;
640  worst=NULL;
641  root=NULL;
642 
643  for(i=pretty_things+1;(unsigned long)i<(unsigned long)indx;i++) {
644 
645  if(i->tab->broken && i->tab->printed) {
646  pos=i->tab->column;
647  root=NULL;
648  }
649 
650  if(!i->tab->printed) i->tab->column=pos;
651 
652  if(!(i->tab->broken))
653  if(!root || (root && (root->column)>=(i->tab->column)))
654  root=i->tab;
655 
656  /* pos=pos+strlen(i->str); */
657  pos=strpos(pos,i->str);
658  i->tab->printed=TRUE;
659 
660  if(pos>page_width)
661  done=FALSE;
662 
663  if(pos>w) {
664  w=pos;
665  worst=root;
666  }
667  }
668 
669  for(i=pretty_things+1;(unsigned long)i<(unsigned long)indx;i++)
670  i->tab->printed=FALSE;
671 
672  if(!done)
673  if(worst)
674  worst->broken=TRUE;
675  else
676  done=TRUE;
677  }
678 }
679 
680 /*** RM: Dec 11 1992 (START) ***/
681 
691 {
692  long c=0;
693  if(t) {
694  if(t->left)
695  c+=count_features(t->left);
696  c++;
697  if(t->right)
698  c+=count_features(t->right);
699  }
700  return c;
701 }
702 
714 {
715  return (t->type==t_type &&
716  count_features(t->attr_list)==2 &&
717  find(FEATCMP,one,t->attr_list) &&
718  find(FEATCMP,two,t->attr_list));
719 }
720 
721 /*** RM: Dec 11 1992 (END) ***/
722 
734 void pretty_list(ptr_psi_term t,long depth)
735 {
736  ptr_tab_brk new;
737  ptr_definition t_type;
738  ptr_psi_term car,cdr;
739  ptr_node n;
740  char sep[4],end[3];
741  long list_depth; /* 20.8 */
742  long done=FALSE; /* RM: Dec 11 1992 */
743 
744  strcpy(sep,"ab");
745  strcpy(end,"cd");
746  t_type=t->type;
747 
748  if (overlap_type(t_type,alist)) {
749  if (!equal_types(t_type,alist)) {
750  pretty_symbol(t_type->keyword); /* RM: Jan 13 1993 */
751  prettyf(DOTDOT);
752  }
753  prettyf("[");
754  strcpy(sep,",");
755  strcpy(end,"]");
756  }
757 
758  /*
759  else if (equal_types(t_type,conjunction)) {
760  prettyf("(");
761  strcpy(sep,DOTDOT);
762  strcpy(end,")");
763  }
764  */
765 
766  else if (equal_types(t_type,disjunction)) {
767  prettyf("{");
768  strcpy(sep,";");
769  strcpy(end,"}");
770  }
771 
772 
773  /* RM: Dec 11 1992 New code for printing lists */
774 
775  new_tab(&new);
776  list_depth=0; /* 20.8 */
777  while(!done) {
778  mark_tab(new);
779  if(list_depth==print_depth)
780  prettyf("...");
781 
782  get_two_args(t->attr_list,&car,&cdr);
783  deref_ptr(car);
784  deref_ptr(cdr);
785 
786 
787  if(list_depth<print_depth)
789 
790  /* Determine how to print the CDR */
791  n=find(INTCMP,(char *)cdr,pointer_names);
792 
793  if(n && n->data) {
794  prettyf("|");
796  done=TRUE;
797  }
798  else
799  if(( /* RM: Feb 1 1993 */
800  (cdr->type==nil && overlap_type(t_type,alist)) ||
801  (cdr->type==disj_nil && t_type==disjunction)
802  )
803  && !cdr->attr_list)
804  done=TRUE;
805  else
806  if(!check_legal_cons(cdr,t_type)) {
807  prettyf("|");
809  done=TRUE;
810  }
811  else {
812  if(list_depth<print_depth)
813  prettyf(sep);
814  t=cdr;
815  }
816 
817  list_depth++;
818  }
819 
820  prettyf(end);
821 }
822 
834 void pretty_tag_or_psi_term(ptr_psi_term p, long sprec, long depth)
835 {
836  ptr_node n,n2;
837 
838  if (p==NULL) {
839  prettyf("<VOID>");
840  return;
841  }
842  if (FALSE /*depth>=print_depth*/) { /* 20.8 */
843  prettyf("...");
844  return;
845  }
846  deref_ptr(p);
847 
848  n=find(INTCMP,(char *)p,pointer_names);
849 
850  if (n && n->data) {
851  if (n->data==(GENERIC)no_name) {
852  n->data=(GENERIC)unique_name();
853  /* sprintf(name,"_%ld%c",++gen_sym_counter,0); */
854  /* n->data=(GENERIC)heap_copy_string(name); */
855  }
856  n2=find(INTCMP,(char *)p,printed_pointers);
857  if(n2==NULL) {
858  prettyf((char *)n->data);
859  (void)heap_insert(INTCMP,(char *)p,&printed_pointers,(GENERIC)n->data);
860  if (!is_top(p)) {
861  prettyf(DOTDOT);
862  pretty_psi_term(p,COLON_PREC,depth);
863  }
864  }
865  else
866  prettyf((char *)n2->data);
867  }
868  else
869  pretty_psi_term(p,sprec,depth);
870 }
871 
888 {
889  if (n) {
890  long f=check_opargs(n->left) | check_opargs(n->right);
891  if (!featcmp(n->key,"1")) return 1 | f;
892  if (!featcmp(n->key,"2")) return 2 | f;
893  return 4 | f;
894  }
895  else
896  return 0;
897 }
898 
899 
913 long opcheck(ptr_psi_term t, long *prec, long *type)
914 {
915  long op;
916  long result=NOTOP;
917  long numarg=check_opargs(t->attr_list);
918  ptr_operator_data opdat=t->type->op_data;
919 
920  *prec=0;
921  if (numarg!=1 && numarg!=3) return NOTOP;
922  while (opdat) {
923  op=opdat->type;
924  if (numarg==1) {
925  if (op==xf || op==yf) { result=POSTFIX; break; }
926  if (op==fx || op==fy) { result=PREFIX; break; }
927  }
928  if (numarg==3)
929  if (op==xfx || op==xfy || op==yfx) { result=INFIX; break; }
930  opdat=opdat->next;
931  }
932  if (opdat==NULL) return NOTOP;
933  *prec=opdat->precedence;
934  *type=op;
935  return result;
936 }
937 
949 long pretty_psi_with_ops(ptr_psi_term t,long sprec,long depth)
950 {
951  // ptr_tab_brk new;
952  ptr_psi_term arg1, arg2;
953  long ttype, a1type, a2type;
954  long tprec, a1prec, a2prec;
955  long tkind, a1kind, a2kind;
956  long p1, p2, argswritten;
957  long sp; /* surrounding parentheses */
958 
959  if (write_canon) return FALSE; /* PVR 24.2.94 */
960 
961  argswritten=TRUE;
962  tkind=opcheck(t, &tprec, &ttype);
963  sp=(tkind==INFIX||tkind==PREFIX||tkind==POSTFIX) && tprec>=sprec;
964  if (sp) prettyf("(");
965  if (tkind==INFIX) {
966  get_two_args(t->attr_list, &arg1, &arg2);
967  deref_ptr(arg1); /* 16.9 */
968  deref_ptr(arg2); /* 16.9 */
969  a1kind = opcheck(arg1, &a1prec, &a1type);
970  a2kind = opcheck(arg2, &a2prec, &a2type);
971 
972  /* The p1 and p2 flags tell whether to put parens around t's args */
973  /* Calculate p1 flag: */
974  if (a1prec>tprec) p1=TRUE;
975  else if (a1prec<tprec) p1=FALSE;
976  else /* equal priority */
977  if (ttype==xfy || ttype==xfx) p1=TRUE;
978  else /* yfx */
979  if (a1type==yfx || a1type==fx || a1type==fy) p1=FALSE;
980  else p1=TRUE;
981 
982  /* Calculate p2 flag: */
983  if (a2prec>tprec) p2=TRUE;
984  else if (a2prec<tprec) p2=FALSE;
985  else /* equal priority */
986  if (ttype==yfx || ttype==xfx) p2=TRUE;
987  else /* xfy */
988  if (a2type==xfy || a2type==xf || a2type==yf) p2=FALSE;
989  else p2=TRUE;
990 
991  /* Write the expression */
992  if (p1) prettyf("(");
994  if (p1) prettyf(")");
995  if (!p1 && strcmp(t->type->keyword->symbol,",")) {
996  prettyf(" ");
997  }
998  pretty_quote_symbol(t->type->keyword); /* RM: Jan 13 1993 */
999  if (listing_flag && !func_flag &&
1000  (!strcmp(t->type->keyword->symbol,",") ||
1001  !strcmp(t->type->keyword->symbol,":-"))) {
1002  prettyf("\n ");
1003  }
1004  else {
1005  if (!p2 && strcmp(t->type->keyword->symbol,".")) prettyf(" ");
1006  }
1007  if (p2) prettyf("(");
1008  pretty_tag_or_psi_term(arg2,MAX_PRECEDENCE+1,depth);
1009  if (p2) prettyf(")");
1010  }
1011  else if (tkind==PREFIX) {
1012  get_two_args(t->attr_list, &arg1, &arg2); /* arg2 does not exist */
1013  a1kind = opcheck(arg1, &a1prec, &a1type);
1014 
1015  /* Calculate p1 flag: */
1016  if (a1type==fx || a1type==fy) p1=FALSE;
1017  else p1=(tprec<=a1prec);
1018 
1019  pretty_quote_symbol(t->type->keyword); /* RM: Jan 13 1993 */
1020  if (!p1) prettyf(" ");
1021  if (p1) prettyf("(");
1022  pretty_tag_or_psi_term(arg1,MAX_PRECEDENCE+1,depth);
1023  if (p1) prettyf(")");
1024  }
1025  else if (tkind==POSTFIX) {
1026  get_two_args(t->attr_list, &arg1, &arg2); /* arg2 does not exist */
1027  a1kind = opcheck(arg1, &a1prec, &a1type);
1028 
1029  /* Calculate p1 flag: */
1030  if (a1type==xf || a1type==yf) p1=FALSE;
1031  else p1=(tprec<=a1prec);
1032 
1033  if (p1) prettyf("(");
1034  pretty_tag_or_psi_term(arg1,MAX_PRECEDENCE+1,depth);
1035  if (p1) prettyf(")");
1036  if (!p1) prettyf(" ");
1037  pretty_quote_symbol(t->type->keyword); /* RM: Jan 13 1993 */
1038  }
1039  else {
1040  argswritten=FALSE;
1041  }
1042  if (sp) prettyf(")");
1043  return argswritten;
1044 }
1045 
1046 /****************************************************************************/
1047 
1058 void pretty_psi_term(ptr_psi_term t,long sprec,long depth)
1059 {
1060  char buf[STRLEN]; /* Big enough for a long number */
1061  ptr_residuation r;
1062  long argswritten;
1063  // double fmod();
1064 
1065  if (t) {
1066  deref_ptr(t); /* PVR */
1067 
1068  /* if (trace) printf("<%ld>",t->status); For brunobug.lf PVR 14.2.94 */
1069 
1070  /* RM: Feb 12 1993 */
1071  if(display_persistent &&
1072  (GENERIC)t>heap_pointer)
1073  prettyf(" $");
1074 
1075  if((t->type==alist || t->type==disjunction) && check_legal_cons(t,t->type))
1076  pretty_list(t,depth+1); /* RM: Dec 11 1992 */
1077  else
1078  if(t->type==nil && !t->attr_list)
1079  prettyf("[]");
1080  else
1081  if(t->type==disj_nil && !t->attr_list) /* RM: Feb 1 1993 */
1082  prettyf("{}");
1083  else {
1084  argswritten=FALSE;
1085  if (t->value_3) {
1086 #ifdef CLIFE
1087  if(t->type->type==block) { /* RM 20 Jan 1993 */
1088  pretty_block(t); /* AA 21 Jan 1993 */
1089  }
1090  else
1091 #endif /* CLIFE */
1092  if (sub_type(t->type,integer)) {
1093  /* Print integers in chunks up to the full precision of the REAL */
1094  long seg,neg,i;
1095  REAL val;
1096  char segbuf[100][PRINT_POWER+3];
1097 
1098  val = *(REAL *)t->value_3;
1099  neg = (val<0.0);
1100  if (neg) val = -val;
1101  if (val>WL_MAXINT) goto PrintReal;
1102  seg=0;
1103  while (val>=(double)PRINT_SPLIT) {
1104  double tmp;
1105  tmp=(REAL)fmod((double)val,(double)PRINT_SPLIT);
1106  (void)snprintf(segbuf[seg],100,seg_format,(unsigned long)tmp);
1107  val=floor(val/(double)PRINT_SPLIT);
1108  seg++;
1109  }
1110  (void)snprintf(segbuf[seg],100,"%s%ld",(neg?"-":""),(unsigned long)val);
1111  for (i=seg; i>=0; i--) prettyf(segbuf[i]);
1112  if (!equal_types(t->type,integer)) {
1113  prettyf(DOTDOT);
1114  pretty_symbol(t->type->keyword); /* RM: Jan 13 1993 */
1115  }
1116  }
1117  else if (sub_type(t->type,real)) {
1118  PrintReal:
1119  (void)snprintf(buf,STRLEN,"%lg",*(REAL *)t->value_3);
1120  prettyf(buf);
1121  if (!equal_types(t->type,real) &&
1122  !equal_types(t->type,integer)) {
1123  prettyf(DOTDOT);
1124  pretty_symbol(t->type->keyword); /* RM: Jan 13 1993 */
1125  }
1126  }
1127  else if (sub_type(t->type,quoted_string)) {
1128  prettyf_quoted_string((char *)t->value_3);
1129  if(!equal_types(t->type,quoted_string)) {
1130  prettyf(DOTDOT);
1131  pretty_quote_symbol(t->type->keyword); /* RM: Jan 13 1993 */
1132  }
1133  }
1134  /* DENYS: BYTEDATA */
1135  else if (sub_type(t->type,sys_bytedata)) {
1137  }
1138  else if (equal_types(t->type,stream)) {
1139  (void)snprintf(buf,STRLEN,"stream(%ld)",(long)t->value_3);
1140  prettyf(buf);
1141  }
1142  else if (equal_types(t->type,eof))
1143  pretty_quote_symbol(eof->keyword); /* RM: Jan 13 1993 */
1144  else if (equal_types(t->type,cut))
1145  pretty_quote_symbol(cut->keyword); /* RM: Jan 13 1993 */
1146  else {
1147  prettyf("*** bad object '");
1148  pretty_symbol(t->type->keyword); /* RM: Jan 13 1993 */
1149  prettyf("'***");
1150  }
1151  }
1152  else {
1153  if (depth<print_depth) /* 20.8 */
1154  argswritten=pretty_psi_with_ops(t,sprec,depth+1);
1155  /* RM: Jan 13 1993 */
1156  if (!argswritten) pretty_quote_symbol(t->type->keyword);
1157  }
1158 
1159  /* write_canon -- PVR 24.2.94 */
1160  if (!argswritten && t->attr_list &&
1161  (depth<print_depth || write_canon)) /* 20.8 */
1162  pretty_attr(t->attr_list,depth+1);
1163 
1164  if (depth>=print_depth && !write_canon && t->attr_list) /* 20.8 */
1165  prettyf("(...)");
1166  }
1167  if ((r=t->resid))
1168  while (r) {
1169  if (r->goal->pending) {
1170  if (FALSE /* write_resids 11.8 */) {
1171  prettyf("\\");
1172  pretty_psi_term(r->goal->aaaa_1,0,depth);
1173  }
1174  else
1175  prettyf("~");
1176  }
1177  r=r->next;
1178  }
1179  }
1180 }
1181 
1199 void do_pretty_attr(ptr_node t,ptr_tab_brk tab,long *cnt,long two,long depth)
1200 {
1201  long v;
1202  char s[4];
1203  ptr_module module;
1204 
1205  if (t) {
1206  if (t->left) {
1207  do_pretty_attr(t->left,tab,cnt,two,depth);
1208  prettyf(",");
1209  }
1210 
1211  /* Don't start each argument on a new line, */
1212  /* unless printing a function body: */
1213  mark_tab(tab);
1214 
1215  v=str_to_int(t->key);
1216  if (v<0) {
1217  if(display_modules) { /* RM: Jan 21 1993 */
1218  module=extract_module_from_name(t->key);
1219  if(module) {
1220  prettyf(module->module_name);
1221  prettyf("#");
1222  }
1223  }
1225 
1226  prettyf(" => ");
1227  }
1228  else if (v== *cnt)
1229  (*cnt)++ ;
1230  else {
1231  (void)snprintf(s,4,"%ld",v);
1232  prettyf(s); /* 6.10 */
1233  prettyf(" => ");
1234  }
1235 
1236  /* pretty_tag_or_psi_term(t->data,(two?COMMA_PREC:MAX_PRECEDENCE+1)); */
1238 
1239  if (t->right) {
1240  prettyf(",");
1241  do_pretty_attr(t->right,tab,cnt,two,depth);
1242  }
1243  }
1244 }
1245 
1246 
1255 {
1256  if (t) {
1257  if (t->left || t->right) return TRUE; else return FALSE;
1258  }
1259  else
1260  return FALSE;
1261 }
1262 
1273 void pretty_attr(ptr_node t,long depth)
1274 {
1275  ptr_tab_brk new;
1276  long cnt=1;
1277 
1278  prettyf("(");
1279  new_tab(&new);
1280 
1281  do_pretty_attr(t,new,&cnt,two_or_more(t),depth);
1282 
1283  prettyf(")");
1284 }
1285 
1294 {
1295  ptr_item i;
1296  long j;
1297 
1298  for(i=pretty_things+1;(unsigned long)i<(unsigned long)indx;i++) {
1299  if(i->tab->broken && i->tab->printed) {
1300  fprintf(outfile,"\n");
1301  for(j=0;j<i->tab->column;j++)
1302  fprintf(outfile," ");
1303  }
1304  fprintf(outfile,"%s",i->str);
1305  i->tab->printed=TRUE;
1306  }
1307 }
1308 
1319 {
1320  ptr_psi_term tok;
1321  ptr_node n2;
1322 
1323  if(n->left) {
1324  pretty_variables(n->left,tab);
1325  prettyf(", ");
1326  }
1327 
1328  mark_tab(tab);
1329  prettyf(n->key);
1330  prettyf(" = ");
1331 
1332  tok=(ptr_psi_term )n->data;
1333  deref_ptr(tok);
1334  n2=find(INTCMP,(char *)tok,printed_pointers);
1335  if(strcmp((char *)n2->data,n->key)<0)
1336  /* Reference to previously printed variable */
1337  prettyf((char *)n2->data);
1338  else {
1339  if (eqsym->op_data) {
1340  long tkind, tprec, ttype, eqprec;
1341  eqprec=eqsym->op_data->precedence;
1342  tkind=opcheck(tok, &tprec, &ttype);
1343  if (tprec>=eqprec) prettyf("(");
1345  if (tprec>=eqprec) prettyf(")");
1346  }
1347  else
1349  }
1350 
1351  if(n->right) {
1352  prettyf(", ");
1353  pretty_variables(n->right,tab);
1354  }
1355 }
1356 
1368 long print_variables(long printflag)
1369 {
1370  ptr_tab_brk new;
1371  GENERIC old_heap_pointer;
1372  if (!printflag) return FALSE; /* 21.1 */
1373 
1376  old_heap_pointer=heap_pointer;
1377 
1380  gen_sym_counter=0;
1384 
1385  indent=TRUE;
1386  const_quote=TRUE;
1389  *buffer=0;
1391 
1392  if (var_tree) {
1393  new_tab(&new);
1395  prettyf(".");
1396  mark_tab(new);
1397  prettyf("\n");
1398  end_tab();
1399 
1400  if (indent) {
1401  work_out_length();
1402  pretty_output();
1403  }
1404  }
1405  heap_pointer=old_heap_pointer;
1406  return (var_tree!=NULL);
1407 }
1408 
1420 {
1421  if(n) {
1422  write_attributes(n->left,tab);
1423  mark_tab(tab);
1425  write_attributes(n->right,tab);
1426  }
1427 }
1428 
1429 
1438 void listing_pred_write(ptr_node n,long fflag)
1439 {
1440  long old_print_depth;
1441 
1443  func_flag=fflag;
1444  indent=TRUE;
1445  const_quote=TRUE;
1451  old_print_depth=print_depth;
1453  main_pred_write(n);
1454  print_depth=old_print_depth;
1455  (void)fflush(outfile);
1456 }
1457 
1470 {
1472  /* write_stderr=FALSE; */
1474  main_pred_write(n);
1475  (void)fflush(outfile);
1476 }
1477 
1485 {
1486  if (n) {
1487  GENERIC old_heap_pointer;
1488  ptr_tab_brk new;
1489 
1490  if (!write_corefs) main_pred_write(n->left);
1491 
1492  old_heap_pointer=heap_pointer;
1495  gen_sym_counter=0;
1496  if (write_corefs)
1497  go_through_tree(n);
1498  else
1501 
1502  *buffer=0;
1503 
1505  new_tab(&new);
1506 
1507  if (write_corefs) {
1508  write_attributes(n,new);
1509  }
1510  else {
1511  mark_tab(new);
1513  }
1514 
1515  end_tab();
1516 
1517  if (indent) {
1518  work_out_length();
1519  pretty_output();
1520  }
1521 
1522  heap_pointer=old_heap_pointer;
1523 
1525  }
1526 }
1527 
1537 {
1538  outfile=stdout;
1540 }
1541 
1551 {
1552  outfile=stderr;
1554 }
1555 
1565 {
1568 }
1569 
1579 void display_psi(FILE *s,ptr_psi_term t)
1580 {
1581  outfile=s;
1583 }
1584 
1585 
1594 {
1595  GENERIC old_heap_pointer;
1596  ptr_tab_brk new;
1597 
1599  if(t) {
1600 
1601  deref_ptr(t);
1602 
1603  old_heap_pointer=heap_pointer;
1606  gen_sym_counter=0;
1607  go_through(t);
1609 
1610  indent=FALSE;
1611  const_quote=TRUE;
1614  *buffer=0;
1616 
1617  new_tab(&new);
1618  mark_tab(new);
1620  end_tab();
1621  if (indent) {
1622  work_out_length();
1623  pretty_output();
1624  }
1625 
1626  heap_pointer=old_heap_pointer;
1627  }
1628  else
1629  printf("*null psi_term*");
1630 }
1631 
1644 {
1645  GENERIC old_heap_pointer;
1646  ptr_tab_brk new;
1647 
1648  output_stream=stdout;
1650  old_heap_pointer=heap_pointer;
1651 
1654  gen_sym_counter=0;
1655  check_pointer(u);
1656  check_pointer(v);
1658 
1659  indent=FALSE;
1660  const_quote=TRUE;
1663  *buffer=0;
1665  new_tab(&new);
1666  mark_tab(new);
1668  prettyf(s);
1670  end_tab();
1671 
1672  if (indent) {
1673  work_out_length();
1674  pretty_output();
1675  }
1676 
1677  heap_pointer=old_heap_pointer;
1678 }
1679 
1691 {
1692  GENERIC old_heap_pointer;
1693  ptr_tab_brk new;
1694  ptr_resid_list r2; /* 21.9 */
1695 
1696  outfile=stdout;
1698  old_heap_pointer=heap_pointer;
1699 
1702  gen_sym_counter=0;
1703 
1704  check_pointer(t);
1705 
1706  r2=r;
1707  while(r2) {
1708  check_pointer(r2->var);
1709  r2=r2->next;
1710  }
1711 
1713 
1714  indent=FALSE;
1715  const_quote=TRUE;
1718  *buffer=0;
1720  new_tab(&new);
1721  mark_tab(new);
1722 
1723  prettyf("residuating ");
1725  prettyf(" on variable(s) {");
1726 
1727  r2=r;
1728  while(r2) {
1730  r2=r2->next;
1731  if(r2)
1732  prettyf(",");
1733  }
1734 
1735  prettyf("}\n");
1736  end_tab();
1737 
1738  heap_pointer=old_heap_pointer;
1739 }
ptr_definition disjunction
symbol in bi module
Definition: def_glob.h:249
ptr_psi_term aaaa_1
Definition: def_struct.h:239
ptr_node printed_pointers
Definition: def_glob.h:1007
ptr_definition alist
symbol in bi module
Definition: def_glob.h:319
ptr_residuation resid
Definition: def_struct.h:189
void get_two_args(ptr_node t, ptr_psi_term *a, ptr_psi_term *b)
get_two_args
Definition: login.c:47
#define is_top(T)
Definition: def_macro.h:113
#define yfx
was enum (operator) but va_arg could not handle - now typedef
Definition: def_const.h:1037
#define FEATCMP
indicates to use featcmp for comparison (in trees.c)
Definition: def_const.h:979
void perr(char *str)
perr
Definition: error.c:763
GENERIC heap_pointer
used to allocate from heap - size allocated subtracted - adj for alignment
Definition: def_glob.h:55
ptr_definition eqsym
symbol in syntax module
Definition: def_glob.h:270
ptr_definition integer
symbol in bi module
Definition: def_glob.h:312
long printed
Definition: def_struct.h:312
#define xfx
was enum (operator) but va_arg could not handle - now typedef
Definition: def_const.h:1021
ptr_goal goal
Definition: def_struct.h:172
#define INTCMP
indicates to use intcmp for comparison (in trees.c)
Definition: def_const.h:971
ptr_residuation next
Definition: def_struct.h:173
#define POSTFIX
used in pretty printing in print.c
Definition: def_const.h:1374
#define NOT_CODED
For LIFE boolean calculation built-in.
Definition: def_const.h:294
ptr_definition cut
symbol in syntax module
Definition: def_glob.h:242
char * two
Definition: def_glob.h:892
ptr_operator_data next
Definition: def_struct.h:76
long display_modules
whether to display modules with symbols
Definition: def_glob.h:741
long column
Definition: def_struct.h:310
#define fx
was enum (operator) but va_arg could not handle - now typedef
Definition: def_const.h:1000
void pretty_symbol(ptr_keyword k)
pretty_symbol
Definition: modules.c:452
includes
#define INT_SIZE
How many types can be encoded on one integer in the transitive closure encoding.
Definition: def_const.h:317
#define DIGIT(C)
Definition: def_macro.h:42
ptr_resid_list next
Definition: def_struct.h:97
ptr_tab_brk tab
Definition: def_struct.h:316
ptr_definition stream
symbol in bi module
Definition: def_glob.h:382
char * strip_module_name(char *str)
strip_module_name
Definition: modules.c:144
ptr_keyword keyword
Definition: def_struct.h:147
#define ISALPHA(C)
Definition: def_macro.h:48
char * str
Definition: def_struct.h:315
struct wl_psi_term * ptr_psi_term
quotedStackCopy
Definition: def_struct.h:62
GENERIC data
Definition: def_struct.h:201
#define NULL
Definition: def_const.h:533
ptr_node var_tree
Definition: def_glob.h:1005
#define xfy
was enum (operator) but va_arg could not handle - now typedef
Definition: def_const.h:1030
#define DOTDOT
used in pretty printing in print.c
Definition: def_const.h:1346
#define REAL
Which C type to use to represent reals and integers in Wild_Life.
Definition: def_const.h:132
char * symbol
Definition: def_struct.h:118
long overlap_type(ptr_definition t1, ptr_definition t2)
overlap_type
Definition: types.c:1579
FILE * outfile
Definition: def_glob.h:974
#define LOWER(C)
Definition: def_macro.h:46
#define SYMBOL(C)
Definition: def_macro.h:57
ptr_node heap_insert(long comp, char *keystr, ptr_node *tree, GENERIC info)
heap_insert
Definition: trees.c:320
ptr_node pointer_names
Definition: def_glob.h:1008
#define PAGE_WIDTH
Initial page width for printing.
Definition: def_const.h:169
ptr_definition sys_bytedata
symbol in sys module
Definition: def_glob.h:983
ptr_node left
Definition: def_struct.h:199
long sub_type(ptr_definition t1, ptr_definition t2)
sub_type
Definition: types.c:1642
ptr_definition real
symbol in bi module
Definition: def_glob.h:375
void pretty_quote_symbol(ptr_keyword k)
pretty_quote_symbol
Definition: modules.c:470
#define PREFIX
used in pretty printing in print.c
Definition: def_const.h:1367
unsigned long * GENERIC
unsigned long *GENERIC
Definition: def_struct.h:35
char * buffer
buffer used only in print.c - there is local with same name in xpred.c
Definition: def_glob.h:781
#define deref_ptr(P)
Definition: def_macro.h:100
char * heap_copy_string(char *s)
heap_copy_string
Definition: trees.c:172
char * key
Definition: def_struct.h:198
long broken
Definition: def_struct.h:311
#define TRUE
Standard boolean.
Definition: def_const.h:268
ptr_item indx
Definition: def_glob.h:970
#define STRCMP
indicates to use strcmp for comparison (c function)
Definition: def_const.h:963
#define PRINT_POWER
Power of ten to split printing (REALs are often more precise than ints.
Definition: def_const.h:190
ptr_definition eof
symbol in syntax module
Definition: def_glob.h:263
#define FALSE
Standard boolean.
Definition: def_const.h:275
ptr_definition nil
symbol in bi module
Definition: def_glob.h:340
ptr_module extract_module_from_name(char *str)
extract_module_from_name
Definition: modules.c:116
GENERIC value_3
Definition: def_struct.h:186
ptr_psi_term var
Definition: def_struct.h:95
ptr_definition disj_nil
symbol in syntax module
Definition: def_glob.h:256
char * module_name
Definition: def_struct.h:106
char * one
Definition: def_glob.h:891
#define equal_types(A, B)
Definition: def_macro.h:111
#define xf
was enum (operator) but va_arg could not handle - now typedef
Definition: def_const.h:993
ptr_node find(long comp, char *keystr, ptr_node tree)
find
Definition: trees.c:394
#define PRINT_DEPTH
Initial depth limit for printing.
Definition: def_const.h:176
long featcmp(char *str1, char *str2)
featcmp
Definition: trees.c:106
#define INFIX
used in pretty printing in print.c
Definition: def_const.h:1360
#define yf
was enum (operator) but va_arg could not handle - now typedef
Definition: def_const.h:1007
#define PRETTY_SIZE
Maximum number of syntactic tokens in a pretty-printed output term.
Definition: def_const.h:147
#define MAX_PRECEDENCE
Maximum operator precedence.
Definition: def_const.h:205
long gen_sym_counter
Definition: def_glob.h:1009
#define PRINT_SPLIT
Size at which to split printing (REALs are often more precise than ints.
Definition: def_const.h:183
#define WL_MAXINT
Maximum exactly representable integer (2^53-1 for double IEEE format)
Definition: def_const.h:140
#define NOTOP
used in pretty printing in print.c
Definition: def_const.h:1353
#define SINGLE(C)
Definition: def_macro.h:52
FILE * output_stream
Definition: def_glob.h:1017
#define STRLEN
Maximum size of file names and input tokens (which includes input strings) (Note: calculated tokens c...
Definition: def_const.h:162
ptr_definition type
Definition: def_struct.h:181
GENERIC value_1
Definition: def_struct.h:85
#define HEAP_ALLOC(A)
Definition: def_macro.h:20
ptr_node attr_list
Definition: def_struct.h:187
ptr_definition pending
Definition: def_struct.h:243
ptr_definition quoted_string
symbol in bi module
Definition: def_glob.h:368
ptr_operator_data op_data
Definition: def_struct.h:158
GENERIC heap_alloc(long s)
heap_alloc
Definition: memory.c:1616
#define fy
was enum (operator) but va_arg could not handle - now typedef
Definition: def_const.h:1014
ptr_node right
Definition: def_struct.h:200
ptr_int_list next
Definition: def_struct.h:86