#include <getopt.h>
#include <gettext.h>
-#include <localcharset.h>
#include <mbswidth.h>
#include "cdecl99.h"
#include "cdecl.h"
#include "help.h"
#include "xtra.h"
-#include "copysym.h"
#include "options.h"
+#include "version.h"
#if HAVE_READLINE_READLINE_H
# include <readline/readline.h>
static void print_version(void)
{
- const char *copysign = copyright_symbol(locale_charset());
-
- puts(PACKAGE_STRING);
- printf("Copyright %s 2023 Nick Bowler.\n", copysign);
- puts("License GPLv3+: GNU GPL version 3 or any later version.");
- puts("This is free software: you are free to change and redistribute it.");
- puts("There is NO WARRANTY, to the extent permitted by law.");
+ do_print_version(PACKAGE_STRING);
}
static void print_usage(FILE *f)
return 1;
}
-static int do_readline(char **linebuf, size_t *n, int batch)
+static int do_readline(char **linebuf, size_t *n, bool batch)
{
#if !HAVE_READLINE
if (!batch) {
#endif
}
-static int repl(int batch)
+static int repl(bool batch)
{
char *line = NULL;
- int ret = 0;
+ bool fail = 0;
size_t n;
while (do_readline(&line, &n, batch)) {
int rc = run_command(line, batch);
if (rc > 0)
break;
- else if (rc < 0)
- ret = -batch;
+ if (rc < 0)
+ fail = batch;
}
free(line);
- return ret;
+ return fail ? EXIT_FAILURE : 0;
}
static int repl_cmdline(unsigned count, char **commands)
{
- int ret = 0;
+ bool fail = 0;
unsigned i;
for (i = 0; i < count; i++) {
int rc = run_command(commands[i], true);
- if (rc < 0)
- ret = -1;
- else if (rc > 0)
+ if (rc > 0)
break;
+ if (rc < 0)
+ fail = true;
}
- return ret;
+ return fail ? EXIT_FAILURE : 0;
}
/* Initialize gettext */
int main(int argc, char **argv)
{
- int rc, execute;
+ int execute;
switch ((execute = initialize(argc, argv))) {
case INIT_EXIT_SUCCESS: return EXIT_SUCCESS;
}
if (execute)
- rc = repl_cmdline(execute, argv);
+ return repl_cmdline(execute, argv);
else
- rc = repl(batch_mode);
-
- if (rc != 0)
- return EXIT_FAILURE;
- return EXIT_SUCCESS;
+ return repl(batch_mode);
}