int main(int argc, char **argv) { int ret = 0; parse_opts(argc, argv); input_file = argv[optind++]; if(input_file == NULL || strcmp(input_file, "-") == 0) { ini = mini_finit(stdin); input_file = "<stdin>"; } else { ini = mini_init(input_file); } if(!ini) { ret = 1; goto cleanup; } for(; optind < argc; optind++) { directives = alpm_list_add(directives, argv[optind]); } if(alpm_list_count(directives) != 1) { verbose = 1; } if(section_list) { list_sections(); } else if(section_name) { show_section(); } else { show_directives(); } if(!ini->eof) { fprintf(stderr, "error reading '%s' (%s)\n", argv[1], strerror(errno)); return 1; } cleanup: cleanup(); return ret; }
int main(int argc, char **argv) { char *outfile=NULL; int read=0, write=0, output=0, list=0, c, index; const struct option long_options[] = { {"list", no_argument, NULL, 'l'}, {"read", no_argument, NULL, 'r'}, {"write", no_argument, NULL, 'w'}, {"output", required_argument, NULL, 'o'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0} }; while ((c = getopt_long(argc, argv, "lrwho:", long_options, &index)) != -1) { switch (c) { case 'l': list = 1; break; case 'r': read = 1; break; case 'w': write = 1; break; case 'h': usage(stdout); return 0; case 'o': output = 1; outfile = optarg; break; case 'v': version(); return 0; default: usage(stderr); return -1; } } if (write+read+list > 1) { fputs("Conflicting actions given simultaneously.\n", stderr); usage(stderr); return -1; } else if (!write+read+list) { write = 1; } if (output && !write) { fputs("It only makes sense to use --output with --write.\n", stderr); usage(stderr); return 1; } if (list) { list_sections(); } else if (read) { FILE *f=NULL; for (index = optind; index < argc; index++) { f = open_file(argv[index], "r"); run_code(argv[index], f); if (fclose(f)) file_error(argv[index], "closing"); } /* If we haven't opened anything, use stdin */ if (!f) run_code("stdin", stdin); } else { FILE *f; if (outfile) f = open_file(outfile, "w"); else f = stdout; if (optind < argc) { fputs("--write takes no arguments\n", stderr); usage(stderr); return -1; } create_code(); output_code(f); } return 0; }