示例#1
0
文件: console.c 项目: patito/bareos
static int console_init_history(const char *histfile)
{
   int ret = 0;

#ifdef HAVE_READLINE
   int max_history_length;

   using_history();

   /*
    * First truncate the history size to an reasonable size.
    */
   max_history_length = (me) ? me->history_length : 100;
   history_truncate_file(histfile, max_history_length);

   /*
    * Read the content of the history file into memory.
    */
   ret = read_history(histfile);

   /*
    * Tell the completer that we want a complete.
    */
   rl_completion_entry_function = dummy_completion_function;
   rl_attempted_completion_function = readline_completion;
   rl_filename_completion_desired = 0;
   stifle_history(max_history_length);
#endif

   return ret;
}
示例#2
0
文件: lua.c 项目: 0w/torch
/* Initialize readline library. */
static void lua_rl_init(lua_State *L)
{
  char *s;

  lua_rl_L = L;

  /* This allows for $if lua ... $endif in ~/.inputrc. */
  rl_readline_name = "lua";
  /* Break words at every non-identifier character except '.' and ':'. */
  rl_completer_word_break_characters = 
    (char *)"\t\r\n !\"#$%&'()*+,-/;<=>?@[\\]^`{|}~";
  rl_completer_quote_characters = "\"'";
#if RL_READLINE_VERSION < 0x0600
  rl_completion_append_character = '\0';
#endif
  rl_attempted_completion_function = lua_rl_complete;
  rl_initialize();

  /* Start using history, optionally set history size and load history file. */
  using_history();
  if ((s = getenv("LUA_HISTSIZE")) &&
      (lua_rl_histsize = atoi(s))) stifle_history(lua_rl_histsize);
  if (!(lua_rl_hist = getenv("LUA_HISTORY"))) {
    char *ss = (char*)malloc((strlen(getenv("HOME"))+13)*sizeof(char));
    strcpy(ss,getenv("HOME"));
    lua_rl_hist = strcat(ss, "/.luahistory");
  }
  read_history(lua_rl_hist);
}
示例#3
0
finishInput(int exitstatus, void *arg)
#endif
{
#ifdef USE_READLINE
	if (useHistory)
	{
		char	   *home;
		char	   *psql_history;

		home = getenv("HOME");
		if (home)
		{
			psql_history = (char *) malloc(strlen(home) + 1 +
										   strlen(PSQLHISTORY) + 1);
			if (psql_history)
			{
				int			hist_size;

				hist_size = GetVariableNum(pset.vars, "HISTSIZE", -1, -1, true);

				if (hist_size >= 0)
					stifle_history(hist_size);

				sprintf(psql_history, "%s/%s", home, PSQLHISTORY);
				write_history(psql_history);
				free(psql_history);
			}
		}
	}
#endif
}
示例#4
0
static void readline_init(void) {
    rl_readline_name = "augtool";
    rl_attempted_completion_function = readline_completion;
    rl_completion_entry_function = readline_path_generator;

    /* Set up persistent history */
    char *home_dir = get_home_dir(getuid());
    char *history_dir = NULL;

    if (home_dir == NULL)
        goto done;

    if (xasprintf(&history_dir, "%s/.augeas", home_dir) < 0)
        goto done;

    if (mkdir(history_dir, 0755) < 0 && errno != EEXIST)
        goto done;

    if (xasprintf(&history_file, "%s/history", history_dir) < 0)
        goto done;

    stifle_history(500);

    read_history(history_file);

 done:
    free(home_dir);
    free(history_dir);
}
示例#5
0
int lua_interactive (int argc, char * argv[])
{
    int error = 0;
    char * line;
    lua_State * L;
    char history_filename[256];

    snprintf(history_filename, 256, "%s/%s", 
             getenv("HOME"), LUA_HISTORY_FILENAME);

    L = luaL_newstate();
    lua_rt_init(L, argc, argv);

    read_history(history_filename);

    while (1) {
        line = readline("X) ");
        add_history(line);
        stifle_history(LUA_HISTORY_LINES);
        write_history(history_filename);

        error = luaL_dostring(L, line);
        if (error) {
            line = (char *) luaL_checkstring(L, -1);
            printf("%s\n", line);
        }
        fflush(stdout);
    }

    return 0;
}
示例#6
0
static void save_history_dotfile(void)
{
    char *dotfile = g_strconcat(g_get_home_dir(), "/.fsp_history", NULL);
    stifle_history(100); /* arbitrarily restrict history file to 100 entries */
    write_history(dotfile);
    g_free(dotfile);
}
示例#7
0
文件: parser.c 项目: chutzimir/coda
/* this is the command execution machine */
void Parser_commands(void)
{
    char *line,
	 *s;

    using_history();
    stifle_history(HISTORY);

    rl_attempted_completion_function = command_completion;
    rl_completion_entry_function = &command_generator;

    while(!done) {
	line = readline(parser_prompt);

	if (!line) break;

	s = skipwhitespace(line);

	if (*s) {
	    add_history(s);
	    execute_line(s);
	}

	free(line);
    }
}
示例#8
0
文件: cli.c 项目: idaohang/gpsr-1
int main( int argc, char **argv )
{
	char file[MAX_FILENAME_LEN + 1];
	char *line, *prompt="> ";
	int i;

	if ( argc == 2 )
		ystrncpy( file, argv[1], MAX_FILENAME_LEN );
	else
		yerror( "missing filename\n" );

	restores( file );
	prints();
	restorer( file );

	for( i = 0; i < status.datan; i++ )
		readdata( status.dataf[i], i );

	port = gp_open( "400x400" );
	using_history();
	stifle_history(1000);
	sprintf( historyfile, "%s/%s", getenv("HOME"), HISTORYFILE );
	if ( !access (historyfile, R_OK) )
		if ( read_history(historyfile) )
			perror( "reading history" );
	while (1) {
		line=readline( prompt );
		if ( line ) {
			add_history( line );
			parser( line );

		} else printf( "\n" );
	}
	return 0;
}
int edit_init(void (*cmd_cb)(void *ctx, char *cmd),
	      void (*eof_cb)(void *ctx),
	      char ** (*completion_cb)(void *ctx, const char *cmd, int pos),
	      void *ctx, const char *history_file, const char *ps)
{
	edit_cb_ctx = ctx;
	edit_cmd_cb = cmd_cb;
	edit_eof_cb = eof_cb;
	edit_completion_cb = completion_cb;

	rl_attempted_completion_function = readline_completion;
	if (history_file) {
		read_history(history_file);
		stifle_history(100);
	}

	eloop_register_read_sock(STDIN_FILENO, edit_read_char, NULL, NULL);

	if (ps) {
		size_t blen = os_strlen(ps) + 3;
		char *ps2 = os_malloc(blen);
		if (ps2) {
			os_snprintf(ps2, blen, "%s> ", ps);
			rl_callback_handler_install(ps2, readline_cmd_handler);
			os_free(ps2);
			return 0;
		}
	}

	rl_callback_handler_install("> ", readline_cmd_handler);

	return 0;
}
示例#10
0
static void
wrapper_for_write_history()
{
#if 1
    /* Alternative code, saves one disk access */
    if (history_is_stifled())
	unstifle_history();
    if (gnuplot_history_size >= 0)
	stifle_history (gnuplot_history_size);

    /* returns 0 on success */
    if (write_history(expanded_history_filename))
	fprintf (stderr, "Warning:  Could not write history file!!!\n");

    unstifle_history();
#else
    /* if writing was successful, truncate history
     *  to gnuplot_history_size lines
     */
    if (write_history(expanded_history_filename)) {
	if (gnuplot_history_size >= 0)
	    history_truncate_file(expanded_history_filename, gnuplot_history_size);
    }
#endif
}
示例#11
0
/*
 * Uses globals:
 *
 *	- char *histfile_name (writes history to file and frees it)
 *	- char *last_in_history (frees it)
 *
 */
static int
linphonec_finish_readline()
{

	stifle_history(HISTSIZE);
	write_history(histfile_name);
	free(histfile_name);
	histfile_name=NULL;
	return 0;
}
示例#12
0
文件: lvm.c 项目: cardamon/lvm2
static void _read_history(struct cmd_context *cmd)
{
	char hist_file[PATH_MAX];

	if (!_hist_file(hist_file, sizeof(hist_file)))
		return;

	if (read_history(hist_file))
		log_very_verbose("Couldn't read history from %s.", hist_file);

	stifle_history(find_config_tree_int(cmd, shell_history_size_CFG, NULL));
}
示例#13
0
static void
byemesg(void)
{

#if defined(HAVE_GNUREADLINE) || defined(HAVE_BSDEDITLINE)
    /*  write out command history only when saying goodbye.  */
    if (cp_interactive && (cp_maxhistlength > 0)) {
        stifle_history(cp_maxhistlength);
        write_history(history_file);
    }
#endif

    printf("%s-%s done\n", ft_sim->simulator, ft_sim->version);
}
void sh_loop(void)
{
    char *line;
    char **args;
    int status;
    int i;
    using_history();
    stifle_history(MAX_HISTORY_SIZE);
    char cwd[1024];
    int flag = 0;
    int argc = 0;
    // rl_initialize();
    // rl_bind_keyseq("\\C-\\", reverse_search);
    signal(SIGQUIT, reverse_search);
    do {
        getcwd(cwd, sizeof(cwd));
        printf("%s", cwd);
        line = readline(">");
        args = sh_split_line(line);
        for(i = 0; args[i] != NULL; i++);
        argc = i;
        add_history(line);
        for(i = 0; args[i] != NULL; i++) {
            if(strcmp(args[i], ">") == 0 && args[i+1] != NULL){
                int save_out = dup(1);
                int file = open(args[i+1], O_CREAT | O_RDWR | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
                dup2(file, 1);
                status = sh_execute(args, argc);
                flag = 1;
                dup2(save_out, 1);
            }
            if(strcmp(args[i], "<") == 0 && args[i+1] != NULL){
                int save_in = dup(0);
                int file = open(args[i+1], O_CREAT | O_RDWR | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
                dup2(file, 0);
                status = sh_execute(args, argc);
                flag = 1;
                dup2(save_in, 0);
            }

        }

        if(flag == 0) status = sh_execute(args, argc);

        free(line);
        free(args);
    }
    while (status);
}
示例#15
0
int
readConsole(Client cntxt)
{
	/* execute from stdin */
	struct stat statb;
	char *buf;

	if (cntxt->promptlength == 0 ||
	   !(fstat(fileno(stdin), &statb) == 0 && S_ISCHR(statb.st_mode))  )
		return -1;

	/* read lines and move string to client buffer. */
#ifdef HAVE_LIBREADLINE
	if( initReadline ==0){
		init_readline();
		using_history();
		stifle_history(1000);
		initReadline =1 ;
	}
#endif
	buf= getConsoleInput(cntxt, cntxt->prompt, 0, 1);
	if( buf) {
		size_t len= strlen(buf);
		if( len >= cntxt->fdin->size) {
			/* extremly dirty inplace buffer overwriting */
			cntxt->fdin->buf= realloc(cntxt->fdin->buf, len+1);
			if( cntxt->fdin->buf == NULL) {
				GDKerror("readConsole: " MAL_MALLOC_FAIL);
				free(buf);
				goto bailout;
			}
			cntxt->fdin->size = len;
		}
		strcpy(cntxt->fdin->buf, buf);
		cntxt->fdin->pos = 0;
		cntxt->fdin->len = len;
		free(buf);
		return 1;
	}
  bailout:
	cntxt->fdin->eof = 1;
#ifdef HAVE_LIBREADLINE
	if( initReadline ){
		deinit_readline();
		initReadline= 0;
	}
#endif
	return -1;
}
int main(int argc, char **argv){
	int  intNo, fd;
	char fileName[51], option;
	FILE* diskFp;

	fd = open(DISK_NAME, O_RDONLY, 0666);
	if(fd > 0)
	{
		loadFileToVirtualDisk();
	}
	close(fd);
	stifle_history(50);
	cli(argc, argv); //Loads the Command Line Interface
	return 0;
}
示例#17
0
//------------------------------------------------------------------------------
void load_history()
{
    char buffer[512];

    get_history_file_name(buffer, sizeof(buffer));

    // Clear existing history.
    stifle_history(0);
    unstifle_history();
    g_new_history_count = 0;

    // Read from disk.
    read_history(buffer);
    using_history();
}
示例#18
0
文件: plot.c 项目: gnuplot/gnuplot
static void
wrapper_for_write_history()
{
    if (!expanded_history_filename)
	return;
    if (history_is_stifled())
	unstifle_history();
    if (gnuplot_history_size >= 0)
	stifle_history (gnuplot_history_size);

    /* returns 0 on success */
    if (write_history(expanded_history_filename))
	fprintf (stderr, "Warning:  Could not write history file!!!\n");

    unstifle_history();
}
示例#19
0
文件: lash.c 项目: alexmaras/lash
/**
 * Runs the lash program. The given parameters allow the user to specify the
 * limits the program should operate within.
 *
 * @param command      The maximum amount of commands to allow
 * @param args         The maximum number of arguments within each command
 * @param arglength    The maximum length of each argument
 * @param promptlength The maximum length of the prompt on the command line
 */
void runLash(int command, int args, int arglength, int promptlength){

	maxcommands     = command;
	maxargs         = args;
	maxarglength    = arglength;
	maxpromptlength = promptlength;

	sprintf(prompt, "%s LaSH %% ", getenv("USER"));

    // ignore all signals that should be passed to jobs
    signal (SIGINT, sighandler);
    signal (SIGQUIT, SIG_IGN);
   	signal (SIGTSTP, SIG_IGN);
   	signal (SIGTTIN, SIG_IGN);
   	signal (SIGTTOU, SIG_IGN);
 //   	signal (SIGCHLD, sighandler);

	stifle_history(100);

	struct LashParser *lash = newLashParser(maxcommands, maxargs, maxarglength);

	// Loop forever. This will be broken if exit is run
	int cont = 1;
	int status;
    while(cont){
		acceptInterrupt = 0;

        char *input = readline(prompt);
		if(strcmp(input, "") != 0){
	        add_history(input);
		}
		status = buildCommand(lash, input);

		if(status == VALID)
			cont = executeCommand(lash);
		else if(status == QUOTE_MISMATCH)
			printf("Error: Quote Mismatch\n");

        free(input);
		clearParser(lash);
    }

	free(lash->commands);
	free(lash);

    exit(0);
}
示例#20
0
int
main (int argc, char **argv)
{
   char *line, *s;

   progname = argv[0];

   initialize_readline();       /* Bind our completer. */

   stifle_history(7);

   /* Loop reading and executing lines until the user quits. */
   for ( ; done == 0; )
   {
      line = readline ("FileMan: ");

      if (!line)
         break;

      /* Remove leading and trailing whitespace from the line.
         Then, if there is anything left, add it to the history list
         and execute it. */
      s = stripwhite(line);

      if (*s) {

         char* expansion;
         int result;

         result = history_expand(s, &expansion);

         if (result < 0 || result == 2) {
            fprintf(stderr, "%s\n", expansion);
         } else {
            add_history(expansion);
            execute_line(expansion);
         }
         free(expansion);
      }

      free(line);
   }
   exit (0);

   return 0;
}
示例#21
0
finishInput(int exitstatus, void *arg)
#endif
{
#ifdef USE_READLINE
	if (useHistory && psql_history)
	{
		int			hist_size;

		hist_size = GetVariableNum(pset.vars, "HISTSIZE", 500, -1, true);
		if (hist_size >= 0)
			stifle_history(hist_size);

		saveHistory(psql_history, true);
		free(psql_history);
		psql_history = NULL;
	}
#endif
}
示例#22
0
/* just in case you're ever in an airplane and discover you
   forgot to install readline-dev. :) */
int init_input()
{
        int   interactive = isatty (fileno (stdin));

#ifdef HAVE_LIBREADLINE
        using_history();
        stifle_history(HISTORY);

        if (!interactive)
        {
                rl_prep_term_function = (rl_vintfunc_t *)noop_fn;
                rl_deprep_term_function = (rl_voidfunc_t *)noop_fn;
        }

        rl_attempted_completion_function = (CPPFunction *)command_completion;
        rl_completion_entry_function = (void *)command_generator;
#endif
        return interactive;
}
示例#23
0
文件: gnuReadline.c 项目: ukaea/epics
/*
 * Create a command-line context
 */
static void
osdReadlineBegin(struct readlineContext *context)
{
    if (rlState == rlNone) {
        epicsAtExit(rlExit, NULL);
        rlState = rlIdle;
    }

    context->osd = &present;
    if (context->in == NULL) {
        long i = 50;

        envGetLongConfigParam(&IOCSH_HISTSIZE, &i);
        if (i < 0)
            i = 0;
        stifle_history(i);
        rl_bind_key('\t', rl_insert);
    }
}
示例#24
0
int
main (int argc, char **argv)
{
	char *line;

	rl_bind_key ('\t', rl_insert);
	stifle_history (10);
	for (;;) {
		line = readline ("Enter a line: ");
		if (line && *line)
			add_history (line);
		printf ("Line: `%s'\n", line);
		if (line && !strcmp (line, "dump")) {
			rl_dump_variables (0,0);
			rl_dump_functions (0,0);
		}
		free (line);
	}
	return 0;
}
示例#25
0
static void cli_interactive(int raw)
{
	const int max_args = 10;
	char *cmd, *argv[max_args], *pos;
	int argc;

	setlinebuf(stdout);
	printf("\nInteractive mode\n\n");
	using_history();
	stifle_history(1000);

	do {
		cli_recv_pending(clif_conn, 0);
		alarm(1);
		cmd = readline("> ");
		alarm(0);
		if (!cmd)
			break;
		if (*cmd)
			add_history(cmd);
		argc = 0;
		pos = cmd;
		for (;;) {
			while (*pos == ' ')
				pos++;
			if (*pos == '\0')
				break;
			argv[argc] = pos;
			argc++;
			if (argc == max_args)
				break;
			while (*pos != '\0' && *pos != ' ')
				pos++;
			if (*pos == ' ')
				*pos++ = '\0';
		}
		if (argc)
			request(clif_conn, argc, argv, raw);
		free(cmd);
	} while (!cli_quit);
}
示例#26
0
static void
rtty_prep()
{
  // readline
  static QByteArray progname;
  QFileInfo fileinfo = QCoreApplication::applicationFilePath();
  progname = fileinfo.baseName().toLocal8Bit();
  rl_readline_name = progname.data();
  rl_getc_function = rtty_getchar;
  rl_attempted_completion_function = rtty_complete;
  rl_completer_quote_characters = "\"'";
  rl_completion_append_character = '\0';
#ifdef RL_READLINE_VERSION
# if RL_READLINE_VERSION > 0x402
  rl_set_paren_blink_timeout(250000);
  rl_bind_key (')', rl_insert_close);
  rl_bind_key (']', rl_insert_close);
  rl_bind_key ('}', rl_insert_close);
  rl_variable_bind("comment-begin","-- ");
# endif
#endif  
  rl_initialize();
  // history
  rtty_history = ".luahistory";
  const char *home = getenv("HOME");
  const char *luaHistory = getenv("LUA_HISTORY");
  const char *luaHistSize = getenv("LUA_HISTSIZE");
  int histSize = 1000;
  if (luaHistory && luaHistory[0])
    rtty_history = luaHistory;
  else if (home && home[0])
    rtty_history = QByteArray(home) + "/" + rtty_history;
  if (luaHistSize && luaHistSize[0])
    histSize = strtol(luaHistSize, 0, 10);
  using_history();
  stifle_history(qBound(25,histSize,250000));
  read_history(rtty_history.constData());
  // done
  rtty_inited = true;
}
示例#27
0
int edit_init(void (*cmd_cb)(void *ctx, char *cmd),
	      void (*eof_cb)(void *ctx),
	      char ** (*completion_cb)(void *ctx, const char *cmd, int pos),
	      void *ctx, const char *history_file)
{
	edit_cb_ctx = ctx;
	edit_cmd_cb = cmd_cb;
	edit_eof_cb = eof_cb;
	edit_completion_cb = completion_cb;

	rl_attempted_completion_function = readline_completion;
	if (history_file) {
		read_history(history_file);
		stifle_history(100);
	}

	eloop_register_read_sock(STDIN_FILENO, edit_read_char, NULL, NULL);

	rl_callback_handler_install("> ", readline_cmd_handler);

	return 0;
}
示例#28
0
文件: eif.c 项目: elijah/eif
/*************************************
 * eif_away
 *
 * The main routine.
 */
void
eif_away()
{

	/* Stuff for the readline. */
	(void) rl_unbind_key(17);	/* Ctrl-Q */
	(void) rl_unbind_key(19);	/* Ctrl-S */

	/* initialize signal handling */
	(void) signal(SIGQUIT, eif_sigdebug);	/* Debugging */

	(void) signal(SIGALRM, SIG_IGN);
	(void) signal(SIGPIPE, eif_pipe);

	(void) signal(SIGINT, eif_interrupt);

	/* We want ^C to abort system calls. */
	/* siginterrupt(SIGINT, 1); */

	prt("\nWelcome to EIF\n");
	prt("Empire Interface Version " VERSION "\n\n");

	/*
	 * The problem with this is that the file is not actually executed
	 * here.  It is executed in the commandloop(). This just sets it up
	 * for input as an exec file.
	 */
	if (cntl.st.readstartup) {
		cmd_exec(cntl.st.startupf, 2);
	}
	/* Only allow up to 100 commands in history */
	stifle_history(100);

	/* Install readline event hook */
	rl_event_hook = (Function *)event_hook;

	while (1)
		commandloop();
}
示例#29
0
文件: readline.c 项目: digarok/gsplus
char *x_readline(const char *prompt) {
	static char buffer[1024];

	char *cp;
	int count;

	if (!readline_init) {
		rl_readline_name = "GS+";
		rl_attempted_completion_function = rl_acf;

		using_history();
		stifle_history(HISTORY_SIZE);

		readline_init = 1;
	}

	cp = readline(prompt);
	if (!cp) {
		if (prompt) fputc('\n', stdout);
		return NULL;
	}
	count = strlen(cp);
	if (count > sizeof(buffer) - 1) {
		free(cp);
		return "";
	}
	memcpy(buffer, cp, count);
	cleanup_buffer(buffer, count);
	free(cp);

	/* append to history, but only if unique from prev. entry */
	if (*buffer) {
		HIST_ENTRY *h = history_get(history_length);
		if (h == NULL || strcmp(buffer, h->line))
			add_history(buffer);
	}
	return buffer;
}
示例#30
0
/*
 * This function saves the readline history when user
 * runs \s command or when psql exits.
 *
 * fname: pathname of history file.  (Should really be "const char *",
 * but some ancient versions of readline omit the const-decoration.)
 *
 * max_lines: if >= 0, limit history file to that many entries.
 *
 * appendFlag: if true, try to append just our new lines to the file.
 * If false, write the whole available history.
 *
 * encodeFlag: whether to encode \n as \x01.  For \s calls we don't wish
 * to do that, but must do so when saving the final history file.
 */
bool
saveHistory(char *fname, int max_lines, bool appendFlag, bool encodeFlag)
{
#ifdef USE_READLINE

	/*
	 * Suppressing the write attempt when HISTFILE is set to /dev/null may
	 * look like a negligible optimization, but it's necessary on e.g. Darwin,
	 * where write_history will fail because it tries to chmod the target
	 * file.
	 */
	if (useHistory && fname &&
		strcmp(fname, DEVNULL) != 0)
	{
		if (encodeFlag)
			encode_history();

		/*
		 * On newer versions of libreadline, truncate the history file as
		 * needed and then append what we've added.  This avoids overwriting
		 * history from other concurrent sessions (although there are still
		 * race conditions when two sessions exit at about the same time). If
		 * we don't have those functions, fall back to write_history().
		 *
		 * Note: return value of write_history is not standardized across GNU
		 * readline and libedit.  Therefore, check for errno becoming set to
		 * see if the write failed.  Similarly for append_history.
		 */
#if defined(HAVE_HISTORY_TRUNCATE_FILE) && defined(HAVE_APPEND_HISTORY)
		if (appendFlag)
		{
			int			nlines;
			int			fd;

			/* truncate previous entries if needed */
			if (max_lines >= 0)
			{
				nlines = Max(max_lines - history_lines_added, 0);
				(void) history_truncate_file(fname, nlines);
			}
			/* append_history fails if file doesn't already exist :-( */
			fd = open(fname, O_CREAT | O_WRONLY | PG_BINARY, 0600);
			if (fd >= 0)
				close(fd);
			/* append the appropriate number of lines */
			if (max_lines >= 0)
				nlines = Min(max_lines, history_lines_added);
			else
				nlines = history_lines_added;
			errno = 0;
			(void) append_history(nlines, fname);
			if (errno == 0)
				return true;
		}
		else
#endif
		{
			/* truncate what we have ... */
			if (max_lines >= 0)
				stifle_history(max_lines);
			/* ... and overwrite file.	Tough luck for concurrent sessions. */
			errno = 0;
			(void) write_history(fname);
			if (errno == 0)
				return true;
		}

		psql_error("could not save history to file \"%s\": %s\n",
				   fname, strerror(errno));
	}
#else
	/* only get here in \s case, so complain */
	psql_error("history is not supported by this installation\n");
#endif

	return false;
}