This repository was archived by the owner on Apr 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsdinit.cpp
More file actions
2877 lines (2326 loc) · 105 KB
/
Copy pathsdinit.cpp
File metadata and controls
2877 lines (2326 loc) · 105 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-2012 William B. Ackerman.
//
// 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 defines the following functions:
parse_level
start_sel_dir_num_iterator
iterate_over_sel_dir_num
install_outfile_string
get_first_session_line
get_next_session_line
prepare_to_read_menus
process_session_info
close_init_file
general_final_exit
conzept::translate_concept_names
configuration::startinfolist
configuration::initialize
start_stats_file_from_GLOB_stats_filename
open_session
and the following external variables:
selector_for_initialize
direction_for_initialize
number_for_initialize
color_index_list
color_randomizer
*/
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include "sd.h"
#include "sdui.h"
#include "sort.h"
#include "mapcachefile.h"
selector_kind selector_for_initialize;
direction_kind direction_for_initialize;
int number_for_initialize;
int *color_index_list;
int color_randomizer[4];
// This gets temporarily allocated. It persists through the entire initialization.
//
static uint32 *global_temp_call_indices;
static int global_callcount; /* Index into the above. */
/* These variables are actually local to test_starting_setup, but they are
expected to be preserved across the throw, so they must be static. */
static parse_block *parse_mark;
static int call_index;
static call_with_name *test_call;
static bool crossiness;
static bool magicness;
static bool intlkness;
extern bool parse_level(Cstring s, Cstring *break_ptr /*= 0*/)
{
int len = strlen(s);
Cstring breakpos = strpbrk(s, "-:");
if (breakpos) len = breakpos-s;
if (break_ptr) *break_ptr = breakpos;
switch (s[0]) {
case 'm': case 'M': calling_level = l_mainstream; return true;
case 'p': case 'P': case '+': calling_level = l_plus; return true;
case 'a': case 'A':
if (s[1] == '1' && len == 2) calling_level = l_a1;
else if (s[1] == '2' && len == 2) calling_level = l_a2;
else if (s[1] == 'l' && s[2] == 'l' && len == 3) calling_level = l_dontshow;
else return false;
return true;
case 'c': case 'C':
if (s[1] == '3' && (s[2] == 'a' || s[2] == 'A') && len == 3)
calling_level = l_c3a;
else if (s[1] == '3' && (s[2] == 'x' || s[2] == 'X') && len == 3)
calling_level = l_c3x;
else if (s[1] == '4' && (s[2] == 'a' || s[2] == 'A') && len == 3)
calling_level = l_c4a;
else if (s[1] == '4' && (s[2] == 'x' || s[2] == 'X') && len == 3)
calling_level = l_c4x;
else {
if (len == 2) {
switch (s[1]) {
case '1': calling_level = l_c1; return true;
case '2': calling_level = l_c2; return true;
case '3': calling_level = l_c3; return true;
case '4': calling_level = l_c4; return true;
default: return false;
}
}
else return false;
}
return true;
default:
return false;
}
}
void start_sel_dir_num_iterator()
{
selector_for_initialize = selector_beaus;
direction_for_initialize = direction_right;
number_for_initialize = 1;
}
bool iterate_over_sel_dir_num(
bool enable_selector_iteration,
bool enable_direction_iteration,
bool enable_number_iteration)
{
// Try different selectors first.
if (selector_used && enable_selector_iteration) {
// This call used a selector and didn't like it. Try again with
// a different selector, until we run out of ideas.
switch (selector_for_initialize) {
case selector_beaus:
selector_for_initialize = selector_ends;
return true;
case selector_ends:
selector_for_initialize = selector_leads;
return true;
case selector_leads:
// This will select just one end of each wave in parallel waves or a tidal wave,
// so "prefer the <anyone> out roll circulate" will work.
selector_for_initialize = selector_sideboys;
return true;
case selector_sideboys:
selector_for_initialize = selector_everyone;
return true;
case selector_everyone:
// This will select #1 and #2 in columns,
// so "<anyone> mark time" will work.
selector_for_initialize = selector_headcorners;
return true;
case selector_headcorners:
// This will select the ends of each wave in a tidal wave,
// so "relay the shadow but <anyone> criss cross it" will work.
selector_for_initialize = selector_boys;
return true;
case selector_boys:
selector_for_initialize = selector_none;
return true;
}
}
// Now try a different direction.
if (direction_used && enable_direction_iteration) {
// This call used a direction and didn't like it. Try again with
// a different direction, until we run out of ideas.
switch (direction_for_initialize) {
case direction_right:
// This allows "spin the windmill, outsides (no direction)" from facing lines.
direction_for_initialize = direction_no_direction;
selector_for_initialize = selector_beaus;
return true;
}
}
// Now try a different number. Only do this if the call actually
// consumes numbers, and the wildcard matching has not filled in all
// required numbers.
if (number_used && enable_number_iteration) {
/* Try again with a different number, until we run out of ideas. */
if (number_for_initialize < 4) {
/* We try all numbers from 1 to 4. We need to do 1-4 to get
"exchange the boxes N/4" on the waves menu.
Getting calls like "N-N-N-N change the web" and
"N-N-N-N relay the top" requires that we play games
with the list, setting the second item odd. */
number_for_initialize++;
selector_for_initialize = selector_beaus;
direction_for_initialize = direction_right;
return true;
}
}
return false;
}
static void test_starting_setup(call_list_kind cl, const setup & test_setup)
{
gg77->iob88.init_step(do_tick, 2);
call_index = -1;
global_callcount = 0;
/* Mark the parse block allocation, so that we throw away the garbage
created by failing attempts. */
parse_mark = get_parse_block_mark();
try_again:
// Throw away garbage.
release_parse_blocks_to_mark(parse_mark);
call_index++;
if (call_index >= number_of_calls[call_list_any]) goto finished;
test_call = main_call_lists[call_list_any][call_index];
// Set the selector (for "so-and-so advance to a column", etc) to "beaus".
// This seems to make most calls work -- note that "everyone run" and
// "no one advance to a column" are illegal. If "beaus" doesn't work, we will
// try "ends" (for the call "fold"), "all", and finally "none" (for the call "run"),
// before giving up.
intlkness = false;
try_another_intlk:
magicness = false;
try_another_magic:
crossiness = false;
try_another_cross:
start_sel_dir_num_iterator();
try_another_selector:
selector_used = false;
direction_used = false;
number_used = false;
mandatory_call_used = false;
config_history_ptr = 1;
configuration::current_config().init_centersp_specific();
configuration::current_config().state = test_setup;
initialize_parse();
// If the call has the "rolldefine" schema, we accept it, since the test setups
// are all in the "roll unsupported" state.
if (test_call->the_defn.schema == schema_roll) goto accept;
// If the call takes 3 or more numeric arguments, accept it. This makes
// "hinge by I x J x K" work from columns.
if ((test_call->the_defn.callflags1 & ((uint32) CFLAG1_NUMBER_MASK)) >=
3*((uint32) CFLAG1_NUMBER_BIT))
goto accept;
// If the call has the "matrix" schema, and it is sex-dependent, we accept it,
// since the test setups that we use might have people placed in such a way
// that something like "1/2 truck" is illegal.
if (test_call->the_defn.schema == schema_matrix &&
test_call->the_defn.stuff.matrix.matrix_def_list->matrix_def_items[0] !=
test_call->the_defn.stuff.matrix.matrix_def_list->matrix_def_items[1])
goto accept;
// We also accept "<ATC> your neighbor" and "<ANYTHING> motivate" calls,
// since we don't know what the tagging call will be.
if (test_call->the_defn.callflagsf & (CFLAGH__TAG_CALL_RQ_MASK | CFLAGH__CIRC_CALL_RQ_BIT))
goto accept;
// Do the call. An error will signal and go to try_again.
try {
if (crossiness)
deposit_concept(&concept_descriptor_table[useful_concept_indices[UC_cross]]);
if (magicness)
deposit_concept(&concept_descriptor_table[useful_concept_indices[UC_magic]]);
if (intlkness)
deposit_concept(&concept_descriptor_table[useful_concept_indices[UC_intlk]]);
if (deposit_call(test_call, &null_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(true, true, true)) goto try_another_selector;
goto try_again;
}
toplevelmove();
}
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 different selectors first.
if (iterate_over_sel_dir_num(true, true, true))
goto try_another_selector;
// Now try giving the "cross" modifier.
if ((test_call->the_defn.callflagsf & ESCAPE_WORD__CROSS) && !crossiness) {
crossiness = true;
goto try_another_cross;
}
// Now try giving the "magic" modifier.
if ((test_call->the_defn.callflagsf & ESCAPE_WORD__MAGIC) && !magicness) {
magicness = true;
goto try_another_magic;
}
// Now try giving the "interlocked" modifier.
if ((test_call->the_defn.callflagsf & ESCAPE_WORD__INTLK) && !intlkness) {
intlkness = true;
goto try_another_intlk;
}
// Otherwise, reject this call.
goto try_again;
}
// It seems to have worked, save it. We don't care about warnings here.
accept:
global_temp_call_indices[global_callcount] = call_index;
global_callcount++;
goto try_again;
finished:
// Create the call list itself. First, just fill it with the indices.
// This is, of course, illegal, and requires a horrible cast. But we need
// to do this in order to read and write write the cache file in an invariant format.
// We will turn them into pointers later.
number_of_calls[cl] = global_callcount;
main_call_lists[cl] = new call_with_name *[global_callcount];
memcpy(main_call_lists[cl],
global_temp_call_indices,
global_callcount*sizeof(uint32));
}
static int canonicalize(char * & cp)
{
for (;;) {
int mc = *cp;
// Skip blanks and hyphens.
if (mc == ' ' || mc == '-') { cp++; continue; }
if (mc == '@') {
// Turn escape codes into very large numbers,
// so they will be listed at the end.
mc = *++cp;
switch (mc) {
case 'v': case 'w': case 'x': case 'y':
return 500; // <ATC>
case 'h':
return 501; // <DIRECTION>
case '6': case 'k': case 'K': case 'V':
return 502; // <ANYONE>
case 'N':
return 503; // <ANYCIRC>
case '0': case 'T': case 'm':
return 504; // <ANYTHING>
case '9':
return 505; // <N>
case 'a': case 'b': case 'B': case 'D':
return 506; // <N/4>
case 'u':
return 507; // <Nth>
case '7': case 'n': case 'j': case 'J': case 'E': case 'Q':
// Skip over @7...@8, @n .. @o, and @j...@l stuff.
while (*cp++ != '@');
// FALL THROUGH!!!!!
default:
cp++;
continue;
}
}
// Canonicalize to lower case.
return (mc >= 'A' && mc <= 'Z') ? mc + 'a'-'A' : mc;
}
}
class DBCOMPARE {
public:
static bool inorder(call_with_name *x, call_with_name *y)
{
char *mp = x->name;
char *np = y->name;
for (;;) {
// First, skip over everything that we need to, in both m and n.
// This includes blanks, hyphens, and insignificant escape sequences.
int mc = canonicalize(mp);
if (!mc) return true;
int nc = canonicalize(np);
if (!nc) return false;
if (mc != nc) return (mc < nc);
mp++;
np++;
}
}
};
static void create_misc_call_lists(call_list_kind cl)
{
int j;
int callcount = 0;
for (j=0; j<number_of_calls[call_list_any]; j++) {
call_with_name *callp = main_call_lists[call_list_any][j];
if (cl == call_list_gcol) { // tidal column
if (callp->the_defn.schema != schema_by_array || callp->the_defn.compound_part)
goto accept; // We don't understand it.
callarray *deflist = callp->the_defn.stuff.arr.def_list->callarray_list;
if ((callp->the_defn.callflags1 & CFLAG1_STEP_REAR_MASK) == CFLAG1_STEP_TO_WAVE) {
if (assoc(b_4x2, (setup *) 0, deflist) ||
assoc(b_4x1, (setup *) 0, deflist) ||
assoc(b_2x2, (setup *) 0, deflist) ||
assoc(b_2x1, (setup *) 0, deflist))
goto accept;
}
else {
if (assoc(b_8x1, (setup *) 0, deflist) ||
assoc(b_4x1, (setup *) 0, deflist) ||
assoc(b_2x1, (setup *) 0, deflist) ||
assoc(b_1x1, (setup *) 0, deflist))
goto accept;
}
}
else { // qtag
call_with_name *callq = callp;
if (callq->the_defn.schema != schema_by_array || callq->the_defn.compound_part)
goto accept; // We don't understand it.
callarray *deflist = callq->the_defn.stuff.arr.def_list->callarray_list;
uint32 touch_flags = callq->the_defn.callflags1 & CFLAG1_STEP_REAR_MASK;
switch (touch_flags) {
case CFLAG1_REAR_BACK_FROM_QTAG:
case CFLAG1_REAR_BACK_FROM_EITHER:
if (assoc(b_4x2, (setup *) 0, deflist) ||
assoc(b_4x1, (setup *) 0, deflist))
goto accept;
break;
}
switch (touch_flags) {
case CFLAG1_STEP_TO_WAVE:
case CFLAG1_REAR_BACK_FROM_EITHER:
if (assoc(b_thar, (setup *) 0, deflist))
goto accept;
}
if (assoc(b_qtag, (setup *) 0, deflist) ||
assoc(b_pqtag, (setup *) 0, deflist) ||
assoc(b_dmd, (setup *) 0, deflist) ||
assoc(b_pmd, (setup *) 0, deflist) ||
assoc(b_1x2, (setup *) 0, deflist) ||
assoc(b_2x1, (setup *) 0, deflist) ||
assoc(b_1x1, (setup *) 0, deflist))
goto accept;
}
continue;
accept:
global_temp_call_indices[callcount] = j;
callcount++;
}
// Create the call list itself.
number_of_calls[cl] = callcount;
main_call_lists[cl] = new call_with_name *[callcount];
memcpy(main_call_lists[cl],
global_temp_call_indices,
callcount*sizeof(uint32));
}
// These are used by the database reading stuff.
static uint32 last_datum, last_12;
static call_with_name *call_root;
static callarray *tp;
// This shows the highest index we have seen so far. It must never exceed max_base_calls-1.
static int highest_base_call;
static FILE *init_file;
static int session_linenum = 0;
// 0 for "no session" line, 1 for real ones, 2 for "new session".
static int session_line_state = 0;
static char rewrite_filename_as_star[2] = { '\0' , '\0' }; // First char could be "*" or "+".
static FILE *database_file;
static FILE *abridge_file;
static FILE *stats_file = (FILE *) 0;
static uint32 read_8_from_database()
{
return fgetc(database_file) & 0xFF;
}
static uint32 read_16_from_database()
{
uint32 bar;
bar = (read_8_from_database() & 0xFF) << 8;
bar |= read_8_from_database() & 0xFF;
return bar;
}
static bool read_database_header(char *msg1, char *msg2)
{
int format_version, n, j;
if (read_16_from_database() != DATABASE_MAGIC_NUM) {
sprintf(msg1,
"Database file \"%s\" has improper format.", database_filename);
return true;
}
format_version = read_16_from_database();
if (format_version != DATABASE_FORMAT_VERSION) {
sprintf(msg1,
"Database format version (%d) is not the required one (%d)",
format_version, DATABASE_FORMAT_VERSION);
strncpy(msg2, "You must recompile the database.", 199);
return true;
}
abs_max_calls = read_16_from_database();
max_base_calls = read_16_from_database();
n = read_16_from_database();
if (n > 80) {
strncpy(msg1, "Database version string is too long.", 199);
return true;
}
for (j=0; j<n; j++)
database_version[j] = (unsigned char) read_8_from_database();
database_version[j] = '\0';
return false;
}
static void read_halfword()
{
last_datum = read_16_from_database();
last_12 = last_datum & 0xFFF;
}
static void read_fullword()
{
uint32 t = read_16_from_database();
last_datum = t << 16 | read_16_from_database();
}
// Found an error while reading a call out of the database.
// Print an error message and quit.
// Should take the call as an argument, but since this entire file uses global variables,
// we will, too.
static void database_error_exit(const char *message)
{
if (call_root)
gg77->iob88.fatal_error_exit(1, message, call_root->name);
else
gg77->iob88.fatal_error_exit(1, message);
}
static void read_array_def_blocks(calldef_block *where_to_put)
{
int j, char_count;
callarray *current_call_block;
if (!(last_datum & 0x8000))
database_error_exit("database phase error: array def block");
current_call_block = 0;
while (last_datum & 0x8000) {
begin_kind this_start_setup;
uint32 this_qualifierstuff;
call_restriction this_restriction;
setup_kind end_setup;
setup_kind end_setup_out;
int this_start_size;
uint32 these_flags;
int extra;
these_flags = (last_datum & 0x7FFF) << 7; // We allow 22 callarray_flags.
read_fullword();
these_flags |= ((last_datum >> 25) & 0x7F);
this_restriction = (call_restriction) ((last_datum >> 17) & 0xFF);
this_qualifierstuff = last_datum & 0x1FFFF;
// Get start setup and end setup.
read_halfword();
this_start_setup = (begin_kind) ((last_datum & 0xFF00) >> 8);
this_start_size = begin_sizes[this_start_setup];
end_setup = (setup_kind) (last_datum & 0xFF);
if (these_flags & CAF__CONCEND) { // See if "concendsetup" was used.
read_halfword(); // Get outer setup and outer rotation.
end_setup_out = (setup_kind) (last_datum & 0xFF);
}
if (these_flags & CAF__PREDS) {
read_halfword(); // Get error message count.
char_count = last_datum & 0xFF;
// We will naturally get 4 items in the "stuff.prd.errmsg" field;
// we are responsible all for the others.
// We subtract 3 because 4 chars are already present, but we need one extra for the pad.
extra = (char_count-3) * sizeof(char);
}
else {
// We will naturally get 4 items in the "stuff.def" field;
// we are responsible all for the others.
extra = (this_start_size-4) * sizeof(unsigned short int);
}
tp = (callarray *) ::operator new(sizeof(callarray) + extra);
tp->next = 0;
if (!current_call_block)
where_to_put->callarray_list = tp; // First time.
else {
current_call_block->next = tp; // Subsequent times.
}
current_call_block = tp;
tp->callarray_flags = these_flags;
tp->qualifierstuff = this_qualifierstuff;
tp->start_setup = (uint8) this_start_setup;
tp->restriction = this_restriction;
if (these_flags & CAF__CONCEND) { // See if "concendsetup" was used.
tp->end_setup = (uint8) s_normal_concentric;
tp->end_setup_in = (uint8) end_setup;
tp->end_setup_out = (uint8) end_setup_out;
}
else {
tp->end_setup = (uint8) end_setup;
}
if (these_flags & CAF__PREDS) {
predptr_pair *temp_predlist;
predptr_pair *this_predlist = (predptr_pair *) 0;
// Read error message text.
for (j=1; j <= ((char_count+1) >> 1); j++) {
read_halfword();
tp->stuff.prd.errmsg[(j << 1)-2] = (char) ((last_datum >> 8) & 0xFF);
if ((j << 1) != char_count+1)
tp->stuff.prd.errmsg[(j << 1)-1] = (char) (last_datum & 0xFF);
}
tp->stuff.prd.errmsg[char_count] = '\0';
read_halfword();
// Demand level 4 group.
if (last_datum != 0x6000) {
database_error_exit("database phase error 4");
}
while ((last_datum & 0xE000) == 0x6000) {
read_halfword(); // Read predicate indicator, that is, level 4 group.
// "predptr_pair" will get us 4 items in the "arr" field;
// we are responsible all for the others.
temp_predlist = (predptr_pair *) ::operator new(sizeof(predptr_pair) +
(this_start_size-4) * sizeof(unsigned short));
temp_predlist->pred = &pred_table[last_datum];
// If this call uses a predicate that takes a selector, flag the call so that
// we will query the user for that selector.
if ((int) last_datum < selector_preds)
call_root->the_defn.callflagsf |= CFLAGH__REQUIRES_SELECTOR;
for (j=0; j < this_start_size; j++) {
read_halfword();
temp_predlist->array_pred_def[j] = (uint16) last_datum;
}
temp_predlist->next = this_predlist;
this_predlist = temp_predlist;
read_halfword(); /* Get next level 4 header, or whatever. */
}
// Need to reverse stuff in "this_predlist".
temp_predlist = 0;
while (this_predlist) {
predptr_pair *revptr = this_predlist;
this_predlist = this_predlist->next;
revptr->next = temp_predlist;
temp_predlist = revptr;
}
tp->stuff.prd.predlist = temp_predlist;
}
else {
for (j=0; j < this_start_size; j++) {
read_halfword();
tp->stuff.array_no_pred_def[j] = (uint16) last_datum;
}
read_halfword();
}
}
}
static void check_tag(int tag)
{
if (tag >= max_base_calls)
database_error_exit("Too many tagged calls -- mkcalls made an error");
if (tag > highest_base_call) highest_base_call = tag;
}
static void read_in_call_definition(calldefn *root_to_use, int char_count)
{
// If we are operating at the "all" level, make fractions visible everywhere,
// to aid in debugging.
if (calling_level == l_dontshow)
root_to_use->callflags1 |= 3*CFLAG1_VISIBLE_FRACTION_BIT;
if (char_count) {
// Read in the name itself, unless we are recursing for a compound call.
char *np, c;
int j;
// We know that call_root has what we want if char_count != 0.
np = call_root->name;
for (j=0; j<char_count; j++)
*np++ = (char) read_8_from_database();
*np = '\0';
/* Scan the name for "@6" or "@e", fill in "needselector" or
"left_changes_name" flag if found. */
np = call_root->name;
while ((c = *np++)) {
if (c == '@') {
switch ((c = *np++)) {
case '6': case 'k': case 'K': case 'V':
root_to_use->callflagsf |= CFLAGH__REQUIRES_SELECTOR;
break;
case 'h':
root_to_use->callflagsf |= CFLAGH__REQUIRES_DIRECTION;
break;
case 'D':
root_to_use->callflagsf |= CFLAGH__ODD_NUMBER_ONLY;
break;
case 'v':
root_to_use->callflagsf |= (CFLAGH__TAG_CALL_RQ_BIT*1);
break;
case 'w':
root_to_use->callflagsf |= (CFLAGH__TAG_CALL_RQ_BIT*2);
break;
case 'x':
root_to_use->callflagsf |= (CFLAGH__TAG_CALL_RQ_BIT*3);
break;
case 'y':
root_to_use->callflagsf |= (CFLAGH__TAG_CALL_RQ_BIT*4);
break;
case 'N':
root_to_use->callflagsf |= CFLAGH__CIRC_CALL_RQ_BIT;
break;
case '0':
root_to_use->callflagsf |= CFLAGH__HAS_AT_ZERO;
break;
case 'm':
root_to_use->callflagsf |= CFLAGH__HAS_AT_M;
break;
}
}
else if (c == '[' || c == ']')
database_error_exit("calls may not have brackets in their name");
}
}
int j;
int lim = 16;
uint32 left_half;
read_halfword();
switch (root_to_use->schema) {
case schema_alias:
check_tag(last_12);
root_to_use->stuff.conc.innerdef.call_id = (uint16) last_12;
read_halfword();
break;
case schema_nothing:
case schema_nothing_noroll:
case schema_roll:
case schema_recenter:
break;
case schema_matrix:
lim = 2;
// !!!! FALL THROUGH !!!!
case schema_partner_matrix:
case schema_partner_partial_matrix:
// !!!! FELL THROUGH !!!!
{
left_half = last_datum;
read_halfword();
root_to_use->stuff.matrix.matrix_flags =
((left_half & 0xFFFF) << 16) | (last_datum & 0xFFFF);
if (root_to_use->stuff.matrix.matrix_flags & MTX_USE_SELECTOR)
root_to_use->callflagsh |= CFLAGH__REQUIRES_SELECTOR;
if (root_to_use->stuff.matrix.matrix_flags & MTX_USE_NUMBER)
root_to_use->callflags1 |= CFLAG1_NUMBER_BIT;
matrix_def_block *this_matrix_block =
(matrix_def_block *) ::operator new(sizeof(matrix_def_block) + sizeof(uint32)*(lim-2));
root_to_use->stuff.matrix.matrix_def_list = this_matrix_block;
this_matrix_block->modifier_level = calling_level;
this_matrix_block->alternate_def_flags = 0;
this_matrix_block->next = (matrix_def_block *) 0;
next_matrix_clause:
for (j=0; j<lim; j++) {
uint32 firstpart;
read_halfword();
firstpart = last_datum & 0xFFFF;
if (firstpart) {
read_halfword();
this_matrix_block->matrix_def_items[j] =
firstpart | ((last_datum & 0xFFFF) << 16);
}
else {
this_matrix_block->matrix_def_items[j] = 0;
}
}
read_halfword();
// Check for compound definition, that is, level 2 group.
if ((last_datum & 0xE000) == 0x4000) {
this_matrix_block->next = (matrix_def_block *)
::operator new(sizeof(matrix_def_block) + sizeof(uint32)*(lim-2));
this_matrix_block = this_matrix_block->next;
this_matrix_block->modifier_level = (dance_level) (last_datum & 0xFFF);
read_fullword();
this_matrix_block->alternate_def_flags = last_datum;
this_matrix_block->next = (matrix_def_block *) 0;
goto next_matrix_clause;
}
}
break;
case schema_by_array:
{
calldef_block *zz, *yy;
zz = new calldef_block;
zz->next = 0;
zz->modifier_seth = 0;
zz->modifier_level = l_mainstream;
root_to_use->stuff.arr.def_list = zz;
read_array_def_blocks(zz); // The first group.
while ((last_datum & 0xE000) == 0x4000) {
yy = new calldef_block;
zz->next = yy;
zz = yy;
zz->modifier_level = (dance_level) (last_datum & 0xFF);
zz->next = 0;
read_fullword();
zz->modifier_seth = last_datum;
read_halfword();
read_array_def_blocks(zz);
}
}
break;
case schema_sequential:
case schema_split_sequential:
case schema_sequential_with_fraction:
case schema_sequential_with_split_1x8_id:
case schema_sequential_alternate:
case schema_sequential_remainder:
{
by_def_item templist[100];
int next_definition_index = 0;
/* Demand a level 2 group. */
if ((last_datum & 0xE000) != 0x4000)
database_error_exit("database phase error 6");
while ((last_datum & 0xE000) == 0x4000) {
check_tag(last_12);
templist[next_definition_index].call_id = (uint16) last_12;
read_fullword();
templist[next_definition_index].modifiers1 = (mods1_word) last_datum;
read_fullword();
templist[next_definition_index++].modifiersh = last_datum;
read_halfword();
}
root_to_use->stuff.seq.howmanyparts = next_definition_index;
root_to_use->stuff.seq.defarray = new by_def_item [next_definition_index];
while (--next_definition_index >= 0)
root_to_use->stuff.seq.defarray[next_definition_index] =
templist[next_definition_index];
}
break;
default: /* These are all the variations of concentric. */
/* Demand a level 2 group. */
if ((last_datum & 0xE000) != 0x4000)
database_error_exit("database phase error 7");
check_tag(last_12);
root_to_use->stuff.conc.innerdef.call_id = (uint16) last_12;
read_fullword();
root_to_use->stuff.conc.innerdef.modifiers1 = (mods1_word) last_datum;
read_fullword();
root_to_use->stuff.conc.innerdef.modifiersh = last_datum;
read_halfword();
check_tag(last_12);
root_to_use->stuff.conc.outerdef.call_id = (uint16) last_12;
read_fullword();
root_to_use->stuff.conc.outerdef.modifiers1 = (mods1_word) last_datum;
read_fullword();
root_to_use->stuff.conc.outerdef.modifiersh = last_datum;
read_halfword();
break;
}
// Look for compound definition.
root_to_use->compound_part = (calldefn *) 0;
if (last_datum == 0x3FFF) {
calldef_schema call_schema;