64 static UBYTE *tablebase = (UBYTE *)
"tablebase";
71 void ClearTableTree(
TABLES T)
102 int InsTableTree(
TABLES T, WORD *tp)
120 if ( q->
right == -1 ) {
135 v2 = tp; v3 = tp + T->
numind;
136 while ( *v1 == *v2 && v2 < v3 ) { v1++; v2++; }
137 if ( v2 >= v3 )
return(-p->
value);
140 if ( iq >= 0 ) { ip = iq; }
154 else if ( *v1 < *v2 ) {
156 if ( iq >= 0 ) { ip = iq; }
171 MesPrint(
"Serious problems in InsTableTree!\n");
182 if ( q->
blnce == 0 )
break;
183 if ( q->
blnce == -2 ) {
184 if ( p->
blnce == -1 ) {
205 if ( boomlijst[s->
parent].left == iq )
214 else if ( q->
blnce == 2 ) {
215 if ( p->
blnce == 1 ) {
263 void RedoTableTree(
TABLES T,
int newsize)
270 tp += T->
numind+TABLEEXTENSION;
288 int FindTableTree(
TABLES T, WORD *tp,
int inc)
293 if ( q->
right == -1 )
return(-1);
295 if ( inc > 1 ) tp += inc-1;
299 v2 = tp; v3 = v1 + T->
numind;
300 while ( *v1 == *v2 && v1 < v3 ) { v1++; v2 += inc; }
307 if ( iq >= 0 ) { ip = iq; }
310 else if ( *v1 < *v2 ) {
312 if ( iq >= 0 ) { ip = iq; }
316 MesPrint(
"Serious problems in FindTableTree\n");
326 WORD DoTableExpansion(WORD *term, WORD level)
329 WORD *t, *tstop, *stopper, *termout, *m, *mm, *tp, *r;
332 AN.TeInFun = AR.TePos = 0;
333 tstop = term + *term;
334 stopper = tstop - ABS(tstop[-1]);
336 while ( t < stopper ) {
337 if ( *t != TABLEFUNCTION ) { t += t[1];
continue; }
338 if ( t[FUNHEAD] > -FUNCTION ) { t += t[1];
continue; }
339 T = functions[-t[FUNHEAD]-FUNCTION].tabl;
340 if ( T == 0 ) { t += t[1];
continue; }
342 if ( t[1] == FUNHEAD+2 && t[FUNHEAD+1] <= -FUNCTION )
break;
343 if ( t[1] < FUNHEAD+1+2*T->
numind ) { t += t[1];
continue; }
344 for ( i = 0; i < T->
numind; i++ ) {
345 if ( t[FUNHEAD+1+2*i] != -SYMBOL )
break;
347 if ( i >= T->
numind )
break;
350 if ( t >= stopper ) {
351 MesPrint(
"Internal error: Missing table_ function");
357 termout = AT.WorkPointer;
359 for ( i = 0; i < T->
totind; i++ ) {
363 m = termout + 1; mm = term + 1;
364 while ( mm < t ) *m++ = *mm++;
366 if ( t[1] == FUNHEAD+2 && t[FUNHEAD+1] <= -FUNCTION ) {
367 *m++ = -t[FUNHEAD+1];
368 *m++ = FUNHEAD+T->
numind*2;
369 for ( j = 2; j < FUNHEAD; j++ ) *m++ = 0;
371 for ( j = 0; j < T->
numind; j++ ) {
372 *m++ = -SNUMBER; *m++ = *tp++;
376 *m++ = SYMBOL; *m++ = 2+T->
numind*2; mm = t + FUNHEAD+1;
378 for ( j = 0; j < T->
numind; j++, mm += 2, tp++ ) {
379 if ( *tp != 0 ) { *m++ = mm[1]; *m++ = *tp; }
382 if ( r[1] == 2 ) m = r;
404 for ( j = 2; j < FUNHEAD; j++ ) *m++ = t[j];
406 for ( j = 0; j < T->
numind; j++ ) {
407 *m++ = -SNUMBER; *m++ = *tp++;
409 tp = t + FUNHEAD + 1 + 2*T->
numind;
411 while ( tp < mm ) *m++ = *tp++;
416 while ( mm < tstop ) *m++ = *mm++;
417 *termout = m - termout;
420 MesCall(
"DoTableExpand");
426 for ( i = 0; i < T->
totind; i++ ) {
427 #if TABLEEXTENSION == 2 432 m = termout + 1; mm = term + 1;
433 while ( mm < t ) *m++ = *mm++;
435 if ( t[1] == FUNHEAD+2 && t[FUNHEAD+1] <= -FUNCTION ) {
436 *m++ = -t[FUNHEAD+1];
437 *m++ = FUNHEAD+T->
numind*2;
438 for ( j = 2; j < FUNHEAD; j++ ) *m++ = 0;
440 for ( j = 0; j < T->
numind; j++ ) {
447 *m++ = -SNUMBER; *m++ = num;
451 *m++ = SYMBOL; *m++ = 2+T->
numind*2; mm = t + FUNHEAD+1;
452 for ( j = 0; j < T->
numind; j++, mm += 2 ) {
459 if ( num != 0 ) { *m++ = mm[1]; *m++ = num; }
462 if ( r[1] == 2 ) m = r;
484 for ( j = 2; j < FUNHEAD; j++ ) *m++ = t[j];
485 for ( j = 0; j < T->
numind; j++ ) {
492 *m++ = -SNUMBER; *m++ = num;
494 tp = t + FUNHEAD + 1 + 2*T->
numind;
496 while ( tp < mm ) *m++ = *tp++;
501 while ( mm < tstop ) *m++ = *mm++;
502 *termout = m - termout;
505 MesCall(
"DoTableExpand");
559 {
"addto", (TFUN)CoTBaddto, 0, PARTEST}
560 ,{
"audit", (TFUN)CoTBaudit, 0, PARTEST}
561 ,{
"cleanup", (TFUN)CoTBcleanup, 0, PARTEST}
562 ,{
"create", (TFUN)CoTBcreate, 0, PARTEST}
563 ,{
"enter", (TFUN)CoTBenter, 0, PARTEST}
564 ,{
"help", (TFUN)CoTBhelp, 0, PARTEST}
565 ,{
"load", (TFUN)CoTBload, 0, PARTEST}
566 ,{
"off", (TFUN)CoTBoff, 0, PARTEST}
567 ,{
"on", (TFUN)CoTBon, 0, PARTEST}
568 ,{
"open", (TFUN)CoTBopen, 0, PARTEST}
569 ,{
"replace", (TFUN)CoTBreplace, 0, PARTEST}
570 ,{
"use", (TFUN)CoTBuse, 0, PARTEST}
573 static UBYTE *tablebasename = 0;
575 int CoTableBase(UBYTE *s)
577 UBYTE *option, c, *t;
578 int i,optlistsize =
sizeof(tboptions)/
sizeof(
KEYWORD), error = 0;
579 while ( *s ==
' ' ) s++;
581 if ( ( tolower(*s) ==
'h' ) && ( tolower(s[1]) ==
'e' )
582 && ( tolower(s[2]) ==
'l' ) && ( tolower(s[3]) ==
'p' )
583 && ( FG.cTable[s[4]] > 1 ) ) {
588 MesPrint(
"&Proper syntax: TableBase \"filename\" options");
591 s++; tablebasename = s;
592 while ( *s && *s !=
'"' ) s++;
593 if ( *s !=
'"' )
goto proper;
595 while ( *s ==
' ' || *s ==
'\t' || *s ==
',' ) s++;
597 while ( FG.cTable[*s] == 0 ) s++;
599 for ( i = 0; i < optlistsize; i++ ) {
600 if ( StrICmp(option,(UBYTE *)(tboptions[i].name)) == 0 ) {
602 while ( *s ==
',' ) s++;
603 error = (tboptions[i].func)(s);
608 MesPrint(
"&Unrecognized option %s in TableBase statement",option);
623 if ( ( TT = T->
spare ) == 0 ) {
624 MesPrint(
"Error: trying to change mode on a table that has no tablebase");
627 if ( TT->
mode == type ) f->
tabl = TT;
668 T->
flags = (WORD *)Malloc1(T->
numind*
sizeof(WORD),
"table flags");
682 DBASE *FindTB(UBYTE *name)
686 for ( i = 0; i < NumTableBases; i++ ) {
688 if ( d->name && ( StrCmp(name,(UBYTE *)(d->name)) == 0 ) ) {
return(d); }
704 int CoTBcreate(UBYTE *s)
707 if ( FindTB(tablebasename) != 0 ) {
708 MesPrint(
"&There is already an open TableBase with the name %s",tablebasename);
711 NewDbase((
char *)tablebasename,0);
720 int CoTBopen(UBYTE *s)
724 if ( ( d = FindTB(tablebasename) ) != 0 ) {
725 MesPrint(
"&There is already an open TableBase with the name %s",tablebasename);
728 d = GetDbase((
char *)tablebasename);
729 if ( CheckTableDeclarations(d) )
return(-1);
738 int CoTBaddto(UBYTE *s)
742 UBYTE *tablename, c, *t, elementstring[ELEMENTSIZE+20], *ss, *es;
743 WORD type, funnum, lbrac, first, num, *expr, *w;
747 int i, j, error = 0, sum;
748 if ( ( d = FindTB(tablebasename) ) == 0 ) {
749 MesPrint(
"&No open tablebase with the name %s",tablebasename);
752 AO.DollarOutSizeBuffer = 32;
753 AO.DollarOutBuffer = (UBYTE *)Malloc1(AO.DollarOutSizeBuffer,
758 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
761 if ( ( s = SkipAName(s) ) == 0 )
goto tableabort;
763 if ( ( GetVar(tablename,&type,&funnum,CFUNCTION,NOAUTO) == NAMENOTFOUND )
764 || ( T = functions[funnum].tabl ) == 0 ) {
765 MesPrint(
"&%s should be a previously declared table",tablename);
766 *s = c;
goto tableabort;
769 MesPrint(
"&%s should be a sparse table",tablename);
770 *s = c;
goto tableabort;
772 basenumber = AddTableName(d,(
char *)tablename,T);
774 if ( basenumber < 0 ) basenumber = -basenumber;
775 else if ( basenumber == 0 ) { *s = c;
goto tableabort; }
779 for ( i = 0, w = AT.WorkPointer; i < T->numind; i++ ) {
780 ParseSignedNumber(x,s);
781 if ( FG.cTable[s[-1]] != 1 || ( *s !=
',' && *s !=
')' ) ) {
782 MesPrint(
"&Table arguments in TableBase addto statement should be numbers");
786 if ( *s ==
')' )
break;
789 if ( *s !=
')' || i < ( T->
numind - 1 ) ) {
790 MesPrint(
"&Incorrect number of table arguments in TableBase addto statement. Should be %d" 795 i = FindTableTree(T,AT.WorkPointer,1);
797 MesPrint(
"&Element %s has not been defined",es);
801 else if ( ExistsObject(d,basenumber,(
char *)es) ) {}
803 int dict = AO.CurrentDictionary;
804 AO.CurrentDictionary = 0;
809 AO.DollarInOutBuffer = 1;
811 ss = AO.DollarOutBuffer;
814 #if ( TABLEEXTENSION == 2 ) 819 lbrac = 0; first = 0;
821 if ( WriteTerm(expr,&lbrac,first,PRINTON,0) ) {
827 AddObject(d,basenumber,(
char *)es,(
char *)(AO.DollarOutBuffer));
829 AO.CurrentDictionary = dict;
837 for ( i = 0; i < T->
totind; i++ ) {
838 #if ( TABLEEXTENSION == 2 ) 843 sum = i * ( T->
numind + TABLEEXTENSION );
845 for ( j = 0; j < T->
numind; j++, sum++ ) {
846 if ( j > 0 ) *t++ =
',';
849 if ( ( t - elementstring ) >= ELEMENTSIZE ) {
850 MesPrint(
"&Table element specification takes more than %ld characters and cannot be handled",
855 if ( ExistsObject(d,basenumber,(
char *)elementstring) ) {
continue; }
862 AO.DollarInOutBuffer = 1;
864 ss = AO.DollarOutBuffer;
867 #if ( TABLEEXTENSION == 2 ) 872 lbrac = 0; first = 0;
874 if ( WriteTerm(expr,&lbrac,first,PRINTON,0) ) {
880 AddObject(d,basenumber,(
char *)elementstring,(
char *)(AO.DollarOutBuffer));
883 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
885 if ( WriteIniInfo(d) )
goto tableabort;
886 M_free(AO.DollarOutBuffer,
"DollarOutBuffer");
887 AO.DollarOutBuffer = 0;
888 AO.DollarOutSizeBuffer = 0;
891 M_free(AO.DollarOutBuffer,
"DollarOutBuffer");
892 AO.DollarOutBuffer = 0;
893 AO.DollarOutSizeBuffer = 0;
906 int CoTBenter(UBYTE *s)
910 UBYTE *arguments, *rhs, *buffer, *t, *u, c, *tablename;
912 int i, j, error = 0, error1 = 0, printall = 0;
915 int dict = AO.CurrentDictionary;
916 AO.CurrentDictionary = 0;
917 if ( ( d = FindTB(tablebasename) ) == 0 ) {
918 MesPrint(
"&No open tablebase with the name %s",tablebasename);
922 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
923 if ( *s ==
'!' ) { printall = 1; s++; }
924 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
928 if ( ( s = SkipAName(s) ) == 0 ) { error = 1;
goto Endofall; }
930 if ( ( GetVar(tablename,&type,&funnum,CFUNCTION,NOAUTO) == NAMENOTFOUND )
931 || ( T = functions[funnum].tabl ) == 0 ) {
932 MesPrint(
"&%s should be a previously declared table",tablename);
935 else if ( T->
sparse == 0 ) {
936 MesPrint(
"&%s should be a sparse table",tablename);
939 else { basenumber = GetTableName(d,(
char *)tablename); }
940 if ( T->
spare == 0 ) { SpareTable(T); }
941 if ( basenumber > 0 ) {
942 for ( i = 0; i < d->info.numberofindexblocks; i++ ) {
943 for ( j = 0; j < NUMOBJECTS; j++ ) {
944 if ( basenumber != d->iblocks[i]->objects[j].tablenumber )
946 arguments = (UBYTE *)(d->iblocks[i]->objects[j].element);
947 rhs = (UBYTE *)ReadObject(d,basenumber,(
char *)arguments);
950 MesPrint(
"%s(%s) = %s",tablename,arguments,rhs);
953 MesPrint(
"%s(%s) = 0",tablename,arguments);
957 u = rhs;
while ( *u ) u++;
959 u = arguments;
while ( *u ) u++;
961 u = tablename;
while ( *u ) u++;
964 buffer = (UBYTE *)Malloc1(size,
"TableBase copy");
965 t = tablename; u = buffer;
966 while ( *t ) *u++ = *t++;
969 while ( *t ) *u++ = *t++;
970 *u++ =
')'; *u++ =
'=';
972 while ( *t ) *u++ = *t++;
973 if ( t == rhs ) *u++ =
'0';
975 M_free(rhs,
"rhs in TBenter");
977 error1 = CoFill(buffer);
979 if ( error1 < 0 )
goto Endofall;
980 if ( error1 != 0 ) error = error1;
981 M_free(buffer,
"TableBase copy");
987 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
991 s = (UBYTE *)(d->tablenames); basenumber = 0;
994 tablename = s;
while ( *s ) s++; s++;
995 while ( *s ) s++; s++;
996 if ( ( GetVar(tablename,&type,&funnum,CFUNCTION,NOAUTO) == NAMENOTFOUND )
997 || ( T = functions[funnum].tabl ) == 0 ) {
998 MesPrint(
"&%s should be a previously declared table",tablename);
1000 else if ( T->
sparse == 0 ) {
1001 MesPrint(
"&%s should be a sparse table",tablename);
1003 if ( T->
spare == 0 ) { SpareTable(T); }
1004 for ( i = 0; i < d->info.numberofindexblocks; i++ ) {
1005 for ( j = 0; j < NUMOBJECTS; j++ ) {
1006 if ( d->iblocks[i]->objects[j].tablenumber == basenumber ) {
1007 arguments = (UBYTE *)(d->iblocks[i]->objects[j].element);
1008 rhs = (UBYTE *)ReadObject(d,basenumber,(
char *)arguments);
1011 MesPrint(
"%s%s = %s",tablename,arguments,rhs);
1014 MesPrint(
"%s%s = 0",tablename,arguments);
1018 u = rhs;
while ( *u ) u++;
1020 u = arguments;
while ( *u ) u++;
1021 size += u-arguments;
1022 u = tablename;
while ( *u ) u++;
1023 size += u-tablename;
1025 buffer = (UBYTE *)Malloc1(size,
"TableBase copy");
1026 t = tablename; u = buffer;
1027 while ( *t ) *u++ = *t++;
1030 while ( *t ) *u++ = *t++;
1031 *u++ =
')'; *u++ =
'=';
1033 while ( *t ) *u++ = *t++;
1034 if ( t == rhs ) *u++ =
'0';
1036 M_free(rhs,
"rhs in TBenter");
1038 error1 = CoFill(buffer);
1040 if ( error1 < 0 )
goto Endofall;
1041 if ( error1 != 0 ) error = error1;
1042 M_free(buffer,
"TableBase copy");
1050 AO.CurrentDictionary = dict;
1064 int CoTestUse(UBYTE *s)
1067 UBYTE *tablename, c;
1068 WORD type, funnum, *w;
1072 *w++ = TYPETESTUSE; *w++ = 2;
1075 if ( ( s = SkipAName(s) ) == 0 )
return(1);
1077 if ( ( GetVar(tablename,&type,&funnum,CFUNCTION,NOAUTO) == NAMENOTFOUND )
1078 || ( T = functions[funnum].tabl ) == 0 ) {
1079 MesPrint(
"&%s should be a previously declared table",tablename);
1082 else if ( T->
sparse == 0 ) {
1083 MesPrint(
"&%s should be a sparse table",tablename);
1086 *w++ = funnum + FUNCTION;
1088 while ( *s ==
' ' || *s ==
',' || *s ==
'\t' ) s++;
1090 AT.WorkPointer[1] = w - AT.WorkPointer;
1096 AddNtoL(AT.WorkPointer[1],AT.WorkPointer);
1109 int CheckTableDeclarations(
DBASE *d)
1112 UBYTE *s, *ss, *t, *command = 0;
1113 int k, error = 0, error1, i;
1115 LONG commandsize = 0;
1117 s = (UBYTE *)(d->tablenames);
1118 for ( k = 0; k < d->topnumber; k++ ) {
1119 if ( GetVar(s,&type,&funnum,ANYTYPE,NOAUTO) == NAMENOTFOUND ) {
1123 ss = s; i = 0;
while ( *ss ) { ss++; i++; }
1124 ss++;
while ( *ss ) { ss++; i++; }
1125 if ( commandsize == 0 ) {
1126 commandsize = i + 15;
1127 if ( commandsize < 100 ) commandsize = 100;
1129 if ( (i+11) > commandsize ) {
1130 if ( command ) { M_free(command,
"table command"); command = 0; }
1133 if ( command == 0 ) {
1134 command = (UBYTE *)Malloc1(commandsize,
"table command");
1136 t = command; ss = tablebase;
while ( *ss ) *t++ = *ss++;
1137 *t++ =
',';
while ( *s ) *t++ = *s++;
1138 s++;
while ( *s ) *t++ = *s++;
1139 *t++ =
')'; *t = 0; s++;
1140 error1 = DoTable(command,1);
1141 if ( error1 ) error = error1;
1143 else if ( ( type != CFUNCTION )
1144 || ( ( T = functions[funnum].tabl ) == 0 )
1145 || ( T->
sparse == 0 ) ) {
1146 MesPrint(
"&%s has been declared previously, but not as a sparse table.",s);
1148 while ( *s ) s++; s++;
while ( *s ) s++; s++;
1156 while ( *s ) s++; s++;
1158 MesPrint(
"&Declaration of table %s in %s different from previous declaration",ss,d->name);
1161 while ( *s ) s++; s++;
1164 if ( command ) { M_free(command,
"table command"); }
1178 int CoTBload(UBYTE *ss)
1181 UBYTE *s, *name, *t, *r, *command, *arguments, *tail;
1183 int num, cs, es, ns, ts, i, j, error = 0, error1;
1184 if ( ( d = FindTB(tablebasename) ) == 0 ) {
1185 MesPrint(
"&No open tablebase with the name %s",tablebasename);
1189 command = (UBYTE *)Malloc1(commandsize,
"Fill command");
1192 while ( *ss ==
',' || *ss ==
' ' || *ss ==
'\t' ) ss++;
1194 name = ss; ss = SkipAName(ss); *ss = 0;
1195 s = (UBYTE *)(d->tablenames);
1199 if ( StrCmp(s,name) ) {
1200 while ( *s ) s++; s++;
while ( *s ) s++; s++; num++;
1203 name = s;
while ( *s ) s++; ns = s-name; s++;
1204 tail = s;
while ( *s ) s++; ts = s-tail; s++;
1205 tail++;
while ( FG.cTable[*tail] == 1 ) tail++;
1209 for ( i = 0; i < d->info.numberofindexblocks; i++ ) {
1210 for ( j = 0; j < NUMOBJECTS; j++ ) {
1211 if ( d->iblocks[i]->objects[j].tablenumber == num ) {
1212 t = arguments = (UBYTE *)(d->iblocks[i]->objects[j].element);
1213 while ( *t ) t++; es = t - arguments;
1214 cs = 2*es + 2*ns + ts + 10;
1215 if ( cs > commandsize ) {
1217 if ( command ) M_free(command,
"Fill command");
1218 command = (UBYTE *)Malloc1(commandsize,
"Fill command");
1220 r = command; t = name;
while ( *t ) *r++ = *t++;
1221 *r++ =
'('; t = arguments;
while ( *t ) *r++ = *t++;
1222 *r++ =
')'; *r++ =
'='; *r++ =
't'; *r++ =
'b'; *r++ =
'l';
1223 *r++ =
'_'; *r++ =
'('; t = name;
while ( *t ) *r++ = *t++;
1224 *r++ =
','; t = arguments;
while ( *t ) *r++ = *t++;
1225 t = tail;
while ( *t ) {
1226 if ( *t ==
'?' && r[-1] !=
',' ) {
1228 if ( FG.cTable[*t] == 0 || *t ==
'$' || *t ==
'[' ) {
1234 else if ( *t ==
'{' ) {
1237 else if ( *t ) { *r++ = *t++;
continue; }
1245 AC.vetotablebasefill = 1;
1246 error1 = CoFill(command);
1247 AC.vetotablebasefill = 0;
1248 if ( error1 < 0 )
goto finishup;
1249 if ( error1 != 0 ) error = error1;
1255 while ( *ss ==
',' || *ss ==
' ' || *ss ==
'\t' ) ss++;
1259 s = (UBYTE *)(d->tablenames);
1263 name = s;
while ( *s ) s++; ns = s-name; s++;
1264 tail = s;
while ( *s ) s++; ts = s-tail; s++;
1265 tail++;
while ( FG.cTable[*tail] == 1 ) tail++;
1269 for ( i = 0; i < d->info.numberofindexblocks; i++ ) {
1270 for ( j = 0; j < NUMOBJECTS; j++ ) {
1271 if ( d->iblocks[i]->objects[j].tablenumber == num ) {
1272 t = arguments = (UBYTE *)(d->iblocks[i]->objects[j].element);
1273 while ( *t ) t++; es = t - arguments;
1274 cs = 2*es + 2*ns + ts + 10;
1275 if ( cs > commandsize ) {
1277 if ( command ) M_free(command,
"Fill command");
1278 command = (UBYTE *)Malloc1(commandsize,
"Fill command");
1280 r = command; t = name;
while ( *t ) *r++ = *t++;
1281 *r++ =
'('; t = arguments;
while ( *t ) *r++ = *t++;
1282 *r++ =
')'; *r++ =
'='; *r++ =
't'; *r++ =
'b'; *r++ =
'l';
1283 *r++ =
'_'; *r++ =
'('; t = name;
while ( *t ) *r++ = *t++;
1284 *r++ =
','; t = arguments;
while ( *t ) *r++ = *t++;
1285 t = tail;
while ( *t ) {
1286 if ( *t ==
'?' && r[-1] !=
',' ) {
1288 if ( FG.cTable[*t] == 0 || *t ==
'$' || *t ==
'[' ) {
1294 else if ( *t ==
'{' ) {
1297 else if ( *t ) { *r++ = *t++;
continue; }
1305 AC.vetotablebasefill = 1;
1306 error1 = CoFill(command);
1307 AC.vetotablebasefill = 0;
1308 if ( error1 < 0 )
goto finishup;
1309 if ( error1 != 0 ) error = error1;
1317 if ( command ) M_free(command,
"Fill command");
1334 WORD TestUse(WORD *term, WORD level)
1336 WORD *tstop, *t, *m, *tstart, tabnum;
1337 WORD *funs, numfuns, error = 0;
1340 CBUF *C = cbuf+AM.rbufnum;
1343 numfuns = C->
lhs[level][1] - 2;
1344 funs = C->
lhs[level] + 2;
1345 GETSTOP(term,tstop);
1347 while ( t < tstop ) {
1348 if ( *t != TABLESTUB ) { t += t[1];
continue; }
1352 if ( *m >= -FUNCTION )
continue;
1354 if ( ( T = functions[tabnum-FUNCTION].tabl ) == 0 )
continue;
1355 if ( T->
sparse == 0 )
continue;
1359 if ( numfuns > 0 ) {
1360 for ( i = 0; i < numfuns; i++ ) {
1361 if ( tabnum == funs[i] )
break;
1363 if ( i >= numfuns && numfuns > 0 )
continue;
1371 for ( i = 0; i < T->
numind; i++, m += 2 ) {
1372 if ( m >= t || *m != -SNUMBER )
break;
1374 if ( ( i == T->
numind ) &&
1375 ( ( isp = FindTableTree(T,tstart+FUNHEAD+1,2) ) >= 0 ) ) {
1381 MesPrint(
"TestUse: Encountered a table element inside tbl_ that does not correspond to a tablebase element");
1393 int CoTBaudit(UBYTE *s)
1397 int i, j, error = 0, num;
1399 if ( ( d = FindTB(tablebasename) ) == 0 ) {
1400 MesPrint(
"&No open tablebase with the name %s",tablebasename);
1403 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
1411 s = (UBYTE *)(d->tablenames); num = 0;
1414 name = s;
while ( *s ) s++; s++;
1415 tail = s;
while ( *s ) s++; s++;
1416 MesPrint(
"Table,sparse,%s%s)",name,tail);
1417 for ( i = 0; i < d->info.numberofindexblocks; i++ ) {
1418 for ( j = 0; j < NUMOBJECTS; j++ ) {
1419 if ( d->iblocks[i]->objects[j].tablenumber == num ) {
1420 MesPrint(
" %s(%s)",name,d->iblocks[i]->objects[j].element);
1433 int CoTBon(UBYTE *s)
1438 if ( ( d = FindTB(tablebasename) ) == 0 ) {
1439 MesPrint(
"&No open tablebase with the name %s",tablebasename);
1442 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
1446 if ( StrICmp(s,(UBYTE *)(
"compress")) == 0 ) {
1447 d->mode &= ~NOCOMPRESS;
1450 MesPrint(
"&subkey %s not defined in TableBase On statement");
1454 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
1464 int CoTBoff(UBYTE *s)
1469 if ( ( d = FindTB(tablebasename) ) == 0 ) {
1470 MesPrint(
"&No open tablebase with the name %s",tablebasename);
1473 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
1477 if ( StrICmp(s,(UBYTE *)(
"compress")) == 0 ) {
1478 d->mode |= NOCOMPRESS;
1481 MesPrint(
"&subkey %s not defined in TableBase Off statement");
1485 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
1495 int CoTBcleanup(UBYTE *s)
1498 MesPrint(
"&TableBase Cleanup statement not yet implemented");
1507 int CoTBreplace(UBYTE *s)
1510 MesPrint(
"&TableBase Replace statement not yet implemented");
1522 int CoTBuse(UBYTE *s)
1527 UBYTE *arguments, *rhs, *buffer, *t, *u, c, *tablename, *p;
1529 int i, j, error = 0, error1 = 0, k;
1531 WORD type, funnum, mode, *w;
1532 if ( ( d = FindTB(tablebasename) ) == 0 ) {
1533 MesPrint(
"&No open tablebase with the name %s",tablebasename);
1536 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
1540 if ( ( s = SkipAName(s) ) == 0 )
return(1);
1542 if ( ( GetVar(tablename,&type,&funnum,CFUNCTION,NOAUTO) == NAMENOTFOUND )
1543 || ( T = functions[funnum].tabl ) == 0 ) {
1544 MesPrint(
"&%s should be a previously declared table",tablename);
1547 else if ( T->
sparse == 0 ) {
1548 MesPrint(
"&%s should be a sparse table",tablename);
1551 else { basenumber = GetTableName(d,(
char *)tablename); }
1553 if ( basenumber > 0 ) {
1554 for ( i = 0; i < d->info.numberofindexblocks; i++ ) {
1555 for ( j = 0; j < NUMOBJECTS; j++ ) {
1556 if ( d->iblocks[i]->objects[j].tablenumber != basenumber )
continue;
1557 arguments = p = (UBYTE *)(d->iblocks[i]->objects[j].element);
1562 for ( k = 0, w = AT.WorkPointer; k < T->numind; k++ ) {
1563 ParseSignedNumber(x,p);
1566 sum = FindTableTree(T,AT.WorkPointer,1);
1568 MesPrint(
"Table %s in tablebase %s has not been loaded properly" 1569 ,tablename,tablebasename);
1575 if ( ( mode & ELEMENTLOADED ) == ELEMENTLOADED ) {
1579 if ( ( mode & ELEMENTUSED ) == 0 )
continue;
1583 rhs = (UBYTE *)ReadijObject(d,i,j,(
char *)arguments);
1585 u = rhs;
while ( *u ) u++;
1587 u = arguments;
while ( *u ) u++;
1588 size += u-arguments;
1589 u = tablename;
while ( *u ) u++;
1590 size += u-tablename;
1592 buffer = (UBYTE *)Malloc1(size,
"TableBase copy");
1593 t = tablename; u = buffer;
1594 while ( *t ) *u++ = *t++;
1597 while ( *t ) *u++ = *t++;
1598 *u++ =
')'; *u++ =
'=';
1600 while ( *t ) *u++ = *t++;
1601 if ( t == rhs ) { *u++ =
'0'; }
1603 M_free(rhs,
"rhs in TBuse xxx");
1605 error1 = CoFill(buffer);
1607 if ( error1 < 0 ) {
return(error); }
1608 if ( error1 != 0 ) error = error1;
1609 M_free(buffer,
"TableBase copy");
1617 while ( *s ==
',' || *s ==
' ' || *s ==
'\t' ) s++;
1621 s = (UBYTE *)(d->tablenames); basenumber = 0;
1624 tablename = s;
while ( *s ) s++; s++;
1625 while ( *s ) s++; s++;
1626 if ( ( GetVar(tablename,&type,&funnum,CFUNCTION,NOAUTO) == NAMENOTFOUND )
1627 || ( T = functions[funnum].tabl ) == 0 ) {
1628 MesPrint(
"&%s should be a previously declared table",tablename);
1630 else if ( T->
sparse == 0 ) {
1631 MesPrint(
"&%s should be a sparse table",tablename);
1634 MesPrint(
"In table %s we have a problem with stubb orders in CoTBuse",tablename);
1638 for ( i = 0; i < d->info.numberofindexblocks; i++ ) {
1639 for ( j = 0; j < NUMOBJECTS; j++ ) {
1640 if ( d->iblocks[i]->objects[j].tablenumber == basenumber ) {
1641 arguments = p = (UBYTE *)(d->iblocks[i]->objects[j].element);
1646 for ( k = 0, w = AT.WorkPointer; k < T->numind; k++ ) {
1647 ParseSignedNumber(x,p);
1650 sum = FindTableTree(T,AT.WorkPointer,1);
1652 MesPrint(
"Table %s in tablebase %s has not been loaded properly" 1653 ,tablename,tablebasename);
1659 if ( ( mode & ELEMENTLOADED ) == ELEMENTLOADED ) {
1663 if ( ( mode & ELEMENTUSED ) == 0 )
continue;
1667 rhs = (UBYTE *)ReadijObject(d,i,j,(
char *)arguments);
1669 u = rhs;
while ( *u ) u++;
1671 u = arguments;
while ( *u ) u++;
1672 size += u-arguments;
1673 u = tablename;
while ( *u ) u++;
1674 size += u-tablename;
1676 buffer = (UBYTE *)Malloc1(size,
"TableBase copy");
1677 t = tablename; u = buffer;
1678 while ( *t ) *u++ = *t++;
1681 while ( *t ) *u++ = *t++;
1682 *u++ =
')'; *u++ =
'=';
1685 while ( *t ) *u++ = *t++;
1686 if ( t == rhs ) { *u++ =
'0'; }
1688 M_free(rhs,
"rhs in TBuse");
1690 error1 = CoFill(buffer);
1692 if ( error1 < 0 ) {
return(error); }
1693 if ( error1 != 0 ) error = error1;
1694 M_free(buffer,
"TableBase copy");
1713 int CoApply(UBYTE *s)
1716 UBYTE *tablename, c;
1717 WORD type, funnum, *w;
1719 LONG maxtogo = MAXPOSITIVE;
1722 if ( FG.cTable[*s] == 1 ) {
1724 while ( FG.cTable[*s] == 1 ) {
1725 maxtogo = maxtogo*10 + (*s-
'0');
1728 while ( *s ==
',' ) s++;
1729 if ( maxtogo > MAXPOSITIVE || maxtogo < 0 ) maxtogo = MAXPOSITIVE;
1731 *w++ = TYPEAPPLY; *w++ = 3; *w++ = maxtogo;
1734 if ( ( s = SkipAName(s) ) == 0 )
return(1);
1736 if ( ( GetVar(tablename,&type,&funnum,CFUNCTION,NOAUTO) == NAMENOTFOUND )
1737 || ( T = functions[funnum].tabl ) == 0 ) {
1738 MesPrint(
"&%s should be a previously declared table",tablename);
1741 else if ( T->
sparse == 0 ) {
1742 MesPrint(
"&%s should be a sparse table",tablename);
1745 *w++ = funnum + FUNCTION;
1747 while ( *s ==
' ' || *s ==
',' || *s ==
'\t' ) s++;
1749 AT.WorkPointer[1] = w - AT.WorkPointer;
1755 AddNtoL(AT.WorkPointer[1],AT.WorkPointer);
1769 "The TableBase statement is used as follows:" 1770 ,
"TableBase \"file.tbl\" keyword subkey(s)" 1771 ,
" in which we have" 1772 ,
"Keyword Subkey(s) Action" 1773 ,
"open Opens file.tbl for R/W" 1774 ,
"create Creates file.tbl for R/W. Old contents are lost" 1775 ,
"load Loads all stubs of all tables" 1776 ,
"load tablename(s) Loads all stubs the tables mentioned" 1777 ,
"enter Loads all stubs and rhs of all tables" 1778 ,
"enter tablename(s) Loads all stubs and rhs of the tables mentioned" 1779 ,
"audit Prints list of contents" 1783 ,
"addto tablename adds all elements if not yet there" 1784 ,
"addto tableelement adds element if not yet there" 1787 ,
"on compress elements are stored in gzip format (default)" 1788 ,
"off compress elements are stored in uncompressed format" 1789 ,
"use compiles all needed elements" 1790 ,
"use tablename(s) compiles all needed elements of these tables" 1792 ,
"Related commands are:" 1793 ,
"testuse marks which tbl_ elements occur for all tables" 1794 ,
"testuse tablename(s) marks which tbl_ elements occur for given tables" 1795 ,
"apply replaces tbl_ if rhs available" 1796 ,
"apply tablename(s) replaces tbl_ for given tables if rhs available" 1800 int CoTBhelp(UBYTE *s)
1802 int i, ii =
sizeof(helptb)/
sizeof(
char *);
1804 for ( i = 0; i < ii; i++ ) MesPrint(
"%s",helptb[i]);
1816 VOID ReWorkT(WORD *term, WORD *funs, WORD numfuns)
1818 WORD *tstop, *tend, *m, *t, *tt, *mm, *mmm, *r, *rr;
1820 tend = term + *term; tstop = tend - ABS(tend[-1]);
1822 while ( t < tstop ) {
1823 if ( *t == TABLESTUB ) {
1824 for ( i = 0; i < numfuns; i++ ) {
1825 if ( -t[FUNHEAD] == funs[i] )
break;
1827 if ( numfuns == 0 || i < numfuns ) {
1829 *m++ = -t[FUNHEAD]; *m++ = i; t += 2; i -= FUNHEAD;
1830 if ( m < t ) {
for ( j = 0; j < FUNHEAD-2; j++ ) *m++ = *t++; }
1831 else { m += FUNHEAD-2; t += FUNHEAD-2; }
1833 while ( i-- > 0 ) { *m++ = *t++; }
1836 while ( tt < tend ) *mm++ = *tt++;
1838 tend = term + *term; tstop = tend - ABS(tend[-1]);
1844 else if ( *t >= FUNCTION ) {
1847 for ( j = 0; j < FUNHEAD; j++ ) {
1848 if ( m == t ) { m++; t++; }
1852 if ( *t <= -FUNCTION ) {
1853 if ( m == t ) { m++; t++; }
1856 else if ( *t < 0 ) {
1857 if ( m == t ) { m += 2; t += 2; }
1858 else { *m++ = *t++; *m++ = *t++; }
1861 rr = t + *t; mmm = m;
1862 for ( j = 0; j < ARGHEAD; j++ ) {
1863 if ( m == t ) { m++; t++; }
1868 ReWorkT(t,funs,numfuns);
1870 if ( m == t ) { m += j; t += j; }
1871 else {
while ( j-- >= 0 ) *m++ = *t++; }
1882 if ( m < t ) {
while ( j-- >= 0 ) *m++ = *t++; }
1883 else { m += j; t += j; }
1887 while ( t < tend ) *m++ = *t++;
1897 WORD Apply(WORD *term, WORD level)
1899 WORD *funs, numfuns;
1902 CBUF *C = cbuf+AM.rbufnum;
1906 numfuns = C->
lhs[level][1] - 2;
1907 funs = C->
lhs[level] + 2;
1908 if ( numfuns > 0 ) {
1909 for ( i = MAXBUILTINFUNCTION-FUNCTION; i < AC.FunctionList.num; i++ ) {
1910 if ( ( T = functions[i].tabl ) != 0 ) {
1911 for ( j = 0; j < numfuns; j++ ) {
1912 if ( i == (funs[j]-FUNCTION) && T->
spare ) {
1913 FlipTable(&(functions[i]),0);
1921 for ( i = MAXBUILTINFUNCTION-FUNCTION; i < AC.FunctionList.num; i++ ) {
1922 if ( ( T = functions[i].tabl ) != 0 ) {
1923 if ( T->
spare ) FlipTable(&(functions[i]),0);
1933 ReWorkT(term,funs,numfuns);
1956 int ApplyExec(WORD *term,
int maxtogo, WORD level)
1959 WORD rhsnumber, *Tpattern, *funs, numfuns, funnum;
1960 WORD ii, *t, *t1, *w, *p, *m, *m1, *u, *r, tbufnum, csize, wilds;
1962 int i, j, isp, stilltogo;
1972 AT.NestPoin->termsize = t;
1973 if ( AT.NestPoin == AT.Nest ) AN.EndNest = t + *t;
1979 if ( *t < FUNCTION ) { t += t[1];
continue; }
1980 if ( functions[*t-FUNCTION].spec > 0 ) { t += t[1];
continue; }
1981 AT.NestPoin->funsize = t;
1985 if ( *t < 0 ) { NEXTARG(t);
continue; }
1986 AT.NestPoin->argsize = t1 = t;
2003 stilltogo = ApplyExec(t,maxtogo,level);
2004 if ( stilltogo != maxtogo ) {
2005 if ( stilltogo <= 0 ) {
2009 maxtogo = stilltogo;
2011 m = term + *term - csize;
2021 C = cbuf+AM.rbufnum;
2024 if ( *t != TABLESTUB ) { t += t[1];
continue; }
2025 funnum = -t[FUNHEAD];
2026 if ( ( funnum < FUNCTION )
2027 || ( funnum >= FUNCTION+WILDOFFSET )
2028 || ( ( T = functions[funnum-FUNCTION].tabl ) == 0 )
2030 || ( T->
spare == 0 ) ) { t += t[1];
continue; }
2031 numfuns = C->
lhs[level][1] - 3;
2032 funs = C->
lhs[level] + 3;
2033 if ( numfuns > 0 ) {
2034 for ( i = 0; i < numfuns; i++ ) {
2035 if ( funs[i] == funnum )
break;
2037 if ( i >= numfuns ) { t += t[1];
continue; }
2040 AT.NestPoin->funsize = t + 1;
2050 Tpattern = T->
pattern[identity];
2054 p = Tpattern+FUNHEAD+1;
2055 for ( i = 0; i < T->
numind; i++, t += 2 ) {
2056 if ( *t != -SNUMBER )
break;
2058 if ( i < T->numind ) { t = r;
continue; }
2059 isp = FindTableTree(T,t1+FUNHEAD+1,2);
2060 if ( isp < 0 ) { t = r;
continue; }
2062 #if ( TABLEEXTENSION == 2 ) 2069 while ( --ii >= 0 ) {
2070 *p = *t; t += 2; p += 2;
2082 AN.WildValue = AN.FullProto + SUBEXPSIZE;
2083 AN.WildStop = AN.FullProto+AN.FullProto[1];
2086 AN.RepFunList = AN.EndNest;
2087 AT.WorkPointer = (WORD *)(((UBYTE *)(AN.EndNest)) + AM.MaxTer/2);
2092 if ( AT.WorkPointer + t1[1] >= AT.WorkTop ) { MesWork(); }
2095 *w++ = -t1[FUNHEAD];
2097 for ( i = 2; i < FUNHEAD; i++ ) *w++ = t1[i];
2099 while ( t < r ) *w++ = *t++;
2102 if ( MatchFunction(BHEAD Tpattern,t,&wilds) > 0 ) {
2123 while ( r < m1 ) *t++ = *r++;
2127 while ( NN > AT.Nest ) {
2129 NN->termsize[0] += j;
2130 NN->funsize[1] += j;
2131 NN->argsize[0] += j;
2132 NN->funsize[2] |= DIRTYFLAG;
2133 NN->argsize[1] |= DIRTYFLAG;
2140 while ( t >= r ) { t[j] = *t; t--; }
2146 while ( NN > AT.Nest ) {
2148 NN->termsize[0] += j;
2149 NN->funsize[1] += j;
2150 NN->argsize[0] += j;
2151 NN->funsize[2] |= DIRTYFLAG;
2152 NN->argsize[1] |= DIRTYFLAG;
2161 if ( maxtogo <= 0 )
return(maxtogo);
2173 WORD ApplyReset(WORD level)
2175 WORD *funs, numfuns;
2178 CBUF *C = cbuf+AM.rbufnum;
2180 numfuns = C->
lhs[level][1] - 2;
2181 funs = C->
lhs[level] + 2;
2182 if ( numfuns > 0 ) {
2183 for ( i = MAXBUILTINFUNCTION-FUNCTION; i < AC.FunctionList.num; i++ ) {
2184 if ( ( T = functions[i].tabl ) != 0 ) {
2185 for ( j = 0; j < numfuns; j++ ) {
2186 if ( i == (funs[j]-FUNCTION) && T->
spare ) {
2187 FlipTable(&(functions[i]),1);
2195 for ( i = MAXBUILTINFUNCTION-FUNCTION; i < AC.FunctionList.num; i++ ) {
2196 if ( ( T = functions[i].tabl ) != 0 ) {
2197 if ( T->
spare ) FlipTable(&(functions[i]),1);
2214 for ( i = MAXBUILTINFUNCTION-FUNCTION; i < AC.FunctionList.num; i++ ) {
2215 if ( ( T = functions[i].tabl ) != 0 && T->
spare && T->
mode == 0 ) {
2216 functions[i].tabl = T->
spare;
2240 for ( i = NumTableBases - 1; i >= 0; i-- ) {
WORD Generator(PHEAD WORD *, WORD)