1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008, 2010 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 <output/driver.h>
34 #include <ui/command-line.h>
35 #include <ui/terminal/msg-ui.h>
36 #include <ui/terminal/read-line.h>
41 #define _(msgid) gettext (msgid)
42 #define N_(msgid) msgid
44 static const struct argp_option test_options [] =
46 {"testing-mode", 'T', 0, OPTION_HIDDEN, 0, 0},
52 parse_test_opts (int key, char *arg, struct argp_state *state)
57 settings_set_testing_mode (true);
60 return ARGP_ERR_UNKNOWN;
66 static const struct argp_option io_options [] =
68 {"error-file", 'e', "FILE", 0,
69 N_("Send error messages to FILE (appended)"), 0},
71 {"device", 'o', "DEVICE", 0,
72 N_("Select output driver DEVICE and disable defaults"), 0},
75 N_("Print a list of known driver classes, then exit"), 0},
77 {"interactive", 'i', 0, 0, N_("Start an interactive session"), 0},
84 parse_io_opts (int key, char *arg, struct argp_state *state)
88 struct llx_list file_list;
92 struct string_map macros;
93 struct string_set drivers;
101 struct source_init *sip = state->hook;
103 struct source_stream *ss = state->input;
105 struct command_line_processor *clp = get_subject (state);
110 state->hook = sip = xzalloc (sizeof (struct source_init));
111 llx_init (&sip->file_list);
112 string_map_init (&sip->macros);
113 string_set_init (&sip->drivers);
116 if (strchr (arg, '='))
118 if (!output_define_macro (arg, &sip->macros))
119 error (0, 0, _("\"%s\" is not a valid macro definition"), arg);
123 llx_push_tail (&sip->file_list, arg, &llx_malloc_mgr);
126 case ARGP_KEY_SUCCESS:
128 struct llx *llx = llx_null (&sip->file_list);
129 while ((llx = llx_next (llx)) != llx_null (&sip->file_list))
131 const char *fn = llx_data (llx);
132 /* Assume it's a syntax file */
133 getl_append_source (ss,
134 create_syntax_file_source (fn),
141 if (sip->interactive || llx_is_empty (&sip->file_list))
143 getl_append_source (ss, create_readln_source (),
148 string_set_insert (&sip->drivers, "interactive");
151 if (!settings_get_testing_mode ())
152 output_read_configuration (&sip->macros, &sip->drivers);
154 output_configure_driver ("csv:csv::");
156 string_map_destroy (&sip->macros);
157 string_set_destroy (&sip->drivers);
164 msg_ui_set_error_file (arg);
167 sip->interactive = true;
170 output_list_classes ();
173 string_set_insert (&sip->drivers, arg);
176 return ARGP_ERR_UNKNOWN;
182 const struct argp io_argp = {io_options, parse_io_opts, 0, 0, 0, 0, 0};
183 const struct argp test_argp = {test_options, parse_test_opts, 0, 0, 0, 0, 0};
186 static const struct argp_child children [] =
188 {&io_argp, 0, N_("Options affecting input and output locations:"), 0},
189 {&test_argp, 0, N_("Diagnostic options:"), 0},
195 propagate_aux (int key, char *arg, struct argp_state *state)
197 if ( key == ARGP_KEY_INIT)
200 for (i = 0 ; i < sizeof (children) / sizeof (children[0]) - 1 ; ++i)
201 state->child_inputs[i] = state->input;
204 return ARGP_ERR_UNKNOWN;
207 const struct argp terminal_argp = {NULL, propagate_aux, 0, 0, children, 0, 0};