#include #include int main(int argc,char *argv[]) { FILE *fp; int done=0; int in; int ln=0; int cp=0; int bottom; int top; int lines=0; int i; char line[1024][1024]; for(i=0;i<1023;i++) { memset(line[i],0,1023); } if(!argv[1]) { printf("error.\n"); return 0; } if(!(fp=fopen(argv[1],"r"))) { } else { for(i=0;!feof(fp);i++) { fgets(line[i],sizeof(line[i]),fp); //} done=strlen(line[i])-1; line[i][done]=(line[i][done]=='\n')?'\0':line[i][done]; lines++; } done=0; fclose(fp); } initscr(); cbreak(); for( ; !done ; in=getch()) { if(in=='\x1b') { in=getch(); if(in=='[') { in=getch(); if(in=='A') { ln--; } if(in=='B') { ln++; } if(in=='C') { cp++; } if(in=='D') { cp--; } } else if(in=='\x1b') {//double escape to exit and save. break; } //continue; } else { if(in=='\n') {//should insert new line... down should do this. ln++; lines++; for(i=lines;i>=ln;i--) { strcpy(line[i],line[i-1]);//take line after and set it to previous //line's value. } for(i=0;line[ln][i];i++) { line[ln][i]=0; } } else if(in=='\b') { if(strlen(line[ln])-1 == -1) { //delete this line. for(i=ln;i":" |",line[i],line[i][strlen(line[i])-1]=='\n'?'\r':'\n'); } } nocbreak(); endwin(); if(!(fopen(argv[1],"w"))) { fprintf(stderr,"couldn't create file!!! oh shit!\n"); return 0; } for(i=0;i