예제 #1
0
static le *
do_search (bool forward, bool regexp, const char *pattern)
{
  le * ok = leNIL;
  const char *ms = NULL;

  if (pattern == NULL)
    pattern = ms = minibuf_read ("%s%s: ", last_search, regexp ? "RE search" : "Search", forward ? "" : " backward");

  if (pattern == NULL)
    return FUNCALL (keyboard_quit);
  if (pattern[0] != '\0')
    {
      free (last_search);
      last_search = xstrdup (pattern);

      if (!search (get_buffer_pt (cur_bp), pattern, forward, regexp))
        minibuf_error ("Search failed: \"%s\"", pattern);
      else
        ok = leT;
    }

  free ((char *) ms);
  return ok;
}
예제 #2
0
char *
term_minibuf_read (const char *prompt, const char *value, size_t pos,
                   Completion * cp, History * hp)
{
  Window *wp, *old_wp = cur_wp;
  char *s = NULL;
  astr as;

  if (hp)
    prepare_history (hp);

  as = do_minibuf_read (prompt, value, pos, cp, hp);
  if (as)
    {
      s = xstrdup (astr_cstr (as));
      astr_delete (as);
    }

  if (cp != NULL && (get_completion_flags (cp) & CFLAG_POPPEDUP)
      && (wp = find_window ("*Completions*")) != NULL)
    {
      set_current_window (wp);
      if (get_completion_flags (cp) & CFLAG_CLOSE)
        FUNCALL (delete_window);
      else if (get_completion_old_bp (cp))
        switch_to_buffer (get_completion_old_bp (cp));
      set_current_window (old_wp);
    }

  return s;
}
예제 #3
0
/*
 * Jump to the specified line number and offset.
 */
static void goto_point(int pointn, int pointo)
{
	if (cur_wp->pointn > pointn)
		do 
			FUNCALL(previous_line);
		while (cur_wp->pointn > pointn);
	else if (cur_wp->pointn < pointn)
		do
			FUNCALL(next_line);
		while (cur_wp->pointn < pointn);
	if (cur_wp->pointo > pointo)
		do
			FUNCALL(backward_char);
		while (cur_wp->pointo > pointo);
	else if (cur_wp->pointo < pointo)
		do
			FUNCALL(forward_char);
		while (cur_wp->pointo < pointo);
}
예제 #4
0
/* Go to coordinates described by pt (ignoring pt.p) */
void
goto_point (Point pt)
{
  if (get_buffer_pt (cur_bp).n > pt.n)
    do
      FUNCALL (previous_line);
    while (get_buffer_pt (cur_bp).n > pt.n);
  else if (get_buffer_pt (cur_bp).n < pt.n)
    do
      FUNCALL (next_line);
    while (get_buffer_pt (cur_bp).n < pt.n);

  if (get_buffer_pt (cur_bp).o > pt.o)
    do
      FUNCALL (backward_char);
    while (get_buffer_pt (cur_bp).o > pt.o);
  else if (get_buffer_pt (cur_bp).o < pt.o)
    do
      FUNCALL (forward_char);
    while (get_buffer_pt (cur_bp).o < pt.o);
}
예제 #5
0
static int kill_line(int literally)
{
  if (!eolp()) {
    if (warn_if_readonly_buffer())
      return FALSE;

    undo_save(UNDO_INSERT_BLOCK, cur_bp->pt,
              astr_len(cur_bp->pt.p->item) - cur_bp->pt.o, 0);
    undo_nosave = TRUE;
    while (!eolp()) {
      kill_ring_push(following_char());
      FUNCALL(delete_char);
    }
    undo_nosave = FALSE;

    thisflag |= FLAG_DONE_KILL;

    if (!literally)
      return TRUE;
  }

  if (list_next(cur_bp->pt.p) != cur_bp->lines) {
    if (!FUNCALL(delete_char))
      return FALSE;

    kill_ring_push('\n');

    thisflag |= FLAG_DONE_KILL;

    return TRUE;
  }

  minibuf_error("End of buffer");

  return FALSE;
}
예제 #6
0
/*
 * Scroll completions up.
 */
void
completion_scroll_up (void)
{
  Window *wp, *old_wp = cur_wp;
  Point pt;

  wp = find_window ("*Completions*");
  assert (wp != NULL);
  set_current_window (wp);
  pt = get_buffer_pt (cur_bp);
  if (pt.n >= get_buffer_last_line (cur_bp) - get_window_eheight (cur_wp) || !FUNCALL (scroll_up))
    gotobob ();
  set_current_window (old_wp);

  term_redisplay ();
}
예제 #7
0
/*
 * Scroll completions down.
 */
void
completion_scroll_down (void)
{
  Window *wp, *old_wp = cur_wp;
  Point pt;

  wp = find_window ("*Completions*");
  assert (wp != NULL);
  set_current_window (wp);
  pt = get_buffer_pt (cur_bp);
  if (pt.n == 0 || !FUNCALL (scroll_down))
    {
      gotoeob ();
      resync_redisplay (cur_wp);
    }
  set_current_window (old_wp);

  term_redisplay ();
}
예제 #8
0
/*
 * Revert an action.  Return the next undo entry.
 */
static undop revert_action(undop up)
{
	int i;

	doing_undo = TRUE;

	if (up->type == UNDO_END_SEQUENCE) {
		undo_save(UNDO_START_SEQUENCE, up->pointn, up->pointo, 0, 0);
		up = up->next;
		while (up->type != UNDO_START_SEQUENCE) {
			revert_action(up);
			up = up->next;
		}
		undo_save(UNDO_END_SEQUENCE, up->pointn, up->pointo, 0, 0);
		goto_point(up->pointn, up->pointo);
		return up->next;
	}

	goto_point(up->pointn, up->pointo);

	switch (up->type) {
	case UNDO_INSERT_CHAR:
		if (up->delta.c == '\n')
			insert_newline();
		else
			insert_char_in_insert_mode(up->delta.c);
		break;
	case UNDO_INTERCALATE_CHAR:
		if (up->delta.c == '\n')
			intercalate_newline();
		else
			intercalate_char(up->delta.c);
		break;
	case UNDO_INSERT_BLOCK:
		undo_save(UNDO_REMOVE_BLOCK, up->pointn, up->pointo, up->delta.block.size, 0);
		undo_nosave = TRUE;
		for (i = 0; i < up->delta.block.size; i++)
			if (up->delta.block.text[i] != '\n')
				insert_char(up->delta.block.text[i]);
			else
				insert_newline();
		undo_nosave = FALSE;
		break;
	case UNDO_REMOVE_CHAR:
		FUNCALL(delete_char);
		break;
	case UNDO_REMOVE_BLOCK:
		undo_save(UNDO_INSERT_BLOCK, up->pointn, up->pointo, up->delta.block.size, 0);
		undo_nosave = TRUE;
		for (i = 0; i < up->delta.block.size; i++)
			FUNCALL(delete_char);
		undo_nosave = FALSE;
		break;
	case UNDO_REPLACE_CHAR:
		undo_save(UNDO_REPLACE_CHAR, up->pointn, up->pointo,
			  cur_wp->pointp->text[up->pointo], 0);
		cur_wp->pointp->text[up->pointo] = up->delta.c;
		cur_bp->flags |= BFLAG_MODIFIED;
		if (cur_bp->flags & BFLAG_FONTLOCK)
			font_lock_reset_anchors(cur_bp, cur_wp->pointp);
		break;
	case UNDO_REPLACE_BLOCK:
		undo_save(UNDO_REPLACE_BLOCK, up->pointn, up->pointo,
			  up->delta.block.size, up->delta.block.osize);
		undo_nosave = TRUE;
		for (i = 0; i < up->delta.block.size; i++)
			FUNCALL(delete_char);
		for (i = 0; i < up->delta.block.osize; i++)
			if (up->delta.block.text[i] != '\n')
				insert_char(up->delta.block.text[i]);
			else
				insert_newline();
		undo_nosave = FALSE;
		break;
	}

	doing_undo = FALSE;

	return up->next;
}
예제 #9
0
static int
my_execute(char *string)
{
  int ii, len;
  int64_t res;
  char *saveptr;
  char *command, *arguments;
  char *args[NARGS], nargs;
  VOIDFPTR command_ptr;
  char str[256];
  void *handler;
  float fargs[NARGS];
  int *iargs = (int *)fargs;
  char **sargs = (char **)fargs;

  /* parsing*/
  strncpy(str,string,255); /*strtok will modify input string, let it be local and non-constant one*/
#ifdef DEBUG
  printf("my_execute: str >%s<\n",str);
#endif
  command = strtok_r(str,"(",&saveptr);
  if(command!=NULL)
  {
#ifdef DEBUG
    printf("command >%s<\n",command);
#endif
  }
  else
  {
    printf("no command found in >%s<\n",str);
    return(-1);
  }

  arguments = strtok_r(NULL,")",&saveptr);
  if(arguments!=NULL)
  {
#ifdef DEBUG
    printf("arguments >%s<\n",arguments);
#endif
    args[0] = strtok_r(arguments,",",&saveptr);
    nargs = 1;

    while( (nargs<NARGS) && (args[nargs]=strtok_r(NULL,",",&saveptr)) != NULL ) nargs ++;

    for(ii=0; ii<nargs; ii++)
    {
      if( (strchr(args[ii],'"')!=NULL) || (strchr(args[ii],'\'')!=NULL) ) /*string*/
      {
        sargs[ii] = args[ii];
        while(sargs[ii][0]==' ') sargs[ii] ++; /*remove leading spaces*/
        len = strlen(sargs[ii]);
        while(sargs[ii][len-1]==' ') len--; /*remove trailing spaces*/
        sargs[ii][len] = '\0';
#ifdef DEBUG
        printf("111: sargs[%2d] >%s<\n",ii,sargs[ii]);
#endif
        sargs[ii] ++; /* remove leading quote */
        len = strlen(sargs[ii]);
        sargs[ii][len-1] = '\0'; /* remove trailing quote */
#ifdef DEBUG
        printf("222: sargs[%2d] >%s<\n",ii,sargs[ii]);
#endif
	  }
      else if(strchr(args[ii],'.')!=NULL) /*float*/
      {
        sscanf(args[ii],"%f",&fargs[ii]);
#ifdef DEBUG
        printf("flo: args[%2d] >%s< %f\n",ii,args[ii],fargs[ii]);
#endif
	  }
      else if(strchr(args[ii],'x')!=NULL) /*hex*/
      {
        sscanf(args[ii],"%x",&iargs[ii]);
#ifdef DEBUG
        printf("hex: args[%2d] >%s< %d (0x%x)\n",ii,args[ii],iargs[ii],iargs[ii]);
#endif
	  }
	  else /*decimal*/
	  {
        sscanf(args[ii],"%i",&iargs[ii]);
#ifdef DEBUG
        printf("dec: args[%2d] >%s< %d\n",ii,args[ii],iargs[ii]);
#endif
	  }
    }
  }

  /* open symbol table */
  handler = dlopen(NULL, RTLD_NOW | RTLD_GLOBAL);
  if(handler == 0)
  {
	printf("my_execute ERROR: dlopen failed on >%s<\n",dlerror());
    return(-1);
  }

  /* find symbol */
  command = strtok_r(command," ",&saveptr); /*remove leading and trailing spaces if any*/
#ifdef DEBUG
  printf("command1 >%s<\n",command);
#endif
  if(command==NULL)
  {
    printf("no command found in >%s<\n",command);    
    return(-1);
  }
  res = dlsym(handler, command);
  if((res != (-1)) && (res != 0))
  {
#ifdef DEBUG
    printf("INFO: >%s()< routine found\n",command);
#endif
  }
  else
  {
    printf("ERROR: dlsym returned %d\n",res);
    printf("ERROR: >%s()< routine not found\n",command);
    return(-1);
  }
  command_ptr = (VOIDFPTR) res;

#ifdef DEBUG
  printf("ints-> %d(0x%x) %d(0x%x) %d(0x%x) %d(0x%x)\n",
    iargs[0],iargs[0],iargs[1],iargs[1],iargs[2],iargs[2],iargs[3],iargs[3]);
  printf("floats-> %f %f %f %f\n",fargs[0],fargs[1],fargs[2],fargs[3]);
  printf("my_execute: Executing >%s<\n",command);fflush(stdout);
#endif

  FUNCALL(i,i,i,i,i,i,i,i);

#ifdef DEBUG
  printf("my_execute: executed\n");fflush(stdout);
#endif

  /* close symbol table */
  if(dlclose((void *)handler) != 0)
  {
    printf("ERROR: failed to unload >%s<\n",command);
    return(-1);
  }

  return(0);
}
예제 #10
0
static astr
do_minibuf_read (const char *prompt, const char *value, size_t pos,
               Completion * cp, History * hp)
{
  static int overwrite_mode = 0;
  int c, thistab, lasttab = -1;
  size_t prompt_len;
  char *s;
  astr as = astr_new_cstr (value), saved = NULL;

  prompt_len = strlen (prompt);
  if (pos == SIZE_MAX)
    pos = astr_len (as);

  for (;;)
    {
      switch (lasttab)
        {
        case COMPLETION_MATCHEDNONUNIQUE:
          s = " [Complete, but not unique]";
          break;
        case COMPLETION_NOTMATCHED:
          s = " [No match]";
          break;
        case COMPLETION_MATCHED:
          s = " [Sole completion]";
          break;
        default:
          s = "";
        }
      draw_minibuf_read (prompt, astr_cstr (as), prompt_len, s, pos);

      thistab = -1;

      switch (c = getkey ())
        {
        case KBD_NOKEY:
          break;
        case KBD_CTRL | 'z':
          FUNCALL (suspend_emacs);
          break;
        case KBD_RET:
          term_move (term_height () - 1, 0);
          term_clrtoeol ();
          if (saved)
            astr_delete (saved);
          return as;
        case KBD_CANCEL:
          term_move (term_height () - 1, 0);
          term_clrtoeol ();
          if (saved)
            astr_delete (saved);
          astr_delete (as);
          return NULL;
        case KBD_CTRL | 'a':
        case KBD_HOME:
          pos = 0;
          break;
        case KBD_CTRL | 'e':
        case KBD_END:
          pos = astr_len (as);
          break;
        case KBD_CTRL | 'b':
        case KBD_LEFT:
          if (pos > 0)
            --pos;
          else
            ding ();
          break;
        case KBD_CTRL | 'f':
        case KBD_RIGHT:
          if (pos < astr_len (as))
            ++pos;
          else
            ding ();
          break;
        case KBD_CTRL | 'k':
          /* FIXME: do kill-register save. */
          if (pos < astr_len (as))
            astr_truncate (as, pos);
          else
            ding ();
          break;
        case KBD_BS:
          if (pos > 0)
            astr_remove (as, --pos, 1);
          else
            ding ();
          break;
        case KBD_CTRL | 'd':
        case KBD_DEL:
          if (pos < astr_len (as))
            astr_remove (as, pos, 1);
          else
            ding ();
          break;
        case KBD_INS:
          overwrite_mode = overwrite_mode ? 0 : 1;
          break;
        case KBD_META | 'v':
        case KBD_PGUP:
          if (cp == NULL)
            {
              ding ();
              break;
            }

          if (get_completion_flags (cp) & CFLAG_POPPEDUP)
            {
              completion_scroll_down ();
              thistab = lasttab;
            }
          break;
        case KBD_CTRL | 'v':
        case KBD_PGDN:
          if (cp == NULL)
            {
              ding ();
              break;
            }

          if (get_completion_flags (cp) & CFLAG_POPPEDUP)
            {
              completion_scroll_up ();
              thistab = lasttab;
            }
          break;
        case KBD_UP:
        case KBD_META | 'p':
          if (hp)
            {
              const char *elem = previous_history_element (hp);
              if (elem)
                {
                  if (!saved)
                    saved = astr_cpy (astr_new (), as);

                  astr_cpy_cstr (as, elem);
                }
            }
          break;
        case KBD_DOWN:
        case KBD_META | 'n':
          if (hp)
            {
              const char *elem = next_history_element (hp);
              if (elem)
                astr_cpy_cstr (as, elem);
              else if (saved)
                {
                  astr_cpy (as, saved);
                  astr_delete (saved);
                  saved = NULL;
                }
            }
          break;
        case KBD_TAB:
        got_tab:
          if (cp == NULL)
            {
              ding ();
              break;
            }

          if (lasttab != -1 && lasttab != COMPLETION_NOTMATCHED
              && get_completion_flags (cp) & CFLAG_POPPEDUP)
            {
              completion_scroll_up ();
              thistab = lasttab;
            }
          else
            {
              astr bs = astr_new ();
              astr_cpy (bs, as);
              thistab = completion_try (cp, bs, true);
              astr_delete (bs);
              switch (thistab)
                {
                case COMPLETION_MATCHED:
                case COMPLETION_MATCHEDNONUNIQUE:
                case COMPLETION_NONUNIQUE:
                  {
                    bs = astr_new ();
                    if (get_completion_flags (cp) & CFLAG_FILENAME)
                      astr_cat (bs, get_completion_path (cp));
                    astr_ncat_cstr (bs, get_completion_match (cp), get_completion_matchsize (cp));
                    if (strncmp (astr_cstr (as), astr_cstr (bs),
                                 astr_len (bs)) != 0)
                      thistab = -1;
                    astr_delete (as);
                    as = bs;
                    pos = astr_len (as);
                    break;
                  }
                case COMPLETION_NOTMATCHED:
                  ding ();
                }
            }
          break;
        case ' ':
          if (cp != NULL)
            goto got_tab;
          /* FALLTHROUGH */
        default:
          if (c > 255 || !isprint (c))
            {
              ding ();
              break;
            }
          astr_insert_char (as, pos++, c);
          if (overwrite_mode && pos != astr_len (as))
            astr_remove (as, pos, 1);
        }

      lasttab = thistab;
    }
}