CVS: libraries/commandline tabcomplete.c,NONE,1.1 commandline.c,1.2,1.3 makefile,1.2,1.3
Chris Liechti <[email protected]>
| Newsgroups | gmane.comp.hardware.texas-instruments.msp430.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/mspgcc/libraries/commandline
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20661/libraries/commandline
Modified Files:
commandline.c makefile
Added Files:
tabcomplete.c
Log Message:
add simple tab complete impl
--- NEW FILE: tabcomplete.c ---
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <mspgcc/util.h>
#include "commandline.h"
void commandline_tabcomplete(
const COMMANDLINE_TABLE * commandline_table,
LINEEDITOR_STATE *lineeditor,
const char *prompt
) {
// tab completion, scan for command starting with given text
const COMMANDLINE_TABLE *match = NULL;
unsigned int length = 0;
bool append_space = false;
// scan command table for a command that starts with the text from the current command line
for (const COMMANDLINE_TABLE *entry=commandline_table; entry->name; entry++) {
if (strncmp(lineeditor->line, entry->name, lineeditor->position) == 0) {
if (match == NULL) {
// save first match
match = entry;
length = strlen(entry->name);
append_space = true;
} else {
// n'th match, find shortest common part
while (length && strncmp(match->name, entry->name, length) != 0) {
length--;
}
append_space = false;
}
}
}
// print common part, update line buffer
if (match != NULL && length > lineeditor->position) {
const char *pos = &match->name[lineeditor->position];
for (unsigned int chars = length - lineeditor->position; chars; chars--) {
putchar(*pos++);
}
strncpy(lineeditor->line, match->name, length);
lineeditor->position = length;
lineeditor->line[lineeditor->position] = '\0';
if (append_space) {
putchar(' ');
lineeditor->line[lineeditor->position++] = ' ';
lineeditor->line[lineeditor->position] = '\0';
}
} else if (length >= lineeditor->position) {
// print a list of possible values, then print the prompt and command line again
printf("\n");
for (const COMMANDLINE_TABLE *entry=commandline_table; entry->name; entry++) {
if (strncmp(lineeditor->line, entry->name, lineeditor->position) == 0) {
printf("%s ", entry->name);
}
}
printf("\n%s%s", prompt, lineeditor->line);
}
}
Index: commandline.c
===================================================================
RCS file: /cvsroot/mspgcc/libraries/commandline/commandline.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -d -r1.2 -r1.3
--- commandline.c 13 Sep 2005 12:25:15 -0000 1.2
+++ commandline.c 4 Apr 2006 22:25:05 -0000 1.3
@@ -31,7 +31,7 @@
if (*ptr == ' ') { // Space is the delimiter
*ptr = '\0';
if (argc >= MAXARGS) {
- //addidional args will get lost...
+ //additional args will get lost...
break;
}
// skip whitespace
Index: makefile
===================================================================
RCS file: /cvsroot/mspgcc/libraries/commandline/makefile,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -d -r1.2 -r1.3
--- makefile 19 Sep 2005 09:28:58 -0000 1.2
+++ makefile 4 Apr 2006 22:25:05 -0000 1.3
@@ -2,7 +2,8 @@
LIBRARYNAME = commandline
CSOURCES = commandline.c commandline_number.c \
help.c reset.c checksum.c \
- memory_write.c memory_erase.c hexdump.c
+ memory_write.c memory_erase.c hexdump.c \
+ tabcomplete.c
#~ ASOURCES =
CPU = msp1
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642