1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #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/line-buffer.h>
34 #include <data/settings.h>
35 #include "read-line.h"
36 #include <output/output.h>
37 #include <data/file-name.h>
38 #include <libpspp/str.h>
39 #include <libpspp/version.h>
40 #include <libpspp/verbose-msg.h>
43 #define _(msgid) gettext (msgid)
44 #define N_(msgid) msgid
47 static void usage (void);
49 char *subst_vars (char *);
51 /* Parses the command line specified by ARGC and ARGV as received by
52 main(). Returns true if normal execution should proceed,
53 false if the command-line indicates that PSPP should exit. */
55 parse_command_line (int argc, char **argv)
57 static struct option long_options[] =
59 {"algorithm", required_argument, NULL, 'a'},
60 {"command", required_argument, NULL, 'c'},
61 {"config-directory", required_argument, NULL, 'B'},
62 {"device", required_argument, NULL, 'o'},
63 {"dry-run", no_argument, NULL, 'n'},
64 {"edit", no_argument, NULL, 'n'},
65 {"help", no_argument, NULL, 'h'},
66 {"include-directory", required_argument, NULL, 'I'},
67 {"interactive", no_argument, NULL, 'i'},
68 {"just-print", no_argument, NULL, 'n'},
69 {"list", no_argument, NULL, 'l'},
70 {"no-include", no_argument, NULL, 'I'},
71 {"no-statrc", no_argument, NULL, 'r'},
72 {"out-file", required_argument, NULL, 'f'},
73 {"pipe", no_argument, NULL, 'p'},
74 {"recon", no_argument, NULL, 'n'},
75 {"safer", no_argument, NULL, 's'},
76 {"syntax", required_argument, NULL, 'x'},
77 {"testing-mode", no_argument, NULL, 'T'},
78 {"verbose", no_argument, NULL, 'v'},
79 {"version", no_argument, NULL, 'V'},
85 bool cleared_device_defaults = false;
86 bool process_statrc = true;
87 bool interactive_mode = false;
92 c = getopt_long (argc, argv, "a:x:B:c:f:hiI:lno:prsvV", long_options, NULL);
98 /* Compatibility options */
100 if ( 0 == strcmp(optarg,"compatible") )
101 set_algorithm(COMPATIBLE);
102 else if ( 0 == strcmp(optarg,"enhanced"))
103 set_algorithm(ENHANCED);
112 if ( 0 == strcmp(optarg,"compatible") )
113 set_syntax(COMPATIBLE);
114 else if ( 0 == strcmp(optarg,"enhanced"))
115 set_syntax(ENHANCED);
124 config_path = optarg;
127 printf (_("%s is not yet implemented."), "-f");
134 interactive_mode = true;
137 if (optarg == NULL || !strcmp (optarg, "-"))
138 getl_clear_include_path ();
140 getl_add_include_dir (optarg);
143 outp_list_classes ();
146 printf (_("%s is not yet implemented."),"-n");
150 if (!cleared_device_defaults)
152 outp_configure_clear ();
153 cleared_device_defaults = true;
155 outp_configure_add (optarg);
158 printf (_("%s is not yet implemented."),"-p");
162 process_statrc = false;
168 verbose_increment_level ();
176 set_testing_mode (true);
190 char *pspprc_fn = fn_search_path ("rc", config_path, NULL);
191 if (pspprc_fn != NULL)
193 getl_append_syntax_file (pspprc_fn);
198 for (i = optind; i < argc; i++)
199 if (strchr (argv[i], '='))
200 outp_configure_macro (argv[i]);
203 getl_append_syntax_file (argv[i]);
207 if (!syntax_files || interactive_mode)
208 getl_append_interactive (readln_read);
213 /* Message that describes PSPP command-line syntax. */
214 static const char pre_syntax_message[] =
215 N_("PSPP, a program for statistical analysis of sample data.\n"
216 "\nUsage: %s [OPTION]... FILE...\n"
217 "\nIf a long option shows an argument as mandatory, then it is mandatory\n"
218 "for the equivalent short option also. Similarly for optional arguments.\n"
220 " -a, --algorithm={compatible|enhanced}\n"
221 " set to `compatible' if you want output\n"
222 " calculated from broken algorithms\n"
223 " -B, --config-dir=DIR set configuration directory to DIR\n"
224 " -o, --device=DEVICE select output driver DEVICE and disable defaults\n"
225 "\nInput and output:\n"
226 " -f, --out-file=FILE send output to FILE (overwritten)\n"
227 " -p, --pipe read script from stdin, send output to stdout\n"
228 " -I-, --no-include clear include path\n"
229 " -I, --include=DIR append DIR to include path\n"
230 "\nLanguage modifiers:\n"
231 " -i, --interactive interpret scripts in interactive mode\n"
232 " -n, --edit just check syntax; don't actually run the code\n"
233 " -r, --no-statrc disable execution of .pspp/rc at startup\n"
234 " -s, --safer don't allow some unsafe operations\n"
235 " -x, --syntax={compatible|enhanced}\n"
236 " set to `compatible' if you want only to accept\n"
237 " spss compatible syntax\n"
238 "\nInformative output:\n"
239 " -h, --help print this help, then exit\n"
240 " -l, --list print a list of known driver classes, then exit\n"
241 " -V, --version show PSPP version, then exit\n"
242 " -v, --verbose increments verbosity level\n"
243 "\nNon-option arguments:\n"
244 " FILE syntax file to execute\n"
245 " KEY=VALUE overrides macros in output initialization file\n"
248 /* Message that describes PSPP command-line syntax, continued. */
249 static const char post_syntax_message[] = N_("\nReport bugs to <%s>.\n");
251 /* Writes a syntax description to stdout. */
255 printf (gettext (pre_syntax_message), program_name);
256 outp_list_classes ();
257 printf (gettext (post_syntax_message), PACKAGE_BUGREPORT);