int main(int argc, char *argv[]) { const char *usage_command = (const char *)basename(argv[0]); int c; opterr = 0; while ( (c=getopt(argc,argv,"h")) != EOF ) { switch ( c ) { case 'h': /* help */ help(stdout, usage_command); exit(0); default: /* usage */ usage(stderr, usage_command); exit(-1); } } argc -= optind; argv += optind; if ( argc != 1 ) { usage(stderr, usage_command); exit(-1); } return buildgraph(argv[0]); } /* main */
int main(int argc, char **argv) { Graph *G = NULL; //read in command line; getCommandLine(argc, argv); //check for -g -h -s -d if(G_Type < 0 || G_Type > 3) { printf("Invalid graph type -g[1|2|3]\n"); exit(1); } if(G_Type == -1 || Operation == -1 || SourceV == -1 || DestinationV == -1) { printf("Lab6 command line options\n"); printf("General options ---------\n"); printf(" -g [1|2|3] graph type (required)\n"); printf(" -h [1|2] Graph operation (required)\n"); printf(" -s S Number of the source vertex 0 <= S < N (required)\n"); printf(" -d D Number of the destination vertex 0<= D < N (required)\n"); printf(" -n N Number of vertices in graph\n"); printf(" -a A Approximate number of adjacent vertices 0<A<N\n"); printf(" -v Enable verbose output\n"); printf(" -r 1234567 seed for the uniform random number generator\n"); exit(1); } printf("Seed: %d\n", seed); srand48(seed); //Draw graph G = buildgraph(); if(DestinationV > G->size) { printf("%d is not a valid point in the graph\n",DestinationV); exit(1); } if(SourceV == DestinationV) { printf("%d is the source and destination\nCost: 0\n",SourceV); exit(0); } //do needed operations if(Operation == 2) { Link_disjoint_paths(G,SourceV,DestinationV); } else if(Operation == 1) { Shortest_Path(G,SourceV,DestinationV); } else { printf(" Invalide input for operation: -h[1|2]\n"); } //destruct graph return 0; }
int main(int argc, char **argv) { char b[256]; char *f, *g; int c, e, h, r, v; g = NULL; e = h = v = 0; r = EXIT_SUCCESS; maxstack = 1; progname = __mp_basename(argv[0]); while ((c = __mp_getopt(argc, argv, __mp_shortopts(b, options_table), options_table)) != EOF) switch (c) { case OF_ADDRESSES: useaddresses = 1; break; case OF_CALLGRAPH: showgraph = 1; break; case OF_COUNTS: showcounts = 1; break; case OF_GRAPHFILE: g = __mp_optarg; break; case OF_HELP: h = 1; break; case OF_LEAKS: showleaks = 1; break; case OF_STACKDEPTH: if (!__mp_getnum(progname, __mp_optarg, (long *) &maxstack, 1)) e = 1; break; case OF_VERSION: v = 1; break; default: e = 1; break; } argc -= __mp_optindex; argv += __mp_optindex; if (v == 1) { fprintf(stdout, "%s %s\n%s %s\n\n", progname, PROGVERSION, __mp_copyright, __mp_author); fputs("This is free software, and you are welcome to redistribute it " "under certain\n", stdout); fputs("conditions; see the GNU Lesser General Public License for " "details.\n\n", stdout); fputs("For the latest mpatrol release and documentation,\n", stdout); fprintf(stdout, "visit %s.\n\n", __mp_homepage); } if (argc > 1) e = 1; if ((e == 1) || (h == 1)) { fprintf(stdout, "Usage: %s [options] [file]\n\n", progname); if (h == 0) fprintf(stdout, "Type `%s --help' for a complete list of " "options.\n", progname); else __mp_showopts(options_table); if (e == 1) exit(EXIT_FAILURE); exit(EXIT_SUCCESS); } if (argc == 1) f = argv[0]; else f = MP_PROFFILE; acount = dcount = 0; atotal = dtotal = 0; acounts = dcounts = NULL; atotals = dtotals = 0; binsize = 0; data = NULL; datasize = 0; nodes = NULL; nodesize = 0; addrs = NULL; symbols = NULL; sbound = mbound = lbound = 0; __mp_newtree(&proftree); __mp_newtree(&temptree); __mp_newlist(&edgelist); __mp_newgraph(&graph); if (strcmp(f, "-") == 0) proffile = stdin; else if ((proffile = fopen(f, "rb")) == NULL) { fprintf(stderr, "%s: Cannot open file `%s'\n", progname, f); exit(EXIT_FAILURE); } readfile(); fclose(proffile); bintable(); fputs("\n\n", stdout); directtable(); fputs("\n\n", stdout); leaktable(); /* The reason that the allocation call graph is not used for the direct * allocation and memory leak tables is that the code to build and display * the allocation call graph was added much later. Rather than convert * these tables to use the new call graph, I decided to keep the code that * already worked and only use the call graph for any new tables. */ buildgraph(); if (showgraph) { fputs("\n\n", stdout); callgraph(); } if (g != NULL) { if (strcmp(g, "stdout") == 0) graphfile = stdout; else if (strcmp(g, "stderr") == 0) graphfile = stderr; else if ((graphfile = fopen(g, "w")) == NULL) { fprintf(stderr, "%s: Cannot open file `%s'\n", progname, g); r = EXIT_FAILURE; } if (r == EXIT_SUCCESS) { fprintf(graphfile, "/* produced by %s %s from %s */\n\n", progname, PROGVERSION, f); if (showleaks) fputs("digraph \"memory leak call graph\"\n{\n", graphfile); else fputs("digraph \"allocation call graph\"\n{\n", graphfile); writegraph(NULL, &graph.start); fputs("}\n", graphfile); if ((graphfile != stdout) && (graphfile != stderr)) fclose(graphfile); } } deletegraph(); if (acounts != NULL) free(acounts); if (dcounts != NULL) free(dcounts); if (data != NULL) free(data); if (nodes != NULL) free(nodes); if (addrs != NULL) free(addrs); if (symbols != NULL) free(symbols); return r; }