home *** CD-ROM | disk | FTP | other *** search
- #include <conio.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <io.h>
- #include <dos.h>
- #include <fcntl.h>
- #include <string.h>
- #include <sys\types.h>
- #include <sys\stat.h>
-
- #define BACKSPACE '\010'
- #define BACKUP "\010"
- #define CR 0x0d
- #define ESC 27
- #define ALPHA '@'
- #define NUMERIC '#'
- #define UP 5
- #define DOWN 24
- #define LEFT 19
- #define RIGHT 4
- #define INSERT 25
- #define DELETE 2
-
- char screen[26][84];
- char fname[20];
- short position;
-
- main()
- {
- short y,x,key;
- short i;
-
- for(y=0;y<26;y++)
- {
- for(x=0;x<79;x++)
- screen[y][x] = 0x20;
- }
-
- load();
- for(y=0;y<26;y++)
- {
- for(x=0;x<80;x++)
- {
- if(screen[y][x]==0)
- screen[y][x]=32;
- if(screen[y][x]==13)
- screen[y][x]=32;
- }
- screen[y][80] = 0;
- }
-
- x = 1;
- y = 2;
-
- printf("\33[01;01H");
- for(;;)
- {
- if(y==1)
- y = 2;
- if(x==0)
- x = 1;
- key = getch();
- if(key==0)
- {
- key = getch();
- switch(key)
- {
- case 72:
- key = UP;
- break;
- case 80:
- key = DOWN;
- break;
- case 75:
- key = LEFT;
- break;
- case 77:
- key = RIGHT;
- break;
- case 71:
- key = CR;
- break;
- case 82:
- key = INSERT;
- break;
- case 83:
- key = DELETE;
- break;
- }
- }
- switch(key)
- {
- case UP:
- if (y>2)
- y--;
- printf("\33[%d;%dH",y,x);
- break;
-
- case DOWN:
- if (y<23)
- y++;
- printf("\33[%d;%dH",y,x);
- break;
-
- case LEFT:
- case 8:
- if (x>1)
- x--;
- printf("\33[%d;%dH",y,x);
- break;
-
- case RIGHT:
- if (x<78)
- x++;
- printf("\33[%d;%dH",y,x);
- break;
-
- case INSERT:
- for(i=24;i>=y;i--)
- {
- memcpy(screen[i+1], screen[i], 79);
- }
- memset(screen[y], 32, 79);
- screen[y][80] = 0;
- display();
- break;
-
- case DELETE:
- for(i=y;i<25;i++)
- {
- memcpy(screen[i], screen[i+1], 79);
- }
- memset(screen[25], 32, 79);
- screen[y][80] = 0;
- display();
- break;
-
- case 03:
- return -1;
- break;
-
- case ESC:
- for(y=0;y<26;y++)
- {
- for(x=0;x<80;x++)
- {
- if(screen[y][x]==0)
- screen[y][x]=32;
- if(screen[y][x]==13)
- screen[y][x]=32;
- }
- screen[y][80] = 0;
- }
- store();
- printf("\nlength %d\nIncludes CR-LF\n", position + 2);
-
- return 0;
- break;
-
- case CR:
- if(y<23)
- y++;
- x = 1;
- printf("\33[%d;%dH",y,x);
- break;
-
- case 10:
- break;
-
- default:
-
- if(isprint(key))
- if((x<78) && (y<24))
- {
- printf("\33[%d;%dH",y,x);
- printf("%c",key);
- screen[y][x] = key;
- x++;
- }
- break;
- }
- }
- }
-
-
- store()
- {
- short x,y;
- FILE *fn;
- char edk;
-
- do
- dataentry("Enter Filename",fname,"@@@@@@@@@@@@@@@");
- while(fname[0] == 0);
-
- position = 0;
- fn = fopen(fname,"w");
- if(fn != 0)
- {
- for(y=1;y<26;y++)
- {
- parse(y,fn);
- }
- }
- else
- printf("file open error %d\n",fn);
- fclose(fn);
- }
-
-
- parse(y,fn)
- short y;
- FILE *fn;
- {
- char *strng;
- char *strt;
- short new;
- char temp[82];
- short edk;
- short cnt;
- char pchr;
-
- edk = 32;
- pchr = 0;
- strng = &screen[y][0];
-
- cnt = 0;
- while(*strng!=0)
- {
- while(*strng==' ')
- {
- strng++;
- cnt++;
- }
-
- switch(*strng)
- {
- case 0:
- return;
- break;
- default:
- fprintf(fn, "P%d\n%d\n", cnt, y);
- fprintf(fn, "%d\n", position);
- while(*strng!=' ')
- {
- if(*strng==0)
- break;
- if(*strng==13)
- break;
-
- fputc((short) *strng, fn);
-
- if((*strng == '@') || (*strng == '!') || (*strng == '#') ||
- (*strng == '|'))
- {
- position++;
- pchr = 2;
- }
- if(*strng == '.')
- {
- if(pchr >= 1)
- position++;
- }
- if(pchr > 0)
- pchr--;
-
- cnt++;
- strng++;
- }
- fputs("\n",fn);
- break;
- }
- }
- }
-
-
- load()
- {
- short x,y, p;
- FILE *fd, *fopen();
- char temp[81];
-
- fname[0] = 0;
- do
- {
- dataentry("Enter Filename",fname,"@@@@@@@@@@@@@@@");
- printf("\33[2J");
- if(fname[0]==0)
- return;
- fd = fopen(fname,"r");
- }
- while(fd==-1);
-
- if(fd != 0)
- {
- do
- {
- p = 0;
- if(fgets(temp, 5, fd)==0)
- break;
-
- if(temp[0] =='P')
- {
- x = atoi(&temp[1]);
- p = 1;
- }
- else
- {
- x = atoi(temp);
- p = 0;
- }
-
- if(fgets(temp, 5, fd)==0)
- break;
- y = atoi(temp);
-
- if(p == 1)
- {
- if(fgets(temp, 5, fd)==0)
- break;
- p = atoi(temp);
- }
- if(fgets(&screen[y][x], 81, fd)==0)
- break;
- }
- while(1);
- display();
- fclose(fd);
- }
- for(y=1;y<26;y++)
- for(x=1;x<80;x++)
- if(screen[y][x] < 0x20)
- screen[y][x] = 0x20;
- }
-
-
- display()
- {
- short y,x;
-
- printf("\33[2J");
- for(y=1;y<26;y++)
- {
- for(x=1;x<79;x++)
- {
- if(screen[y][x]=='\n')
- screen[y][x] = 32;
- printf("\33[%d;%dH",y,x);
- putch((short) screen[y][x] & 0xff);
- }
- }
- }
-
-
- edchr(char s)
- {
- if(s == ' ')
- return 1;
-
- if(s == 0)
- return 1;
-
- if(s == '#')
- return 1;
-
- if(s == '@')
- return 1;
-
- if(s == '|')
- return 1;
-
- if(s == '!')
- return 1;
-
- return 0;
- }
-
-