Exemplo n.º 1
0
static bool HHVM_FUNCTION(readline_read_history,
                          const String& filename /* = null */) {
  if (filename.isNull()) {
    return read_history(nullptr) == 0;
  } else {
    return read_history(filename.data()) == 0;
  }
}
Exemplo n.º 2
0
static bool HHVM_FUNCTION(readline_read_history,
                          const Variant& filename /* = null */) {
  if (filename.isNull()) {
    return read_history(nullptr) == 0;
  } else {
    auto const filenameString = filename.toString();
    return read_history(filenameString.data()) == 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;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: chrippa/xmms2
gint
main (gint argc, gchar **argv)
{
	cli_infos_t *cli_infos;

	setlocale (LC_ALL, "");

	cli_infos = cli_infos_init (argc - 1, argv + 1);

	/* Execute command, if connection status is ok */
	if (cli_infos) {
		if (cli_infos->mode == CLI_EXECUTION_MODE_INLINE) {
			loop_once (cli_infos, argc - 1, argv + 1);
		} else {
			gchar *filename;

			filename = configuration_get_string (cli_infos->config,
			                                     "HISTORY_FILE");

			read_history (filename);
			using_history ();
			loop_run (cli_infos);
			write_history (filename);
		}
	}

	cli_infos_free (cli_infos);

	return 0;
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
0
Arquivo: lua.c Projeto: 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);
}
Exemplo n.º 8
0
/* Load the history list from the history file. */
void
load_history ()
{
  char *hf;

  /* Truncate history file for interactive shells which desire it.
     Note that the history file is automatically truncated to the
     size of HISTSIZE if the user does not explicitly set the size
     differently. */
  set_if_not ("HISTFILESIZE", get_string_value ("HISTSIZE"));
  stupidly_hack_special_variables ("HISTFILESIZE");

  /* Read the history in HISTFILE into the history list. */
  hf = get_string_value ("HISTFILE");

  if (hf && *hf)
    {
      struct stat buf;

      if (stat (hf, &buf) == 0)
	{
	  read_history (hf);
	  using_history ();
	  history_lines_in_file = where_history ();
	}
    }
}
Exemplo n.º 9
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);
}
Exemplo n.º 10
0
/* Startup calls and initializations */
static void clipit_init() {
	/* Create clipboard */
	primary = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
	clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
	g_timeout_add(CHECK_INTERVAL, item_check, NULL);

	/* Read preferences */
	read_preferences();

	/* Read history */
	if (prefs.save_history)
		read_history();

	/* Bind global keys */
	keybinder_init();
	keybinder_bind(prefs.history_key, history_hotkey, NULL);
	keybinder_bind(prefs.actions_key, actions_hotkey, NULL);
	keybinder_bind(prefs.menu_key, menu_hotkey, NULL);
	keybinder_bind(prefs.search_key, search_hotkey, NULL);
	keybinder_bind(prefs.offline_key, offline_hotkey, NULL);

	/* Create status icon */
	if (!prefs.no_icon)
	{
#ifdef HAVE_APPINDICATOR
	create_app_indicator(1);
#else
	status_icon = gtk_status_icon_new_from_icon_name("clipit-trayicon");
	gtk_status_icon_set_tooltip((GtkStatusIcon*)status_icon, _("Clipboard Manager"));
	g_signal_connect((GObject*)status_icon, "button_press_event", (GCallback)status_icon_clicked, NULL);
#endif
	}
}
Exemplo n.º 11
0
static void
jtag_load_history( void )
{
    char *home = getenv( "HOME" );
    char *file;

    using_history();

    if (!home)
        return;

    file = malloc( strlen(home) + strlen(JTAGDIR) + strlen(HISTORYFILE) + 3 );	/* 2 x "/" and trailing \0 */
    if (!file)
        return;

    strcpy( file, home );
    strcat( file, "/" );
    strcat( file, JTAGDIR );
    strcat( file, "/" );
    strcat( file, HISTORYFILE );

    read_history( file );

    free( file );
}
Exemplo n.º 12
0
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;
}
Exemplo n.º 13
0
bool Yap_InitReadline(Term enable) {
  // don't call readline within emacs
  if (Yap_Embedded)
    return false;
  if (!(GLOBAL_Stream[StdInStream].status & Tty_Stream_f) ||
      getenv("INSIDE_EMACS") || enable != TermTrue) {
    if (GLOBAL_Flags)
      setBooleanGlobalPrologFlag(READLINE_FLAG, false);
    return false;
  }
  GLOBAL_Stream[StdInStream].u.irl.buf = NULL;
  GLOBAL_Stream[StdInStream].u.irl.ptr = NULL;
  GLOBAL_Stream[StdInStream].status |= Readline_Stream_f;
#if _WIN32
  rl_instream = stdin;
#endif
  // rl_outstream = stderr;
  using_history();
  const char *s = Yap_AbsoluteFile("~/.YAP.history", true);
  history_file = s;
  if (read_history(s) != 0) {
    FILE *f = fopen(s, "a");
    if (f) {
      fclose(f);
    }
  }
  rl_readline_name = "YAP Prolog";
  rl_attempted_completion_function = prolog_completion;
  // rl_prep_terminal(1);
  if (GLOBAL_Flags)
    setBooleanGlobalPrologFlag(READLINE_FLAG, true);
  return Yap_ReadlineOps(GLOBAL_Stream + StdInStream);
}
Exemplo n.º 14
0
int main(int argc, char **argv)
{
  mudlle_init();

  define_string_vector("argv", (const char *const *)argv, argc);

#ifdef USE_READLINE
  bool is_tty = isatty(0);
  if (is_tty)
    {
      using_history();
      read_history(HISTORY_FILE);
      rl_bind_key('\t', rl_insert);

      if (atexit(history_exit))
        perror("atexit(history_exit)");
    }
#endif

  struct oport *out = make_file_oport(stdout);
  struct session_context context;
  session_start(&context,
                &(const struct session_info){
                  .mout        = out,
                  .merr        = out,
                  .maxseclevel = MAX_SECLEVEL });
Exemplo n.º 15
0
Console::Console(QString _name, CommandInterpreter *_interpreter) :
  stopping(false),
  name(_name),
  interpreter(_interpreter)
{
  QObject::connect(this, SIGNAL(read(QString)),
                   interpreter, SLOT(handleString(QString)));
  QObject::connect(interpreter, SIGNAL(write(QString)),
                   this, SLOT(write(QString)));
  QObject::connect(interpreter, SIGNAL(writeAsync(QString)),
                   this, SLOT(writeAsync(QString)));
  QObject::connect(interpreter, SIGNAL(exit()), this, SLOT(quit()));


  /** allow conditional parsing of the inputrc file */
  rl_readline_name = name.toAscii();
  /** tell the completer that we want a crack first. */
  rl_console = this;
  rl_attempted_completion_function = &Console::ConsoleCompletion;
  rl_event_hook = poll;
  rl_catch_signals = 0;
  // rl_set_keyboard_input_timeout(100000);

  using_history();
  historyFile = QDir::homePath() + QString("/.%1_history").arg(name);
  QFile file(historyFile);
  if (!file.exists()) {
    // create file
    file.open(QIODevice::ReadWrite);
    file.close();
  }
  read_history(historyFile.toAscii().constData());
  //    rl_bind_key('\t', readline_completion);
}
int main(int argc, char *argv[])
{
    read_history(history_file);
    load_tab_completion();
    signal(SIGINT, &sighandler); // Don't die on sigint

    FILE * fd_sig = fdopen(5, "r"); // get signals to read from fd5
    if(!fd_sig)
        exit(0);

    FILE * fd_out = fdopen(6, "w"); // output lines on fd6
    if(!fd_out)
        exit(0);

    if(argc > 1) // load the prompt if available
        prompt = argv[1];

    do 
    {
        read_command(fd_sig, fd_out);
    } while(command);
 
    free(command);
    command = NULL;
    fclose(fd_sig);
    fclose(fd_out);

    write_history(history_file);
    return 0;
}
Exemplo n.º 17
0
void
cli_context_loop (cli_context_t *ctx, gint argc, gchar **argv)
{
	/* Execute command, if connection status is ok */
	if (argc == 0) {
		gchar *filename = configuration_get_string (ctx->config, "HISTORY_FILE");

		ctx->mode = CLI_EXECUTION_MODE_SHELL;

		/* print welcome message before initialising readline */
		if (configuration_get_boolean (ctx->config, "SHELL_START_MESSAGE")) {
			g_printf (_("Welcome to the XMMS2 CLI shell!\n"));
			g_printf (_("Type 'help' to list the available commands "
			            "and 'exit' (or CTRL-D) to leave the shell.\n"));
		}
		readline_resume (ctx);

		read_history (filename);
		using_history ();

		while (!cli_context_in_status (ctx, CLI_ACTION_STATUS_FINISH)) {
			cli_context_event_loop_select (ctx);
		}

		write_history (filename);
	} else {
		ctx->mode = CLI_EXECUTION_MODE_INLINE;
		cli_context_command_or_flag_dispatch (ctx, argc , argv);

		while (cli_context_in_status (ctx, CLI_ACTION_STATUS_BUSY) ||
		       cli_context_in_status (ctx, CLI_ACTION_STATUS_REFRESH)) {
			cli_context_event_loop_select (ctx);
		}
	}
}
Exemplo n.º 18
0
/*
 * Use globals:
 *
 *	- char *histfile_name (also sets this)
 *      - char *last_in_history (allocates it)
 */
static int
linphonec_initialize_readline()
{
	/*rl_bind_key('\t', rl_insert);*/

	/* Allow conditional parsing of ~/.inputrc */
	rl_readline_name = "linphonec";

	/* Call idle_call() every second */
	rl_set_keyboard_input_timeout(LPC_READLINE_TIMEOUT);
	rl_event_hook=linphonec_idle_call;

	/* Set history file and read it */
	histfile_name = ms_strdup_printf ("%s/.linphonec_history",
		getenv("HOME"));
	read_history(histfile_name);

	/* Initialized last_in_history cache*/
	last_in_history[0] = '\0';

	/* Register a completion function */
	rl_attempted_completion_function = linephonec_readline_completion;

	/* printf("Readline initialized.\n"); */
        setlinebuf(stdout);
	return 0;
}
Exemplo n.º 19
0
//------------------------------------------------------------------------------
static void load_history()
{
    char buffer[1024];
    get_history_file_name(buffer, sizeof(buffer));
    read_history(buffer);
    history_set_pos(history_length);
}
Exemplo n.º 20
0
int main(int argc, char *argv[]) {

    if(argc <= 1){
        show_usage();
        return 0;
    }

    //surpress stderr, because dblib.c display ugly error message
    freopen("/dev/null", "w", stderr);
 
    dbinfo = (struct dbconfig *)malloc(sizeof(struct dbconfig));
    if (!set_cmd_option( argc, argv, dbinfo)){
        return 0;
    }
    if (!connect_db(dbinfo)){
        return 0;
    }

    //set hisotry file path
    history_file = (char *)malloc(256);
    strcpy(history_file, getenv("HOME"));
    strcat(history_file, MSSQL_HISTORY_FILE_NAME);
    read_history(history_file); //read history for incremental search (ctrl + r)

    rl_startup_hook = my_startup; //set up readline with original method binding
    my_readline();
}
Exemplo n.º 21
0
int cli_init(struct parser_state *_state)
{
	const char *home;

	rl_readline_name = "nft";
	rl_instream  = stdin;
	rl_outstream = stdout;

	rl_callback_handler_install("nft> ", cli_complete);
	rl_attempted_completion_function = cli_completion;

	home = getenv("HOME");
	if (home == NULL)
		home = "";
	snprintf(histfile, sizeof(histfile), "%s/%s", home, CMDLINE_HISTFILE);

	read_history(histfile);
	history_set_pos(history_length);

	state	= _state;
	scanner = scanner_init(state);

	while (!eof)
		rl_callback_read_char();
	return 0;
}
Exemplo n.º 22
0
void shellHistoryInit(){
#ifdef USE_READLINE
    using_history();
    read_history( ".dbshell" );
#else
    cout << "type \"exit\" to exit" << endl;
#endif
}
Exemplo n.º 23
0
static PyObject *
read_history_file(PyObject *self, PyObject *args)
{
    PyObject *filename_obj = Py_None, *filename_bytes;
    if (!PyArg_ParseTuple(args, "|O:read_history_file", &filename_obj))
        return NULL;
    if (filename_obj != Py_None) {
        if (!PyUnicode_FSConverter(filename_obj, &filename_bytes))
            return NULL;
        errno = read_history(PyBytes_AsString(filename_bytes));
        Py_DECREF(filename_bytes);
    } else
        errno = read_history(NULL);
    if (errno)
        return PyErr_SetFromErrno(PyExc_IOError);
    Py_RETURN_NONE;
}
Exemplo n.º 24
0
static int f_read_history(lua_State *L)
{
	const char* file = lua_tostring(L,1);
	if(read_history(file) != 0)
		luaL_error(L, "reading history from file %s failed", file);
	lua_pushboolean(L, 1);
	return 1;
}
Exemplo n.º 25
0
bool ReadLineEditor::Open() {
  rl_initialize();
  rl_attempted_completion_function = AttemptedCompletion;
  rl_completer_word_break_characters = kWordBreakCharacters;
  rl_bind_key('\t', rl_complete);
  using_history();
  return read_history(Shell::kHistoryFileName) == 0;
}
Exemplo n.º 26
0
void readline_load_history(void) {
#ifndef WIN32
	char line[1024];
	
	strcpy(line,getenv("HOME"));
	strcat(line,"/.xilprg_history");
	read_history(line);
#endif
}
Exemplo n.º 27
0
/**
 * A simple ASON REPL shell.
 **/
int
main(void)
{
	ason_ns_t *ns = ason_ns_create(ASON_NS_RAM, "");
	char *line;
	ason_t *value;
	wordexp_t exp;

	if (wordexp("~/.asonq", &exp, 0))
		errx(1, "Could not perform shell expansion");

	if (! ns)
		errx(1, "Could not create namespace");

	using_history();
	read_history(exp.we_wordv[0]);

	for (;;) {
		line = readline("> ");

		if (! line) {
			printf("\n");
			break;
		}

		if (! *line) {
			free(line);
			continue;
		}

		add_history(line);
		write_history(exp.we_wordv[0]);

		if (command(line, ns)) {
			free(line);
			continue;
		}

		value = ason_ns_read(ns, line);

		free(line);

		if (! value) {
			printf("Syntax Error\n");
			continue;
		}

		line = ason_asprint_unicode(value);

		if (! line)
			errx(1, "Could not serialize value");

		printf("%s\n", line);
		free(line);
	}
}
Exemplo n.º 28
0
void attribute_hidden Rstd_read_history(const char *s)
{
#ifdef HAVE_LIBREADLINE
# ifdef HAVE_READLINE_HISTORY_H
    if(R_Interactive && UsingReadline) {
	read_history(s);
    }
# endif /* HAVE_READLINE_HISTORY_H */
#endif /* HAVE_LIBREADLINE */
}
Exemplo n.º 29
0
GNUReadlineUI::GNUReadlineUI(const std::string & histfile)
  :
  UI(),
  m_histfile(histfile)
{
  rl_set_signals();
  rl_cleanup_after_signal();
  using_history();
  read_history(m_histfile.c_str());
}
Exemplo n.º 30
0
static PyObject *
read_history_file(PyObject *self, PyObject *args)
{
	char *s = NULL;
	if (!PyArg_ParseTuple(args, "|z:read_history_file", &s))
		return NULL;
	errno = read_history(s);
	if (errno)
		return PyErr_SetFromErrno(PyExc_IOError);
	Py_RETURN_NONE;
}