Consolidate quoting style in printed strings.
[pspp] / src / ui / source-init-opts.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2008, 2010  Free Software Foundation
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
19 #include "source-init-opts.h"
20
21 #include <stdbool.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include "data/file-name.h"
26 #include "data/por-file-reader.h"
27 #include "data/settings.h"
28 #include "data/sys-file-reader.h"
29 #include "language/syntax-file.h"
30 #include "language/syntax-string-source.h"
31 #include "libpspp/assertion.h"
32 #include "libpspp/argv-parser.h"
33 #include "libpspp/getl.h"
34 #include "libpspp/llx.h"
35 #include "libpspp/message.h"
36 #include "ui/syntax-gen.h"
37
38 #include "gl/error.h"
39 #include "gl/xalloc.h"
40
41 #include "gettext.h"
42 #define _(msgid) gettext (msgid)
43 #define N_(msgid) msgid
44
45 enum
46   {
47     OPT_ALGORITHM,
48     OPT_INCLUDE,
49     OPT_NO_INCLUDE,
50     OPT_SAFER,
51     OPT_SYNTAX,
52     N_SOURCE_INIT_OPTIONS
53   };
54
55 static const struct argv_option source_init_options[N_SOURCE_INIT_OPTIONS] =
56   {
57     {"algorithm", 'a', required_argument, OPT_ALGORITHM},
58     {"include", 'I', required_argument, OPT_INCLUDE},
59     {"no-include", 0, no_argument, OPT_NO_INCLUDE},
60     {"safer", 's', no_argument, OPT_SAFER},
61     {"syntax", 'x', required_argument, OPT_SYNTAX},
62   };
63
64 static void
65 source_init_option_callback (int id, void *ss_)
66 {
67   struct source_stream *ss = ss_;
68
69   switch (id)
70     {
71     case OPT_ALGORITHM:
72       if (!strcmp (optarg, "compatible"))
73         settings_set_algorithm (COMPATIBLE);
74       else if (!strcmp (optarg, "enhanced"))
75         settings_set_algorithm (ENHANCED);
76       else
77         /* TRANSLATORS: Leave the words `compatible' and `enhanced' in their
78         original English. */
79         error (1, 0,
80                _("Algorithm must be either `compatible' or `enhanced'."));
81       break;
82
83     case OPT_INCLUDE:
84       if (!strcmp (optarg, "-"))
85         getl_clear_include_path (ss);
86       else
87         getl_add_include_dir (ss, optarg);
88       break;
89
90     case OPT_NO_INCLUDE:
91       getl_clear_include_path (ss);
92       break;
93
94     case OPT_SAFER:
95       settings_set_safer_mode ();
96       break;
97
98     case OPT_SYNTAX:
99       if (!strcmp (optarg, "compatible") )
100         settings_set_syntax (COMPATIBLE);
101       else if (!strcmp (optarg, "enhanced"))
102         settings_set_syntax (ENHANCED);
103       else
104         /* TRANSLATORS: Leave the words `compatible' and `enhanced' in their
105         original English. */
106         error (1, 0,
107                _("Syntax must be either `compatible' or `enhanced'."));
108       break;
109
110     default:
111       NOT_REACHED ();
112     }
113 }
114
115 void
116 source_init_register_argv_parser (struct argv_parser *ap,
117                                   struct source_stream *ss)
118 {
119   argv_parser_add_options (ap, source_init_options, N_SOURCE_INIT_OPTIONS,
120                            source_init_option_callback, ss);
121 }