C Language Line Editor
The code goes as follows:
//line editor
#include
#include
#include
#define Right 77
#define Left 75
#define Home 71
#define End 79
#define Enter 13
#define Space 32
#define Escape 27
#define Backspace 8
void main(void)
{
//def
char * current;
char * last;
char * first;
char * i;
int x,y,len;//for presentation purposes
char ch;
char line[11];
//init
x=25;
y=10;
current =first =last =line; //or =&line[i];
//shell
do
{
gotoxy(x,y);
// may be we should print the whole array here
//after we initiate it with " "
ch=getch();
if(ch==0)
{
ch = getch();
switch(ch)
{
case Left:
{
if(current>first)
{
current --;
x--;
}
break;
}
case Right:
{
if(current
{
current++;
x++;
}
break;
}
case Home:
{
current =first;
x =25;
break;
}
case End:
{
current =last;
x =35 ;//+len;
break;
}
}//switch
}//if = extended
else //normal
{
switch(ch)
{
case Space://i think this shoul be altered to backspace , and moved to def
{
if(current
{
*current = ch;
printf("%c",*current);
current++;
x++;
}
break;
}
case Escape:
{
exit(0);
}
default:
{
if(current
{
if((ch>=97 && ch<=122) || (ch>=65 && ch<=57))
{
gotoxy(x,y);
*current++;
printf("%c",*current);
x++;
}
if(ch>=48 && ch<=57)
{
gotoxy(x,y);
*current =ch;
printf("%d",ch);
x++;
}
// put case space here
}//if
}//def
}//switch
}//else = normal
}while(1);//shell
}//main