int main(int argc, char **argv) { term_init(); set_default_opts(); if (getenv("NVC_GDB") != NULL) register_gdb_signal_handlers(); else register_trace_signal_handlers(); atexit(fbuf_cleanup); static struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { "work", required_argument, 0, 'w' }, { "dump", no_argument, 0, 'd' }, { "codegen", no_argument, 0, 'c' }, { "make", no_argument, 0, 'm' }, { "std", required_argument, 0, 's' }, { 0, 0, 0, 0 } }; int c, index = 0; const char *spec = "aehrvL:"; while ((c = getopt_long(argc, argv, spec, long_options, &index)) != -1) { switch (c) { case 0: // Set a flag break; case 'h': usage(); exit(EXIT_SUCCESS); case 'v': printf("%s\n%s\n", version_string, copy_string); exit(EXIT_SUCCESS); case 'w': opt_set_str("work-name", optarg); break; case 'L': lib_add_search_path(optarg); break; case 's': set_standard(parse_standard(optarg)); break; case 'a': case 'e': case 'd': case 'r': case 'c': case 'm': // Subcommand options are parsed later argc -= (optind - 1); argv += (optind - 1); goto getopt_out; case '?': // getopt_long already printed an error message exit(EXIT_FAILURE); default: abort(); } } getopt_out: switch (c) { case 'a': return analyse(argc, argv); case 'e': return elaborate(argc, argv); case 'r': return run(argc, argv); case 'd': return dump_cmd(argc, argv); case 'c': return codegen(argc, argv); case 'm': return make_cmd(argc, argv); default: fprintf(stderr, "%s: missing command\n", PACKAGE); return EXIT_FAILURE; } }
int main(int argc, char **argv) { term_init(); set_default_opts(); intern_strings(); if (getenv("NVC_GDB") != NULL) register_gdb_signal_handlers(); else register_trace_signal_handlers(); if (is_debugger_running()) atexit(tree_gc); atexit(fbuf_cleanup); static struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { "work", required_argument, 0, 'w' }, { "std", required_argument, 0, 's' }, { "messages", required_argument, 0, 'M' }, { "map", required_argument, 0, 'p' }, { "ignore-time", no_argument, 0, 'i' }, { "force-init", no_argument, 0, 'f' }, { 0, 0, 0, 0 } }; opterr = 0; const char *work_name = "work"; const char *work_path = work_name; lib_t work = NULL; const int next_cmd = scan_cmd(1, argc, argv); int c, index = 0; const char *spec = "aehrvL:"; while ((c = getopt_long(next_cmd, argv, spec, long_options, &index)) != -1) { switch (c) { case 0: // Set a flag break; case 'h': usage(); exit(EXIT_SUCCESS); case 'v': printf("%s\n%s\n", version_string, copy_string); exit(EXIT_SUCCESS); case 'w': parse_work_name(optarg, &work_name, &work_path); break; case 'L': lib_add_search_path(optarg); break; case 's': set_standard(parse_standard(optarg)); break; case 'M': set_message_style(parse_message_style(optarg)); break; case 'p': parse_library_map(optarg); break; case 'i': opt_set_int("ignore-time", 1); break; case 'f': opt_set_int("force-init", 1); break; case '?': fatal("unrecognised global option %s", argv[optind - 1]); default: abort(); } } work = lib_new(work_name, work_path); lib_set_work(work); argc -= next_cmd - 1; argv += next_cmd - 1; return process_command(argc, argv); }