Exemple #1
0
static char *shell_completion(const char *partial, int state) {
	static int completion_pass = 0, completion_matches_offset = 0;

	if(state == 0) {
		if(completion_matches) {
			for(int i = 0; i < completion_matches_count; i++)
				if(completion_matches[i])
					free(completion_matches[i]);

			free(completion_matches);
		
			completion_matches = NULL;
			completion_matches_count = 0;
		}

		completion_pass = 0;

		char *tmp = rl_line_buffer;

		while(isspace(*tmp)) tmp++;

		int not_first = 0;

		for(; *tmp; tmp++) {
			for(const char *sep = rl_basic_word_break_characters; *sep; sep++) {
				if(*tmp == *sep) {
					not_first = 1;

					break;
				}
			}

			if(not_first)
				break;
		}

		if(not_first) {
			completion_pass = 1;

			return rl_filename_completion_function(partial, state);
		} else {
			shell_enumerate_commands(completion_context, shell_completion_filler, (void *) partial);

			completion_matches_offset = 0;
		}
	}

	if(completion_pass) {
		return rl_filename_completion_function(partial, state);

	} else if(completion_matches_offset == completion_matches_count) {
		return NULL;
	} else {
		char *val = completion_matches[completion_matches_offset];

		completion_matches[completion_matches_offset++] = NULL;

		return val;
	}
}
Exemple #2
0
static void
cmd_flashmem_complete (urj_chain_t *chain, char ***matches, size_t *match_cnt,
                       const char *text, size_t text_len, size_t token_point)
{
    switch (token_point)
    {
    case 1: /* [addr|msbin] */
        break;

    case 2: /* filename */
    {
#ifdef HAVE_LIBREADLINE
        int state;
        char *match;

        state = 0;
        while (1)
        {
            match = rl_filename_completion_function (text, state++);
            if (!match)
                break;
            urj_completion_add_match_dupe (matches, match_cnt, match);
            free (match);
        }
#endif
        break;
    }

    case 3: /* [noverify] */
        urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "noverify");
        break;
    }
}
Exemple #3
0
/* Complete on filenames.  */
VEC (char_ptr) *
filename_completer (struct cmd_list_element *ignore, 
		    const char *text, const char *word)
{
  int subsequent_name;
  VEC (char_ptr) *return_val = NULL;

  subsequent_name = 0;
  while (1)
    {
      char *p, *q;

      p = rl_filename_completion_function (text, subsequent_name);
      if (p == NULL)
	break;
      /* We need to set subsequent_name to a non-zero value before the
	 continue line below, because otherwise, if the first file
	 seen by GDB is a backup file whose name ends in a `~', we
	 will loop indefinitely.  */
      subsequent_name = 1;
      /* Like emacs, don't complete on old versions.  Especially
         useful in the "source" command.  */
      if (p[strlen (p) - 1] == '~')
	{
	  xfree (p);
	  continue;
	}

      if (word == text)
	/* Return exactly p.  */
	q = p;
      else if (word > text)
	{
	  /* Return some portion of p.  */
	  q = xmalloc (strlen (p) + 5);
	  strcpy (q, p + (word - text));
	  xfree (p);
	}
      else
	{
	  /* Return some of TEXT plus p.  */
	  q = xmalloc (strlen (p) + (text - word) + 5);
	  strncpy (q, word, text - word);
	  q[text - word] = '\0';
	  strcat (q, p);
	  xfree (p);
	}
      VEC_safe_push (char_ptr, return_val, q);
    }
#if 0
  /* There is no way to do this just long enough to affect quote
     inserting without also affecting the next completion.  This
     should be fixed in readline.  FIXME.  */
  /* Ensure that readline does the right thing
     with respect to inserting quotes.  */
  rl_completer_word_break_characters = "";
#endif
  return return_val;
}
Exemple #4
0
void urj_completion_mayben_add_file (char ***matches, size_t *cnt,
                                     const char *text, size_t text_len,
                                     bool search)
{
#ifdef HAVE_LIBREADLINE
    int state;
    size_t implicit_len;
    char *match, *search_text;

    /* Use the search path if path isn't explicitly relative/absolute */
    if (search && text[0] != '/' && text[0] != '.')
    {
        const char *jtag_data_dir = urj_get_data_dir ();
        implicit_len = strlen (jtag_data_dir) + 1;

        search_text = malloc (implicit_len + text_len + 1);
        if (!search_text)
            return;

        sprintf (search_text, "%s/%s", jtag_data_dir, text);
        text = search_text;
        text_len += implicit_len;
    }
    else
    {
        implicit_len = 0;
        search_text = NULL;
    }

    state = 0;
    while (1)
    {
        match = rl_filename_completion_function (text, state++);
        if (!match)
            break;
        urj_completion_add_match_dupe (matches, cnt, match + implicit_len);
        free (match);
    }

    free (search_text);
#endif
}
Exemple #5
0
char *
octave_rl_filename_completion_function (const char *text, int state)
{
  return rl_filename_completion_function (text, state);
}