/* This file is part of Eclat. Copyright (C) 2012 Sergey Poznyakoff. Eclat 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 3, or (at your option) any later version. Eclat is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Eclat. If not, see . */ #ifdef HAVE_GETOPT_H # include #endif static char *pp_cmd_buffer; static size_t pp_cmd_bufsize; static size_t pp_cmd_buflevel; struct replvar { char **s_ptr; char *s_val; }; int replace_string_var(void *p) { struct replvar *rv = p; *rv->s_ptr = rv->s_val; return 0; } OPTIONS_BEGIN("eclat", [],[<>], [], [], []) GROUP(Selecting program mode) OPTION(lint,t,, []) BEGIN lint_mode = 1; END OPTION(,E,, []) BEGIN preprocess_only = 1; END OPTION(dry-run,n,, []) BEGIN dry_run_mode = 1; parse_debug_level("main.1"); parse_debug_level("curl.1"); END OPTION(config-file,c,FILE, []) BEGIN conffile = optarg; END GROUP(Commands) OPTION(start-instances,,, []) BEGIN eclat_command = eclat_command_start_instances; END OPTION(stop-instances,,, []) BEGIN eclat_command = eclat_command_stop_instances; END OPTION(describe-tags,,, []) BEGIN eclat_command = eclat_command_describe_tags; END GROUP(Modifiers) OPTION(region,,NAME, []) BEGIN struct replvar *rv = grecs_malloc(sizeof(*rv)); rv->s_ptr = ®ion_name; rv->s_val = optarg; add_config_finish_hook(replace_string_var, rv); END OPTION(access-file,a,NAME, []) BEGIN struct replvar *rv = grecs_malloc(sizeof(*rv)); rv->s_ptr = &access_file_name; rv->s_val = optarg; add_config_finish_hook(replace_string_var, rv); END OPTION(access-key,O,KEY, []) BEGIN access_key = optarg; END OPTION(secret-key,W,KEY, []) BEGIN secret_key = optarg; END OPTION(ssl,,, []) BEGIN use_ssl = 1; END GROUP(Preprocessor control) OPTION(include-directory,I,DIR, []) BEGIN grecs_preproc_add_include_dir(optarg); END OPTION(define,D,SYMBOL[=VALUE], []) BEGIN size_t len; char *p; len = 4; for (p = optarg; *p; p++) { if (*p == '\\' || *p == '"') len++; len++; } if (pp_cmd_buflevel + len + 1 > pp_cmd_bufsize) { pp_cmd_bufsize = pp_cmd_buflevel + len + 1; pp_cmd_buffer = grecs_realloc(pp_cmd_buffer, pp_cmd_bufsize); } memcpy(pp_cmd_buffer + pp_cmd_buflevel, " \"-D", 4); pp_cmd_buflevel += 4; p = optarg; do { if (*p == '\\' || *p == '"') pp_cmd_buffer[pp_cmd_buflevel++] = '\\'; pp_cmd_buffer[pp_cmd_buflevel++] = *p; } while (*p++); END OPTION(preprocessor,,COMMAND, []) BEGIN grecs_preprocessor = optarg; END OPTION(no-preprocessor,,, []) BEGIN grecs_preprocessor = NULL; END GROUP(Debugging) OPTION(dump-grammar-trace,,, []) BEGIN grecs_gram_trace (1); END OPTION(dump-lex-trace,,, []) BEGIN grecs_lex_trace (1); END OPTION(debug,d,CAT[.LEVEL], []) BEGIN if (parse_debug_level(optarg)) { die(EX_USAGE, "invalid debugging category or level"); } END GROUP([]) OPTION(config-help,,, []) BEGIN config_help(); exit(0); END OPTIONS_END void set_program_name(const char *arg) { program_name = strrchr(arg, '/'); if (!program_name) program_name = arg; else program_name++; } void parse_options(int argc, char *argv[], int *index) { GETOPT(argc, argv, *index, exit(EX_USAGE)) if (pp_cmd_buffer && grecs_preprocessor) { char *cmd = grecs_malloc(strlen(grecs_preprocessor) + pp_cmd_buflevel + 1); strcpy(cmd, grecs_preprocessor); strcat(cmd, pp_cmd_buffer); grecs_preprocessor = cmd; free(pp_cmd_buffer); } }