Example #1
0
void linenoise_cleanup( int id )
{
	int j;

#ifdef LINENOISE_AUTOSAVE_FNAME
	if( id == LINENOISE_ID_LUA ) {
		if( linenoise_savehistory( id, LINENOISE_AUTOSAVE_FNAME ) == 0 )
			printf( "History saved to %s.\n", LINENOISE_AUTOSAVE_FNAME );
		else
			printf( "Unable to save history to %s.\n", LINENOISE_AUTOSAVE_FNAME );
	}
#endif
	if( histories[ id ] ) {
		for( j = 0; j < history_lengths[ id ]; j++ )
			free( histories[ id ][ j ] );
		free( histories[ id ] );
		histories[ id ] = NULL;
	}
	history_lengths[ id ] = 0;
}
Example #2
0
// Lua: elua.save_history( filename )
// Only available if linenoise support is enabled
static int elua_save_history( lua_State *L )
{
#ifdef BUILD_LINENOISE
  const char* fname = luaL_checkstring( L, 1 );
  int res;
  
  res = linenoise_savehistory( LINENOISE_ID_LUA, fname );
  if( res == 0 )
    printf( "History saved to %s.\n", fname );
  else if( res == LINENOISE_HISTORY_NOT_ENABLED )
    printf( "linenoise not enabled for Lua.\n" );
  else if( res == LINENOISE_HISTORY_EMPTY )
    printf( "History empty, nothing to save.\n" );
  else
    printf( "Unable to save history to %s.\n", fname );
  return 0;  
#else // #ifdef BUILD_LINENOISE
  return luaL_error( L, "linenoise support not enabled." );
#endif // #ifdef BUILD_LINENOISE
}
Example #3
0
File: picoc.c Project: fjrti/remix
/* picoc: picoc_save_history(filename). only available if linenoise is enabled */
static void picoc_save_history(struct ParseState *Parser, struct Value *ReturnValue,
			struct Value **Param, int NumArgs)
{
#ifdef BUILD_LINENOISE
	const char *fname = Param[0]->Val->Identifier;
	int res;
  
	res = linenoise_savehistory(LINENOISE_ID_PICOC, fname);
	if (res == 0)
		printf("History saved to %s.\n", fname);
	else if (res == LINENOISE_HISTORY_NOT_ENABLED)
		printf("Linenoise not enabled for picoc.\n");
	else if (res == LINENOISE_HISTORY_EMPTY)
		printf("History empty, nothing to save.\n");
	else
		printf("Unable to save history to %s.\n", fname);
	ReturnValue->Val->Integer = 0;
#else
	ProgramFail(NULL, "Linenoise support was not enabled.");
	ReturnValue->Val->Integer = -1;
#endif	/* #ifdef BUILD_LINENOISE */
}