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/>. */
22 #include <data/settings.h>
23 #include <output/output.h>
25 #include <ui/command-line.h>
26 #include <libpspp/verbose-msg.h>
27 #include <libpspp/llx.h>
28 #include <data/file-name.h>
29 #include "terminal-opts.h"
30 #include <libpspp/getl.h>
31 #include <language/syntax-file.h>
32 #include "read-line.h"
35 #define _(msgid) gettext (msgid)
36 #define N_(msgid) msgid
39 static const struct argp_option test_options [] =
41 {"verbose", 'v', 0, 0, N_("Increase diagnostic verbosity level"), 0},
42 {"testing-mode", 'T', 0, OPTION_HIDDEN, 0, 0},
48 parse_test_opts (int key, char *arg, struct argp_state *state)
53 settings_set_testing_mode (true);
56 verbose_increment_level ();
59 return ARGP_ERR_UNKNOWN;
65 static const struct argp_option io_options [] =
67 {"error-file", 'e', "FILE", 0,
68 N_("Send error messages to FILE (appended)"), 0},
70 {"device", 'o', "DEVICE", 0,
71 N_("Select output driver DEVICE and disable defaults"), 0},
74 N_("Print a list of known driver classes, then exit"), 0},
76 {"interactive", 'i', 0, 0, N_("Start an interactive session"), 0},
83 parse_io_opts (int key, char *arg, struct argp_state *state)
87 struct llx_list file_list;
88 bool cleared_device_defaults;
97 struct source_init *sip = state->hook;
99 struct source_stream *ss = state->input;
101 struct command_line_processor *clp = get_subject (state);
106 state->hook = sip = xzalloc (sizeof (struct source_init));
107 llx_init (&sip->file_list);
110 if (strchr (arg, '='))
111 outp_configure_macro (arg);
114 llx_push_tail (&sip->file_list, arg, &llx_malloc_mgr);
117 case ARGP_KEY_SUCCESS:
119 struct llx *llx = llx_null (&sip->file_list);
120 while ((llx = llx_next (llx)) != llx_null (&sip->file_list))
122 const char *fn = llx_data (llx);
123 /* Assume it's a syntax file */
124 getl_append_source (ss,
125 create_syntax_file_source (fn),
132 if (sip->interactive || llx_is_empty (&sip->file_list))
134 getl_append_source (ss, create_readln_source (),
139 if (!sip->cleared_device_defaults)
140 outp_configure_add ("interactive");
148 msg_ui_set_error_file (arg);
151 sip->interactive = true;
154 outp_list_classes ();
157 if (! sip->cleared_device_defaults)
159 outp_configure_clear ();
160 sip->cleared_device_defaults = true;
162 outp_configure_add (arg);
165 return ARGP_ERR_UNKNOWN;
171 const struct argp io_argp = {io_options, parse_io_opts, 0, 0, 0, 0, 0};
172 const struct argp test_argp = {test_options, parse_test_opts, 0, 0, 0, 0, 0};
175 static const struct argp_child children [] =
177 {&io_argp, 0, N_("Options affecting input and output locations:"), 0},
178 {&test_argp, 0, N_("Diagnostic options:"), 0},
184 propagate_aux (int key, char *arg, struct argp_state *state)
186 if ( key == ARGP_KEY_INIT)
189 for (i = 0 ; i < sizeof (children) / sizeof (children[0]) - 1 ; ++i)
190 state->child_inputs[i] = state->input;
193 return ARGP_ERR_UNKNOWN;
196 const struct argp terminal_argp = {NULL, propagate_aux, 0, 0, children, 0, 0};