static void parse_cmdline(int argc, char * const argv[]) { int ch; int index = 0; struct option options[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {"geometry", required_argument, NULL, 'g'}, {"resolution", required_argument, NULL, 'r'}, {"center", required_argument, NULL, 'c'}, {"width", required_argument, NULL, 'w'}, {"height", required_argument, NULL, 'H'}, {"method", required_argument, NULL, 'm'}, {"nthreads", required_argument, NULL, 'n'}, {"output", required_argument, NULL, 'o'}, }; while ((ch = getopt_long(argc, argv, "hc:H:m:n:o:r:w:g:V", options, &index)) != -1) { switch (ch) { case 'h': do_usage(argv[0], 0); break; case 'V': do_version(argv[0]); break; case 'g': do_geometry(argv[0], optarg); break; case 'r': do_resolution(argv[0], optarg); break; case 'c': do_center(argv[0], optarg); break; case 'w': do_width(argv[0], optarg); break; case 'H': do_height(argv[0], optarg); break; case 'm': do_method(argv[0], optarg); break; case 'n': do_nthreads(argv[0], optarg); break; case 'o': do_output(argv[0], optarg); break; default: do_usage(argv[0], 1); } } if (plot == NULL) do_method(argv[0], "generic"); if (!output) { fprintf(stderr, "no output file.\n"); exit(1); } }
int main(int argc, char *argv[]) { fd_set rfds; int nfds; #if defined(DMALLOC) free(malloc(1)); #endif atexit(cleanup); if(check_options(argc, argv) != 0) return -1; #ifdef HAVE_DAEMON if((options & OPT_DAEMON) != 0 && daemon(1, 0) != 0) return -1; #endif /* * read the list of addresses in the address list file. */ if(do_infile() != 0) return -1; /* * connect to the scamper process */ if(do_scamperconnect() != 0) return -1; if(do_outfile() != 0) return -1; /* attach */ if(do_attach() != 0) return -1; for(;;) { if(scamper_fd == -1) { break; } nfds = 0; FD_ZERO(&rfds); /* will always read the scamper process */ FD_SET(scamper_fd, &rfds); if(nfds < scamper_fd) nfds = scamper_fd; /* might read commands from stdin */ if(stdin_fd != -1) { FD_SET(stdin_fd, &rfds); if(nfds < stdin_fd) nfds = stdin_fd; } if(more > 0) { do_method(); } if(select(nfds+1, &rfds, NULL, NULL, NULL) < 0) { if(errno == EINTR) continue; break; } if(stdin_fd != -1 && FD_ISSET(stdin_fd, &rfds)) { if(do_stdinread() != 0) return -1; } if(FD_ISSET(scamper_fd, &rfds)) { if(do_scamperread() != 0) return -1; } } return 0; }