[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-readline] ^@ inserted when calling rl_delete_text
From: |
Manuel Schölling |
Subject: |
[Bug-readline] ^@ inserted when calling rl_delete_text |
Date: |
Tue, 15 Jul 2008 11:45:23 +0200 |
User-agent: |
Thunderbird 2.0.0.14 (X11/20080512) |
Hi guys,
I'm trying to build a completion function for gnuplot but when I call
rl_delete_text to delete the text to complete I always get the chars ^@
as a prefix of my completions.
But if I do not want complete a word and press just <tab> to list all
files ^@ is not added (because there is no word to delete and
rl_delete_text is not called).
I'm using readline-5.2_p12-r1 on my Gentoo linux 2.6.25-tuxonice-r1 (64
bit).
My source code (just a minimal example) is at the end of this mail.
Here is an example, this one is working fine:
command <tab>
result:
command main.c~, \
main.c, \
main.o, \
a.out
but this one does not work:
command m<tab>
result:
command address@hidden@, \
address@hidden@, \
address@hidden
Is this a bug in readline or am I too stupid to use rl_delete_text?
Any hints and tips welcome!
Cheers,
Manuel
--- source code ---
#include <stdio.h>
#include <stdlib.h>
#include <readline/readline.h>
#include <readline/history.h>
int multi_complete(int count, int key);
int main (void)
{
char *buf;
// rl_bind_key ('\t', rl_insert);
rl_bind_key('\t', multi_complete);
while (1)
{
buf = readline ("> ");
if (buf == NULL)
break;
if (buf[0] != '\0')
{
add_history (buf);
printf ("You entered: %s\n", buf);
}
free (buf);
}
putchar ('\n');
exit (EXIT_SUCCESS);
return 0;
}
int multi_complete(int count, int key) {
// get tail
int tail_len = rl_end-rl_point+1;
char *tail = malloc(tail_len);;
strncpy(tail,rl_line_buffer+rl_point, tail_len);
// get file completions
int end = rl_point;
char delimiter = 0;
char found_quote = 0;
char quote_char = '\0';
char *text;
if (rl_point)
/* This (possibly) changes rl_point. If it returns a non-zero char,
we know we have an open quote. */
quote_char = _rl_find_completion_word (&found_quote, &delimiter);
rl_completion_found_quote = found_quote;
rl_completion_quote_character = quote_char;
int start = rl_point;
rl_point = end;
text = rl_copy_text (start, end);
char **matches = rl_completion_matches(text,
rl_filename_completion_function);
// remove text to complete and quote
rl_delete_text(start, end);
char seperator[2];
seperator[0] = quote_char;
seperator[1] = '\0';
int i;
for (i = 1; matches[i] != NULL; i++) {
rl_insert_text(matches[i]);
rl_insert_text(seperator);
if (matches[i+1] != NULL) {
rl_insert_text(tail);
rl_insert_text(", \\\n\t");
}
}
}
- [Bug-readline] ^@ inserted when calling rl_delete_text,
Manuel Schölling <=