int main(int argc, char *argv[]) { // Check that all params are given if(argc != 2) { fprintf(stderr, "Usage: ./bic graphFile\n"); return 1; } // Parse the input file and generate graph char* filename = argv[1]; Graph *graph = parseGraphFile(filename); // Find biconnected components bicc(graph); destroyGraph(graph); }
int main(int argc, char* argv[]) { bool correctInput=true; for(int i=1;i<argc;++i) { if(argv[i][0] == '-') { int j=1; while(argv[i][j] != '\0') { switch(argv[i][j++]) { case 'h': printHelp(0); //This will exit the program break; case 'v': setVerbosity(VERBOSE); //Print more info break; case 'd': setVerbosity(DEBUG); //Implies verbose too PRINT(DEBUG,"Setting verbosity to debug\n"); break; case 's': setVerbosity(SILENT); //Print nothing but critical errors break; default: correctInput = false; PRINT(CRITICAL,"Unknown parameter -%c\n",argv[i][j]); break; } } } else { if(first == NULL) { PRINT(VERBOSE,"Trying to read file %s... ",argv[i]); graphFile = fopen(argv[i], "r"); if(graphFile == NULL) { PRINT(VERBOSE, "failed\n"); PRINT(CRITICAL, "Failed to open %s: %s\n",argv[i], strerror(errno)); exit(errno); } else { PRINT(VERBOSE, "done\n"); parseGraphFile(graphFile); PRINT(DEBUG,"Done parsing graph\n"); fclose(graphFile); } } else { PRINT(ALERT,"Only one file can be supplied per run.\n Ignoring %s\n",argv[i]); } } if(!correctInput) { printHelp(1); } } //If the graph was read correctly, solve it! if(entrypoint != NULL) { PRINT(VERBOSE, "Traveling graph from %c:\n", entrypoint->id); travelGraph(); } else { PRINT(CRITICAL,"No graph file found (or reading it failed)\n"); printHelp(2); } //Clean up memory freeAllNodes(first); return 0; }