/* * boom.c - BOOM, main function * * Copyright 2012 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ #include #include #include #include #include #include "lang.h" static void open_stdin(const char *name) { int fd; fd = open(name, O_RDONLY); if (fd < 0) { perror(name); exit(1); } if (dup2(fd, 0) < 0) { perror("dup2"); exit(1); } } static void usage(const char *name) { fprintf(stderr, "usage: %s file [[-type] file ...] ...\n\n" " file types:\n" " -c characteristics\n" " -i inventory\n" , name); exit(1); } int main(int argc, char **argv) { void (*parse)(void) = parse_hierarchy; int i; for (i = 1; i != argc; i++) { if (*argv[i] == '-') { if (!strcmp(argv[i], "-c")) parse = parse_characteristics; else if (!strcmp(argv[i], "-i")) parse = parse_inventory; else usage(*argv); } else { open_stdin(argv[i]); parse(); } } return 0; }