Fixed bug reporting the significance of paired value t-test.
[pspp-builds.git] / src / ui / terminal / command-line.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2007 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #include <config.h>
18 #include "command-line.h"
19 #include "msg-ui.h"
20 #include <libpspp/message.h>
21 #include <ctype.h>
22 #include <stdio.h>
23 #include <errno.h>
24 #include <getopt.h>
25 #include <stdlib.h>
26 #include <libpspp/assertion.h>
27 #include <libpspp/copyleft.h>
28 #include <libpspp/message.h>
29 #include <language/syntax-file.h>
30 #include "progname.h"
31 #include <data/settings.h>
32 #include <output/output.h>
33 #include <data/file-name.h>
34 #include <libpspp/getl.h>
35 #include <libpspp/str.h>
36 #include <libpspp/version.h>
37 #include <libpspp/verbose-msg.h>
38 #include "read-line.h"
39
40 #include "xalloc.h"
41
42 #include "gettext.h"
43 #define _(msgid) gettext (msgid)
44 #define N_(msgid) msgid
45
46 static void usage (void);
47
48 /* Parses the command line specified by ARGC and ARGV as received by
49    main().  Returns true if normal execution should proceed,
50    false if the command-line indicates that PSPP should exit. */
51 bool
52 parse_command_line (int argc, char **argv, struct source_stream *ss)
53 {
54   static struct option long_options[] =
55   {
56     {"algorithm", required_argument, NULL, 'a'},
57     {"command", required_argument, NULL, 'c'},
58     {"config-directory", required_argument, NULL, 'B'},
59     {"device", required_argument, NULL, 'o'},
60     {"dry-run", no_argument, NULL, 'n'},
61     {"edit", no_argument, NULL, 'n'},
62     {"error-file", required_argument, NULL, 'e'},
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'},
78     {0, 0, 0, 0},
79   };
80
81   int c, i;
82
83   bool cleared_device_defaults = false;
84   bool process_statrc = true;
85   bool interactive_mode = false;
86   int syntax_files = 0;
87
88   for (;;)
89     {
90       c = getopt_long (argc, argv, "a:x:B:c:e:f:hiI:lno:prsvV", long_options, NULL);
91       if (c == -1)
92         break;
93
94       switch (c)
95         {
96           /* Compatibility options */
97         case 'a':
98           if ( 0 == strcmp(optarg,"compatible") )
99               settings_set_algorithm(COMPATIBLE);
100           else if ( 0 == strcmp(optarg,"enhanced"))
101               settings_set_algorithm(ENHANCED);
102           else
103             {
104               usage ();
105               return false;
106             }
107           break;
108
109         case 'x':
110           if ( 0 == strcmp(optarg,"compatible") )
111             settings_set_syntax (COMPATIBLE);
112           else if ( 0 == strcmp(optarg,"enhanced"))
113             settings_set_syntax (ENHANCED);
114           else
115             {
116               usage ();
117               return false;
118             }
119           break;
120         case 'e':
121           msg_ui_set_error_file (optarg);
122           break;
123         case 'B':
124           config_path = optarg;
125           break;
126         case 'f':
127           printf (_("%s is not yet implemented."), "-f");
128           putchar('\n');
129           break;
130         case 'h':
131           usage ();
132           return false;
133         case 'i':
134           interactive_mode = true;
135           break;
136         case 'I':
137           if (optarg == NULL || !strcmp (optarg, "-"))
138             getl_clear_include_path (ss);
139           else
140             getl_add_include_dir (ss, optarg);
141           break;
142         case 'l':
143           outp_list_classes ();
144           return false;
145         case 'n':
146           printf (_("%s is not yet implemented."),"-n");
147           putchar('\n');
148           break;
149         case 'o':
150           if (!cleared_device_defaults)
151             {
152               outp_configure_clear ();
153               cleared_device_defaults = true;
154             }
155           outp_configure_add (optarg);
156           break;
157         case 'p':
158           printf (_("%s is not yet implemented."),"-p");
159           putchar('\n');
160           break;
161         case 'r':
162           process_statrc = false;
163           break;
164         case 's':
165           settings_set_safer_mode ();
166           break;
167         case 'v':
168           verbose_increment_level ();
169           break;
170         case 'V':
171           puts (version);
172           puts (legal);
173           return false;
174         case 'T':
175           settings_set_testing_mode (true);
176           break;
177         case '?':
178           usage ();
179           return false;
180         case 0:
181           break;
182         default:
183           NOT_REACHED ();
184         }
185     }
186
187   if (process_statrc)
188     {
189       char *pspprc_fn = fn_search_path ("rc", config_path);
190       if (pspprc_fn != NULL)
191         {
192           getl_append_source (ss,
193                               create_syntax_file_source (pspprc_fn),
194                               GETL_BATCH,
195                               ERRMODE_CONTINUE
196                               );
197
198           free (pspprc_fn);
199         }
200     }
201
202   for (i = optind; i < argc; i++)
203     if (strchr (argv[i], '='))
204       outp_configure_macro (argv[i]);
205     else
206       {
207         getl_append_source (ss,
208                             create_syntax_file_source (argv[i]),
209                             GETL_BATCH,
210                             ERRMODE_CONTINUE
211                             );
212         syntax_files++;
213       }
214
215   if (!syntax_files || interactive_mode)
216     {
217       getl_append_source (ss, create_readln_source (),
218                           GETL_INTERACTIVE,
219                           ERRMODE_CONTINUE
220                           );
221       if (!cleared_device_defaults)
222         outp_configure_add ("interactive");
223     }
224
225   return true;
226 }
227
228 /* Message that describes PSPP command-line syntax. */
229 static const char pre_syntax_message[] =
230 N_("PSPP, a program for statistical analysis of sample data.\n"
231 "\nUsage: %s [OPTION]... FILE...\n"
232 "\nIf a long option shows an argument as mandatory, then it is mandatory\n"
233 "for the equivalent short option also.  Similarly for optional arguments.\n"
234 "\nConfiguration:\n"
235 "  -a, --algorithm={compatible|enhanced}\n"
236 "                            set to `compatible' if you want output\n"
237 "                            calculated from broken algorithms\n"
238 "  -B, --config-dir=DIR      set configuration directory to DIR\n"
239 "  -o, --device=DEVICE       select output driver DEVICE and disable defaults\n"
240 "\nInput and output:\n"
241 "  -e, --error-file=FILE     send error messages to FILE (appended)\n"
242 "  -f, --out-file=FILE       send output to FILE (overwritten)\n"
243 "  -p, --pipe                read syntax from stdin, send output to stdout\n"
244 "  -I-, --no-include         clear include path\n"
245 "  -I, --include=DIR         append DIR to include path\n"
246 "\nLanguage modifiers:\n"
247 "  -i, --interactive         interpret syntax in interactive mode\n"
248 "  -n, --edit                just check syntax; don't actually run the code\n"
249 "  -r, --no-statrc           disable execution of .pspp/rc at startup\n"
250 "  -s, --safer               don't allow some unsafe operations\n"
251 "  -x, --syntax={compatible|enhanced}\n"
252 "                            set to `compatible' if you want only to accept\n"
253 "                            spss compatible syntax\n"
254 "\nInformative output:\n"
255 "  -h, --help                print this help, then exit\n"
256 "  -l, --list                print a list of known driver classes, then exit\n"
257 "  -V, --version             show PSPP version, then exit\n"
258 "  -v, --verbose             increments verbosity level\n"
259 "\nNon-option arguments:\n"
260 " FILE                       syntax file to execute\n"
261 " KEY=VALUE                  overrides macros in output initialization file\n"
262 "\n");
263
264 /* Message that describes PSPP command-line syntax, continued. */
265 static const char post_syntax_message[] = N_("\nReport bugs to <%s>.\n");
266
267 /* Writes a syntax description to stdout. */
268 static void
269 usage (void)
270 {
271   printf (gettext (pre_syntax_message), program_name);
272   outp_list_classes ();
273   printf (gettext (post_syntax_message), PACKAGE_BUGREPORT);
274 }