main.c (1160B)
1 #include "config.h" 2 #if HAVE_ERR 3 #include <err.h> 4 #endif 5 #include <stdint.h> 6 #include <stdio.h> 7 #include <stdlib.h> 8 #if !(HAVE_GETPROGNAME || HAVE_PROGRAM_INVOCATION_SHORT_NAME || HAVE__PROGNAME) 9 #include <string.h> 10 #endif 11 #if HAVE_PLEDGE 12 #include <unistd.h> 13 #endif 14 #include "parser.h" 15 16 int 17 main(int argc, char **argv) 18 { 19 FILE *input; 20 const char *fname; 21 22 #if !(HAVE_GETPROGNAME || HAVE_PROGRAM_INVOCATION_SHORT_NAME || HAVE__PROGNAME) 23 const char *progname; 24 if ((progname = strrchr(argv[0], '/')) == NULL) 25 progname = argv[0]; 26 else 27 progname++; 28 setprogname(progname); 29 #endif 30 #if HAVE_PLEDGE 31 if (pledge("stdio rpath", NULL) == -1) 32 err(EXIT_FAILURE, "pledge"); 33 #endif 34 if (argc > 2) { 35 warnx("%s: Too many arguments", argv[2]); 36 goto usage; 37 } else if (argc == 2) { 38 if ((input = fopen(argv[1], "r")) == NULL) { 39 fclose(input); 40 err(EXIT_FAILURE, "%s", argv[1]); 41 } 42 fname = argv[1]; 43 } else { 44 input = stdin; 45 fname = "<stdin>"; 46 } 47 48 struct parser p = { 49 .input = input, 50 .fname = fname, 51 .line = 1, 52 .col = 1 53 }; 54 parse_document(&p); 55 fclose(input); 56 return 0; 57 usage: 58 fprintf(stderr, "usage: %s [file]\n", getprogname()); 59 return 1; 60 }