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"
31 #include "line-buffer.h"
34 #include "read-line.h"
41 #define _(msgid) gettext (msgid)
42 #define N_(msgid) msgid
45 static void usage (void);
47 char *subst_vars (char *);
49 /* Parses the command line specified by ARGC and ARGV as received by
50 main(). Returns true if normal execution should proceed,
51 false if the command-line indicates that PSPP should exit. */
53 parse_command_line (int argc, char **argv)
55 static struct option long_options[] =
57 {"algorithm", required_argument, NULL, 'a'},
58 {"command", required_argument, NULL, 'c'},
59 {"config-directory", required_argument, NULL, 'B'},
60 {"device", required_argument, NULL, 'o'},
61 {"dry-run", no_argument, NULL, 'n'},
62 {"edit", no_argument, NULL, 'n'},
63 {"help", no_argument, NULL, 'h'},
64 {"include-directory", required_argument, NULL, 'I'},
65 {"interactive", no_argument, NULL, 'i'},
66 {"just-print", no_argument, NULL, 'n'},
67 {"list", no_argument, NULL, 'l'},
68 {"no-include", no_argument, NULL, 'I'},
69 {"no-statrc", no_argument, NULL, 'r'},
70 {"out-file", required_argument, NULL, 'f'},
71 {"pipe", no_argument, NULL, 'p'},
72 {"recon", no_argument, NULL, 'n'},
73 {"safer", no_argument, NULL, 's'},
74 {"syntax", required_argument, NULL, 'x'},
75 {"testing-mode", no_argument, NULL, 'T'},
76 {"verbose", no_argument, NULL, 'v'},
77 {"version", no_argument, NULL, 'V'},
83 bool cleared_device_defaults = false;
84 bool process_statrc = true;
85 bool interactive_mode = false;
90 c = getopt_long (argc, argv, "a:x:B:c:f:hiI:lno:prsvV", long_options, NULL);
96 /* Compatibility options */
98 if ( 0 == strcmp(optarg,"compatible") )
99 set_algorithm(COMPATIBLE);
100 else if ( 0 == strcmp(optarg,"enhanced"))
101 set_algorithm(ENHANCED);
110 if ( 0 == strcmp(optarg,"compatible") )
111 set_syntax(COMPATIBLE);
112 else if ( 0 == strcmp(optarg,"enhanced"))
113 set_syntax(ENHANCED);
122 config_path = optarg;
125 printf (_("%s is not yet implemented."), "-f");
132 interactive_mode = true;
135 if (optarg == NULL || !strcmp (optarg, "-"))
136 getl_clear_include_path ();
138 getl_add_include_dir (optarg);
141 outp_list_classes ();
144 printf (_("%s is not yet implemented."),"-n");
148 if (!cleared_device_defaults)
150 outp_configure_clear ();
151 cleared_device_defaults = true;
153 outp_configure_add (optarg);
156 printf (_("%s is not yet implemented."),"-p");
160 process_statrc = false;
174 set_testing_mode (true);
188 char *pspprc_fn = fn_search_path ("rc", config_path, NULL);
189 if (pspprc_fn != NULL)
191 getl_append_syntax_file (pspprc_fn);
196 for (i = optind; i < argc; i++)
197 if (strchr (argv[i], '='))
198 outp_configure_macro (argv[i]);
201 getl_append_syntax_file (argv[i]);
205 if (!syntax_files || interactive_mode)
206 getl_append_interactive (readln_read);
211 /* Message that describes PSPP command-line syntax. */
212 static const char pre_syntax_message[] =
213 N_("PSPP, a program for statistical analysis of sample data.\n"
214 "\nUsage: %s [OPTION]... FILE...\n"
215 "\nIf a long option shows an argument as mandatory, then it is mandatory\n"
216 "for the equivalent short option also. Similarly for optional arguments.\n"
218 " -a, --algorithm={compatible|enhanced}\n"
219 " set to `compatible' if you want output\n"
220 " calculated from broken algorithms\n"
221 " -B, --config-dir=DIR set configuration directory to DIR\n"
222 " -o, --device=DEVICE select output driver DEVICE and disable defaults\n"
223 " -d, --define=VAR[=VALUE] set environment variable VAR to VALUE, or empty\n"
224 " -u, --undef=VAR undefine environment variable VAR\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);