+static void printhelp(FILE *file) {
+ fputs("usage: adnslogres [<options>] [<logfile>]\n"
+ " adnslogres --version|--help\n"
+ "options: -c <concurrency> set max number of outstanding queries\n"
+ " -p use poll(2) instead of select(2)\n"
+ " -d turn on debugging\n"
+ " -C <config> use instead of contents of resolv.conf\n",
+ stdout);
+}
+
+static void usage(void) {
+ printhelp(stderr);
+ exit(1);
+}
+
+int main(int argc, char *argv[]) {
+ int c, opts, maxpending;
+ extern char *optarg;
+ FILE *inf;
+
+ if (argv[1] && !strncmp(argv[1],"--",2)) {
+ if (!strcmp(argv[1],"--help")) {
+ printhelp(stdout);
+ } else if (!strcmp(argv[1],"--version")) {
+ fputs(VERSION_MESSAGE("adnslogres"),stdout);
+ } else {
+ usage();
+ }
+ if (ferror(stdout) || fclose(stdout)) { perror("stdout"); exit(1); }
+ exit(0);
+ }
+
+ maxpending= DEFMAXPENDING;
+ opts= 0;
+ while ((c= getopt(argc, argv, "c:C:dp")) != -1)
+ switch (c) {
+ case 'c':
+ maxpending= atoi(optarg);
+ if (maxpending < 1 || maxpending > MAXMAXPENDING) {
+ fprintf(stderr, "%s: unfeasible concurrency %d\n", progname, maxpending);
+ exit(1);
+ }
+ break;
+ case 'C':
+ config_text= optarg;
+ break;
+ case 'd':
+ opts|= OPT_DEBUG;
+ break;
+ case 'p':
+ opts|= OPT_POLL;
+ break;
+ default:
+ usage();
+ }
+
+ argc-= optind;
+ argv+= optind;
+
+ inf= NULL;
+ if (argc == 0)
+ inf= stdin;
+ else if (argc == 1)
+ inf= fopen(*argv, "r");
+ else
+ usage();
+
+ if (!inf)
+ aargh("couldn't open input");
+
+ proclog(inf, stdout, maxpending, opts);
+
+ if (fclose(inf))
+ aargh("fclose input");
+ if (fclose(stdout))
+ aargh("fclose output");
+