mirror of
https://github.com/vivier/EMILE.git
synced 2025-02-25 23:29:10 +00:00
Command Line Interpreter
This commit is contained in:
parent
c80730558f
commit
a6eb91ec1c
75
second/cli.c
Normal file
75
second/cli.c
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "console.h"
|
||||
|
||||
void cli_edit(char *s, int length)
|
||||
{
|
||||
int l = strlen(s);
|
||||
int pos = l;
|
||||
int c = 1;
|
||||
int i;
|
||||
|
||||
printf("%s", s);
|
||||
|
||||
while ((c = console_getchar()) != '\r')
|
||||
{
|
||||
if ( (c > 0x1f) && (c < 0x7f) && (l < length - 1) )
|
||||
{
|
||||
for (i = l; i > pos; i--)
|
||||
s[i] = s[i - 1];
|
||||
s[pos] = c;
|
||||
printf("%s", s + pos);
|
||||
l++;
|
||||
pos++;
|
||||
for (i = l; i > pos; i--)
|
||||
putchar('\b');
|
||||
}
|
||||
else switch(c)
|
||||
{
|
||||
case '':
|
||||
if (pos > 0)
|
||||
{
|
||||
putchar('\b');
|
||||
pos--;
|
||||
}
|
||||
break;
|
||||
case '':
|
||||
if (pos < l)
|
||||
{
|
||||
putchar(s[pos]);
|
||||
pos++;
|
||||
}
|
||||
break;
|
||||
case '\b': /* backspace */
|
||||
if (pos > 0)
|
||||
{
|
||||
putchar('\b');
|
||||
pos--;
|
||||
strcpy(s + pos, s + pos + 1);
|
||||
printf("%s", s + pos);
|
||||
putchar(' ');
|
||||
for (i = l; i > pos; i--)
|
||||
putchar('\b');
|
||||
l--;
|
||||
}
|
||||
break;
|
||||
case 0x7f: /* Delete */
|
||||
if (pos < l)
|
||||
{
|
||||
strcpy(s + pos, s + pos + 1);
|
||||
l--;
|
||||
printf("%s", s + pos);
|
||||
for (i = l; i > pos; i--)
|
||||
putchar('\b');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
7
second/cli.h
Normal file
7
second/cli.h
Normal file
@ -0,0 +1,7 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
|
||||
*
|
||||
*/
|
||||
|
||||
extern void cli_edit(char *s, int length);
|
Loading…
x
Reference in New Issue
Block a user