Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/parsifal/ss-kb.syn @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 Copyright 1992, Jerome T. Holland | |
3 See the file COPYING for license and usage terms. | |
4 */ | |
5 | |
6 /* Keyboard syntax for Sample Spreadsheet */ | |
7 | |
8 backspace = '\b' | |
9 delete = 339 | |
10 letter = 'a-z' + 'A-Z' | |
11 digit = '0-9' | |
12 eof = 0 | |
13 any key =~eof | |
14 yes ='y' + 'Y' | |
15 no =~yes | |
16 | |
17 text character = 32..127 | |
18 | |
19 up = 328 | |
20 page up = 329 | |
21 left = 331 | |
22 right = 333 | |
23 down = 336 | |
24 page down = 337 | |
25 control page up = 388 | |
26 control page down = 374 | |
27 control left = 371 | |
28 control right = 372 | |
29 home = 327 | |
30 control home = 375 | |
31 end = 335 | |
32 control end = 373 | |
33 escape = 27 | |
34 return = '\r' | |
35 | |
36 alt x = 301 | |
37 | |
38 F1 = 315 | |
39 F2 = 316 | |
40 | |
41 file error message = !display_message(&file_error_msg); | |
42 goto query = !accept_text(&goto_msg,""); | |
43 load name query = !accept_text(&load_from_msg, file_name); | |
44 no such file message = !accept_text(&nonexistent_msg, file_name); | |
45 overwrite query = !display_message(&file_exists_msg); | |
46 save changes query = !display_message(&changes_msg); | |
47 save name query = !accept_text(&save_to_msg, file_name); | |
48 print file query = !accept_text(&print_to_msg, file_name); | |
49 block query = !accept_text(&block_msg,""); | |
50 decimals query = !accept_text(&decimals_msg, ""); | |
51 bad decimals message = !accept_text(&bad_decimals_msg,NULL); | |
52 | |
53 [ | |
54 // sticky edit text | |
55 ~allow macros | |
56 default token type = void | |
57 ~lines and columns | |
58 ~diagnose errors | |
59 reduction choices | |
60 parser file name = "#.cpp" | |
61 ] | |
62 | |
63 | |
64 grammar | |
65 -> {top level command =update_status();}..., eof | |
66 | |
67 top level command | |
68 -> recalc request =recalc(); | |
69 -> utility menu, 'f' + 'F' =toggle_formula_display(); | |
70 -> main menu, 'a'+'A' =autocalc_flag = !autocalc_flag; | |
71 // -> edit request, edit text, return? =set_cell_text(); | |
72 -> edit request, edit text, return =set_cell_text(); | |
73 -> edit request, edit text, escape | |
74 -> delete request =delete_cell(); | |
75 -> page up =page_up(); | |
76 -> page down =page_down(); | |
77 -> control left =scroll_left(); | |
78 -> control right =scroll_right(); | |
79 -> home =home(); | |
80 -> end =end(); | |
81 -> up =cursor_up(); | |
82 -> down =cursor_down(); | |
83 -> left =cursor_left(); | |
84 -> right =cursor_right(); | |
85 -> load file | |
86 -> save file | |
87 -> clear spreadsheet | |
88 -> format | |
89 -> exit =quit(); | |
90 -> error | |
91 -> goto | |
92 -> column menu, 'i' + 'I' =insert_column(); | |
93 -> column menu, 'd' + 'D' =delete_column(); | |
94 -> column width | |
95 -> row menu, 'i' + 'I' =insert_row(); | |
96 -> row menu, 'd' + 'D' =delete_row(); | |
97 -> any menu, escape | |
98 -> print menu, 'o' + 'O', print file name =print(); | |
99 | |
100 any menu | |
101 -> main menu | |
102 -> spreadsheet menu | |
103 -> utility menu | |
104 -> column menu | |
105 -> row menu | |
106 | |
107 format | |
108 -> format menu, 'c' + 'C', block =set_conversion(currency); | |
109 -> format menu, 'g' + 'G', block =set_conversion(general); | |
110 -> format menu, 'f' + 'F', digits spec:n, block =set_decimals(n); | |
111 -> label menu, how:h, block =set_alignment(h); | |
112 | |
113 (int) how | |
114 -> 'l' + 'L' =LEFT; | |
115 -> 'c' + 'C' =CENTER; | |
116 -> 'r' + 'R' =RIGHT; | |
117 | |
118 (int) digits spec, bad digits spec | |
119 -> decimals query, edit number, return =check_digits(); | |
120 -> bad digits spec, bad decimals message, edit number, return =check_digits(); | |
121 | |
122 recalc request | |
123 -> F1 | |
124 -> utility menu, 'r' + 'R' | |
125 | |
126 delete request | |
127 -> delete | |
128 -> main menu, 'd' + 'D' | |
129 | |
130 goto | |
131 -> main menu, 'g' + 'G', goto query, cell name =go(); | |
132 | |
133 column width request | |
134 -> column menu, 'w' + 'W' =accept_text(&col_width_msg,""); | |
135 | |
136 column width, column width request | |
137 -> column width request, edit number, return =set_column_width(); | |
138 | |
139 column width | |
140 -> column width request, edit number, escape | |
141 | |
142 cell name, bad cell name | |
143 -> edit text, return =parse_cell_name(); | |
144 -> edit text, escape | |
145 -> bad cell name, edit text, return =parse_cell_name(); | |
146 -> bad cell name, edit text, escape | |
147 | |
148 block, bad block | |
149 -> block query, edit text, return =parse_block(); | |
150 -> block query, edit text, escape | |
151 -> bad block, edit text, return =parse_block(); | |
152 -> bad block, edit text, escape | |
153 | |
154 exit | |
155 -> exit request, save changes | |
156 | |
157 exit request | |
158 -> main menu, 'q' + 'Q' | |
159 -> alt x | |
160 | |
161 load file | |
162 -> spreadsheet menu, 'l' + 'L', save changes, load spreadsheet | |
163 | |
164 save file | |
165 -> spreadsheet menu, 's' + 'S', save spreadsheet | |
166 | |
167 save changes | |
168 -> not changed | |
169 -> changed, save changes query, no | |
170 -> changed, save changes query, yes, save spreadsheet | |
171 | |
172 changed, not changed | |
173 -> !STATUS(n_changes, changed); | |
174 | |
175 save spreadsheet | |
176 -> save name query, write file | |
177 -> save name query, old file, overwrite query, no, save spreadsheet | |
178 | |
179 load spreadsheet | |
180 -> load name query, old file =load_file(); | |
181 -> load name query, new file, no such file message, load spreadsheet | |
182 | |
183 print file name | |
184 -> print file query, new file | |
185 -> print file query, old file, overwrite query, yes | |
186 -> print file query, old file, overwrite query, no, print file name | |
187 | |
188 new file, old file | |
189 -> edit text, return =check_file_name(); | |
190 | |
191 write file, file error | |
192 -> new file =write_file(); | |
193 -> old file, overwrite query, yes =write_file(); | |
194 | |
195 write file | |
196 -> file error, file error message, any key | |
197 | |
198 clear spreadsheet | |
199 -> clear spreadsheet request, yes =clear(); | |
200 -> clear spreadsheet request, no | |
201 | |
202 clear spreadsheet request | |
203 -> spreadsheet menu, 'c' + 'C' =display_message(&clear_spreadsheet); | |
204 | |
205 main menu | |
206 -> '/' =display_menu(&main_menu); | |
207 | |
208 spreadsheet menu | |
209 -> main menu, 's' + 'S' =display_menu(&spreadsheet_menu); | |
210 | |
211 column menu | |
212 -> main menu, 'c' + 'C' =display_menu(&column_menu); | |
213 | |
214 row menu | |
215 -> main menu, 'r' + 'R' =display_menu(&row_menu); | |
216 | |
217 utility menu | |
218 -> main menu, 'u' + 'U' =display_menu(&utility_menu); | |
219 | |
220 format menu | |
221 -> main menu, 'f' + 'F' =display_menu(&format_menu); | |
222 | |
223 label menu | |
224 -> format menu, 'l' + 'L' =display_menu(&label_menu); | |
225 | |
226 print menu | |
227 -> spreadsheet menu, 'p' + 'P' =pm_msg(); | |
228 -> print menu, 'w' + 'W' + 'n' + 'N' =print_wide = !print_wide, pm_msg(); | |
229 -> print menu, 'l' + 'L' =(print_border = !print_border),pm_msg(); | |
230 -> print menu, 'b' + 'B', | |
231 block =print_block=TRUE,print_from=first_cell,print_to=last_cell,pm_msg(); | |
232 | |
233 edit request | |
234 -> F2 =init_cell_edit(); | |
235 -> main menu, 'e' + 'E' =init_cell_edit(); | |
236 -> text character - '/':c =init_text_input(c); | |
237 -> ^S =init_text_input('ä'); //228 | |
238 -> ^P =init_text_input('ã'); //227 | |
239 | |
240 (void) edit text | |
241 -> | |
242 -> edit text, text character:c =insert_char(c); | |
243 -> edit text, ^S =insert_char(228); | |
244 -> edit text, ^P =insert_char(227); | |
245 -> edit text, edit key | |
246 | |
247 (void) edit number | |
248 -> | |
249 -> edit number, digit:d =insert_char(d); | |
250 -> edit number, edit key | |
251 | |
252 (void) edit key | |
253 -> backspace =backspace_char(); | |
254 -> delete =delete_char(); | |
255 -> left =text_cursor_left(); | |
256 -> right =text_cursor_right(); | |
257 -> home =text_cursor_home(); | |
258 -> end =text_cursor_end(); | |
259 -> error =beep(); | |
260 | |
261 { | |
262 #include "ssd.h" | |
263 | |
264 char text_buffer[100]; | |
265 int text_index; | |
266 pair<int> text_cursor = {INPUT_LINE, 1}; | |
267 | |
268 #define GET_INPUT {int c;\ | |
269 PCB.input_code = ((c=getch()) != 0 ? c : getch()+256);} | |
270 | |
271 #define SYNTAX_ERROR | |
272 | |
273 #define STATUS(x,y) PCB.reduction_token = (x)?kb_##y##_token:kb_not_##y##_token | |
274 | |
275 void beep(void) { | |
276 sound(440); | |
277 delay(75); | |
278 nosound(); | |
279 } | |
280 | |
281 void accept_text(message *m, char *t) { | |
282 display_message(m); | |
283 init_text_edit(t); | |
284 } | |
285 | |
286 void backspace_char(void) { | |
287 if (text_cursor.col == 1) return; | |
288 text_cursor_left(); | |
289 delete_char(); | |
290 } | |
291 | |
292 int check_digits(void){ | |
293 char *tb = text_buffer + 1; | |
294 int n; | |
295 for (n = 0; *tb;) n = 10*n + *tb++ - '0'; | |
296 if (n > 7) CHANGE_REDUCTION(bad_digits_spec); | |
297 return n; | |
298 } | |
299 | |
300 void delete_cell(void) { | |
301 cell_pointer cp = ss[ac.ssc.row][ac.ssc.col]; | |
302 if (cp) free(cp); | |
303 ss[ac.ssc.row][ac.ssc.col] = NULL; | |
304 update_cell(ac.scc, ac.ssc); | |
305 set_active_cell(); | |
306 } | |
307 | |
308 void delete_char(void) { | |
309 strcpy(&text_buffer[text_cursor.col], &text_buffer[text_cursor.col+1]); | |
310 display_field( | |
311 text_cursor, | |
312 SCREEN_WIDTH - text_cursor.col, | |
313 LEFT, | |
314 TEXT_COLOR, | |
315 "%s", | |
316 &text_buffer[text_cursor.col] | |
317 ); | |
318 set_cursor(text_cursor); | |
319 } | |
320 | |
321 void delete_column(void) { | |
322 int i,j; | |
323 new_column = ac.ssc.col; | |
324 for (i = 0; i < MAXROWS; i++) if (ss[i][new_column]) free(ss[i][new_column]); | |
325 for (i = new_column; i < max_col; i++) | |
326 for (j = 0; j <= max_row; j++) | |
327 ss[j][i] = ss[j][i+1]; | |
328 for (j = 0; j <= max_row; j++) ss[j][max_col] = NULL; | |
329 max_col--; | |
330 inserted_columns = -1; | |
331 relabel(0,new_column); | |
332 new_column = inserted_columns = 0; | |
333 } | |
334 | |
335 void delete_row(void) { | |
336 int i,j; | |
337 new_row = ac.ssc.row; | |
338 for (i = 0; i < MAXCOLS; i++) if (ss[new_row][i]) free(ss[new_row][i]); | |
339 for (i = new_row; i < max_row; i++) | |
340 for (j = 0; j <= max_col; j++) | |
341 ss[i][j] = ss[i+1][j]; | |
342 for (j = 0; j <= max_col; j++) ss[max_row][j] = NULL; | |
343 max_row--; | |
344 inserted_rows = -1; | |
345 relabel(new_row,0); | |
346 new_row = inserted_rows = 0; | |
347 } | |
348 | |
349 void init_cell_edit(void) { | |
350 cell_pointer cp = ss[ac.ssc.row][ac.ssc.col]; | |
351 if (cp) strcpy(text_buffer+1, cp->text); | |
352 else text_buffer[1] = 0; | |
353 text_cursor.col = strlen(text_buffer+1) + 1; | |
354 textattr(TEXT_COLOR); | |
355 _setcursortype(_NORMALCURSOR); | |
356 input_msg.msg = text_buffer+1; | |
357 display_message(&input_msg); | |
358 set_cursor(text_cursor); | |
359 } | |
360 | |
361 void init_text_edit(char *c) { | |
362 if (c) strcpy(text_buffer+1, c); | |
363 text_cursor.col = strlen(text_buffer+1) + 1; | |
364 textattr(TEXT_COLOR); | |
365 _setcursortype(_NORMALCURSOR); | |
366 input_msg.msg = text_buffer+1; | |
367 display_message(&input_msg); | |
368 set_cursor(text_cursor); | |
369 } | |
370 | |
371 void init_text_input(int c) { | |
372 textattr(TEXT_COLOR); | |
373 _setcursortype(_NORMALCURSOR); | |
374 text_buffer[text_cursor.col = 1] = c; | |
375 set_cursor(text_cursor); | |
376 putch(c); | |
377 text_buffer[++text_cursor.col] = 0; | |
378 } | |
379 | |
380 void insert_char(int c){ | |
381 int n = strlen(&text_buffer[text_cursor.col]); | |
382 memmove(&text_buffer[text_cursor.col+1], &text_buffer[text_cursor.col], n+1); | |
383 text_buffer[81] = 0; | |
384 text_buffer[text_cursor.col++] = c; | |
385 putch(c); | |
386 display_field(text_cursor, n, LEFT, TEXT_COLOR, &text_buffer[text_cursor.col]); | |
387 set_cursor(text_cursor); | |
388 } | |
389 | |
390 void insert_column(void) { | |
391 int i,j; | |
392 if (max_col + 1 >= MAXCOLS) { | |
393 for (i = 0; i < MAXROWS; i++) if (ss[i][max_col]) free(ss[i][max_col]); | |
394 } | |
395 max_col++; | |
396 new_column = ac.ssc.col; | |
397 for (i = max_col; i > new_column; i--) | |
398 for (j = 0; j <= max_row; j++) | |
399 ss[j][i] = ss[j][i-1]; | |
400 for (j = 0; j < MAXROWS; j++) ss[j][new_column] = NULL; | |
401 inserted_columns = 1; | |
402 relabel(0,new_column); | |
403 new_column = inserted_columns = 0; | |
404 } | |
405 | |
406 void insert_row(void) { | |
407 int i,j; | |
408 if (max_row + 1 >= MAXROWS) { | |
409 for (i = 0; i < MAXCOLS; i++) if (ss[max_row][i]) free(ss[max_row][i]); | |
410 } | |
411 max_row++; | |
412 new_row = ac.ssc.row; | |
413 for (i = max_row; i > new_row; i--) | |
414 for (j = 0; j <= max_col; j++) | |
415 ss[i][j] = ss[i-1][j]; | |
416 for (j = 0; j < MAXCOLS; j++) ss[new_row][j] = NULL; | |
417 inserted_rows = 1; | |
418 relabel(new_row,0); | |
419 new_row = inserted_rows = 0; | |
420 } | |
421 | |
422 void recalc(void) { | |
423 int i,j; | |
424 recalc_flag = 1; | |
425 circular_flag = 0; | |
426 for (i = 0; i <= max_row; i++) for (j = 0; j <= max_col; j++) { | |
427 cell_pointer cp = ss[i][j]; | |
428 | |
429 if (cp == NULL || cp->type != formula) continue; | |
430 if (cp->recalc == recalc_count) eval(cp); | |
431 } | |
432 recalc_count += 2; | |
433 recalc_flag = 0; | |
434 update_screen(); | |
435 set_active_cell(); | |
436 } | |
437 | |
438 void relabel(int row, int col) { | |
439 int i,j; | |
440 | |
441 n_changes++; | |
442 for (i = row; i <= max_row; i++) for (j = col; j <= max_col; j++) { | |
443 cell_pointer cp = ss[i][j]; | |
444 | |
445 if (cp == NULL || cp->type != formula) continue; | |
446 relabel_formula(cp); | |
447 } | |
448 update_screen(); | |
449 set_active_cell(); | |
450 } | |
451 | |
452 void set_cell_text(void) { | |
453 char *tb = text_buffer + 1; | |
454 cell_pointer cp = realloc( | |
455 ss[ac.ssc.row][ac.ssc.col], | |
456 sizeof(cell_descriptor) + strlen(tb) | |
457 ); | |
458 n_changes++; | |
459 assert(cp); | |
460 if (ac.ssc.row > max_row) max_row = ac.ssc.row; | |
461 if (ac.ssc.col > max_col) max_col = ac.ssc.col; | |
462 strcpy(cp->text, tb); | |
463 cp->error = 0; | |
464 ss[ac.ssc.row][ac.ssc.col] = cp; | |
465 cp->recalc = recalc_count; | |
466 _setcursortype(_NOCURSOR); | |
467 eval(cp); | |
468 if (cp->type != text && autocalc_flag) recalc(); | |
469 else { | |
470 update_cell(ac.scc, ac.ssc); | |
471 set_active_cell(); | |
472 } | |
473 } | |
474 | |
475 void text_cursor_end(void) { | |
476 while (text_buffer[text_cursor.col]) { | |
477 text_cursor.col++; | |
478 } | |
479 set_cursor(text_cursor); | |
480 } | |
481 | |
482 void text_cursor_home(void) { | |
483 if (text_cursor.col == 1) return; | |
484 text_cursor.col = 1; | |
485 set_cursor(text_cursor); | |
486 } | |
487 | |
488 void text_cursor_left(void) { | |
489 if (text_cursor.col == 1) return; | |
490 text_cursor.col--; | |
491 set_cursor(text_cursor); | |
492 } | |
493 | |
494 void text_cursor_right(void) { | |
495 if (text_buffer[text_cursor.col] == 0) return; | |
496 if (text_cursor.col >= SCREEN_WIDTH) return; | |
497 text_cursor.col++; | |
498 set_cursor(text_cursor); | |
499 } | |
500 | |
501 void toggle_formula_display(void) { | |
502 formula_flag = !formula_flag; | |
503 display_message(&form_msg); | |
504 update_screen(); | |
505 set_active_cell(); | |
506 } | |
507 | |
508 } | |
509 | |
510 |