forked from tech-squares/sd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdmatch.cpp
More file actions
2222 lines (1860 loc) · 76.4 KB
/
Copy pathsdmatch.cpp
File metadata and controls
2222 lines (1860 loc) · 76.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:3; fill-column:88 -*-
// SD -- square dance caller's helper.
//
// Copyright (C) 1990-2013 William B. Ackerman.
// Copyright (C) 1993 Alan Snyder
//
// This file is part of "Sd".
//
// Sd is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Sd is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Sd; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// This is for version 37.
/* This file defines the following functions:
matcher_initialize
all methods of matcher_class
*/
#include <string.h> /* for strcpy */
#include <stdio.h> /* for sprintf */
#include <ctype.h> /* for tolower */
// The definitions of "matcher_class" and "pat2_block" are in sdui.h.
#include "sdui.h"
void matcher_class::initialize_for_parse(int which_commands, bool show, bool only_want_extension)
{
// Reclaim all old modifier blocks. These are global over the entire program.
// All other fields get initialized (right here!) for every parse.
while (s_modifier_active_list) {
modifier_block *item = s_modifier_active_list;
s_modifier_active_list = item->gc_ptr;
item->gc_ptr = s_modifier_inactive_list;
s_modifier_inactive_list = item;
}
::memset(&m_active_result, 0, sizeof(match_result));
m_active_result.valid = true;
m_active_result.match.kind = ui_start_select;
m_active_result.match.call_conc_options = null_options;
m_current_result = &m_active_result;
m_only_extension = only_want_extension;
m_user_bracket_depth = 0;
m_match_count = 0;
m_exact_count = 0;
m_showing = show;
m_showing_has_stopped = false;
m_verify = false;
m_lowest_yield_depth = 999;
m_call_menu = which_commands;
m_echo_stuff[0] = 0; // Needed if no matches or user input is empty.
m_yielding_matches = 0;
m_final_result.valid = false;
m_final_result.exact = false;
m_space_ok = false;
/* **** Also need to consider initializing these?
int m_extended_bracket_depth;
char m_user_input[INPUT_TEXTLINE_SIZE+1]; // the current user input
char m_full_extension[INPUT_TEXTLINE_SIZE+1]; // the extension for the current pattern
int m_user_input_size; // This is always equal to strlen(m_user_input).
*/
}
namespace {
Cstring n_4_patterns[] = {
"0/4",
"1/4",
"2/4",
"3/4",
"4/4",
"5/4",
(Cstring) 0
};
int translate_keybind_spec(char key_name[])
{
int key_length;
int d1, d2, digits;
bool shift = false;
bool ctl = false;
bool alt = false;
bool ctlalt = false;
/* Compress hyphens out, and canonicalize to lower case. */
for (d1=key_length=0 ; key_name[d1] ; d1++) {
if (key_name[d1] != '-') key_name[key_length++] = tolower(key_name[d1]);
}
if (key_length < 2) return -1;
switch (key_name[0]) {
case 's': shift = true; break;
case 'c': ctl = true; break;
case 'a':
case 'm': alt = true; break;
}
switch (key_name[1]) {
case 'c': ctlalt = alt; break;
case 'a':
case 'm': ctlalt = ctl; break;
}
d2 = key_name[key_length-1] - '0';
if (d2 >= 0 && d2 <= 9) {
digits = d2;
d1 = key_name[key_length-2] - '0';
if (d1 >= 0 && d1 <= 9) {
digits += d1*10;
key_length--;
}
if (key_name[key_length-2] == 'f') {
if (digits < 1 || digits > 12)
return -1;
else if (key_length == 2) {
return FKEY+digits;
}
else if (key_length == 3 && shift) {
return SFKEY+digits;
}
else if (key_length == 3 && ctl) {
return CFKEY+digits;
}
else if (key_length == 3 && alt) {
return AFKEY+digits;
}
else if (key_length == 4 && ctlalt) {
return CAFKEY+digits;
}
else {
return -1;
}
}
if (key_name[key_length-2] == 'n') {
if (digits > 9 || key_length < 3)
return -1;
else if (key_length == 3 && ctl) {
return CTLNKP+digits;
}
else if (key_length == 3 && alt) {
return ALTNKP+digits;
}
else if (key_length == 4 && ctlalt) {
return CTLALTNKP+digits;
}
else {
return -1;
}
}
if (key_name[key_length-2] == 'e') {
if (digits > 15)
return -1;
if (key_length == 2) {
return EKEY+digits;
}
else if (key_length == 3 && shift) {
return SEKEY+digits;
}
else if (key_length == 3 && ctl) {
return CEKEY+digits;
}
else if (key_length == 3 && alt) {
return AEKEY+digits;
}
else if (key_length == 4 && ctlalt) {
return CAEKEY+digits;
}
else {
return -1;
}
}
else if (key_length == 2 && ctl) {
return CTLDIG+digits;
}
else if (key_length == 2 && alt) {
return ALTDIG+digits;
}
else if (key_length == 3 && ctlalt) {
return CTLALTDIG+digits;
}
else {
return -1;
}
}
else if (key_name[key_length-1] >= 'a' && key_name[key_length-1] <= 'z') {
if (key_length == 2 && ctl) {
return CTLLET+key_name[key_length-1]+'A'-'a';
}
else if (key_length == 2 && alt) {
return ALTLET+key_name[key_length-1]+'A'-'a';
}
else if (key_length == 3 && ctlalt) {
return CTLALTLET+key_name[key_length-1]+'A'-'a';
}
else {
return -1;
}
}
else
return -1;
}
// This returns zero if the name was clearly not able to be hashed
// (contains NUL, comma, atsign, or single quote). It returns 1
// if it could clearly be hashed (no blanks). It returns 2 if it
// had blanks, and might be questionable. Patterns to match
// (call or concept names, etc. can have blanks in them and still
// be hashed. Strings the user types can't be hashed if they have blanks.
int get_hash(Cstring string, int *bucket_p)
{
char c1 = string[0];
char c2 = string[1];
char c3 = string[2];
int bucket;
if (c1 == '<' && ((int) c2 & ~32) == 'A' && ((int) c3 & ~32) == 'N') {
*bucket_p = matcher_class::BRACKET_HASH;
return 1;
}
else if ((c1 && c1 != ',' && c1 != '@' && c1 != '\'') &&
(c2 && c2 != ',' && c2 != '@' && c2 != '\'') &&
(c3 && c3 != ',' && c3 != '@' && c3 != '\'')) {
// We use a hash function that ignores the "32" bit, so it is insensitive to case.
bucket = (((((int) c1 & ~32) << 3) + ((int) c2 & ~32)) << 3) + ((int) c3 & ~32);
bucket += bucket * 20;
bucket += bucket >> 7;
bucket &= (matcher_class::NUM_NAME_HASH_BUCKETS-1);
*bucket_p = bucket;
if (c1 != ' ' && c2 != ' ' && c3 != ' ') return 1;
else return 2;
}
else
return 0;
}
void hash_me(int bucket, int i)
{
gg77->matcher_p->call_hashers[bucket].add_one(i);
}
bool foobar(const char *user)
{
if (!user[0]) return true;
if (user[0] != ' ') return false;
if (!user[1]) return true;
if (user[1] != 'e') return false;
if (!user[2]) return true;
if (user[2] != 'r') return false;
if (!user[3]) return true;
if (user[3] != 's' && user[3] != '\'') return false;
return true;
}
} // namespace
void matcher_class::copy_sublist(const match_result *outbar, modifier_block *tails)
{
if (outbar->real_next_subcall) {
modifier_block *out;
const match_result *newoutbar = outbar->real_next_subcall;
if (s_modifier_inactive_list) {
out = s_modifier_inactive_list;
s_modifier_inactive_list = out->gc_ptr;
}
else
out = new modifier_block;
*out = newoutbar->match;
out->packed_next_conc_or_subcall = (modifier_block *) 0;
out->packed_secondary_subcall = (modifier_block *) 0;
out->gc_ptr = s_modifier_active_list;
s_modifier_active_list = out;
tails->packed_next_conc_or_subcall = out;
copy_sublist(newoutbar, out);
}
if (outbar->real_secondary_subcall) {
modifier_block *out;
const match_result *newoutbar = outbar->real_secondary_subcall;
if (s_modifier_inactive_list) {
out = s_modifier_inactive_list;
s_modifier_inactive_list = out->gc_ptr;
}
else
out = new modifier_block;
*out = newoutbar->match;
out->packed_next_conc_or_subcall = (modifier_block *) 0;
out->packed_secondary_subcall = (modifier_block *) 0;
out->gc_ptr = s_modifier_active_list;
s_modifier_active_list = out;
tails->packed_secondary_subcall = out;
copy_sublist(newoutbar, out);
}
}
void matcher_class::copy_to_user_input(const char *stuff)
{
// See comments in sdui.h about INPUT_TEXTLINE_SIZE and MAX_TEXT_LINE_LENGTH.
// The target is known to be allocated to INPUT_TEXTLINE_SIZE+1.
// The source is null-terminated and in an area of size MAX_TEXT_LINE_LENGTH.
::strcpy(m_user_input, stuff);
m_user_input_size = ::strlen(m_user_input);
}
void matcher_class::erase_matcher_input()
{
m_user_input[0] = '\0';
m_user_input_size = 0;
}
int matcher_class::delete_matcher_word()
{
bool deleted_letter = false;
int orig_size = m_user_input_size;
while (m_user_input_size > 0) {
if (m_user_input[m_user_input_size-1] == ' ') {
if (deleted_letter) break;
}
else
deleted_letter = true;
m_user_input_size--;
m_user_input[m_user_input_size] = '\0';
}
return orig_size-m_user_input_size;
}
// Returns true if it processed the thing.
bool matcher_class::process_accel_or_abbrev(modifier_block & mb, char linebuff[])
{
m_active_result.match = mb;
m_active_result.indent = false;
m_active_result.real_next_subcall = (match_result *) 0;
m_active_result.real_secondary_subcall = (match_result *) 0;
m_final_result.match = m_active_result.match;
switch (m_final_result.match.kind) {
case ui_command_select:
strcpy(linebuff, command_commands[m_final_result.match.index]);
m_final_result.match.index = -1-command_command_values[m_final_result.match.index];
break;
case ui_resolve_select:
strcpy(linebuff, resolve_menu[m_final_result.match.index].command_name);
m_final_result.match.index = -1-resolve_menu[m_final_result.match.index].action;
break;
case ui_start_select:
strcpy(linebuff, startup_commands[m_final_result.match.index]);
break;
case ui_concept_select:
gg77->unparse_call_name(get_concept_name(m_final_result.match.concept_ptr),
linebuff,
&m_final_result.match.call_conc_options);
// Reject off-level concept accelerator key presses.
if (!allowing_all_concepts &&
get_concept_level(m_final_result.match.concept_ptr) > calling_level)
return false;
m_final_result.match.index = 0;
break;
case ui_call_select:
gg77->unparse_call_name(get_call_name(m_final_result.match.call_ptr),
linebuff,
&m_final_result.match.call_conc_options);
m_final_result.match.index = 0;
break;
default:
return false;
}
m_final_result.valid = true;
m_active_result.valid = true;
return true;
}
void matcher_class::do_accelerator_spec(Cstring inputline, bool is_accelerator)
{
if (!inputline[0] || inputline[0] == '#') return; // This is a blank line or a comment.
char key_name[MAX_FILENAME_LENGTH];
char *key_org;
char junk_name[MAX_FILENAME_LENGTH];
int ccount;
int menu_type = call_list_any;
int keybindcode = -1;
if (sscanf(inputline, "%s %n%s", key_name, &ccount, junk_name) == 2) {
key_org = key_name;
if (key_name[0] == '+') {
menu_type = e_match_startup_commands;
key_org = &key_name[1];
}
else if (key_name[0] == '*') {
menu_type = e_match_resolve_commands;
key_org = &key_name[1];
}
if (is_accelerator)
keybindcode = translate_keybind_spec(key_org);
else
keybindcode = 0;
}
if (keybindcode < 0)
gg77->iob88.fatal_error_exit(1, "Bad format in key binding", inputline);
m_active_result.match.kind = ui_call_select;
Cstring target = inputline+ccount;
if (!strcmp(target, "deleteline"))
m_active_result.match.index = special_index_deleteline;
else if (!strcmp(target, "deleteword"))
m_active_result.match.index = special_index_deleteword;
else if (!strcmp(target, "copytext"))
m_active_result.match.index = special_index_copytext;
else if (!strcmp(target, "cuttext"))
m_active_result.match.index = special_index_cuttext;
else if (!strcmp(target, "pastetext"))
m_active_result.match.index = special_index_pastetext;
else if (!strcmp(target, "lineup"))
m_active_result.match.index = special_index_lineup;
else if (!strcmp(target, "linedown"))
m_active_result.match.index = special_index_linedown;
else if (!strcmp(target, "pageup"))
m_active_result.match.index = special_index_pageup;
else if (!strcmp(target, "pagedown"))
m_active_result.match.index = special_index_pagedown;
else if (!strcmp(target, "quoteanything"))
m_active_result.match.index = special_index_quote_anything;
else {
::strcpy(m_user_input, target);
m_user_input_size = ::strlen(m_user_input);
int matches = match_user_input(menu_type, false, false, false);
m_active_result = m_final_result;
if ((matches != 1 && matches - m_yielding_matches != 1 && !m_active_result.exact)) {
// Didn't find the target of the key binding. Below C4X, failure to find
// something could just mean that it was a call off the list. At C4X, we
// take it seriously. So the initialization file should always be tested at C4X.
if (calling_level >= l_c4x)
gg77->iob88.fatal_error_exit(1, "Didn't find target of accelerator or abbreviation", inputline);
return;
}
if (m_active_result.match.packed_next_conc_or_subcall ||
m_active_result.match.packed_secondary_subcall) {
if (calling_level >= l_c4x)
gg77->iob88.fatal_error_exit(1, "Target of accelerator or abbreviation is too complicated", inputline);
return;
}
}
if (is_accelerator) {
modifier_block **table_thing;
if (m_active_result.match.kind == ui_start_select) {
table_thing = &m_fcn_key_table_start[keybindcode-FCN_KEY_TAB_LOW];
}
else if (m_active_result.match.kind == ui_resolve_select) {
table_thing = &m_fcn_key_table_resolve[keybindcode-FCN_KEY_TAB_LOW];
}
else if (m_active_result.match.kind == ui_concept_select ||
m_active_result.match.kind == ui_call_select ||
m_active_result.match.kind == ui_command_select) {
table_thing = &m_fcn_key_table_normal[keybindcode-FCN_KEY_TAB_LOW];
}
else
gg77->iob88.fatal_error_exit(1, "Anomalous accelerator", inputline);
modifier_block *newthing = new modifier_block;
*newthing = m_active_result.match;
if (*table_thing)
gg77->iob88.fatal_error_exit(1, "Redundant accelerator", inputline);
*table_thing = newthing;
}
else {
abbrev_block **table_thing;
if (m_active_result.match.kind == ui_start_select) {
table_thing = &m_abbrev_table_start;
}
else if (m_active_result.match.kind == ui_resolve_select) {
table_thing = &m_abbrev_table_resolve;
}
else if (m_active_result.match.kind == ui_concept_select ||
m_active_result.match.kind == ui_call_select ||
m_active_result.match.kind == ui_command_select) {
table_thing = &m_abbrev_table_normal;
}
else
gg77->iob88.fatal_error_exit(1, "Anomalous abbreviation", inputline);
abbrev_block *newthing = new abbrev_block;
newthing->key = new char[::strlen(key_org)+1];
::strcpy((char *) newthing->key, key_org);
newthing->value = m_active_result.match;
newthing->next = *table_thing;
*table_thing = newthing;
}
}
/* Call MATCHER_INITIALIZE first.
This function sets up the concept list. The concepts are found
in the external array concept_descriptor_table. For each
i, the field concept_descriptor_table[i].name has the text that we
should display for the user.
*/
void matcher_initialize()
{
int i, j;
int concept_number;
const concept_descriptor *p;
// Decide whether we allow the "diagnose" concept, by deciding
// when we will stop the concept list scan.
concept_kind end_marker = (ui_options.diagnostic_mode) ?
constant_with_marker_end_of_list :
constant_with_concept_diagnose;
// Create the concept lists, both universal and level-restricted.
for (concept_number=0 ; ; concept_number++) {
p = access_concept_descriptor_table(concept_number);
if (get_concept_kind(p) == end_marker) break;
gg77->matcher_p->m_concept_list.add_one(concept_number);
if (get_concept_level(p) <= calling_level)
gg77->matcher_p->m_level_concept_list.add_one(concept_number);
}
// Initialize the hash buckets for call names.
int bucket;
uint32 ku;
// First, do the selectors. Before that, be sure "<anyone>" is hashed.
// These list all the buckets that selectors can go to.
if (!get_hash("<an", &bucket))
gg77->iob88.fatal_error_exit(2, "Can't hash selector base");
index_list selector_hasher;
selector_hasher.add_one(bucket);
for (i=1; i<selector_INVISIBLE_START; i++) {
if (!get_hash(selector_list[i].name, &bucket)) {
char errbuf[255];
sprintf(errbuf, "Can't hash selector %d - 1!", i);
gg77->iob88.fatal_error_exit(2, errbuf);
}
/* See if this bucket is already accounted for. */
for (j=0; j<selector_hasher.the_list_size; j++) {
if (selector_hasher.the_list[j] == bucket) goto already_in1;
}
selector_hasher.add_one(bucket);
// Now do it again for the singular names.
already_in1:
if (!get_hash(selector_list[i].sing_name, &bucket)) {
char errbuf[255];
sprintf(errbuf, "Can't hash selector %d - 2!", i);
gg77->iob88.fatal_error_exit(2, errbuf);
}
for (j=0; j<selector_hasher.the_list_size; j++) {
if (selector_hasher.the_list[j] == bucket) goto already_in2;
}
selector_hasher.add_one(bucket);
already_in2: ;
}
// Next, do the taggers. Before that, be sure "<atc>" is hashed.
// These list all the buckets that taggers can go to.
if (!get_hash("<at", &bucket))
gg77->iob88.fatal_error_exit(2, "Can't hash tagger base!");
index_list tagger_hasher;
tagger_hasher.add_one(bucket);
for (i=0; i<NUM_TAGGER_CLASSES; i++) {
for (ku=0; ku<number_of_taggers[i]; ku++) {
// Some taggers ("@6 start vertical tag") can't be hashed because
// of the at sign. That's OK.
if (get_call_name(tagger_calls[i][ku])[0] != '@') {
if (!get_hash(get_call_name(tagger_calls[i][ku]), &bucket)) {
char errbuf[255];
sprintf(errbuf, "Can't hash tagger %d %d!", i, (int) ku);
gg77->iob88.fatal_error_exit(2, errbuf);
}
}
for (j=0; j<tagger_hasher.the_list_size; j++) {
if (tagger_hasher.the_list[j] == bucket) goto already_in3;
}
tagger_hasher.add_one(bucket);
already_in3: ;
}
}
/* Now do the calls. */
for (i=0; i<number_of_calls[call_list_any]; i++) {
Cstring name = get_call_name(main_call_lists[call_list_any][i]);
doitagain:
if (name[0] == '@') {
switch (name[1]) {
case '6': case 'k': case 'K': case 'V':
// This is a call like "<anyone> run". Put it into every bucket
// that could match a selector.
for (j=0 ; j<selector_hasher.the_list_size ; j++)
hash_me(selector_hasher.the_list[j], i);
continue;
case 'v': case 'w': case 'x': case 'y':
// This is a call like "<atc> your neighbor".
// Put it into every bucket that could match a tagger.
for (j=0 ; j<tagger_hasher.the_list_size ; j++)
hash_me(tagger_hasher.the_list[j], i);
continue;
case '0': case 'T': case 'm':
// We act as though any string starting with "[" hashes to BRACKET_HASH.
hash_me(matcher_class::BRACKET_HASH, i);
continue;
case 'e':
// If this is "@e", hash it to both "left" and to whatever naturally follows.
(void) get_hash("left", &bucket);
hash_me(bucket, i);
name += 2;
goto doitagain;
default:
if (!get_escape_string(name[1])) {
// If this escape is something like "@2", as in "@2scoot and plenty",
// ignore it. Hash it under "scoot and plenty".
name += 2;
goto doitagain;
}
break;
}
}
if (get_hash(name, &bucket)) {
hash_me(bucket, i);
continue;
}
// If we get here, this call needs to be put into the extra bucket at the end,
// and also into EVERY OTHER BUCKET!!!!
for (bucket=0 ; bucket < matcher_class::NUM_NAME_HASH_BUCKETS+1 ; bucket++)
hash_me(bucket, i);
}
// Now do the concepts from the full concept list.
for (i=0; i<gg77->matcher_p->m_concept_list.the_list_size; i++) {
int the_item = gg77->matcher_p->m_concept_list.the_list[i];
Cstring name = get_concept_name(access_concept_descriptor_table(the_item));
if (name[0] == '@' && (name[1] == '6' || name[1] == 'k' || name[1] == 'K' || name[1] == 'V')) {
// This is a call like "<anyone> run". Put it into every bucket
// that could match a selector.
for (j=0 ; j<selector_hasher.the_list_size ; j++) {
bucket = selector_hasher.the_list[j];
gg77->matcher_p->conc_hashers[bucket].add_one(the_item);
}
continue;
}
else if (get_hash(name, &bucket)) {
gg77->matcher_p->conc_hashers[bucket].add_one(the_item);
continue;
}
// If we get here, this concept needs to be put into the extra bucket at the end,
// and also into EVERY OTHER BUCKET!!!!
for (bucket=0 ; bucket < matcher_class::NUM_NAME_HASH_BUCKETS+1 ; bucket++) {
gg77->matcher_p->conc_hashers[bucket].add_one(the_item);
}
}
// Now do the "level concepts".
for (i=0; i<gg77->matcher_p->m_level_concept_list.the_list_size; i++) {
int the_item = gg77->matcher_p->m_level_concept_list.the_list[i];
Cstring name = get_concept_name(access_concept_descriptor_table(the_item));
if (name[0] == '@' && (name[1] == '6' || name[1] == 'k' || name[1] == 'K' || name[1] == 'V')) {
// This is a call like "<anyone> run". Put it into every bucket
// that could match a selector.
for (j=0 ; j<selector_hasher.the_list_size ; j++) {
bucket = selector_hasher.the_list[j];
gg77->matcher_p->conclvl_hashers[bucket].add_one(the_item);
}
continue;
}
else if (get_hash(name, &bucket)) {
gg77->matcher_p->conclvl_hashers[bucket].add_one(the_item);
continue;
}
// If we get here, this concept needs to be put into the extra bucket at the end,
// and also into EVERY OTHER BUCKET!!!!
for (bucket=0 ; bucket < matcher_class::NUM_NAME_HASH_BUCKETS+1 ; bucket++) {
gg77->matcher_p->conclvl_hashers[bucket].add_one(the_item);
}
}
}
/*
* Call Verification
*/
/* These variables are actually local to verify_call, but they are
expected to be preserved across the throw, so they must be static. */
static parse_block *parse_mark;
static call_list_kind savecl;
/*
* Return TRUE if the specified call appears to be legal in the
* current context.
*/
bool matcher_class::verify_call()
{
// If we are not verifying, we return TRUE immediately,
// thereby causing the item to be listed.
if (!m_verify) return true;
bool resultval = true;
interactivity = interactivity_verify; // So deposit_call doesn't ask user for info.
warning_info saved_warnings = config_save_warnings();
int old_history_ptr = config_history_ptr;
parse_mark = get_parse_block_mark();
save_parse_state();
savecl = parse_state.call_list_to_use;
start_sel_dir_num_iterator();
try_another_selector:
selector_used = false;
direction_used = false;
number_used = false;
mandatory_call_used = false;
verify_used_number = false;
verify_used_selector = false;
verify_used_direction = false;
// Do the call. An error will signal and go to failed.
try {
bool theres_a_call_in_here = false;
parse_block *save1 = (parse_block *) 0;
modifier_block *anythings = &m_final_result.match;
restore_parse_state();
/* This stuff is duplicated in uims_get_call_command in sdui-tty.c . */
while (anythings) {
call_conc_option_state save_stuff = m_final_result.match.call_conc_options;
// First, if we have already deposited a call, and we see more stuff, it must be
// concepts or calls for an "anything" subcall.
if (save1) {
parse_block *tt = get_parse_block();
set_parse_block_concept(save1, &concept_marker_concept_mod);
set_parse_block_next(save1, tt);
set_parse_block_concept(tt, &concept_marker_concept_mod);
set_parse_block_call(tt, access_base_calls(base_call_null));
set_parse_block_call_to_print(tt, access_base_calls(base_call_null));
set_parse_block_replacement_key(tt, DFM1_CALL_MOD_MAND_ANYCALL/DFM1_CALL_MOD_BIT);
parse_state.concept_write_ptr = get_parse_block_subsidiary_root_addr(tt);
save1 = (parse_block *) 0;
}
m_final_result.match.call_conc_options = anythings->call_conc_options;
if (anythings->kind == ui_call_select) {
verify_options = anythings->call_conc_options;
if (deposit_call(anythings->call_ptr, &anythings->call_conc_options)) {
// The problem may be just that the current number is
// inconsistent with the call's "odd number only" requirement.
number_used = true;
if (iterate_over_sel_dir_num(verify_used_selector,
verify_used_direction,
verify_used_number))
goto try_another_selector;
goto failed;
}
save1 = *parse_state.concept_write_ptr;
theres_a_call_in_here = true;
}
else if (anythings->kind == ui_concept_select) {
verify_options = anythings->call_conc_options;
if (deposit_concept(anythings->concept_ptr)) goto failed;
}
else break; /* Huh? */
m_final_result.match.call_conc_options = save_stuff;
anythings = anythings->packed_next_conc_or_subcall;
}
parse_state.call_list_to_use = savecl; /* deposit_concept screwed it up */
/* If we didn't see a call, the user is just verifying
a string of concepts. Accept it. */
if (!theres_a_call_in_here) goto accept;
/* If the parse stack is nenempty, a subsidiary call is needed and hasn't been filled in.
Therefore, the parse tree is incomplete. We can print such parse trees, but we
can't execute them. So we just assume the call works. */
if (parse_state.parse_stack_index != 0) goto accept;
toplevelmove(); // This might throw an error.
goto accept;
}
catch(error_flag_type) {
// A call failed. If the call had some mandatory substitution, pass it anyway.
if (mandatory_call_used) goto accept;
// Or a bad choice of selector or number may be the cause.
// Try again with a different selector, until we run out of ideas.
if (iterate_over_sel_dir_num(verify_used_selector,
verify_used_direction,
verify_used_number))
goto try_another_selector;
goto failed;
}
failed:
resultval = false;
accept:
restore_parse_state();
release_parse_blocks_to_mark(parse_mark);
config_history_ptr = old_history_ptr;
config_restore_warnings(saved_warnings);
interactivity = interactivity_normal;
return resultval;
}
/*
* Record a match. Extension is how the current input would be extended to
* match the current pattern. Result is the value of the
* current pattern. Special case: if user input is empty, extension is
* not set.
*/
void matcher_class::record_a_match()
{
int old_yield = m_lowest_yield_depth;
m_extended_bracket_depth = 0;
if (!m_showing) {
char *s1 = m_echo_stuff;
const char *s2 = m_full_extension;
if (m_match_count == 0) {
// This is the first match. Set m_echo_stuff to the
// full extension that we have. Count brackets.
for ( ; ; s1++,s2++) {
*s1 = *s2;
if (!*s1) break;
else if (*s1 == '[') m_extended_bracket_depth++;
else if (*s1 == ']') m_extended_bracket_depth--;
}
}
else {
// Shorten m_echo_stuff to the maximal common prefix.
// Count brackets.
for ( ; ; s1++,s2++) {
if (!*s1) break;
else if (*s1 != *s2) {
*s1 = 0;
break;
}
else if (*s1 == '[') m_extended_bracket_depth++;
else if (*s1 == ']') m_extended_bracket_depth--;
}
}
}
// Copy if we are doing the "show" operation, whether we are verifying or not.
if (m_showing) m_final_result = m_active_result;
// Always copy the first match.
// Also, always copy, and process modifiers, if we are processing the
// "verify" operation. Also, copy the first exact match, and any
// exact match that isn't yielding relative to what we have so far.
if (m_match_count == 0 ||
m_verify ||
(*m_full_extension == '\0' &&
(m_exact_count == 0 || m_current_result->yield_depth <= old_yield))) {
m_final_result = m_active_result;
m_lowest_yield_depth = m_current_result->yield_depth;
/* We need to copy the modifiers to reasonably stable storage. */
copy_sublist(&m_final_result, &m_final_result.match);
}
if (*m_full_extension == '\0') {
m_exact_count++;
m_final_result.exact = true;
}
m_match_count++;
if (m_current_result->yield_depth > old_yield)
m_yielding_matches++;
if (m_showing) {
if (verify_call()) gg77->iob88.show_match(-1);
}
}
/* ************************************************************************
This procedure must obey certain properties. Be sure that no modifications
to this procedure compromise this, or else fix the stuff in
"scan_concepts_and_calls" that depends on it.