|
|
1.1 root 1: /*
2: * vis.c 1.8
3: *
4: * Executive for spreadsheet program
5: *
6: * A. F. Gettier
7: * Bell Laboratories
8: * Update made 11/10/82 19:33:40
9: * Retrieved 11/15/82 13:22:53
10: */
11: #include <stdio.h>
12: #include "curses.h"
13: #include <signal.h>
14: #include "vis.h"
15:
16: static char *sccs__id="@(#)vis.c 1.8\n";
17:
18: extern int LINES, COLS;
19:
20: /* extern FILE* _outf; */
21:
22: main(argc, argv)
23: int argc;
24: char *argv[];
25: {
26: int i;
27:
28: /*
29: * Initialize the parser
30: */
31:
32: /* _outf = fopen("outf","w"); */
33: pinit();
34:
35: /*
36: * Initialize the screen
37: */
38:
39: scrinit();
40:
41: /*
42: * Initialize the Hashing Functions
43: */
44:
45: hashinit();
46:
47: /*
48: * Read from file if it is given as arg
49: */
50: while ( argc > 1 ) {
51:
52: FILE *file;
53: move( LINES-2, 0 );
54: clrtoeol();
55: standout();
56:
57: if ( (file = fopen( argv[1], "r" )) == 0 ) {
58: printw( "CANNOT OPEN FILE: %s", argv[1] );
59: move( LINES-1, 0 );
60: standend();
61: refresh();
62: exit();
63: }
64:
65: printw( "READING FILE: %s", argv[1] );
66: standend();
67: refresh();
68: startlex( "" );
69: readfile( file );
70: (void)yyparse();
71: argc--; argv++;
72: }
73:
74: /*
75: * Now loop on the keyboard
76: */
77:
78: loop {
79: char buffer[80];
80: char *tbuf;
81:
82: do {
83: /*
84: * Print the prompt
85: */
86:
87: move( 0, 0 );
88: printw( ">> " );
89: clrtoeol();
90: refresh();
91:
92: /*
93: * Get a line of input
94: */
95:
96: } while( !vgline( buffer ) );
97:
98: /*
99: * erase the old prompt
100: */
101:
102: move( 0, 0 );
103: clrtoeol();
104:
105: /*
106: * Print the user input
107: */
108:
109: move( LINES-1, 0 );
110: clrtoeol();
111: printw( "%s", buffer );
112:
113: /*
114: * clear for errors
115: */
116:
117: move( LINES-2, 0 );
118: clrtoeol();
119:
120: i = 0;
121: while ( buffer[i] == ' ' || buffer[i] == '\t'
122: || buffer[i] == '\n' )
123: i++;
124: if ( buffer[i] == '\0' ) continue;
125:
126: /*
127: * Do the work
128: */
129:
130: refresh();
131: startlex( buffer );
132: (void)yyparse();
133: }
134: }
135:
136: vgline( buffer )
137: char *buffer;
138: {
139: char *tbuf;
140:
141: tbuf = buffer;
142: loop {
143: *tbuf = (char)getch();
144:
145: if ( *tbuf == '\014' )
146: wrefresh( curscr );
147: else if ( *tbuf == _tty.sg_erase ) {
148: if ( tbuf == buffer ) {
149: beep();
150: continue;
151: }
152: tbuf--;
153: addch( '\b' );
154: addch( ' ' );
155: addch( '\b' );
156: }
157:
158: else if ( *tbuf == _tty.sg_kill )
159: return(0);
160:
161: else if ( *tbuf == '\n' || *tbuf == '\r') {
162: *tbuf = '\n';
163: addch( *tbuf );
164: *tbuf = '\0';
165: break;
166: }
167:
168: else if ( *tbuf >= ' ' || *tbuf == '\t' ) {
169: addch( *tbuf );
170: tbuf++;
171: }
172:
173: refresh();
174: }
175: return(1);
176: }
177:
178: yyerror(s)
179: char *s;
180: {
181: move( LINES-2, 0 );
182: standout();
183: printw( "%s", s );
184: standend();
185: clrtoeol();
186: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.