Add support for reading SPSS/PC+ system files.
[pspp] / src / ui / source-init-opts.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2008, 2010, 2014  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/settings.h"
27 #include "language/lexer/include-path.h"
28 #include "language/lexer/lexer.h"
29 #include "libpspp/assertion.h"
30 #include "libpspp/argv-parser.h"
31 #include "libpspp/llx.h"
32 #include "libpspp/message.h"
33 #include "ui/syntax-gen.h"
34
35 #include "gl/error.h"
36 #include "gl/xalloc.h"
37
38 #include "gettext.h"
39 #define _(msgid) gettext (msgid)
40 #define N_(msgid) msgid
41
42 enum
43   {
44     OPT_ALGORITHM,
45     OPT_INCLUDE,
46     OPT_NO_INCLUDE,
47     OPT_SAFER,
48     OPT_SYNTAX,
49     N_SOURCE_INIT_OPTIONS
50   };
51
52 static const struct argv_option source_init_options[N_SOURCE_INIT_OPTIONS] =
53   {
54     {"algorithm", 'a', required_argument, OPT_ALGORITHM},
55     {"include", 'I', required_argument, OPT_INCLUDE},
56     {"no-include", 0, no_argument, OPT_NO_INCLUDE},
57     {"safer", 's', no_argument, OPT_SAFER},
58     {"syntax", 'x', required_argument, OPT_SYNTAX},
59   };
60
61 static void
62 source_init_option_callback (int id, void *aux UNUSED)
63 {
64   switch (id)
65     {
66     case OPT_ALGORITHM:
67       if (!strcmp (optarg, "compatible"))
68         settings_set_algorithm (COMPATIBLE);
69       else if (!strcmp (optarg, "enhanced"))
70         settings_set_algorithm (ENHANCED);
71       else
72         error (1, 0,
73                _("Algorithm must be either `%s' or `%s'."), "compatible", "enhanced");
74       break;
75
76     case OPT_INCLUDE:
77       if (!strcmp (optarg, "-"))
78         include_path_clear ();
79       else
80         include_path_add (optarg);
81       break;
82
83     case OPT_NO_INCLUDE:
84       include_path_clear ();
85       break;
86
87     case OPT_SAFER:
88       settings_set_safer_mode ();
89       break;
90
91     case OPT_SYNTAX:
92       if (!strcmp (optarg, "compatible") )
93         settings_set_syntax (COMPATIBLE);
94       else if (!strcmp (optarg, "enhanced"))
95         settings_set_syntax (ENHANCED);
96       else
97         error (1, 0,
98                _("Syntax must be either `%s' or `%s'."), "compatible", "enhanced");
99       break;
100
101     default:
102       NOT_REACHED ();
103     }
104 }
105
106 void
107 source_init_register_argv_parser (struct argv_parser *ap)
108 {
109   argv_parser_add_options (ap, source_init_options, N_SOURCE_INIT_OPTIONS,
110                            source_init_option_callback, NULL);
111 }