static void output_tree (tsp_bbnode *bbnode, char *buf, int buflen, int depth, int maxdepth, double mod, char *format) { char mybuf[1024]; double v = bbnode->lowerbound; size_t outcnt; size_t i; if (mod > 0.0) v = fmod(v, mod); sprintf (mybuf, "%d ", bbnode->id); sprintf (mybuf + strlen(mybuf), format, v); printf ("%s", mybuf); if (bbnode->child0 == (tsp_bbnode *) NULL && bbnode->child1 == (tsp_bbnode *) NULL) { if (bbnode->status == BB_DONE) printf ("X"); printf ("\n"); } else if (maxdepth > 0 && depth >= maxdepth) { if (bbnode->status == BB_DONE) printf ("+"); printf ("\n"); } else { printf (" "); outcnt = strlen(mybuf) + 1; if (bbnode->parent == (tsp_bbnode *) NULL || bbnode->parent->child1 == bbnode) { buf[buflen] = ' '; } else { buf[buflen] = '|'; } for (i=1; i<outcnt; i++) buf[buflen+i] = ' '; buflen += outcnt; output_tree (bbnode->child0, buf, buflen, depth+1, maxdepth, mod, format); buf[buflen] = '\0'; printf ("%s", buf); output_tree (bbnode->child1, buf, buflen, depth+1, maxdepth, mod, format); } }
static int report_tree (char *probname, double restart_upbound, int bbcount, double branchzeit, int maxdepth, double mod, char *format, tsp_bbnode *rootbbnode) { double lower = 0.0; int leafcount = 0; char buf[16384]; lower = restart_upbound; collect_leaves (rootbbnode, &lower, &leafcount, (double *) NULL, (tsp_bbnode **) NULL); printf ("%s: >= %.2f <= %.2f bb %d active %d time %.2f\n", probname, lower, restart_upbound, bbcount, leafcount, branchzeit); output_tree (rootbbnode, buf, 0, 0, maxdepth, mod, format); return 0; }
void output_tree(node * nd,int jr) { if(nd == NULL) return; int i; if(nd->n_node == 0) { for(i = 0; i < jr; i++) printf(" "); switch(nd->type_flag) { case 0: printf("%s: %d\n",nd->token,nd->val.i); break; case 1: printf("%s: %s\n",nd->token,nd->val.c); break; case 2: printf("%s: %f\n",nd->token,nd->val.f); break; case 3: printf("%s\n",nd->token); break; default: printf("error type\n"); } } else { for(i = 0; i < jr; i++) printf(" "); printf("%s(%d)\n",nd->token,nd->lineno); jr++; for(i = 0; i < nd->n_node; i++) output_tree(nd->child_node[i],jr); } return; }
/*-------------------------------------------------------------------------*/ int main (int argc, char *argv[]) { int i; reader_init(); /* Get arguments, set up defaults */ parseargs(argc, argv); if (!aFiles.size) { if (add_expfile(&aFiles, "*.c")) exit_nomem(" (main: add_expfile)"); } if (!sObjExt) sObjExt = ".o"; if (!aSrcExt.size) { if (array_addfile(&aSrcExt, ".c") || array_addfile(&aObjExt, NULL)) exit_nomem(" (main: add suffix)"); if (array_addfile(&aSrcExt, ".cc") || array_addfile(&aObjExt, NULL)) exit_nomem(" (main: add suffix)"); if (array_addfile(&aSrcExt, ".cp") || array_addfile(&aObjExt, NULL)) exit_nomem(" (main: add suffix)"); if (array_addfile(&aSrcExt, ".cpp") || array_addfile(&aObjExt, NULL)) exit_nomem(" (main: add suffix)"); if (array_addfile(&aSrcExt, ".cxx") || array_addfile(&aObjExt, NULL)) exit_nomem(" (main: add suffix)"); if (array_addfile(&aSrcExt, ".C") || array_addfile(&aObjExt, NULL)) exit_nomem(" (main: add suffix)"); if (array_addfile(&aSrcExt, ".CC") || array_addfile(&aObjExt, NULL)) exit_nomem(" (main: add suffix)"); if (array_addfile(&aSrcExt, ".CP") || array_addfile(&aObjExt, NULL)) exit_nomem(" (main: add suffix)"); if (array_addfile(&aSrcExt, ".CPP") || array_addfile(&aObjExt, NULL)) exit_nomem(" (main: add suffix)"); if (array_addfile(&aSrcExt, ".CXX") || array_addfile(&aObjExt, NULL)) exit_nomem(" (main: add suffix)"); } if (bVerbose) { printf("MkDepend %s -- Make Dependency Generator\n", VERSION); putchar('\n'); } /* Look for the Makefile to modify */ if (sMake) { bMakeExists = !stat(sMake, &aMakeStat); } else if (!sDepfile) { sMake = "Makefile"; bMakeExists = !stat(sMake, &aMakeStat); if (!bMakeExists) { sMake = "makefile"; bMakeExists = !stat(sMake, &aMakeStat); } if (!bMakeExists) { sMake = "Makefile.mk"; bMakeExists = !stat(sMake, &aMakeStat); } if (!bMakeExists) { sMake = "makefile.mk"; bMakeExists = !stat(sMake, &aMakeStat); } if (!bMakeExists) { sMake = "GNUMakefile"; bMakeExists = !stat(sMake, &aMakeStat); } if (!bMakeExists) sMake = "Makefile"; } /* Add the source files to the tree */ if (!aFiles.size) { printf("%s: No files given.\n", aPgmName); set_rc(RETURN_WARN, TRUE); } else { struct stat aStat; /* buffer for stat() */ for (i = 0; i < aFiles.size; i++) { if (stat(aFiles.strs[i], &aStat)) { printf("%s: Warning: Can't find source '%s'.\n", aPgmName , aFiles.strs[i]); set_rc(RETURN_WARN, FALSE); } else if (nodes_addsource(aFiles.strs[i], FALSE)) exit_nomem(" (main: add source)"); } /* If this leaves us with no source files at all, readfiles() * will complain. */ } /* Mark the exceptional files */ for (i = 0; i < aAvoid.size; i++) { if (nodes_addsource(aAvoid.strs[i], TRUE)) exit_nomem(" (main: add avoided source)"); } /* Read and analyse all those files */ set_rc(readfiles(), 0); /* Handle the selection of files */ if (IS_SELECT_MODE) { Node * pNode; /* First, mark all nodes with selected files */ for (i = 0; i < aSelect.size; i++) { pNode = nodes_find(aSelect.strs[i]); if (pNode) pNode->flags |= NODE_SELECT; } /* Now walk the tree and propagate the select information */ nodes_initwalk(); while (NULL != (pNode = nodes_inorder()) ) { if (!(pNode->flags & (NODE_IGNORE)) && (pNode->flags & (NODE_SOURCE|NODE_AVOID)) == NODE_SOURCE) { NODES_UNMARK(pNode); nodes_mark_select(pNode); } } } if (returncode < RETURN_ERROR && sMake) set_rc(output(TRUE), 0); if (returncode < RETURN_ERROR && sMake && bVerbose) printf("%s '%s'.\n", bMakeExists ? "Updated" : "Created", sMake); if (returncode < RETURN_ERROR && sDepfile) set_rc(bFlat ? output(FALSE) : output_tree(), 0); if (returncode < RETURN_ERROR && sDepfile && bVerbose) printf("Created '%s'.\n", sDepfile); return (returncode == RETURN_WARN && bNoWarnExit) ? RETURN_OK : returncode; }