1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 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, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 #include "command-line.h"
22 #include <libpspp/message.h>
28 #include <libpspp/alloc.h>
29 #include <libpspp/assertion.h>
30 #include <libpspp/copyleft.h>
31 #include <libpspp/message.h>
32 #include <language/syntax-file.h>
34 #include <data/settings.h>
35 #include <output/output.h>
36 #include <data/file-name.h>
37 #include <libpspp/getl.h>
38 #include <libpspp/str.h>
39 #include <libpspp/version.h>
40 #include <libpspp/verbose-msg.h>
41 #include "read-line.h"
44 #define _(msgid) gettext (msgid)
45 #define N_(msgid) msgid
48 static void usage (void);
50 char *subst_vars (char *);
53 /* Parses the command line specified by ARGC and ARGV as received by
54 main(). Returns true if normal execution should proceed,
55 false if the command-line indicates that PSPP should exit. */
57 parse_command_line (int argc, char **argv, struct source_stream *ss)
59 static struct option long_options[] =
61 {"algorithm", required_argument, NULL, 'a'},
62 {"command", required_argument, NULL, 'c'},
63 {"config-directory", required_argument, NULL, 'B'},
64 {"device", required_argument, NULL, 'o'},
65 {"dry-run", no_argument, NULL, 'n'},
66 {"edit", no_argument, NULL, 'n'},
67 {"error-file", required_argument, NULL, 'e'},
68 {"help", no_argument, NULL, 'h'},
69 {"include-directory", required_argument, NULL, 'I'},
70 {"interactive", no_argument, NULL, 'i'},
71 {"just-print", no_argument, NULL, 'n'},
72 {"list", no_argument, NULL, 'l'},
73 {"no-include", no_argument, NULL, 'I'},
74 {"no-statrc", no_argument, NULL, 'r'},
75 {"out-file", required_argument, NULL, 'f'},
76 {"pipe", no_argument, NULL, 'p'},
77 {"recon", no_argument, NULL, 'n'},
78 {"safer", no_argument, NULL, 's'},
79 {"syntax", required_argument, NULL, 'x'},
80 {"testing-mode", no_argument, NULL, 'T'},
81 {"verbose", no_argument, NULL, 'v'},
82 {"version", no_argument, NULL, 'V'},
88 bool cleared_device_defaults = false;
89 bool process_statrc = true;
90 bool interactive_mode = false;
95 c = getopt_long (argc, argv, "a:x:B:c:e:f:hiI:lno:prsvV", long_options, NULL);
101 /* Compatibility options */
103 if ( 0 == strcmp(optarg,"compatible") )
104 set_algorithm(COMPATIBLE);
105 else if ( 0 == strcmp(optarg,"enhanced"))
106 set_algorithm(ENHANCED);
115 if ( 0 == strcmp(optarg,"compatible") )
116 set_syntax(COMPATIBLE);
117 else if ( 0 == strcmp(optarg,"enhanced"))
118 set_syntax(ENHANCED);
126 msg_ui_set_error_file (optarg);
129 config_path = optarg;
132 printf (_("%s is not yet implemented."), "-f");
139 interactive_mode = true;
142 if (optarg == NULL || !strcmp (optarg, "-"))
143 getl_clear_include_path (ss);
145 getl_add_include_dir (ss, optarg);
148 outp_list_classes ();
151 printf (_("%s is not yet implemented."),"-n");
155 if (!cleared_device_defaults)
157 outp_configure_clear ();
158 cleared_device_defaults = true;
160 outp_configure_add (optarg);
163 printf (_("%s is not yet implemented."),"-p");
167 process_statrc = false;
173 verbose_increment_level ();
181 set_testing_mode (true);
195 char *pspprc_fn = fn_search_path ("rc", config_path);
196 if (pspprc_fn != NULL)
198 getl_append_source (ss, create_syntax_file_source (pspprc_fn));
204 for (i = optind; i < argc; i++)
205 if (strchr (argv[i], '='))
206 outp_configure_macro (argv[i]);
209 getl_append_source (ss, create_syntax_file_source (argv[i]));
213 if (!syntax_files || interactive_mode)
214 getl_append_source (ss, create_readln_source () );
219 /* Message that describes PSPP command-line syntax. */
220 static const char pre_syntax_message[] =
221 N_("PSPP, a program for statistical analysis of sample data.\n"
222 "\nUsage: %s [OPTION]... FILE...\n"
223 "\nIf a long option shows an argument as mandatory, then it is mandatory\n"
224 "for the equivalent short option also. Similarly for optional arguments.\n"
226 " -a, --algorithm={compatible|enhanced}\n"
227 " set to `compatible' if you want output\n"
228 " calculated from broken algorithms\n"
229 " -B, --config-dir=DIR set configuration directory to DIR\n"
230 " -o, --device=DEVICE select output driver DEVICE and disable defaults\n"
231 "\nInput and output:\n"
232 " -e, --error-file=FILE send error messages to FILE (appended)\n"
233 " -f, --out-file=FILE send output to FILE (overwritten)\n"
234 " -p, --pipe read syntax from stdin, send output to stdout\n"
235 " -I-, --no-include clear include path\n"
236 " -I, --include=DIR append DIR to include path\n"
237 "\nLanguage modifiers:\n"
238 " -i, --interactive interpret syntax in interactive mode\n"
239 " -n, --edit just check syntax; don't actually run the code\n"
240 " -r, --no-statrc disable execution of .pspp/rc at startup\n"
241 " -s, --safer don't allow some unsafe operations\n"
242 " -x, --syntax={compatible|enhanced}\n"
243 " set to `compatible' if you want only to accept\n"
244 " spss compatible syntax\n"
245 "\nInformative output:\n"
246 " -h, --help print this help, then exit\n"
247 " -l, --list print a list of known driver classes, then exit\n"
248 " -V, --version show PSPP version, then exit\n"
249 " -v, --verbose increments verbosity level\n"
250 "\nNon-option arguments:\n"
251 " FILE syntax file to execute\n"
252 " KEY=VALUE overrides macros in output initialization file\n"
255 /* Message that describes PSPP command-line syntax, continued. */
256 static const char post_syntax_message[] = N_("\nReport bugs to <%s>.\n");
258 /* Writes a syntax description to stdout. */
262 printf (gettext (pre_syntax_message), program_name);
263 outp_list_classes ();
264 printf (gettext (post_syntax_message), PACKAGE_BUGREPORT);