Fixed some issues with internationalisation
[pspp-builds.git] / src / cmdline.c
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
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.
9
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.
14
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., 59 Temple Place - Suite 330, Boston, MA
18    02111-1307, USA. */
19
20 #include <config.h>
21 #include "cmdline.h"
22 #include <assert.h>
23 #include <ctype.h>
24 #include <stdio.h>
25 #include <errno.h>
26 #include <getopt.h>
27 #include <stdlib.h>
28 #include "alloc.h"
29 #include "error.h"
30 #include "filename.h"
31 #include "getline.h"
32 #include "main.h"
33 #include "output.h"
34 #include "settings.h"
35 #include "str.h"
36 #include "var.h"
37 #include "version.h"
38
39 void welcome (void);
40 static void usage (void);
41
42 char *subst_vars (char *);
43
44 /* Parses the command line specified by ARGC and ARGV as received by
45    main(). */
46 void
47 parse_command_line (int argc, char **argv)
48 {
49   static struct option long_options[] =
50   {
51     {"command", required_argument, NULL, 'c'},
52     {"config-directory", required_argument, NULL, 'B'},
53     {"device", required_argument, NULL, 'o'},
54     {"dry-run", no_argument, NULL, 'n'},
55     {"edit", no_argument, NULL, 'n'},
56     {"help", no_argument, NULL, 'h'},
57     {"include-directory", required_argument, NULL, 'I'},
58     {"interactive", no_argument, NULL, 'i'},
59     {"just-print", no_argument, NULL, 'n'},
60     {"list", no_argument, NULL, 'l'},
61     {"no-include", no_argument, NULL, 'I'},
62     {"no-statrc", no_argument, NULL, 'r'},
63     {"out-file", required_argument, NULL, 'f'},
64     {"pipe", no_argument, NULL, 'p'},
65     {"recon", no_argument, NULL, 'n'},
66     {"safer", no_argument, NULL, 's'},
67     {"testing-mode", no_argument, &set_testing_mode, 1},
68     {"verbose", no_argument, NULL, 'v'},
69     {"version", no_argument, NULL, 'V'},
70     {0, 0, 0, 0},
71   };
72
73   int c, i;
74
75   int cleared_device_defaults = 0;
76
77   int no_statrc = 0;
78
79   for (;;)
80     {
81       c = getopt_long (argc, argv, "B:c:f:hiI:lno:prsvV", long_options, NULL);
82       if (c == -1)
83         break;
84
85       switch (c)
86         {
87         case 'c':
88           {
89             static int n_cmds;
90             
91             struct getl_script *script = xmalloc (sizeof *script);
92             
93             {
94               struct getl_line_list *line;
95
96               script->first_line = line = xmalloc (sizeof *line);
97               line->line = xstrdup ("commandline");
98               line->len = --n_cmds;
99               line = line->next = xmalloc (sizeof *line);
100               line->line = xstrdup (optarg);
101               line->len = strlen (optarg);
102               line->next = NULL;
103             }
104
105             getl_add_virtual_file (script);
106           }
107           break;
108         case 'B':
109           config_path = optarg;
110           break;
111         case 'f':
112           printf(_("%s is not yet implemented."), "-f");
113           putchar('\n');
114           break;
115         case 'h':
116           usage ();
117           assert (0);
118         case 'i':
119           getl_interactive = 2;
120           break;
121         case 'I':
122           if (optarg == NULL || !strcmp (optarg, "-"))
123             getl_clear_include_path ();
124           else
125             getl_add_include_dir (optarg);
126           break;
127         case 'l':
128           outp_list_classes ();
129           err_hcf (1);
130         case 'n':
131           printf (_("%s is not yet implemented."),"-n");
132           putchar('\n');
133           break;
134         case 'o':
135           if (!cleared_device_defaults)
136             {
137               outp_configure_clear ();
138               cleared_device_defaults = 1;
139             }
140           outp_configure_add (optarg);
141           break;
142         case 'p':
143           printf (_("%s is not yet implemented."),"-p");
144           putchar('\n');
145           break;
146         case 'r':
147           no_statrc = 1;
148           break;
149         case 's':
150           set_safer = 1;
151           break;
152         case 'v':
153           err_verbosity++;
154           break;
155         case 'V':
156           puts (version);
157           puts (_("\nCopyright (C) 1997-9, 2000 Free Software Foundation, "
158                   "Inc.\n"
159                   "This is free software; see the source for copying "
160                   "conditions.  There is NO\n"
161                   "WARRANTY; not even for MERCHANTABILITY or FITNESS "
162                   "FOR A PARTICULAR PURPOSE.\n\n"
163                   "Written by Ben Pfaff <blp@gnu.org>."));
164           err_hcf (1);
165         case '?':
166           usage ();
167           assert (0);
168         case 0:
169           break;
170         default:
171           assert (0);
172         }
173     }
174
175   if (set_testing_mode)
176     {
177       /* FIXME: Later this option should do some other things, too. */
178       set_viewwidth = 9999;
179     }
180
181   for (i = optind; i < argc; i++)
182     {
183       int separate = 1;
184
185       if (!strcmp (argv[i], "+"))
186         {
187           separate = 0;
188           if (++i >= argc)
189             usage ();
190         }
191       else if (strchr (argv[i], '='))
192         {
193           outp_configure_macro (argv[i]);
194           continue;
195         }
196       getl_add_file (argv[i], separate, 0);
197     }
198   if (getl_head)
199     getl_head->separate = 0;
200
201   if (getl_am_interactive)
202     getl_interactive = 1;
203
204   if (!no_statrc)
205     {
206       char *pspprc_fn = fn_search_path ("rc", config_path, NULL);
207
208       if (pspprc_fn)
209         getl_add_file (pspprc_fn, 0, 1);
210
211       free (pspprc_fn);
212     }
213 }
214
215 /* Message that describes PSPP command-line syntax. */
216 static const char pre_syntax_message[] =
217 N_("PSPP, a program for statistical analysis of sample data.\n"
218 "\nUsage: %s [OPTION]... FILE...\n"
219 "\nIf a long option shows an argument as mandatory, then it is mandatory\n"
220 "for the equivalent short option also.  Similarly for optional arguments.\n"
221 "\nConfiguration:\n"
222 "  -B, --config-dir=DIR      set configuration directory to DIR\n"
223 "  -o, --device=DEVICE       select output driver DEVICE and disable defaults\n"
224 "  -d, --define=VAR[=VALUE]  set environment variable VAR to VALUE, or empty\n"
225 "  -u, --undef=VAR           undefine environment variable VAR\n"
226 "\nInput and output:\n"
227 "  -f, --out-file=FILE       send output to FILE (overwritten)\n"
228 "  -p, --pipe                read script from stdin, send output to stdout\n"
229 "  -I-, --no-include         clear include path\n"
230 "  -I, --include=DIR         append DIR to include path\n"
231 "  -c, --command=COMMAND     execute COMMAND before .pspp/rc at startup\n"
232 "\nLanguage modifiers:\n"
233 "  -i, --interactive         interpret scripts in interactive mode\n"
234 "  -n, --edit                just check syntax; don't actually run the code\n"
235 "  -r, --no-statrc           disable execution of .pspp/rc at startup\n"
236 "  -s, --safer               don't allow some unsafe operations\n"
237 "\nInformative output:\n"
238 "  -h, --help                print this help, then exit\n"
239 "  -l, --list                print a list of known driver classes, then exit\n"
240 "  -V, --version             show PSPP version, then exit\n"
241 "  -v, --verbose             increments verbosity level\n"
242 "\nNon-option arguments:\n"
243 " FILE1 FILE2                run FILE1, clear the dictionary, run FILE2\n"
244 " FILE1 + FILE2              run FILE1 then FILE2 without clearing dictionary\n"
245 " KEY=VALUE                  overrides macros in output initialization file\n"
246 "\n");
247
248 /* Message that describes PSPP command-line syntax, continued. */
249 static const char post_syntax_message[] = N_("\nReport bugs to <%s>.\n");
250
251 /* Writes a syntax description to stdout and terminates. */
252 static void
253 usage (void)
254 {
255   printf (gettext (pre_syntax_message), pgmname);
256   outp_list_classes ();
257   printf (gettext (post_syntax_message),PACKAGE_BUGREPORT);
258
259   err_hcf (1);
260 }