+ ssize_t rc;
+
+ if ((rc = getline(linebuf, n, stdin)) < 0) {
+ if (ferror(stdin))
+ print_error("%s", strerror(errno));
+ return 0;
+ }
+
+ if (rc-- && (*linebuf)[rc] == '\n')
+ (*linebuf)[rc] = '\0';
+ return 1;
+}
+
+static int do_readline(char **linebuf, size_t *n, int interactive)
+{
+#if !HAVE_READLINE
+ if (interactive) {
+ fputs("> ", stdout);
+ fflush(stdout);
+ }
+
+ return do_getline(linebuf, n);
+#else
+ if (!interactive)
+ return do_getline(linebuf, n);
+
+ free(*linebuf);
+ if (!(*linebuf = readline("> ")))
+ return 0;
+
+ do_add_history(*linebuf);
+ return 1;
+#endif
+}
+
+static int repl(int interactive)
+{
+ char *line = NULL;
+ int ret = 0;
+ size_t n;
+
+ while (do_readline(&line, &n, interactive)) {
+ int rc = run_command(line, interactive);
+ if (rc > 0)
+ break;
+ else if (rc < 0)
+ ret = -!interactive;
+ }
+
+ free(line);
+ return ret;
+}
+
+/* Initialize gettext */
+static void init_i18n(void)
+{
+ if (!ENABLE_NLS)
+ return;
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+}
+
+enum {
+ INIT_EXIT_SUCCESS = -1,
+ INIT_EXIT_FAILURE = -2
+};
+
+static int initialize(int argc, char **argv)
+{
+ int i, opt, quiet = 0, execute = 0;
+ const char *filename = NULL;
+
+ XTRA_PACKED_LOPTS(lopts);