* Fix autocompletion in r_line

- All argc/argv responsability has been moved to the callback
  - Makes the code simpler in r_line
  - Do not bypass 70 column width in list of options
  - Remove deprecated code
This commit is contained in:
pancake 2010-06-29 01:18:30 +02:00
parent affbba8aa2
commit 664732593c
3 changed files with 35 additions and 38 deletions

8
TODO
View File

@ -13,6 +13,7 @@ Questions:
----------
* imports from PE doesnt works with /a because there's an indirect call
* rabin2 doesnt works for osx-x86 mach0 bins..so io.va=1 fails
* Store version information in libraries ? debian claims for it
Bugs:
-----
@ -27,16 +28,12 @@ Bugs:
TODO:
-----
* rarc2 : choose syntax in runtime
* Store version information in libraries ? debian claims for it
* nibble: trace counts after step..thats not correct!
* implement grep{col,row}
* pancake: dietline.c : do not show all options at first tab if matches
* nibble: mach0 new binary format is not supported by bin_mach0 :(
* java disassembler do not uses the constant pool
################# * java disassembler do not uses the constant pool
* Implement r_sys_setenv stuff from r1 in core/file.c:33 (!!?)
* pancake: Implement search.align
* Initial analysis looking for xrefs to strings and so? ax? ./a@@entry0
- Launched at startup
* Handle metadata from disassembler (structs, hexdump, ...)
- r_meta_print (RMeta, RMetaItem, RPrint);
* pancake: FileDescriptors: dd -- copy from !fd in r1
@ -64,6 +61,7 @@ TODO:
===
* rasign2 : must be done, write manpage
* distribute 'spp' with 'rarc2' ?
* Initial analysis looking for xrefs to strings and so? ax? ./a@@entry0 - Launched at startup
Transaction notes
=================

View File

@ -75,8 +75,6 @@ static char *tmp_argv[TMP_ARGV_SZ];
static int autocomplete(RLine *line) {
RCore *core = line->user;
struct list_head *pos;
line->completion.argc = CMDS;
line->completion.argv = radare_argv;
if (core) {
if ((!memcmp (line->buffer.data, "s ", 2)) ||
(!memcmp (line->buffer.data, "f ", 2)) ||
@ -108,7 +106,23 @@ static int autocomplete(RLine *line) {
tmp_argv[i] = NULL;
line->completion.argc = i;
line->completion.argv = tmp_argv;
} else {
int i,j;
for (i=j=0; radare_argv[i] && i<CMDS; i++)
if (!memcmp (radare_argv[i], line->buffer.data, line->buffer.index))
tmp_argv[j++] = radare_argv[i];
tmp_argv[j] = NULL;
line->completion.argc = j;
line->completion.argv = tmp_argv;
}
} else {
int i,j;
for (i=j=0; radare_argv[i] && i<CMDS; i++)
if (!memcmp (radare_argv[i], line->buffer.data, line->buffer.index))
tmp_argv[j++] = radare_argv[i];
tmp_argv[j] = NULL;
line->completion.argc = j;
line->completion.argv = tmp_argv;
}
return R_TRUE;
}

View File

@ -169,35 +169,20 @@ R_API int r_line_hist_chop(const char *file, int limit) {
}
R_API void r_line_autocomplete() {
int argc;
const char **argv;
int argc = 0;
const char **argv = NULL;
int i, opt, len = 0;
/* prepare argc and argv */
if (I.completion.run != NULL)
if (I.completion.run != NULL) {
I.completion.run (&I);
opt = argc = I.completion.argc;
argv = I.completion.argv;
}
argc = I.completion.argc;
argv = I.completion.argv;
// TODO: implement partial autocompletion ?
if (I.buffer.index>0)
for (i=0,opt=0; argv[i] && i<argc; i++)
if (!strncmp (argv[i], I.buffer.data, I.buffer.index))
opt++;
// XXX: This autocompletion method is hacky
if (I.buffer.length>0 && opt==1) {
for (i=0; i<argc; i++) {
if (!strncmp (I.buffer.data, argv[i], I.buffer.length)) {
strcpy (I.buffer.data, argv[i]);
I.buffer.index = I.buffer.length = strlen (I.buffer.data) + 1;
/* fucking inneficient */
strcat (I.buffer.data, " ");
I.buffer.length = ++I.buffer.index;
break;
}
}
} else
/* autocomplete */
if (argc==1) {
char *p = strchr (I.buffer.data, ' ');
if (p) p++; else p = I.buffer.data;
@ -207,21 +192,21 @@ R_API void r_line_autocomplete() {
I.buffer.length = strlen (I.buffer.data);
}
#define COLS 70
/* show options */
//if (I.buffer.index==0 || opt>1) {
if (argc>1) {
if (opt>1) {
if (I.echo)
printf ("%s%s\n", I.prompt, I.buffer.data);
for (i=0; i<argc; i++) {
for (len=i=0; i<argc; i++) {
if (argv[i] == NULL)
break;
// if (I.buffer.length==0 || !strncmp (argv[i], I.buffer.data, I.buffer.length)) {
len += strlen (argv[i]);
// if (len+I.buffer.length+4 >= columns) break;
len += strlen (argv[i]) + 4;
if (len>0 && len>COLS) {
printf ("\n");
len = 0;
}
if (I.echo)
printf ("%s\t", argv[i]);
if (5==(i%6)) printf ("\n");
// }
}
if (I.echo)
printf ("\n");