int sprintTriePath(CTXTdeclc char * buffer, BTNptr pLeaf) {

  BTNptr pRoot;
  int ctr = 0;

  if ( IsNULL(pLeaf) ) {
    return sprintf(buffer, "NULL");
  }

  if ( ! IsLeafNode(pLeaf) ) {
    fprintf(stderr, "printTriePath() called with non-Leaf node!\n");
    printTrieNode(stderr, pLeaf);
    return -1;
  }

  if  (IsEscapeNode(pLeaf) ) {
    //    printf("escape\n");
    pRoot = BTN_Parent(pLeaf);
    if ( IsNonNULL(pRoot) ) {
      ctr = ctr + sprintTrieSymbol(buffer+ctr, BTN_Symbol(pRoot));
      return ctr;
    }
    else {
      fprintf(stderr, "ESCAPE node");
      return 0;
    }
  }

  SymbolStack_ResetTOS;
  SymbolStack_PushPathRoot(pLeaf,pRoot);
  if ( IsTrieFunctor(BTN_Symbol(pRoot)) ) {
    //    printf("tf\n");
    SymbolStack_Push(BTN_Symbol(pRoot));
    ctr = ctr + symstkSPrintNextTerm(CTXTc buffer+ctr,FALSE);
  }
  else {
    //    printf("nontf\n");
    ctr = ctr + sprintTrieSymbol(buffer+ctr,BTN_Symbol(pRoot));
    ctr = ctr + sprintf(buffer+ctr, "(");
    ctr = ctr + symstkSPrintNextTerm(CTXTc buffer+ctr,FALSE);
    while ( ! SymbolStack_IsEmpty ) {
      ctr = ctr + sprintf(buffer+ctr, ",");
      ctr = ctr + symstkSPrintNextTerm(CTXTc buffer+ctr,FALSE);
    }
        ctr = ctr + sprintf(buffer+ctr, ")");
  }
  return ctr;
}
Esempio n. 2
0
void printTriePath(FILE *fp, BTNptr pLeaf, xsbBool printLeafAddr) {

  BTNptr pRoot;

  if ( IsNULL(pLeaf) ) {
    fprintf(fp, "NULL");
    return;
  }

  if ( ! IsLeafNode(pLeaf) ) {
    fprintf(fp, "printTriePath() called with non-Leaf node!\n");
    printTrieNode(fp, pLeaf);
    return;
  }

  if ( printLeafAddr )
    fprintf(fp, "Leaf %p: ", pLeaf);

  if ( IsEscapeNode(pLeaf) ) {
    pRoot = BTN_Parent(pLeaf);
    if ( IsNonNULL(pRoot) )
      printTrieSymbol(fp, BTN_Symbol(pRoot));
    else
      fprintf(fp, "ESCAPE node");
    return;
  }

  SymbolStack_ResetTOS;
  SymbolStack_PushPathRoot(pLeaf,pRoot);
  if ( IsTrieFunctor(BTN_Symbol(pRoot)) ) {
    SymbolStack_Push(BTN_Symbol(pRoot));
    symstkPrintNextTerm(fp,FALSE);
  }
  else {
    printTrieSymbol(fp,BTN_Symbol(pRoot));
    fprintf(fp, "(");
    symstkPrintNextTerm(fp,FALSE);
    while ( ! SymbolStack_IsEmpty ) {
      fprintf(fp, ",");
      symstkPrintNextTerm(fp,FALSE);
    }
    fprintf(fp, ")");
  }
}