Esempio n. 1
0
int
rl_vi_yank_to(int count, int key)
{
  int c, save = rl_point;

  if (_rl_uppercase_p (key))
    rl_stuff_char ('$');

  if (rl_vi_domove (key, &c))
    {
      rl_ding ();
      return -1;
    }

  /* These are the motion commands that do not require adjusting the
     mark. */
  if ((strchr (" l|h^0%bB", c) == 0) && (rl_mark < rl_end))
    rl_mark++;

  rl_begin_undo_group ();
  rl_kill_text (rl_point, rl_mark);
  rl_end_undo_group ();
  rl_do_undo ();
  rl_point = save;

  return (0);
}
Esempio n. 2
0
int
rl_vi_delete(int count, int key)
{
  int end;

  if (rl_end == 0)
    {
      rl_ding ();
      return -1;
    }

  if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
    end = _rl_find_next_mbchar (rl_line_buffer, rl_point, count, MB_FIND_NONZERO);
  else
    end = rl_point + count;

  if (end >= rl_end)
    end = rl_end;

  rl_kill_text (rl_point, end);

  if (rl_point > 0 && rl_point == rl_end)
    rl_backward_char (1, key);
  return (0);
}
Esempio n. 3
0
File: misc.c Progetto: bminor/bash
/* What to do when you abort reading an argument. */
int
rl_discard_argument (void)
{
  rl_ding ();
  rl_clear_message ();
  _rl_reset_argument ();

  return 0;
}
Esempio n. 4
0
File: util.c Progetto: bminor/bash
int
rl_tty_status (int count, int key)
{
#if defined (TIOCSTAT)
  ioctl (1, TIOCSTAT, (char *)0);
  rl_refresh_line (count, key);
#else
  rl_ding ();
#endif
  return 0;
}
Esempio n. 5
0
int
rl_vi_change_to(int count, int key)
{
  int c, start_pos;

  if (_rl_uppercase_p (key))
    rl_stuff_char ('$');
  else if (vi_redoing)
    rl_stuff_char (_rl_vi_last_motion);

  start_pos = rl_point;

  if (rl_vi_domove (key, &c))
    {
      rl_ding ();
      return -1;
    }

  /* These are the motion commands that do not require adjusting the
     mark.  c[wW] are handled by special-case code in rl_vi_domove(),
     and already leave the mark at the correct location. */
  if ((strchr (" l|hwW^0bB", c) == 0) && (rl_mark < rl_end))
    rl_mark++;

  /* The cursor never moves with c[wW]. */
  if ((_rl_to_upper (c) == 'W') && rl_point < start_pos)
    rl_point = start_pos;

  if (vi_redoing)
    {
      if (vi_insert_buffer && *vi_insert_buffer)
	rl_begin_undo_group ();
      rl_delete_text (rl_point, rl_mark);
      if (vi_insert_buffer && *vi_insert_buffer)
	{
	  rl_insert_text (vi_insert_buffer);
	  rl_end_undo_group ();
	}
    }
  else
    {
      rl_begin_undo_group ();		/* to make the `u' command work */
      rl_kill_text (rl_point, rl_mark);
      /* `C' does not save the text inserted for undoing or redoing. */
      if (_rl_uppercase_p (key) == 0)
        _rl_vi_doing_insert = 1;
      _rl_vi_set_last (key, count, rl_arg_sign);
      rl_vi_insertion_mode (1, key);
    }

  return (0);
}
Esempio n. 6
0
File: misc.c Progetto: bminor/bash
/* Get the previous item out of our interactive history, making it the current
   line.  If there is no previous history, just ding. */
int
rl_get_previous_history (int count, int key)
{
  HIST_ENTRY *old_temp, *temp;

  if (count < 0)
    return (rl_get_next_history (-count, key));

  if (count == 0 || history_list () == 0)
    return 0;

  /* either not saved by rl_newline or at end of line, so set appropriately. */
  if (_rl_history_saved_point == -1 && (rl_point || rl_end))
    _rl_history_saved_point = (rl_point == rl_end) ? -1 : rl_point;

  /* If we don't have a line saved, then save this one. */
  rl_maybe_save_line ();

  /* If the current line has changed, save the changes. */
  rl_maybe_replace_line ();

  temp = old_temp = (HIST_ENTRY *)NULL;
  while (count)
    {
      temp = previous_history ();
      if (temp == 0)
	break;

      old_temp = temp;
      --count;
    }

  /* If there was a large argument, and we moved back to the start of the
     history, that is not an error.  So use the last value found. */
  if (!temp && old_temp)
    temp = old_temp;

  if (temp == 0)
    {
      rl_maybe_unsave_line ();
      rl_ding ();
    }
  else
    {
      rl_replace_from_history (temp, 0);
      _rl_history_set_point ();
    }

  return 0;
}
Esempio n. 7
0
int
_rl_arg_overflow ()
{
  if (rl_numeric_arg > 1000000)
    {
      _rl_argcxt = 0;
      rl_explicit_arg = rl_numeric_arg = 0;
      rl_ding ();
      rl_restore_prompt ();
      rl_clear_message ();
      RL_UNSETSTATE(RL_STATE_NUMERICARG);
      return 1;
    }
  return 0;
}
Esempio n. 8
0
/* Move to the end of the ?next? word. */
int
rl_vi_end_word(int count, int key)
{
  if (count < 0)
    {
      rl_ding ();
      return -1;
    }

  if (_rl_uppercase_p (key))
    rl_vi_eWord (count, key);
  else
    rl_vi_eword (count, key);
  return (0);
}
Esempio n. 9
0
/* A simplified loop for vi. Don't dispatch key at end.
   Don't recognize minus sign?
   Should this do rl_save_prompt/rl_restore_prompt? */
static int
rl_digit_loop1(void)
{
  int key, c;

  RL_SETSTATE(RL_STATE_NUMERICARG);
  while (1)
    {
      if (rl_numeric_arg > 1000000)
	{
	  rl_explicit_arg = rl_numeric_arg = 0;
	  rl_ding ();
	  rl_clear_message ();
	  RL_UNSETSTATE(RL_STATE_NUMERICARG);
	  return 1;
	}
      rl_message ("(arg: %d) ", rl_arg_sign * rl_numeric_arg);
      RL_SETSTATE(RL_STATE_MOREINPUT);
      key = c = rl_read_key ();
      RL_UNSETSTATE(RL_STATE_MOREINPUT);

      if (c >= 0 && _rl_keymap[c].type == ISFUNC &&
	  _rl_keymap[c].function == rl_universal_argument)
	{
	  rl_numeric_arg *= 4;
	  continue;
	}

      c = UNMETA (c);
      if (_rl_digit_p (c))
	{
	  if (rl_explicit_arg)
	    rl_numeric_arg = (rl_numeric_arg * 10) + _rl_digit_value (c);
	  else
	    rl_numeric_arg = _rl_digit_value (c);
	  rl_explicit_arg = 1;
	}
      else
	{
	  rl_clear_message ();
	  rl_stuff_char (key);
	  break;
	}
    }

  RL_UNSETSTATE(RL_STATE_NUMERICARG);
  return (0);
}
Esempio n. 10
0
File: macro.c Progetto: bminor/bash
/* Execute the most recently defined keyboard macro.
   COUNT says how many times to execute it. */
int
rl_call_last_kbd_macro (int count, int ignore)
{
  if (current_macro == 0)
    _rl_abort_internal ();

  if (RL_ISSTATE (RL_STATE_MACRODEF))
    {
      rl_ding ();		/* no recursive macros */
      current_macro[--current_macro_index] = '\0';	/* erase this char */
      return 0;
    }

  while (count--)
    _rl_with_macro_input (savestring (current_macro));
  return 0;
}
Esempio n. 11
0
File: misc.c Progetto: bminor/bash
/* Restore the _rl_saved_line_for_history if there is one. */
int
rl_maybe_unsave_line (void)
{
  if (_rl_saved_line_for_history)
    {
      /* Can't call with `1' because rl_undo_list might point to an undo
	 list from a history entry, as in rl_replace_from_history() below. */
      rl_replace_line (_rl_saved_line_for_history->line, 0);
      rl_undo_list = (UNDO_LIST *)_rl_saved_line_for_history->data;
      _rl_free_history_entry (_rl_saved_line_for_history);
      _rl_saved_line_for_history = (HIST_ENTRY *)NULL;
      rl_point = rl_end;	/* rl_replace_line sets rl_end */
    }
  else
    rl_ding ();
  return 0;
}
Esempio n. 12
0
/* Next word in vi mode. */
int
rl_vi_next_word(int count, int key)
{
  if (count < 0)
    return (rl_vi_prev_word (-count, key));

  if (rl_point >= (rl_end - 1))
    {
      rl_ding ();
      return (0);
    }

  if (_rl_uppercase_p (key))
    rl_vi_fWord (count, key);
  else
    rl_vi_fword (count, key);
  return (0);
}
Esempio n. 13
0
File: util.c Progetto: bminor/bash
/* How to abort things. */
int
_rl_abort_internal (void)
{
  rl_ding ();
  rl_clear_message ();
  _rl_reset_argument ();
  rl_clear_pending_input ();

  RL_UNSETSTATE (RL_STATE_MACRODEF);
  while (rl_executing_macro)
    _rl_pop_executing_macro ();

  RL_UNSETSTATE (RL_STATE_MULTIKEY);	/* XXX */

  rl_last_func = (rl_command_func_t *)NULL;

  _rl_longjmp (_rl_top_level, 1);
  return (0);
}
Esempio n. 14
0
/* Do a vi style search. */
int
rl_vi_search(int count, int key)
{
  switch (key)
    {
    case '?':
      rl_noninc_forward_search (count, key);
      break;

    case '/':
      rl_noninc_reverse_search (count, key);
      break;

    default:
      rl_ding ();
      break;
    }
  return (0);
}
Esempio n. 15
0
File: macro.c Progetto: bminor/bash
int
rl_print_last_kbd_macro (int count, int ignore)
{
  char *m;

  if (current_macro == 0)
    {
      rl_ding ();
      return 0;
    }
  m = _rl_untranslate_macro_value (current_macro, 1);
  rl_crlf ();
  printf ("%s", m);
  fflush (stdout);
  rl_crlf ();
  FREE (m);
  rl_forced_update_display ();
  rl_display_fixed = 1;

  return 0;
}
Esempio n. 16
0
/* Read all of the messages from the transcript since the last read */
static void check_msgs(void)
{
	char msg[MSG_LEN];
	int count;
	fd_set fds;
	int fd;
	struct timeval t;

	/* Timeout of 0. */
	t.tv_sec = 0;
	t.tv_usec = 0;

	/* Does ctrl have data available for reading? */
	FD_ZERO(&fds);
	fd = fileno(ctrl);
	FD_SET(fd, &fds);
	count = select(FD_SETSIZE, &fds, NULL, NULL, &t);

	if(count > 0) {
		/* Go back to the last read point. */
		fseek(ctrl, last_read_pos, SEEK_SET);

		while(fgets(msg, MSG_LEN, ctrl) != NULL) {
			char *str;
			if(str = strstr(msg, ">")) {
				if(strstr(str, nick)) {
					rl_ding();
				}
			}
			print_line(msg);
		}

		/* Update the last read position */
		last_read_pos = ftell(ctrl);

		/* Set the file position at the end of the file */
		fseek(ctrl, 0L, SEEK_END);
	}
}
Esempio n. 17
0
static int
input_complete(int arg UNUSED, int key UNUSED)
{
  static int complete_flag;
  char buf[256];

  if (rl_last_func != input_complete)
    complete_flag = 0;
  switch (cmd_complete(rl_line_buffer, rl_point, buf, complete_flag))
    {
    case 0:
      complete_flag = 1;
      break;
    case 1:
      rl_insert_text(buf);
      break;
    default:
      complete_flag = 1;
#ifdef HAVE_RL_DING
      rl_ding();
#endif
    }
  return 0;
}
Esempio n. 18
0
int
rl_vi_delete_to(int count, int key)
{
  int c;

  if (_rl_uppercase_p (key))
    rl_stuff_char ('$');
  else if (vi_redoing)
    rl_stuff_char (_rl_vi_last_motion);

  if (rl_vi_domove (key, &c))
    {
      rl_ding ();
      return -1;
    }

  /* These are the motion commands that do not require adjusting the
     mark. */
  if ((strchr (" l|h^0bB", c) == 0) && (rl_mark < rl_end))
    rl_mark++;

  rl_kill_text (rl_point, rl_mark);
  return (0);
}
Esempio n. 19
0
int
ding ()
{
  return rl_ding ();
}
Esempio n. 20
0
static void
cli_mld_beep (const struct match_list_displayer *displayer)
{
  rl_ding ();
}
Esempio n. 21
0
int
main(int argc, char ** argv)
{
  command_t cmd; int i;
  char * in, * args, buffer[MAX_COMMAND_LENGTH];
  struct sigaction thread_signal_action, old_signal_action;
  struct thread_data_t * thread_datum;

  /* Sanitize input */
  if (argc != 2) {
    fprintf(stderr, "USAGE: %s port\n", argv[0]);
    return EXIT_FAILURE;
  }

  /* Crypto initialization */
  if (init_crypto(new_shmid(&i))) {
    fprintf(stderr, "FATAL: unable to enter secure mode\n");
    return EXIT_FAILURE;
  }

  /* Database initialization */
  if (init_db(BANKING_DB_FILE, &session_data.db_conn)) {
    fprintf(stderr, "FATAL: unable to connect to database\n");
    shutdown_crypto(old_shmid(&i));
    return EXIT_FAILURE;
  }

  /* Socket initialization */
  if ((session_data.sock = init_server_socket(argv[1])) < 0) {
    fprintf(stderr, "FATAL: unable to start server\n");
    destroy_db(BANKING_DB_FILE, session_data.db_conn);
    shutdown_crypto(old_shmid(&i));
    return EXIT_FAILURE;
  }

  /* Thread initialization */
  gcry_pthread_mutex_init((void **)(&session_data.accept_mutex));
  gcry_pthread_mutex_init((void **)(&session_data.keystore_mutex));
  /* Save the old list of blocked signals for later */
  pthread_sigmask(SIG_SETMASK, NULL, &old_signal_action.sa_mask);
  /* Worker threads inherit this mask (ignore everything except SIGUSRs) */
  memset(&thread_signal_action, '\0', sizeof(struct sigaction));
  sigfillset(&thread_signal_action.sa_mask);
  sigdelset(&thread_signal_action.sa_mask, SIGUSR1);
  sigdelset(&thread_signal_action.sa_mask, SIGUSR2);
  thread_signal_action.sa_handler = &handle_interruption;
  pthread_sigmask(SIG_SETMASK, &thread_signal_action.sa_mask, NULL);
  /* Afterwhich, all signals should be ignored in the handler */
  sigfillset(&thread_signal_action.sa_mask);
  /* Kick off the workers */
  for (i = 0; i < MAX_CONNECTIONS; ++i) {
    /* Thread data initialization */
    thread_datum = &session_data.thread_data[i];
    memset(thread_datum, '\0', sizeof(struct thread_data_t));
    thread_datum->sock = BANKING_FAILURE;
    thread_datum->remote_addr_len = sizeof(thread_datum->remote_addr);
    thread_datum->signal_action = &thread_signal_action;
    if (pthread_create(&thread_datum->id, NULL, &handle_client,
                                                thread_datum)) {
      thread_datum->id = (pthread_t)(BANKING_FAILURE);
      fprintf(stderr, "WARNING: unable to start worker thread\n");
    }
  }
  /* Reset the signal mask to the prior behavior, and ignore SIGUSRs */
  sigaddset(&old_signal_action.sa_mask, SIGUSR1);
  sigaddset(&old_signal_action.sa_mask, SIGUSR2);
  pthread_sigmask(SIG_SETMASK, &old_signal_action.sa_mask, NULL);

  /* Session Signal initialization */
  memset(&session_data.signal_action, '\0', sizeof(struct sigaction));
  /* The signal handler should ignore SIGTERM and SIGINT */
  sigemptyset(&session_data.signal_action.sa_mask);
  sigaddset(&session_data.signal_action.sa_mask, SIGTERM);
  sigaddset(&session_data.signal_action.sa_mask, SIGINT);
  session_data.signal_action.sa_handler = &handle_signal;
  /* Make sure any ignored signals remain ignored */
  sigaction(SIGTERM, NULL, &old_signal_action);
  if (old_signal_action.sa_handler != SIG_IGN) {
    sigaction(SIGTERM, &session_data.signal_action, NULL);
  }
  sigaction(SIGINT, NULL, &old_signal_action);
  if (old_signal_action.sa_handler != SIG_IGN) {
    sigaction(SIGINT, &session_data.signal_action, NULL);
  }
  session_data.caught_signal = 0;
  /* TODO tab-completion for commands */
  rl_bind_key('\t', rl_insert);

  /* Issue an interactive prompt, only quit on signal */
  while (!session_data.caught_signal && (in = readline(SHELL_PROMPT))) {
    /* Ignore empty strings */
    if (*in != '\0') {
      /* Add the original command to the shell history */
      memset(buffer, '\0', MAX_COMMAND_LENGTH);
      strncpy(buffer, in, MAX_COMMAND_LENGTH);
      buffer[MAX_COMMAND_LENGTH - 1] = '\0';
      for (i = 0; buffer[i] == ' '; ++i);
      add_history(buffer + i);
      /* Catch invalid commands prior to invocation */
      if (validate_command(in, &cmd, &args)) {
        fprintf(stderr, "ERROR: invalid command '%s'\n", in);
        rl_ding();
      } else {
        /* Hook the command's return value to this signal */
        session_data.caught_signal = ((cmd == NULL) || cmd(args));
      }
    }
    free(in);
    in = NULL;
  }

  /* Teardown */
  handle_signal(0);
  return EXIT_SUCCESS;
}