2012-04-25 23:14:39 +03:00
|
|
|
/*
|
|
|
|
* 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 <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2012-05-01 02:11:53 +03:00
|
|
|
#include <string.h>
|
2012-04-25 23:14:39 +03:00
|
|
|
#include <fcntl.h>
|
|
|
|
|
2012-04-26 09:02:48 +03:00
|
|
|
#include "lang.h"
|
2012-04-25 23:14:39 +03:00
|
|
|
|
|
|
|
|
2012-04-28 17:41:07 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-25 23:14:39 +03:00
|
|
|
static void usage(const char *name)
|
2012-03-18 18:24:12 +02:00
|
|
|
{
|
2012-05-01 02:11:53 +03:00
|
|
|
fprintf(stderr,
|
|
|
|
"usage: %s file [[-type] file ...] ...\n\n"
|
|
|
|
" file types:\n"
|
|
|
|
" -c characteristics\n"
|
|
|
|
" -i inventory\n"
|
|
|
|
, name);
|
2012-04-25 23:14:39 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2012-05-01 02:11:53 +03:00
|
|
|
void (*parse)(void) = parse_hierarchy;
|
2012-04-28 17:46:42 +03:00
|
|
|
int i;
|
|
|
|
|
2012-05-01 02:11:53 +03:00
|
|
|
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();
|
|
|
|
}
|
2012-04-28 17:46:42 +03:00
|
|
|
}
|
2012-03-18 18:24:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|