static void symstkPrintNextTerm(FILE *fp, xsbBool list_recursion) { Cell symbol; if ( SymbolStack_IsEmpty ) { fprintf(fp, "<no subterm>"); return; } SymbolStack_Pop(symbol); switch ( TrieSymbolType(symbol) ) { case XSB_INT: if ( list_recursion ) fprintf(fp, "|" IntegerFormatString "]", int_val(symbol)); else fprintf(fp, IntegerFormatString, int_val(symbol)); break; case XSB_FLOAT: if ( list_recursion ) fprintf(fp, "|%f]", float_val(symbol)); else fprintf(fp, "%f", float_val(symbol)); break; case XSB_STRING: { char *string = string_val(symbol); if ( list_recursion ) { if ( string == nil_sym ) fprintf(fp, "]"); else fprintf(fp, "|%s]", string); } else fprintf(fp, "%s", string); } break; case XSB_TrieVar: if ( list_recursion ) fprintf(fp, "|V" IntegerFormatString "]", DecodeTrieVar(symbol)); else fprintf(fp, "V" IntegerFormatString, DecodeTrieVar(symbol)); break; case XSB_STRUCT: { Psc psc; int i; if ( list_recursion ) fprintf(fp, "|"); psc = DecodeTrieFunctor(symbol); fprintf(fp, "%s(", get_name(psc)); for (i = 1; i < (int)get_arity(psc); i++) { symstkPrintNextTerm(fp,FALSE); fprintf(fp, ","); } symstkPrintNextTerm(fp,FALSE); fprintf(fp, ")"); if ( list_recursion ) fprintf(fp, "]"); } break; case XSB_LIST: if ( list_recursion ) fprintf(fp, ","); else fprintf(fp, "["); symstkPrintNextTerm(fp,FALSE); symstkPrintNextTerm(fp,TRUE); break; default: fprintf(fp, "<unknown symbol>"); break; } }
static int symstkSPrintNextTerm(CTXTdeclc char * buffer, xsbBool list_recursion) { int ctr = 0; Cell symbol; if ( SymbolStack_IsEmpty ) { // fprintf(fp, "<no subterm>"); return 0; } SymbolStack_Pop(symbol); switch ( TrieSymbolType(symbol) ) { case XSB_INT: if ( list_recursion ) ctr = ctr + sprintf(buffer+ctr, "|" IntegerFormatString "]", int_val(symbol)); else ctr = ctr + sprintf(buffer+ctr, IntegerFormatString, int_val(symbol)); break; case XSB_FLOAT: if ( list_recursion ) ctr = ctr + sprintf(buffer+ctr, "|%f]", float_val(symbol)); else ctr = ctr + sprintf(buffer+ctr, "%f", float_val(symbol)); break; case XSB_STRING: { char *string = string_val(symbol); if ( list_recursion ) { if ( string == nil_string ) ctr = ctr + sprintf(buffer+ctr, "]"); else { // ctr = ctr + sprintf(buffer+ctr, "|%s]", string); ctr = ctr + sprintf(buffer+ctr, "|"); ctr = sprint_quotedname(buffer, ctr, string); ctr = ctr + sprintf(buffer+ctr, "]"); } } else // ctr = ctr + sprintf(buffer+ctr, "%s", string); ctr = sprint_quotedname(buffer, ctr, string); } break; case XSB_TrieVar: if ( list_recursion ) ctr = ctr + sprintf(buffer+ctr, "|V" IntegerFormatString "]", DecodeTrieVar(symbol)); else ctr = ctr + sprintf(buffer+ctr, "_V" IntegerFormatString, DecodeTrieVar(symbol)); break; case XSB_STRUCT: { Psc psc; int i; if (isboxedfloat(symbol)) { if ( list_recursion ) ctr = ctr + sprintf(buffer+ctr, "|%lf]", boxedfloat_val(symbol)); else ctr = ctr + sprintf(buffer+ctr, "%lf", boxedfloat_val(symbol)); break; } if ( list_recursion ) ctr = ctr + sprintf(buffer+ctr, "|"); psc = DecodeTrieFunctor(symbol); // ctr = ctr + sprintf(buffer+ctr, "%s(", get_name(psc)); ctr = sprint_quotedname(buffer, ctr, get_name(psc)); ctr = ctr + sprintf(buffer+ctr, "("); for (i = 1; i < (int)get_arity(psc); i++) { ctr = ctr + symstkSPrintNextTerm(CTXTc buffer+ctr,FALSE); ctr = ctr + sprintf(buffer+ctr, ","); } ctr = ctr + symstkSPrintNextTerm(CTXTc buffer+ctr,FALSE); ctr = ctr + sprintf(buffer+ctr, ")"); if ( list_recursion ) ctr = ctr + sprintf(buffer+ctr, "]"); } break; case XSB_LIST: if ( list_recursion ) ctr = ctr + sprintf(buffer+ctr, ","); else ctr = ctr + sprintf(buffer+ctr, "["); ctr = ctr + symstkSPrintNextTerm(CTXTc buffer+ctr,FALSE); ctr = ctr + symstkSPrintNextTerm(CTXTc buffer+ctr,TRUE); break; default: ctr = ctr + sprintf(buffer+ctr, "<unknown symbol>"); break; } return ctr; }