/* This file is part of NSsync -*- c -*- Copyright (C) 2011-2017 Sergey Poznyakoff NSsync 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. NSsync 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 NSsync. If not, see . */ #ifdef HAVE_GETOPT_H # include #endif #include static struct grecs_txtacc *pp_cmd_acc; static char *program_name; OPTIONS_BEGIN("nssync", [], [<>], [], [], []) OPTION(lint,t,, []) BEGIN lint_mode = 1; END OPTION(,E,, []) BEGIN preprocess_only = 1; END OPTION(dry-run,n,, []) BEGIN debug_level++; dry_run_mode = 1; END OPTION(force,f,, []) BEGIN force = 1; END OPTION(config-file,c,FILE, []) BEGIN config_file = optarg; END OPTION(cron,,, []) BEGIN server_mode = 0; END OPTION(server,s,, []) BEGIN server_mode = 1; END OPTION(foreground,F,, []) BEGIN foreground = 1; END OPTION(syslog,S,, []) BEGIN syslog_option = 1; END GROUP(Preprocessor control) OPTION(include-directory,I,DIR, []) BEGIN grecs_preproc_add_include_dir(optarg); END OPTION(define,D,SYMBOL[=VALUE], []) BEGIN char *p; if (!pp_cmd_acc) pp_cmd_acc = grecs_txtacc_create(); grecs_txtacc_grow(pp_cmd_acc, " \"-D", 4); for (p = optarg; *p; p++) { if (*p == '\\' || *p == '"') grecs_txtacc_grow_char(pp_cmd_acc, '\\'); grecs_txtacc_grow_char(pp_cmd_acc, *p); } grecs_txtacc_grow_char(pp_cmd_acc, '"'); END OPTION(preprocessor,,COMMAND, []) BEGIN grecs_preprocessor = optarg; END OPTION(no-preprocessor,,, []) BEGIN grecs_preprocessor = NULL; END GROUP(Debugging) OPTION(debug,d,, []) BEGIN debug_level++; END OPTION(debug-parser,x,, []) BEGIN grecs_gram_trace(1); END OPTION(debug-lexer,X,, []) BEGIN grecs_lex_trace(1); END GROUP([]) OPTION(config-help,,, []) BEGIN config_help(); exit(0); END OPTIONS_END void parse_options(int argc, char *argv[]) { program_name = strrchr(argv[0], '/'); if (program_name) program_name++; else program_name = argv[0]; GETOPT(argc, argv,, exit(EX_USAGE)) if (pp_cmd_acc && grecs_preprocessor) { char *args, *cmd; grecs_txtacc_grow_char(pp_cmd_acc, 0); args = grecs_txtacc_finish(pp_cmd_acc, 0); cmd = grecs_malloc(strlen(grecs_preprocessor) + strlen(args) + 1); strcpy(cmd, grecs_preprocessor); strcat(cmd, args); grecs_preprocessor = cmd; } grecs_txtacc_free(pp_cmd_acc); syslog_tag = grecs_strdup(program_name); if (!pidfile) { size_t sz = 0; grecs_asprintf(&pidfile, &sz, "%s/%s.pid", LOCALSTATEDIR, program_name); } }