int powaur_crawl(alpm_list_t *targets) { int ret = 0; char cwd[PATH_MAX]; if (!getcwd(cwd, PATH_MAX)) { return error(PW_ERR_GETCWD); } if (chdir(powaur_dir)) { return error(PW_ERR_CHDIR, powaur_dir); } struct pw_hashdb *hashdb = build_hashdb(); if (!hashdb) { pw_fprintf(PW_LOG_ERROR, stderr, "Unable to build hash database!\n"); ret = -1; } alpm_list_t *i, *target_pkgs; struct graph *graph; struct stack *topost = stack_new(sizeof(int)); int have_cycles; for (i = targets; i; i = i->next) { stack_reset(topost); graph = NULL; target_pkgs = alpm_list_add(NULL, i->data); build_dep_graph(&graph, hashdb, target_pkgs, RESOLVE_THOROUGH); if (have_cycles) { printf("Cyclic dependencies for package \"%s\"\n", i->data); } graph_toposort(graph, topost); if (stack_empty(topost)) { printf("Package \"%s\" has no dependencies.\n", i->data); } else { printf("\n"); pw_printf(PW_LOG_INFO, "\"%s\" topological order: ", i->data); print_topo_order(graph, topost); } graph_free(graph); alpm_list_free(target_pkgs); } stack_free(topost); hashdb_free(hashdb); if (chdir(cwd)) { return error(PW_ERR_RESTORECWD); } return ret; }
int main (int argc, char* argv[]) { FILE* fp = fopen(argv[1], "r"); // Create the symbol table symbols = malloc(sizeof(symbolTable)); symbols->first = NULL; symbols->last = NULL; symbols->size = 0; //Create the sortedSymbols list sortedSyms = malloc(sizeof(sortedSymbolList)); sortedSyms->first = NULL; sortedSyms->size = 0; read_file(fp); print_topo_order(); fclose(fp); free(symbols); free(sortedSyms); }