home *** CD-ROM | disk | FTP | other *** search
- #include <setjmp.h>
- #include <string.h>
- #include "pico.h"
-
- int debug, saw_eof;
- Tree *tree;
-
- static void run(Tree *t);
-
- static disp = 1;
- static jmp_buf jb;
-
- extern int main(int argc, char *argv[]) {
- extern int optind;
- int c, err = 0;
-
- while ((c = getopt(argc, argv, "dn")) != -1)
- if (c == 'd')
- debug = 1;
- else if (c == 'n')
- disp = 0;
- else
- err = 1;
- if (err || argc - optind != 0) {
- fprintf(stderr, "usage: pico [-nd]");
- exit(1);
- }
- buf[0].data = ealloc(DEF_X * DEF_Y);
- buf[1].data = ealloc(DEF_X * DEF_Y);
- setjmp(jb);
- while (1) {
- fprintf(stderr, "> ");
- fflush(stderr);
- yyparse();
- if (saw_eof)
- return 0;
- if (tree != NULL)
- run(tree);
- afree();
- }
- }
-
- #define swap(x,y) {\
- unsigned char *tmp = x;\
- x = y;\
- y = tmp;\
- }
-
- static void run(Tree *t) {
- int f;
- switch (t->t) {
- case Quit:
- exit(0);
- case Undo:
- swap(buf[0].data, buf[1].data);
- if (disp)
- display(buf[0].data);
- break;
- case Read:
- if ((f = readfile(t->kids[0])) > 0) {
- swap(buf[0].data, buf[1].data);
- memcpy(buf[0].data, buf[f].data, DEF_X * DEF_Y);
- if (disp)
- display(buf[0].data);
- }
- break;
- case Write:
- writefile(t->kids[0]);
- break;
- case Files:
- showfiles();
- break;
- default:
- swap(buf[0].data, buf[1].data);
- compile(t);
- #ifdef sgi
- if (debug)
- system("dis pico.out");
- #else
- if (debug)
- system("echo ',-1?' | adb " DUMPFILE);
- #endif
- if (disp)
- display(buf[0].data);
- break;
- }
- }
-
- extern void error(char *s) {
- fprintf(stderr, "%s\n", s);
- longjmp(jb,1);
- }
-