#include "cdecl99.h"
#include "cdecl.h"
#include "help.h"
+#include "xtra.h"
#include "copysym.h"
+#include "options.h"
static const char *progname = "cdecl99";
static bool interactive = true;
-#include "options.h"
-static const char sopts[] = SOPT_STRING;
-static const struct option lopts[] = {
- LOPTS_INITIALIZER,
- {0}
-};
-
void print_error(const char *fmt, ...)
{
va_list(ap);
progname);
}
-static void print_help(void)
+static void print_help(const struct option *lopts)
{
+ struct lopt_help help = {0};
const struct option *opt;
print_usage(stdout);
puts(_("Options:"));
for (opt = lopts; opt->name; opt++) {
- struct lopt_help help;
-
if (!lopt_get_help(opt, &help))
continue;
textdomain(PACKAGE);
}
-int main(int argc, char **argv)
+enum {
+ INIT_EXIT_SUCCESS = -1,
+ INIT_EXIT_FAILURE = -2
+};
+
+static int initialize(int argc, char **argv)
{
- bool show_intro = true;
+ int i, opt, quiet = 0, execute = 0;
const char *filename = NULL;
- unsigned execute = 0;
- int i, opt, rc;
+
+ XTRA_PACKED_LOPTS(lopts);
if (argc > 0)
progname = argv[0];
init_i18n();
- while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
+ while ((opt = getopt_long(argc, argv, SOPT_STRING, lopts, 0)) != -1) {
switch (opt) {
case 'q':
- show_intro = false;
+ quiet = 1;
break;
case 'b':
interactive = false;
break;
case 'V':
print_version();
- return EXIT_SUCCESS;
+ return INIT_EXIT_SUCCESS;
case 'H':
- print_help();
- return EXIT_SUCCESS;
+ print_help(lopts);
+ return INIT_EXIT_SUCCESS;
default:
print_usage(stderr);
- return EXIT_FAILURE;
+ return INIT_EXIT_FAILURE;
}
}
}
fprintf(stderr, "\n");
print_usage(stderr);
- return EXIT_FAILURE;
+ return INIT_EXIT_FAILURE;
}
/* --filename and --execute imply --batch. */
interactive = false;
/* --batch implies --quiet */
- if (interactive && show_intro)
+ if (interactive && !quiet)
print_version();
/* --execute supersedes --filename */
if (!freopen(filename, "r", stdin)) {
print_error("failed to open %s: %s", filename,
strerror(errno));
- return EXIT_FAILURE;
+ return INIT_EXIT_FAILURE;
}
}
+ return execute;
+}
+
+int main(int argc, char **argv)
+{
+ int rc, execute;
+
+ switch ((execute = initialize(argc, argv))) {
+ case INIT_EXIT_SUCCESS: return EXIT_SUCCESS;
+ case INIT_EXIT_FAILURE: return EXIT_FAILURE;
+ }
+
if (interactive)
rc = repl();
else if (execute)