Esempio n. 1
0
int main(){
	history_remove();
	history_load();
	history_add(__T("abcd"));
	assert( _tcscmp(history_get(0),__T("abcd"))==0 );
	history_add(__T("qwerrr"));
	assert( _tcscmp(history_get(0),__T("qwerrr"))==0 );
	history_add(__T("zxcv"));
	assert( _tcscmp(history_get(0),__T("zxcv"))==0 );
	history_save();
	history_load();
	history_add(__T("zxcv1"));
	assert( _tcscmp(history_get(0),__T("zxcv1"))==0 );
	assert( _tcscmp(history_get(1),__T("zxcv"))==0 );
	assert( _tcscmp(history_get(2),__T("qwerrr"))==0 );
	assert( _tcscmp(history_get(3),__T("abcd"))==0 );
	history_delete(1);
	history_save();
	history_load();
	assert( _tcscmp(history_get(0),__T("zxcv1"))==0 );
	assert( _tcscmp(history_get(1),__T("zxcv"))!=0 );
	assert( _tcscmp(history_get(2),__T("qwerrr"))==0 );
	assert( _tcscmp(history_get(3),__T("abcd"))==0 );
	history_pin(2);
	check_ni_wi();
	history_add(__T("asdff"));
	history_add(__T("asdfff"));
	history_add(__T("asdffff"));
	assert( _tcscmp(history_get(0),__T("asdffff"))==0 );
	assert( _tcscmp(history_get(1),__T("asdfff"))==0 );
	assert( _tcscmp(history_get(2),__T("qwerrr"))==0 );
	assert( _tcscmp(history_get(3),__T("asdff"))==0 );
	history_pin(3);
	check_ni_wi();
	history_unpin(2);
	check_ni_wi();
	history_pin(11);
	history_pin(13);
	check_ni_wi();
	history_pin(5);
	history_pin(6);
	check_ni_wi();
	history_delete(4);
	history_delete(5);
	check_ni_wi();
	{
		TCHAR buffer[VIEW_HISTORY*MAX_PATH];
		int len = history_to_json(buffer);
		buffer[len+1] = __T('\0');
		_tprintf(__T("\n%d,%s\n"),len,buffer);
	}
	return 0;
}
Esempio n. 2
0
static void
history_shift(Rune c, void* f, int n){
	if(n){
		history_save();
		history_advance(n);
	}
	history_load();
}
Esempio n. 3
0
void history_default(void)
{
  int i;
  for(i=0; i < NUM_HISTORY_ENTRIES; i++)
    memset(&history.entries[i], 0, sizeof(t_history_entry));

  /* restore history */
  history_load();
}
Esempio n. 4
0
void history_first()
{
    if( current_mode )
    {
        if( !current_mode->has_loaded )
        {
            history_load( current_mode );
        }

        current_mode->pos = 0;
    }
}
Esempio n. 5
0
input_state* input_init(void) {
	input_state *input;

	input = malloc(sizeof(input_state));
	input->history_current =
		input->history_first = NULL;
	input->cursor = 0;

	history_load(input);
	history_add(input);

	set_attr(input);
	reset_term(input, false);

	return input;
}
Esempio n. 6
0
static void
flush_line(Rune c, void* f, int v){
	if(pty_mode || f == NULL){
		append_character(v);
	}else{
		(*(void(*)(int)) f)(v);
	}
	cursor_shift(-cursor);
	erase_line();
	fflush(stderr);
	render(stdout, line->buf, utf8_of_rune);
	fflush(stdout);
	if(pty_mode || f == NULL) line->buf->c--; /* FIXME! store history without the flushing character! */
	hist_cur = hist_len - 1;
	history_save();
	if(--lines <= 0) exit(0);
	history_add();
	history_load();
}
Esempio n. 7
0
File: history.c Progetto: BrEacK/mc
GList *
history_get (const char *input_name)
{
    GList *hist = NULL;
    char *profile;
    mc_config_t *cfg;

    if (num_history_items_recorded == 0)        /* this is how to disable */
        return NULL;
    if ((input_name == NULL) || (*input_name == '\0'))
        return NULL;

    profile = mc_config_get_full_path (MC_HISTORY_FILE);
    cfg = mc_config_init (profile);

    hist = history_load (cfg, input_name);

    mc_config_deinit (cfg);
    g_free (profile);

    return hist;
}
Esempio n. 8
0
wchar_t *history_get( int idx )
{
    int len;

    if( !current_mode )
        return 0;

    len = al_get_count( &current_mode->item );

    if( (idx >= len ) && !current_mode->has_loaded )
    {
        history_load( current_mode );
        len = al_get_count( &current_mode->item );
    }

    if( idx < 0 )
        return 0;

    if( idx >= len )
        return 0;

    return item_get( current_mode, al_get( &current_mode->item, len - 1 - idx ) )->data;
}
Esempio n. 9
0
/* main loop, parse lines into trees and execute them
 * ----------------------------------------------------------------------- */
void sh_loop(void) {
  struct parser p;
  union node *list;
  stralloc cmd;

  /* if we're in interactive mode some 
     additional stuff is to be initialized */
  if(source->mode & SOURCE_IACTIVE)
    history_load();
  
  stralloc_init(&cmd);

  parse_init(&p, P_DEFAULT);
  
  while(!(parse_gettok(&p, P_DEFAULT) & T_EOF)) {
    p.pushback++;
    parse_lineno = source->line;

    var_setvint("LINENO", parse_lineno, V_DEFAULT);
    
    /* launch the parser to get a complete command */
    if((list = parse_list(&p)))
    {
      struct eval e;
      
      if(source->mode & SOURCE_IACTIVE)
      {
        tree_printlist(list, &cmd, NULL);
        stralloc_catc(&cmd, '\n');
        stralloc_nul(&cmd);
        history_set(cmd.s);
        cmd.s = NULL;
        history_advance();
      }

#ifdef DEBUG
/*      debug_list(list, 0);
      buffer_putnlflush(fd_err->w);*/
#endif /* DEBUG */
      eval_push(&e, E_JCTL);
      eval_tree(&e, list, E_ROOT|E_LIST);
      sh->exitcode = eval_pop(&e);
      
      stralloc_zero(&cmd);

      tree_free(list);
    } else if(!(p.tok & (T_NL | T_SEMI | T_BGND))) {
      /* we have a parse error */
      if(p.tok != T_EOF)
        parse_error(&p, 0);

      /* exit if not interactive */
      if(!(source->mode & SOURCE_IACTIVE))
        sh_exit(1);

      /* ..otherwise discard the input buffer */
      source_flush();
      p.pushback = 0;
    }
    
    if(p.tok & (T_NL|T_SEMI|T_BGND))
      p.pushback = 0;

    /* reset prompt */
    prompt_number = 0;
  }
}
Esempio n. 10
0
int main (int argc, char *argv[])
{
#ifdef HW_RVL
  /* initialize DVD device */
  DI_Init();
#endif

  u16 usBetweenFrames;
  long long now, prev;
  
  /* Initialize OGC subsystems */
  ogc_video__init();
  ogc_input__init();
  ogc_audio__init();

#ifdef HW_DOL
  /* Initialize GC DVD interface */
  DVD_Init ();
  dvd_drive_detect();
#endif

#ifdef HW_RVL
  /* Power Button callback */
  SYS_SetPowerCallback(Power_Off);
#endif

  /* Initialize FAT Interface */
  if (fatInitDefault() == true)
  {
    fat_enabled = 1;
  }

  /* Default Config */
  legal();
  set_option_defaults ();
  config_load();
#ifdef HW_RVL
  /* Load SMB Settings */
  loadSettings();
#endif

  /* Restore Recent Files list */
  set_history_defaults();
  history_load();

  /* Initialize Virtual Machine */
  init_machine ();

  /* Show Menu */
  MainMenu();
  ConfigRequested = 0;

  /* Initialize Frame timings */
  frameticker = 0;
  usBetweenFrames = sms.display ? 20000 : 16666;
  prev = gettime();

  /* Emulation Loop */
  while (1)
  {
    /* update inputs */
    ogc_input__update();

    /* Frame synchronization */
    if (gc_pal != sms.display)
    {
      /* use timers */
      now = gettime();
      if (diff_usec(prev, now) > usBetweenFrames)
      {
        /* Frame skipping */
        prev = now;
        system_frame(1);
      }
      else
      {
        /* Delay */
        while (diff_usec(prev, now) < usBetweenFrames) now = gettime();

        /* Render Frame */
        prev = now;
        system_frame(0);
      }
    }
    else
    {
      /* use VSync */
      if (frameticker > 1)
      {
        /* Frame skipping */
        frameticker--;
        system_frame (1);
      }
      else
      {
        /* Delay */
        while (!frameticker) usleep(10);  
        
        system_frame (0);
      }

      frameticker--;
    }

    /* update video & audio */
    ogc_video__update();
    ogc_audio__update();

    /* Check for Menu request */
    if (ConfigRequested)
    {
      /* reset AUDIO */
      ogc_audio__reset();

      /* go to menu */
      MainMenu ();
      ConfigRequested = 0;
      ogc_video__reset();

      /* reset frame timings */
      frameticker = 0;
      usBetweenFrames = sms.display ? 20000 : 16666;
      prev = gettime();
    }
  }
  return 0;
}
Esempio n. 11
0
File: main.c Progetto: nich2000/ncs
//==============================================================================
int main(int argc, char *argv[])
{
  //---------------------------------------------------------------------------
  #ifdef USE_PYTHON_APP
  exec_interactive_interpreter(argc, argv);
  #endif
  //---------------------------------------------------------------------------
  if(argc > 1)
  {
    if((strcmp(argv[1], CMD_S_VERSION) == 0) || ((strcmp(argv[1], CMD_VERSION) == 0)))
    {
      print_version();
      return 0;
    }
    if((strcmp(argv[1], CMD_S_HELP) == 0) || ((strcmp(argv[1], CMD_HELP) == 0)))
    {
      print_help(1);
      return 0;
    }
    if((strcmp(argv[1], CMD_S_CONFIG) == 0) || ((strcmp(argv[1], CMD_CONFIG) == 0)))
    {
      if(read_config() >= ERROR_WARNING)
        log_add_fmt(LOG_ERROR, "main,\nmessage: %s",
                    last_error()->message);
      print_config();
      return 0;
    }
  }
  //---------------------------------------------------------------------------
  print_version();
  //---------------------------------------------------------------------------
  if(read_config() >= LOG_ERROR)
    log_add_fmt(LOG_ERROR, "main,\nmessage: %s",
                last_error()->message);
  print_config();
  //---------------------------------------------------------------------------
  log_add(LOG_INFO, "application started");
  log_add(LOG_INFO, "-------------------");
  //---------------------------------------------------------------------------
  if(sock_init() >= ERROR_NORMAL)
    goto exit;
  //---------------------------------------------------------------------------
  #ifdef USE_PYTHON
  if(py_init() >= ERROR_NORMAL)
    goto exit;
  #endif
  //---------------------------------------------------------------------------
  #ifdef PI_DEVICE
  if(gpio_init() >= ERROR_NORMAL)
    goto exit;
  #endif
  //---------------------------------------------------------------------------
  char command[256];
  if(argc > 1)
  {
    // Read params
    for(int i = 1; i < argc; i++)
    {
      if((strcmp(argv[i], PARAM_S_PORT) == 0) || ((strcmp(argv[i], PARAM_PORT) == 0)))
      {
        cmd_server_port = atoi(argv[++i]);
      }
      else if((strcmp(argv[i], PARAM_S_WEB_PORT) == 0) || ((strcmp(argv[i], PARAM_WEB_PORT) == 0)))
      {
        web_server_port = atoi(argv[++i]);
      }
      else if((strcmp(argv[i], PARAM_S_WS_PORT) == 0) || ((strcmp(argv[i], PARAM_WS_PORT) == 0)))
      {
        ws_server_port = atoi(argv[++i]);
      }
      else if((strcmp(argv[i], PARAM_S_HOST) == 0) || ((strcmp(argv[i], PARAM_HOST) == 0)))
      {
        strcpy((char*)cmd_server_host, argv[++i]);
      }
      else if((strcmp(argv[i], PARAM_S_COUNT) == 0) || ((strcmp(argv[i], PARAM_COUNT) == 0)))
      {
        cmd_clients_count = atoi(argv[++i]);
      }
    }
    // Read cmd
    for(int i = 1; i < argc; i++)
    {
      if((strcmp(argv[i], CMD_S_ALL) == 0) || ((strcmp(argv[i], CMD_ALL) == 0)))
      {
        strcpy(command, CMD_ALL);
      }
      else if((strcmp(argv[i], CMD_S_SERVER) == 0) || ((strcmp(argv[i], CMD_SERVER) == 0)))
      {
        strcpy(command, CMD_SERVER);
      }
      else if((strcmp(argv[i], CMD_S_WEB_SERVER) == 0) || ((strcmp(argv[i], CMD_WEB_SERVER) == 0)))
      {
        strcpy(command, CMD_WEB_SERVER);
      }
      else if((strcmp(argv[i], CMD_S_WS_SERVER) == 0) || ((strcmp(argv[i], CMD_WS_SERVER) == 0)))
      {
        strcpy(command, CMD_WS_SERVER);
      }
      else if((strcmp(argv[i], CMD_S_CLIENT) == 0) || ((strcmp(argv[i], CMD_CLIENT) == 0)))
      {
        strcpy(command, CMD_CLIENT);
      }
    }

    handle_command_str(NULL, command);
  }
  //---------------------------------------------------------------------------
  if(history_load() >= ERROR_NORMAL)
    log_add_fmt(LOG_ERROR, "main,\nmessage: %s",
                last_error()->message);
  log_add(LOG_INFO, "command mode");
  //---------------------------------------------------------------------------
  strcpy(command, "\0");
  while(TRUE)
  {
//    char ch = getcode();
//    if(ch == '\033')
//    {
//      getchar(); // skip the [
//      ch = getchar();
//      switch(ch)
//      {
//        case 'A': // arrow up
//        {
//          strcpy(command, history_prev());
//          break;
//        }
//        case 'B': // arrow down
//        {
//          strcpy(command, history_next());
//          break;
//        }
//      }
//      if(strlen(command) != 0)
//      {
//        printf("%s\n", command);
//        continue;
//      }
//    }

//    if(strlen(command) == 0)
//    {
//      printf("manual input\n");
      fgets(command, sizeof(command), stdin);
      history_add(command);
//    };

    switch(handle_command_str(NULL, command))
    {
      case EXEC_NONE:
      {
        make_last_error(ERROR_NONE, errno, "exit by user command");
        goto exit;
      }
      case EXEC_UNKNOWN:
        log_add_fmt(LOG_CMD, "unknown command: %s",
                    command);
        break;
      case EXEC_DONE:
        log_add_fmt(LOG_CMD, "done command: %s",
                    command);
        break;
    }
    strcpy(command, "\0");
  }
  //---------------------------------------------------------------------------
  exit:
  sock_deinit();
  #ifdef PI_DEVICE
  gpio_close();
  #endif
  //---------------------------------------------------------------------------
  #ifdef USE_PYTHON
  py_final();
  #endif
  //---------------------------------------------------------------------------
  log_add_fmt(LOG_INFO, "application finished, result: %s\n", last_error()->message);
  //---------------------------------------------------------------------------
  return 0;
  //---------------------------------------------------------------------------
}
Esempio n. 12
0
const wchar_t *history_prev_match( const wchar_t *needle )
{
    if( current_mode )
    {
        if( current_mode->pos > 0 )
        {
            for( current_mode->pos--; current_mode->pos>=0; current_mode->pos-- )
            {
                item_t *i = item_get( current_mode, al_get( &current_mode->item, current_mode->pos ) );
                wchar_t *haystack = (wchar_t *)i->data;

                if( history_test( needle, haystack ) )
                {
                    int is_used;

                    /*
                      This is ugly.  Whenever we call item_get(),
                      there is a chance that the return value of any
                      previous call to item_get will become
                      invalid. The history_is_used function uses the
                      item_get() function. Therefore, we must create
                      a copy of the haystack string, and if the string
                      is unused, we must call item_get anew.
                    */

                    haystack = wcsdup(haystack );

                    is_used = history_is_used( haystack );

                    free( haystack );

                    if( !is_used )
                    {
                        i = item_get( current_mode, al_get( &current_mode->item, current_mode->pos ) );
                        al_push_long( &current_mode->used, current_mode->pos );
                        return i->data;
                    }
                }
            }
        }

        if( !current_mode->has_loaded )
        {
            /*
              We found no match in the list, try loading the history
              file and continue the search
            */
            history_load( current_mode );
            return history_prev_match( needle );
        }
        else
        {
            /*
              We found no match in the list, and the file is already
              loaded. Set poition before first element and return
              original search string.
            */
            current_mode->pos=-1;
            if( al_peek_long( &current_mode->used ) != -1 )
                al_push_long( &current_mode->used, -1 );
        }

    }

    return needle;
}
Esempio n. 13
0
/**
   Save the specified mode to file
*/
static void history_save_mode( void *n, history_mode_t *m )
{
    FILE *out;
    history_mode_t *on_disk;
    int i;
    int has_new=0;
    wchar_t *tmp_name;

    int ok = 1;

    /*
      First check if there are any new entries to save. If not, then
      we can just return
    */
    for( i=0; i<al_get_count(&m->item); i++ )
    {
        void *ptr = al_get( &m->item, i );
        has_new = item_is_new( m, ptr );
        if( has_new )
        {
            break;
        }
    }

    if( !has_new )
    {
        return;
    }

    signal_block();

    /*
      Set up on_disk variable to describe the current contents of the
      history file
    */
    on_disk = history_create_mode( m->name );
    history_load( on_disk );

    tmp_name = history_filename( on_disk, m->name, L".tmp" );

    if( tmp_name )
    {
        tmp_name = wcsdup(tmp_name );

        if( (out=wfopen( tmp_name, "w" ) ) )
        {
            hash_table_t mine;

            hash_init( &mine, &hash_item_func, &hash_item_cmp );

            for( i=0; i<al_get_count(&m->item); i++ )
            {
                void *ptr = al_get( &m->item, i );
                int is_new = item_is_new( m, ptr );
                if( is_new )
                {
                    hash_put( &mine, item_get( m, ptr ), L"" );
                }
            }

            /*
              Re-save the old history
            */
            for( i=0; ok && (i<al_get_count(&on_disk->item)); i++ )
            {
                void *ptr = al_get( &on_disk->item, i );
                item_t *i = item_get( on_disk, ptr );
                if( !hash_get( &mine, i ) )
                {
                    if( item_write( out, on_disk, ptr ) == -1 )
                    {
                        ok = 0;
                        break;
                    }
                }

            }

            hash_destroy( &mine );

            /*
              Add our own items last
            */
            for( i=0; ok && (i<al_get_count(&m->item)); i++ )
            {
                void *ptr = al_get( &m->item, i );
                int is_new = item_is_new( m, ptr );
                if( is_new )
                {
                    if( item_write( out, m, ptr ) == -1 )
                    {
                        ok = 0;
                    }
                }
            }

            if( fclose( out ) || !ok )
            {
                /*
                  This message does not have high enough priority to
                  be shown by default.
                */
                debug( 2, L"Error when writing history file" );
            }
            else
            {
                wrename( tmp_name, history_filename( on_disk, m->name, 0 ) );
            }
        }
        free( tmp_name );
    }

    halloc_free( on_disk);

    if( ok )
    {

        /*
          Reset the history. The item_t entries created in this session
          are not lost or dropped, they are stored in the session_item
          hash table. On reload, they will be automatically inserted at
          the end of the history list.
        */

        if( m->mmap_start && (m->mmap_start != MAP_FAILED ) )
        {
            munmap( m->mmap_start, m->mmap_length );
        }

        al_truncate( &m->item, 0 );
        al_truncate( &m->used, 0 );
        m->pos = 0;
        m->has_loaded = 0;
        m->mmap_start=0;
        m->mmap_length=0;

        m->save_timestamp=time(0);
        m->new_count = 0;
    }

    signal_unblock();
}
Esempio n. 14
0
File: main.c Progetto: huynhrene/dex
int main(int argc, char *argv[])
{
	const char *term = getenv("TERM");
	const char *home = getenv("HOME");
	const char *tag = NULL;
	const char *rc = NULL;
	const char *command = NULL;
	char *command_history_filename;
	char *search_history_filename;
	char *editor_dir;
	bool read_rc = true;
	int i;

	if (!home)
		home = "";
	home_dir = xstrdup(home);

	for (i = 1; i < argc; i++) {
		const char *opt = argv[i];

		if (opt[0] != '-' || !opt[1])
			break;
		if (!opt[2]) {
			switch (opt[1]) {
			case 'R':
				read_rc = false;
				continue;
			case 't':
				tag = opt_arg(opt, argv[++i]);
				continue;
			case 'r':
				rc = opt_arg(opt, argv[++i]);
				continue;
			case 'c':
				command = opt_arg(opt, argv[++i]);
				continue;
			case 'V':
				printf("%s %s\nWritten by Timo Hirvonen\n", program, version);
				return 0;
			}
			if (opt[1] == '-') {
				i++;
				break;
			}
		}
		printf("Usage: %s [-R] [-V] [-c command] [-t tag] [-r rcfile] [file]...\n", argv[0]);
		return 1;
	}

	if (!isatty(1)) {
		fprintf(stderr, "stdout doesn't refer to a terminal\n");
		return 1;
	}
	if (term == NULL || term[0] == 0) {
		fprintf(stderr, "TERM not set\n");
		return 1;
	}
	switch (term_init(term)) {
	case -1:
		fprintf(stderr, "terminal is hardcopy\n");
		return 1;
	case -2:
		fprintf(stderr, "terminal could not be found\n");
		return 1;
	case -3:
		fprintf(stderr, "terminfo database could not be found\n");
		return 1;
	}

	// create this early. needed if lock-files is true
	editor_dir = editor_file("");
	mkdir(editor_dir, 0755);
	free(editor_dir);

	setlocale(LC_CTYPE, "");
	charset = nl_langinfo(CODESET);
	if (streq(charset, "UTF-8"))
		term_utf8 = true;

	exec_builtin_rc(builtin_rc);
	fill_builtin_colors();

	// NOTE: syntax_changed() uses window. should possibly create window after reading rc
	window = new_window();
	root_frame = new_root_frame(window);

	if (read_rc) {
		if (rc) {
			read_config(commands, rc, true);
		} else {
			char *filename = editor_file("rc");
			if (read_config(commands, filename, false)) {
				free(filename);
				filename = xsprintf("%s/rc", pkgdatadir);
				read_config(commands, filename, true);
			}
			free(filename);
		}
	}

	update_all_syntax_colors();
	sort_aliases();

	/* Terminal does not generate signals for control keys. */
	set_signal_handler(SIGINT, SIG_IGN);
	set_signal_handler(SIGQUIT, SIG_IGN);
	set_signal_handler(SIGPIPE, SIG_IGN);

	/* Terminal does not generate signal for ^Z but someone can send
	 * us SIGTSTP nevertheless. SIGSTOP can't be caught.
	 */
	set_signal_handler(SIGTSTP, handle_sigtstp);

	set_signal_handler(SIGCONT, handle_sigcont);
	set_signal_handler(SIGWINCH, handle_sigwinch);

	load_file_history();
	command_history_filename = editor_file("command-history");
	search_history_filename = editor_file("search-history");
	history_load(&command_history, command_history_filename, command_history_size);
	history_load(&search_history, search_history_filename, search_history_size);
	if (search_history.count)
		search_set_regexp(search_history.ptrs[search_history.count - 1]);

	/* Initialize terminal but don't update screen yet.  Also display
	 * "Press any key to continue" prompt if there were any errors
	 * during reading configuration files.
	 */
	term_raw();
	if (nr_errors) {
		any_key();
		clear_error();
	}

	editor_status = EDITOR_RUNNING;

	for (; i < argc; i++)
		window_open_buffer(window, argv[i], false, NULL);
	if (window->views.count == 0)
		window_open_empty_buffer(window);
	set_view(window->views.ptrs[0]);

	if (command || tag)
		resize();

	if (command)
		handle_command(commands, command);
	if (tag) {
		PTR_ARRAY(array);
		ptr_array_add(&array, xstrdup("tag"));
		ptr_array_add(&array, xstrdup(tag));
		ptr_array_add(&array, NULL);
		run_commands(commands, &array);
		ptr_array_free(&array);
	}
	resize();
	main_loop();
	ui_end();

	// unlock files and add files to file history
	remove_frame(root_frame);

	history_save(&command_history, command_history_filename);
	history_save(&search_history, search_history_filename);
	free(command_history_filename);
	free(search_history_filename);
	save_file_history();
	return 0;
}