X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=inline;f=src%2Fui%2Fsource-init-opts.c;h=9627fdf57a5525696f2ba5953b110a0b2f14cf94;hb=refs%2Fbuilds%2F20111223030502%2Fpspp;hp=61a108e0eec65cb4686fca5d8f1932024dfd771a;hpb=dfd1972f7bcb550a4fc3b05dbe7e71d12334b0a7;p=pspp
diff --git a/src/ui/source-init-opts.c b/src/ui/source-init-opts.c
index 61a108e0ee..9627fdf57a 100644
--- a/src/ui/source-init-opts.c
+++ b/src/ui/source-init-opts.c
@@ -1,5 +1,5 @@
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2008 Free Software Foundation
+ Copyright (C) 2008, 2010 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -15,121 +15,103 @@
along with this program. If not, see . */
#include
-#include
+
#include "source-init-opts.h"
+
#include
-#include
-#include
-#include
-#include
-#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include
+
+#include "data/file-name.h"
+#include "data/por-file-reader.h"
+#include "data/settings.h"
+#include "data/sys-file-reader.h"
+#include "language/lexer/include-path.h"
+#include "language/lexer/lexer.h"
+#include "libpspp/assertion.h"
+#include "libpspp/argv-parser.h"
+#include "libpspp/llx.h"
+#include "libpspp/message.h"
+#include "ui/syntax-gen.h"
+
+#include "gl/error.h"
+#include "gl/xalloc.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
-static const struct argp_option post_init_options [] = {
- {"algorithm", 'a', "{compatible|enhanced}", 0, N_("set to `compatible' if you want output calculated from broken algorithms"), 0},
- {"include", 'I', "DIR", 0, N_("Append DIR to include path"), 0},
- {"no-include", 'I', 0, 0, N_("Clear include path"), 0},
- {"no-statrc", 'r', 0, 0, N_("Disable execution of .pspp/rc at startup"), 0},
- {"config-dir", 'B', "DIR", 0, N_("Set configuration directory to DIR"), 0},
- {"safer", 's', 0, 0, N_("Don't allow some unsafe operations"), 0},
- {"syntax", 'x', "{compatible|enhanced}", 0, N_("Set to `compatible' if you want only to accept SPSS compatible syntax"), 0},
- { 0, 0, 0, 0, 0, 0 }
-};
-
-static error_t
-parse_post_init_opts (int key, char *arg, struct argp_state *state)
-{
- struct source_init
+enum
{
- bool process_statrc;
+ OPT_ALGORITHM,
+ OPT_INCLUDE,
+ OPT_NO_INCLUDE,
+ OPT_SAFER,
+ OPT_SYNTAX,
+ N_SOURCE_INIT_OPTIONS
};
- struct source_init *sip = state->hook;
-
- struct source_stream *ss = state->input;
-
- if ( state->input == NULL)
- return 0;
+static const struct argv_option source_init_options[N_SOURCE_INIT_OPTIONS] =
+ {
+ {"algorithm", 'a', required_argument, OPT_ALGORITHM},
+ {"include", 'I', required_argument, OPT_INCLUDE},
+ {"no-include", 0, no_argument, OPT_NO_INCLUDE},
+ {"safer", 's', no_argument, OPT_SAFER},
+ {"syntax", 'x', required_argument, OPT_SYNTAX},
+ };
- switch (key)
+static void
+source_init_option_callback (int id, void *aux UNUSED)
+{
+ switch (id)
{
- case ARGP_KEY_INIT:
- state->hook = sip = xzalloc (sizeof (struct source_init));
- sip->process_statrc = true;
- break;
- case ARGP_KEY_FINI:
- free (sip);
- break;
- case 'a':
- if ( 0 == strcmp (arg, "compatible") )
+ case OPT_ALGORITHM:
+ if (!strcmp (optarg, "compatible"))
settings_set_algorithm (COMPATIBLE);
- else if ( 0 == strcmp (arg, "enhanced"))
+ else if (!strcmp (optarg, "enhanced"))
settings_set_algorithm (ENHANCED);
else
- {
- argp_failure (state, 1, 0, _("Algorithm must be either \"compatible\" or \"enhanced\"."));
- }
- break;
- case 'B':
- config_path = arg;
+ /* TRANSLATORS: Leave the words `compatible' and `enhanced' in their
+ original English. */
+ error (1, 0,
+ _("Algorithm must be either `compatible' or `enhanced'."));
break;
- case 'I':
- if (arg == NULL || !strcmp (arg, "-"))
- getl_clear_include_path (ss);
+
+ case OPT_INCLUDE:
+ if (!strcmp (optarg, "-"))
+ include_path_clear ();
else
- getl_add_include_dir (ss, arg);
+ include_path_add (optarg);
break;
- case 'r':
- sip->process_statrc = false;
- break;
- case ARGP_KEY_SUCCESS:
- if (sip->process_statrc)
- {
- char *pspprc_fn = fn_search_path ("rc", config_path);
- if (pspprc_fn != NULL)
- {
- getl_append_source (ss,
- create_syntax_file_source (pspprc_fn),
- GETL_BATCH,
- ERRMODE_CONTINUE
- );
-
- free (pspprc_fn);
- }
- }
+
+ case OPT_NO_INCLUDE:
+ include_path_clear ();
break;
- case 's':
+
+ case OPT_SAFER:
settings_set_safer_mode ();
break;
- case 'x':
- if ( 0 == strcmp (arg, "compatible") )
+
+ case OPT_SYNTAX:
+ if (!strcmp (optarg, "compatible") )
settings_set_syntax (COMPATIBLE);
- else if ( 0 == strcmp (arg, "enhanced"))
+ else if (!strcmp (optarg, "enhanced"))
settings_set_syntax (ENHANCED);
else
- {
- argp_failure (state, 1, 0, _("Syntax must be either \"compatible\" or \"enhanced\"."));
- }
+ /* TRANSLATORS: Leave the words `compatible' and `enhanced' in their
+ original English. */
+ error (1, 0,
+ _("Syntax must be either `compatible' or `enhanced'."));
break;
+
default:
- return ARGP_ERR_UNKNOWN;
+ NOT_REACHED ();
}
-
- return 0;
}
-const struct argp post_init_argp =
- {post_init_options, parse_post_init_opts, 0, 0, 0, 0, 0};
-
+void
+source_init_register_argv_parser (struct argv_parser *ap)
+{
+ argv_parser_add_options (ap, source_init_options, N_SOURCE_INIT_OPTIONS,
+ source_init_option_callback, NULL);
+}