int rl_hist_get_next(t_rl_reader *r, long key) { (void)key; debug_log("get hist next"); if (!r->hist->cur) return (0); if (r->hist->cur->next) { exec_tcaps("rc"); exec_tcaps("cd"); r->hist->cur = r->hist->cur->next; reader_clear(r); reader_write(r, r->hist->cur->cmd); if (r->hist->cur->cmd) ft_putstr(r->hist->cur->cmd); } return (0); }
/*-------------------------------------------------------------------------*/ static int output_node_tree (Node * pNode, int bUsers, int bSelect) /* Output the collected dependencies (bUsers is FALSE) resp. the collected * users (bUsers is TRUE) in tree form into the Depfile. * If <bSelect> is TRUE, only files marked as selected are considered. * * Return 0 on success, RETURN_WARN on a mild error, RETURN_ERROR on a * severe error. */ { StackNode * pTop; /* Stackbase, next free Stacktop */ int rc; Node * pRNode; /* referenced node */ NodeRef * pRef; /* Next node to work on */ int level; /* Depth in dependency tree */ char aObjname[FILENAME_MAX+1]; int i, len; assert(pNode); rc = RETURN_OK; /* If bSelect is true, but the pNode is not marked as selected, * there is nothing to print. */ if (bSelect && !(pNode->flags & (NODE_SELECT|NODE_ISELECT))) return rc; do { pTop = pStack; aObjname[FILENAME_MAX] = '\0'; /* Print name of the basenode */ if (!bUsers) { if (reader_write(pNode->pName)) { rc = RETURN_ERROR; break; /* outer while */ } if (reader_write((pNode->flags & NODE_NOTFND) ? " : (not found)\n" : " :\n") ) { rc = RETURN_ERROR; break; /* outer while */ } } /* Initialize the tree output */ pTop->pRef = bUsers ? pNode->pUsers : pNode->pDeps; level = 1; pRef = pTop->pRef; /* Tree output loop */ while (1) { int bQuoteIt; /* On end of this level: pop stack */ if (!pRef) { if (pTop == pStack) break; pRef = pTop->pRef; level--; pTop = pTop->pPrev; continue; } /* If the file wasn't found, skip this node. */ if (pRef->pNode->flags & NODE_IGNORE) { pRef = pRef->pNext; continue; } /* If bSelect is true, but this node is not marked, skip it */ if (bSelect && !(pRef->pNode->flags & (NODE_SELECT|NODE_ISELECT))) { pRef = pRef->pNext; continue; } /* Output filename of referenced node */ pRNode = pRef->pNode; if (!(pRNode->flags & NODE_SOURCE) && pRNode->iInclude >= 0) { if (aIncl[pRNode->iInclude].pSymbol) strcpy(aObjname, aIncl[pRNode->iInclude].pSymbol); else strcpy(aObjname, aIncl[pRNode->iInclude].pPath); strcat(aObjname, pRNode->pPath); strcat(aObjname, pRNode->pBase); } else { strcpy(aObjname, pRNode->pName); } assert(aObjname[FILENAME_MAX] == '\0'); len = (signed)strlen(aObjname); bQuoteIt = (strchr(aObjname+1, ' ') != NULL); for (i = 0; i < level-1; i++) if (reader_writen(" ", 4)) { rc = RETURN_ERROR; break; /* for */ } if (!rc && i < level && reader_writen(bUsers ? " -> " : " <- ", 4)) rc = RETURN_ERROR; if (!rc && bQuoteIt && reader_writen("'", 1)) rc = RETURN_ERROR; if (!rc && reader_writen(aObjname, (size_t)len)) rc = RETURN_ERROR; if (!rc && bQuoteIt && reader_writen("'", 1)) rc = RETURN_ERROR; if (!rc && (pRNode->flags & NODE_NOTFND) && reader_writen(" (not found)", 12)) rc = RETURN_ERROR; if (!rc && reader_writen("\n", 1)) rc = RETURN_ERROR; if (rc) break; /* tree-while() */ /* Push this level onto the stack */ if (!pTop->pNext) { StackNode * pNew; pNew = malloc(sizeof(*pNew)); if (!pNew) { if (bVerbose) printf("%-78s\r", ""); printf("%s: Out of memory.\n", aPgmName); rc = RETURN_ERROR; break; /* tree-while */ } memset(pNew, 0, sizeof(*pNew)); pTop->pNext = pNew; pNew->pPrev = pTop; pTop = pNew; } else { pTop = pTop->pNext; } pTop->pRef = pRef->pNext; /* Continue with next deeper level */ level++; pRef = bUsers ? pRNode->pUsers : pRNode->pDeps; } /* end while(1) - tree output loop */ } while(0); return rc; }
/*-------------------------------------------------------------------------*/ static int output_node_flat (Node * pNode, int bAsMake, int bSelect) /* For a given node pNode Output the collected dependencies/users into a * file, either as Makefile (bAsMake is TRUE) or as Depfile (bAsMake is * FALSE). * The file must have been opened by the caller in the reader module. * If <bSelect> is true, only files marked as SELECTed are printed. * * Return 0 on success, RETURN_WARN on a mild error, RETURN_ERROR on a * severe error. */ { int rc; NodeRef * pList, * pRef; long suffix; /* Suffix index */ size_t slen; /* Linelen so far */ size_t len; char aObjname[FILENAME_MAX+1]; assert(pNode); rc = RETURN_OK; aObjname[FILENAME_MAX] = '\0'; /* If bSelect is true, but the pNode is not marked as selected, * there is nothing to print. */ if (bSelect && !(pNode->flags & (NODE_SELECT|NODE_ISELECT))) return rc; /* First, output the dependencies list always */ pList = nodes_deplist(pNode, FALSE, bSelect); assert(pList); pRef = pList; /* Check for a given suffix. * Search backwards in case later definitions overwrote * earlier ones. */ slen = strlen(pNode->pName); len = 0; if (!bAsMake) suffix = -1; else for (suffix = aSrcExt.size-1; suffix >= 0; suffix--) { len = strlen(aSrcExt.strs[suffix]); if (!strcmp(pNode->pName+slen-len, aSrcExt.strs[suffix])) break; } do { /* Construct the name of the dependency target and write it */ if (suffix >= 0) { char * pObjPat, * pObjExt; short bQuoteIt; pObjExt = aObjExt.size ? aObjExt.strs[suffix] : NULL; pObjPat = aObjPat.size ? aObjPat.strs[suffix] : NULL; make_objname( aObjname, pNode->pName, (int)len, pObjExt, pObjPat); assert(aObjname[FILENAME_MAX] == '\0'); bQuoteIt = (NULL != strchr(aObjname, ' ')); if ((bQuoteIt && reader_write("\"")) || reader_write(aObjname) || (bQuoteIt && reader_write("\"")) ) { rc = RETURN_ERROR; break; /* while */ } slen = strlen(aObjname); if (!((pObjExt || pObjPat) ? bGiveSrc[suffix] : bDefGSrc)) pRef = pRef->pNext; } else { short bQuoteIt; bQuoteIt = (NULL != strchr(pNode->pName, ' ')); if ((bQuoteIt && reader_write("\"")) || reader_write(pNode->pName) || (bQuoteIt && reader_write("\"")) ) { rc = RETURN_ERROR; break; /* outer while */ } pRef = pRef->pNext; } if (bAsMake) { if (reader_write(" :")) { rc = RETURN_ERROR; break; /* while */ } slen += 2; rc = output_list_flat(pRef, (int)slen, " ", TRUE); } else { if (reader_write(" :\n")) { rc = RETURN_ERROR; break; /* while */ } if (pRef) rc = output_list_flat(pRef, 0, " <-", FALSE); } nodes_freelist(pList); slen = 0; /* If demanded, output the list of users as well */ if (RETURN_OK == rc && !bAsMake) { pList = nodes_deplist(pNode, TRUE, bSelect); assert(pList); if (pList->pNext) rc = output_list_flat(pList->pNext, 0, " ->", FALSE); nodes_freelist(pList); } } while(0); if (reader_writen("\n", 1)) rc = RETURN_ERROR; return rc; }