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 <output/output.h>
24 #include <data/file-name.h>
25 #include <libpspp/getl.h>
26 #include <language/syntax-file.h>
28 #include <libpspp/llx.h>
29 #include <data/por-file-reader.h>
30 #include <data/sys-file-reader.h>
31 #include <libpspp/message.h>
32 #include <ui/syntax-gen.h>
33 #include <language/syntax-string-source.h>
34 #include <data/file-name.h>
35 #include <data/settings.h>
38 #define _(msgid) gettext (msgid)
39 #define N_(msgid) msgid
41 static const struct argp_option post_init_options [] = {
42 {"algorithm", 'a', "{compatible|enhanced}", 0, N_("set to `compatible' if you want output calculated from broken algorithms"), 0},
43 {"include", 'I', "DIR", 0, N_("Append DIR to include path"), 0},
44 {"no-include", 'I', 0, 0, N_("Clear include path"), 0},
45 {"no-statrc", 'r', 0, 0, N_("Disable execution of .pspp/rc at startup"), 0},
46 {"config-dir", 'B', "DIR", 0, N_("Set configuration directory to DIR"), 0},
47 {"safer", 's', 0, 0, N_("Don't allow some unsafe operations"), 0},
48 {"syntax", 'x', "{compatible|enhanced}", 0, N_("Set to `compatible' if you want only to accept SPSS compatible syntax"), 0},
53 parse_post_init_opts (int key, char *arg, struct argp_state *state)
60 struct source_init *sip = state->hook;
62 struct source_stream *ss = state->input;
64 if ( state->input == NULL)
70 state->hook = sip = xzalloc (sizeof (struct source_init));
71 sip->process_statrc = true;
77 if ( 0 == strcmp (arg, "compatible") )
78 settings_set_algorithm (COMPATIBLE);
79 else if ( 0 == strcmp (arg, "enhanced"))
80 settings_set_algorithm (ENHANCED);
83 argp_failure (state, 1, 0, _("Algorithm must be either \"compatible\" or \"enhanced\"."));
90 if (arg == NULL || !strcmp (arg, "-"))
91 getl_clear_include_path (ss);
93 getl_add_include_dir (ss, arg);
96 sip->process_statrc = false;
98 case ARGP_KEY_SUCCESS:
99 if (sip->process_statrc)
101 char *pspprc_fn = fn_search_path ("rc", config_path);
102 if (pspprc_fn != NULL)
104 getl_append_source (ss,
105 create_syntax_file_source (pspprc_fn),
115 settings_set_safer_mode ();
118 if ( 0 == strcmp (arg, "compatible") )
119 settings_set_syntax (COMPATIBLE);
120 else if ( 0 == strcmp (arg, "enhanced"))
121 settings_set_syntax (ENHANCED);
124 argp_failure (state, 1, 0, _("Syntax must be either \"compatible\" or \"enhanced\"."));
128 return ARGP_ERR_UNKNOWN;
134 const struct argp post_init_argp =
135 {post_init_options, parse_post_init_opts, 0, 0, 0, 0, 0};