1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include "source-init-opts.h"
23 #include <data/file-name.h>
24 #include <libpspp/getl.h>
25 #include <language/syntax-file.h>
27 #include <libpspp/llx.h>
28 #include <data/por-file-reader.h>
29 #include <data/sys-file-reader.h>
30 #include <libpspp/message.h>
31 #include <ui/syntax-gen.h>
32 #include <language/syntax-string-source.h>
33 #include <data/file-name.h>
34 #include <data/settings.h>
37 #define _(msgid) gettext (msgid)
38 #define N_(msgid) msgid
40 static const struct argp_option post_init_options [] = {
41 {"algorithm", 'a', "{compatible|enhanced}", 0, N_("set to `compatible' if you want output calculated from broken algorithms"), 0},
42 {"include", 'I', "DIR", 0, N_("Append DIR to include path"), 0},
43 {"no-include", 'I', 0, 0, N_("Clear include path"), 0},
44 {"no-statrc", 'r', 0, 0, N_("Disable execution of .pspp/rc at startup"), 0},
45 {"config-dir", 'B', "DIR", 0, N_("Set configuration directory to DIR"), 0},
46 {"safer", 's', 0, 0, N_("Don't allow some unsafe operations"), 0},
47 {"syntax", 'x', "{compatible|enhanced}", 0, N_("Set to `compatible' if you want only to accept SPSS compatible syntax"), 0},
52 parse_post_init_opts (int key, char *arg, struct argp_state *state)
59 struct source_init *sip = state->hook;
61 struct source_stream *ss = state->input;
63 if ( state->input == NULL)
69 state->hook = sip = xzalloc (sizeof (struct source_init));
70 sip->process_statrc = true;
76 if ( 0 == strcmp (arg, "compatible") )
77 settings_set_algorithm (COMPATIBLE);
78 else if ( 0 == strcmp (arg, "enhanced"))
79 settings_set_algorithm (ENHANCED);
82 argp_failure (state, 1, 0, _("Algorithm must be either \"compatible\" or \"enhanced\"."));
89 if (arg == NULL || !strcmp (arg, "-"))
90 getl_clear_include_path (ss);
92 getl_add_include_dir (ss, arg);
95 sip->process_statrc = false;
97 case ARGP_KEY_SUCCESS:
98 if (sip->process_statrc)
100 char *pspprc_fn = fn_search_path ("rc", config_path);
101 if (pspprc_fn != NULL)
103 getl_append_source (ss,
104 create_syntax_file_source (pspprc_fn),
114 settings_set_safer_mode ();
117 if ( 0 == strcmp (arg, "compatible") )
118 settings_set_syntax (COMPATIBLE);
119 else if ( 0 == strcmp (arg, "enhanced"))
120 settings_set_syntax (ENHANCED);
123 argp_failure (state, 1, 0, _("Syntax must be either \"compatible\" or \"enhanced\"."));
127 return ARGP_ERR_UNKNOWN;
133 const struct argp post_init_argp =
134 {post_init_options, parse_post_init_opts, 0, 0, 0, 0, 0};