|
|
1.1 root 1: #include <stdio.h>
2: #include <signal.h>
3: #include <setjmp.h>
4: #include "pico.h"
5: #include "pico2.h"
6:
7: int DEF_LL = 512; /* default linelength */
8: int DEF_NL = 512; /* default number of lines */
9:
10: short CURSCRATCH = 1;
11: short CUROLD = 0;
12:
13: char *progr;
14: struct SRC src[MANY];
15: int nsrc = 2; /* 0,1 reserved for Old, and Scratch */
16:
17: char frameb = 0; /* open framebuffer */
18: char metheus = 0; /* open metheus display */
19: char faster = 1; /* update display 1 line iso 1 pel at a time */
20: char usednew = 0; /* did program use Scratch ? */
21: char usedold = 0; /* did program use Old ? */
22: char seetree = 0;
23: char optim = 1;
24:
25: int nrparams = 0;
26: char isglobal = 0;
27: int whichdevice = 0;
28:
29: extern char nesting;
30: extern int linenumber, nalloc;
31: FILE *INPUT = stdin;
32: jmp_buf begin;
33: int (*oldquit)();
34:
35: onquit()
36: {
37: fprintf(stderr, "\ninterrupted\n");
38: oldquit = signal(SIGINT, onquit);
39: if (INPUT != stdin) undirect();
40: fflush(stderr);
41: longjmp(begin, 0);
42: }
43:
44: Reset()
45: {
46: if (linenumber < 1) linenumber = 1;
47: nalloc = 0; nesting = 0;
48: usednew = usedold = nrparams = 0;
49: }
50:
51: main(argc, argv)
52: char **argv;
53: {
54: int i=1, base=1;
55: char c;
56:
57: Reset();
58: while (argc > base && argv[base][0] == '-')
59: { while ((c = argv[base][i++]) != '\0')
60: switch (c) {
61: case 'f': frameb = 1; break;
62: case 'm': metheus = 1; break;
63: case 't': seetree = 1; break;
64: case 'o': optim = 1 - optim; break;
65: case 'd': DEF_LL = 1280; DEF_NL = 1024; break;
66: case 'w': DEF_LL = atoi(&argv[base][i]); goto done;
67: case 'h': DEF_NL = atoi(&argv[base][i]); goto done;
68: case '0': case '1': case '2':
69: case '3': case '4': case '5':
70: case '6': case '7': case '8': case '9':
71: whichdevice = c - '0';
72: break;
73: default : Usage("unknown option");
74: }
75: done: base++; i = 1;
76: }
77: Init();
78: Old->nchan = Scratch->nchan = 1;
79: snore()
80: fprintf(stderr, "b&w, %dx%d pel, ", DEF_LL, DEF_NL);
81: if (metheus)
82: fprintf(stderr, "metheus display\n");
83: else if (frameb)
84: fprintf(stderr, "framebuffer\n");
85: else
86: fprintf(stderr, "no display\n");
87:
88: setwindow(0, 0, DEF_LL, DEF_NL);
89: for (; base < argc; base++)
90: prepare(argv[base]);
91:
92: linenumber = i = 1;
93: setjmp(begin);
94: signal(SIGINT, onquit);
95:
96: if (i && (i = open("/usr/lib/pico/defines", 0)) > 0)
97: { close(i);
98: redirect("/usr/lib/pico/defines");
99: linenumber = i = 0; /* to avoid a loop via longjmp */
100: }
101:
102: do { Reset();
103: Prompt;
104: } while (yyparse());
105:
106: }
107:
108: Init()
109: {
110: syminit(); /* initialize symbol table */
111: nopix(Old); /* allocate workspace */
112: nopix(Scratch);
113: ABSENT
114: }
115:
116: extern char lastyy, operator, nolf;
117: static int curline;
118:
119: yyerror(s1, d)
120: char *s1;
121: { extern int pline;
122: extern char *thisfun;
123:
124: if (nesting > 0)
125: fprintf(stderr, "line %d/%d: ", linenumber-curline, pline);
126: fprintf(stderr, s1, d);
127: fprintf(stderr, "\n");
128:
129: if (lastyy != '\n')
130: do; while(yylex() != ';' || nolf);
131: nesting = 1; operator = 0; sympurge(); nesting = 0;
132: thisfun = '\0';
133: if (INPUT != stdin) undirect();
134:
135: longjmp(begin, 0);
136: }
137:
138: redirect(s)
139: char *s;
140: { extern char lastyy;
141:
142: if (INPUT != stdin)
143: { fprintf(stderr, "cannot redirect recursively\n");
144: return 0;
145: }
146: curline = linenumber;
147: if ((INPUT = fopen(s, "r")) == NULL)
148: { fprintf(stderr, "cannot open %s\n", s);
149: INPUT = stdin;
150: return 0;
151: }
152: ungetc('\n', stdin);
153: lastyy = '\n';
154: return 1;
155: }
156:
157: undirect()
158: {
159: if (INPUT != stdin)
160: { fclose(INPUT);
161: } else
162: { fprintf(stderr, "\n");
163: exit(0);
164: }
165: INPUT = stdin;
166: linenumber = curline-1; /* 1 <cr> was unget */
167: curline = 0;
168: }
169:
170: dohelp()
171: { int pid, rpid, retcode;
172:
173: if ((pid = fork()) == 0)
174: { signal(SIGINT, oldquit);
175: execl("/bin/cat", "/bin/cat", "/usr/lib/pico/help", 0);
176: fprintf(stderr, "pico: /bin/cat not found...\n");
177: exit(0100);
178: }
179: signal(SIGINT, SIG_IGN);
180: while ((rpid = wait(&retcode)) != pid && rpid != -1)
181: ;
182: signal(SIGINT, onquit);
183: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.