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 "terminal-opts.h"
26 #include <data/settings.h>
27 #include <data/file-name.h>
28 #include <language/syntax-file.h>
29 #include <libpspp/getl.h>
30 #include <libpspp/llx.h>
31 #include <libpspp/string-map.h>
32 #include <libpspp/string-set.h>
33 #include <libpspp/verbose-msg.h>
34 #include <output/driver.h>
35 #include <ui/command-line.h>
36 #include <ui/terminal/msg-ui.h>
37 #include <ui/terminal/read-line.h>
42 #define _(msgid) gettext (msgid)
43 #define N_(msgid) msgid
45 static const struct argp_option test_options [] =
47 {"verbose", 'v', 0, 0, N_("Increase diagnostic verbosity level"), 0},
48 {"testing-mode", 'T', 0, OPTION_HIDDEN, 0, 0},
54 parse_test_opts (int key, char *arg, struct argp_state *state)
59 settings_set_testing_mode (true);
62 verbose_increment_level ();
65 return ARGP_ERR_UNKNOWN;
71 static const struct argp_option io_options [] =
73 {"error-file", 'e', "FILE", 0,
74 N_("Send error messages to FILE (appended)"), 0},
76 {"device", 'o', "DEVICE", 0,
77 N_("Select output driver DEVICE and disable defaults"), 0},
80 N_("Print a list of known driver classes, then exit"), 0},
82 {"interactive", 'i', 0, 0, N_("Start an interactive session"), 0},
89 parse_io_opts (int key, char *arg, struct argp_state *state)
93 struct llx_list file_list;
97 struct string_map macros;
98 struct string_set drivers;
106 struct source_init *sip = state->hook;
108 struct source_stream *ss = state->input;
110 struct command_line_processor *clp = get_subject (state);
115 state->hook = sip = xzalloc (sizeof (struct source_init));
116 llx_init (&sip->file_list);
117 string_map_init (&sip->macros);
118 string_set_init (&sip->drivers);
121 if (strchr (arg, '='))
123 if (!output_define_macro (arg, &sip->macros))
124 error (0, 0, _("\"%s\" is not a valid macro definition"), arg);
128 llx_push_tail (&sip->file_list, arg, &llx_malloc_mgr);
131 case ARGP_KEY_SUCCESS:
133 struct llx *llx = llx_null (&sip->file_list);
134 while ((llx = llx_next (llx)) != llx_null (&sip->file_list))
136 const char *fn = llx_data (llx);
137 /* Assume it's a syntax file */
138 getl_append_source (ss,
139 create_syntax_file_source (fn),
146 if (sip->interactive || llx_is_empty (&sip->file_list))
148 getl_append_source (ss, create_readln_source (),
153 string_set_insert (&sip->drivers, "interactive");
156 if (!settings_get_testing_mode ())
157 output_read_configuration (&sip->macros, &sip->drivers);
159 output_configure_driver ("csv:csv::");
161 string_map_destroy (&sip->macros);
162 string_set_destroy (&sip->drivers);
169 msg_ui_set_error_file (arg);
172 sip->interactive = true;
175 output_list_classes ();
178 string_set_insert (&sip->drivers, arg);
181 return ARGP_ERR_UNKNOWN;
187 const struct argp io_argp = {io_options, parse_io_opts, 0, 0, 0, 0, 0};
188 const struct argp test_argp = {test_options, parse_test_opts, 0, 0, 0, 0, 0};
191 static const struct argp_child children [] =
193 {&io_argp, 0, N_("Options affecting input and output locations:"), 0},
194 {&test_argp, 0, N_("Diagnostic options:"), 0},
200 propagate_aux (int key, char *arg, struct argp_state *state)
202 if ( key == ARGP_KEY_INIT)
205 for (i = 0 ; i < sizeof (children) / sizeof (children[0]) - 1 ; ++i)
206 state->child_inputs[i] = state->input;
209 return ARGP_ERR_UNKNOWN;
212 const struct argp terminal_argp = {NULL, propagate_aux, 0, 0, children, 0, 0};