106WORD GetIfDollarNum(WORD *ifp, WORD *ifstop)
110 if ( ifp[2] < 0 ) {
return(-ifp[2]-1); }
112 if ( ifp+3 < ifstop && ifp[3] == IFDOLLAREXTRA ) {
113 if ( d->nfactors == 0 ) {
114 MLOCK(ErrorMessageLock);
115 MesPrint(
"Attempt to use a factor of an unfactored $-variable");
116 MUNLOCK(ErrorMessageLock);
119 num = GetIfDollarNum(ifp+3,ifstop);
120 if ( num > d->nfactors ) {
121 MLOCK(ErrorMessageLock);
122 MesPrint(
"Dollar factor number %s out of range",num);
123 MUNLOCK(ErrorMessageLock);
129 w = d->factors[num-1].where;
130 if ( w == 0 )
return(d->factors[num].value);
132 if ( *w == 0 )
return(0);
133 if ( *w == 4 && w[3] == 3 && w[2] == 1 && w[1] < MAXPOSITIVE && w[4] == 0 ) {
136 if ( ( w[w[0]] != 0 ) || ( ABS(w[w[0]-1]) != w[0]-1 ) ) {
137 MLOCK(ErrorMessageLock);
138 MesPrint(
"Dollar factor number expected but found expression");
139 MUNLOCK(ErrorMessageLock);
143 MLOCK(ErrorMessageLock);
144 MesPrint(
"Dollar factor number out of range");
145 MUNLOCK(ErrorMessageLock);
153 if ( d->type == DOLZERO ) {
156 else if ( d->type == DOLNUMBER || d->type == DOLTERMS ) {
157 w = d->where;
goto getnumber;
160 MLOCK(ErrorMessageLock);
161 MesPrint(
"Dollar factor number is wrong type");
162 MUNLOCK(ErrorMessageLock);
173int FindVar(WORD *v, WORD *term)
175 WORD *t, *tstop, *m, *mstop, *f, *fstop, *a, *astop;
178 while ( t < tstop ) {
179 if ( *v == *t && *v < FUNCTION ) {
182 m = t+2; mstop = t+t[1];
183 while ( m < mstop ) {
184 if ( *m == v[1] )
return(1);
191 m = t+2; mstop = t+t[1];
192 while ( m < mstop ) {
193 if ( *m == v[1] )
return(1);
198 m = t+2; mstop = t+t[1];
199 while ( m < mstop ) {
200 if ( *m == v[1] && m[1] == v[2] )
return(1);
201 if ( *m == v[2] && m[1] == v[1] )
return(1);
207 else if ( *v == VECTOR && *t == INDEX )
goto InVe;
208 else if ( *v == INDEX && *t == VECTOR )
goto InVe;
209 else if ( ( *v == VECTOR || *v == INDEX ) && *t == DOTPRODUCT ) {
210 m = t+2; mstop = t+t[1];
211 while ( m < mstop ) {
212 if ( v[1] == m[0] || v[1] == m[1] )
return(1);
216 else if ( *t >= FUNCTION ) {
217 if ( *v == FUNCTION && v[1] == *t )
return(1);
218 if ( functions[*t-FUNCTION].spec > 0 ) {
219 if ( *v == VECTOR || *v == INDEX ) {
221 for ( i = FUNHEAD; i < t[1]; i++ ) {
222 if ( v[1] == t[i] )
return(1);
227 fstop = t + t[1]; f = t + FUNHEAD;
228 while ( f < fstop ) {
232 if ( *v == SYMBOL && v[1] == f[1] )
return(1);
238 if ( ( *v == VECTOR || *v == INDEX )
239 && ( v[1] == f[1] ) )
return(1);
246 if ( *v == FUNCTION && v[1] == -*f && *f <= -FUNCTION )
return(1);
247 if ( *f <= -FUNCTION ) f++;
253 a = f + ARGHEAD; astop = f + *f;
254 while ( a < astop ) {
255 if ( FindVar(v,a) == 1 )
return(1);
280WORD DoIfStatement(PHEAD WORD *ifcode, WORD *term)
284 UWORD *coef1 = 0, *coef2, *coef3, *cc;
285 WORD ncoef1, ncoef2, ncoef3, i = 0, first, *r, acoef, ismul1, ismul2, j;
286 UWORD *Spac1, *Spac2;
287 ifstop = ifcode + ifcode[1];
289 if ( ifp >= ifstop )
return(1);
290 if ( ( ifp + ifp[1] ) >= ifstop ) {
293 if ( ifp[2] )
return(1);
297 if ( HowMany(BHEAD ifp,term) )
return(1);
300 if ( Lus(term,ifp[3],ifp[4],ifp[5],ifp[6],ifp[2]) )
return(1);
303 if ( CountDo(term,ifp) )
return(1);
312 int nummodopt, dtype = -1;
313 if ( AS.MultiThreaded ) {
314 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
315 if ( ifp[2] == ModOptdollars[nummodopt].number )
break;
317 if ( nummodopt < NumModOptdollars ) {
318 dtype = ModOptdollars[nummodopt].type;
319 if ( dtype == MODLOCAL ) {
320 d = ModOptdollars[nummodopt].dstruct+AT.identity;
328 if ( dtype == DOLZERO )
return(0);
329 if ( dtype == DOLUNDEFINED ) {
330 if ( AC.UnsureDollarMode == 0 ) {
331 MesPrint(
"$%s is undefined",AC.dollarnames->namebuffer+d->name);
338 r = ifp+2; j = ifp[1] - 2;
340 if ( *r == AR.CurExpr )
return(1);
345 r = ifp+2; j = ifp[1] - 2;
347 if ( ( Expressions[AR.CurExpr].vflags & ISFACTORIZED ) != 0 )
353 if ( ( Expressions[*r].vflags & ISFACTORIZED ) == 0 )
return(0);
359 WORD *OccStop = ifp + ifp[1];
361 while ( ifp < OccStop ) {
362 if ( FindVar(ifp,term) == 1 )
return(1);
363 if ( *ifp == DOTPRODUCT ) ifp += 3;
372 if ( ifp[3] == ( ifp[1] + 3 ) )
return(DoIfStatement(BHEAD ifp,term));
373 ifstop = ifp + ifp[1];
381 coef3 = NumberMalloc(
"DoIfStatement");
382 Spac1 = NumberMalloc(
"DoIfStatement");
383 Spac2 = (UWORD *)(TermMalloc(
"DoIfStatement"));
384 ncoef1 = 0; first = 1; ismul1 = 0;
388 if ( ifp[-2] == ORCOND && ncoef1 ) {
390 ncoef1 = 1; coef1[0] = coef1[1] = 1;
393 if ( ifp[-2] == ANDCOND && !ncoef1 )
goto SkipCond;
402 cc = (UWORD *)(ifp + 3);
403 for ( i = 0; i < j; i++ ) coef2[i] = cc[i];
407 coef2[0] = HowMany(BHEAD ifp,term);
409 if ( coef2[0] == 0 ) ncoef2 = 0;
412 acoef = CountDo(term,ifp);
413 coef2[0] = ABS(acoef);
415 if ( acoef == 0 ) ncoef2 = 0;
416 else if ( acoef < 0 ) ncoef2 = -1;
419 acoef = Lus(term,ifp[3],ifp[4],ifp[5],ifp[6],ifp[2]);
420 coef2[0] = ABS(acoef);
422 if ( acoef == 0 ) ncoef2 = 0;
423 else if ( acoef < 0 ) ncoef2 = -1;
429 cc = (UWORD *)(r - i);
430 if ( ncoef2 < 0 ) ncoef2 = (ncoef2+1)>>1;
431 else ncoef2 = (ncoef2-1)>>1;
432 i--;
for ( j = 0; j < i; j++ ) coef2[j] = cc[j];
435 ncoef2 = coef2[0] = DoIfStatement(BHEAD ifp,term);
454 int nummodopt, dtype = -1;
455 if ( AS.MultiThreaded ) {
456 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
457 if ( ifp[2] == ModOptdollars[nummodopt].number )
break;
459 if ( nummodopt < NumModOptdollars ) {
460 dtype = ModOptdollars[nummodopt].type;
461 if ( dtype == MODLOCAL ) {
462 d = ModOptdollars[nummodopt].dstruct+AT.identity;
465 LOCK(d->pthreadslockread);
473 if ( ifp+3 < ifstop && ifp[3] == IFDOLLAREXTRA ) {
474 if ( d->nfactors == 0 ) {
475 MLOCK(ErrorMessageLock);
476 MesPrint(
"Attempt to use a factor of an unfactored $-variable");
477 MUNLOCK(ErrorMessageLock);
480 WORD num = GetIfDollarNum(ifp+3,ifstop);
482 while ( ifp+3 < ifstop && ifp[3] == IFDOLLAREXTRA ) ifp += 3;
483 if ( num > d->nfactors ) {
484 MLOCK(ErrorMessageLock);
485 MesPrint(
"Dollar factor number %s out of range",num);
486 MUNLOCK(ErrorMessageLock);
490 ncoef2 = 1; coef2[0] = d->nfactors; coef2[1] = 1;
493 w = d->factors[num-1].where;
495 if ( d->factors[num-1].value < 0 ) {
496 ncoef2 = -1; coef2[0] = -d->factors[num-1].value; coef2[1] = 1;
499 ncoef2 = 1; coef2[0] = d->factors[num-1].value; coef2[1] = 1;
506 if ( i == ( *w-1 ) ) {
508 if ( *r < 0 ) ncoef2 = -ncoef2;
509 i--; cc = coef2; r = w + 1;
510 while ( --i >= 0 ) *cc++ = (UWORD)(*r++);
520 if ( AC.UnsureDollarMode == 0 ) {
522 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
524 MLOCK(ErrorMessageLock);
525 MesPrint(
"$%s is undefined",AC.dollarnames->namebuffer+d->name);
526 MUNLOCK(ErrorMessageLock);
529 ncoef2 = 0; coef2[0] = 0; coef2[1] = 1;
532 ncoef2 = coef2[0] = 0; coef2[1] = 1;
535 if ( d->where[0] != INDEX || d->where[1] != 3
536 || d->where[2] < 0 || d->where[2] >= AM.OffsetIndex ) {
537 if ( AC.UnsureDollarMode == 0 ) {
539 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
541 MLOCK(ErrorMessageLock);
542 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
543 MUNLOCK(ErrorMessageLock);
546 ncoef2 = 0; coef2[0] = 0; coef2[1] = 1;
549 d->index = d->where[2];
552 if ( d->index == 0 ) {
553 ncoef2 = coef2[0] = 0; coef2[1] = 1;
555 else if ( d->index > 0 && d->index < AM.OffsetIndex ) {
556 ncoef2 = 1; coef2[0] = d->index; coef2[1] = 1;
558 else if ( AC.UnsureDollarMode == 0 ) {
560 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
562 MLOCK(ErrorMessageLock);
563 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
564 MUNLOCK(ErrorMessageLock);
567 ncoef2 = coef2[0] = 0; coef2[1] = 1;
570 if ( d->where[0] <= -FUNCTION ||
571 ( d->where[0] < 0 && d->where[2] != 0 )
572 || ( d->where[0] > 0 && d->where[d->where[0]] != 0 )
574 if ( AC.UnsureDollarMode == 0 ) {
576 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
578 MLOCK(ErrorMessageLock);
579 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
580 MUNLOCK(ErrorMessageLock);
583 ncoef2 = coef2[0] = 0; coef2[1] = 1;
588 if ( d->where[0] == -SNUMBER ) {
589 if ( d->where[1] == 0 ) {
590 ncoef2 = coef2[0] = 0;
592 else if ( d->where[1] < 0 ) {
594 coef2[0] = -d->where[1];
598 coef2[0] = d->where[1];
602 else if ( d->where[0] == -INDEX
603 && d->where[1] >= 0 && d->where[1] < AM.OffsetIndex ) {
604 if ( d->where[1] == 0 ) {
605 ncoef2 = coef2[0] = 0; coef2[1] = 1;
608 ncoef2 = 1; coef2[0] = d->where[1];
612 else if ( d->where[0] > 0
613 && d->where[ARGHEAD] == (d->where[0]-ARGHEAD)
614 && ABS(d->where[d->where[0]-1]) ==
615 (d->where[0] - ARGHEAD-1) ) {
616 i = d->where[d->where[0]-1];
617 ncoef2 = (ABS(i)-1)/2;
618 if ( i < 0 ) { ncoef2 = -ncoef2; i = -i; }
619 i--; cc = coef2; r = d->where + ARGHEAD+1;
620 while ( --i >= 0 ) *cc++ = (UWORD)(*r++);
623 if ( AC.UnsureDollarMode == 0 ) {
625 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
627 MLOCK(ErrorMessageLock);
628 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
629 MUNLOCK(ErrorMessageLock);
632 ncoef2 = 0; coef2[0] = 0; coef2[1] = 1;
637 if ( d->where[d->where[0]] == 0 ) {
638 r = d->where + d->where[0]-1;
640 if ( i == ( d->where[0]-1 ) ) {
642 if ( *r < 0 ) ncoef2 = -ncoef2;
643 i--; cc = coef2; r = d->where + 1;
644 while ( --i >= 0 ) *cc++ = (UWORD)(*r++);
649 if ( AC.UnsureDollarMode == 0 ) {
651 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
653 MLOCK(ErrorMessageLock);
654 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
655 MUNLOCK(ErrorMessageLock);
658 ncoef2 = 0; coef2[0] = 0; coef2[1] = 1;
663 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslockread); }
668 r = ifp+2; j = ifp[1] - 2; ncoef2 = 0;
670 if ( *r == AR.CurExpr ) { ncoef2 = 1;
break; }
677 r = ifp+2; j = ifp[1] - 2;
680 if ( ( Expressions[AR.CurExpr].vflags & ISFACTORIZED ) != 0 ) {
687 if ( ( Expressions[*r].vflags & ISFACTORIZED ) == 0 ) {
699 WORD *OccStop = ifp + ifp[1], *ifpp = ifp+2;
701 while ( ifpp < OccStop ) {
702 if ( FindVar(ifpp,term) == 1 ) {
705 if ( *ifpp == DOTPRODUCT ) ifp += 3;
716 if ( ifp[-2] != ORCOND && ifp[-2] != ANDCOND ) {
717 if ( ( ifp[-2] == EQUAL || ifp[-2] == NOTEQUAL ) &&
718 ( ismul2 || ismul1 ) ) {
719 if ( ismul1 && ismul2 ) {
720 if ( coef1[0] == coef2[0] ) i = 1;
726 Divvy(BHEAD coef2,&ncoef2,coef1,ncoef1);
727 cc = coef2; ncoef3 = ncoef2;
731 Divvy(BHEAD coef1,&ncoef1,coef2,ncoef2);
732 cc = coef1; ncoef3 = ncoef1;
734 if ( ncoef3 < 0 ) ncoef3 = -ncoef3;
736 if ( ifp[-2] == EQUAL ) i = 1;
739 else if ( cc[ncoef3] != 1 ) {
740 if ( ifp[-2] == EQUAL ) i = 0;
744 for ( j = 1; j < ncoef3; j++ ) {
745 if ( cc[ncoef3+j] != 0 )
break;
748 if ( ifp[-2] == EQUAL ) i = 0;
751 else if ( ifp[-2] == EQUAL ) i = 1;
757 else if ( AddRat(BHEAD coef1,ncoef1,coef2,-ncoef2,coef3,&ncoef3) ) {
758 NumberFree(coef3,
"DoIfStatement"); NumberFree(Spac1,
"DoIfStatement"); TermFree(Spac2,
"DoIfStatement");
759 MesCall(
"DoIfStatement");
return(-1);
763 if ( ncoef3 > 0 ) i = 1;
767 if ( ncoef3 >= 0 ) i = 1;
771 if ( ncoef3 < 0 ) i = 1;
775 if ( ncoef3 <= 0 ) i = 1;
779 if ( ncoef3 == 0 ) i = 1;
783 if ( ncoef3 != 0 ) i = 1;
787donemul:
if ( i ) { ncoef2 = 1; coef2 = Spac2; coef2[0] = coef2[1] = 1; }
797 for ( j = 0; j < i; j++ ) coef1[j] = coef2[j];
801 }
while ( ifp < ifstop );
803 NumberFree(coef3,
"DoIfStatement"); NumberFree(Spac1,
"DoIfStatement"); TermFree(Spac2,
"DoIfStatement");
804 if ( ncoef1 )
return(1);
818WORD HowMany(PHEAD WORD *ifcode, WORD *term)
821 WORD *m, *t, *r, *w, power, RetVal, i, topje, *newterm;
822 WORD *OldWork, *ww, *mm;
827 AN.WildValue = w = m + SUBEXPSIZE;
830 OldWork = AT.WorkPointer;
831 if ( ( ifcode[4] & 1 ) != 0 ) {
833 ww = AT.WorkPointer; i = m[0]; mm = m;
836 *ww++ = 1; *ww++ = 1; *ww++ = 3;
838 RepSto = AN.RepPoint;
841 if (
Generator(BHEAD OldWork,AR.Cnumlhs) ) {
844 AN.RepPoint = RepSto;
845 AT.WorkPointer = OldWork;
849 if (
EndSort(BHEAD ww,0) < 0 ) {}
851 AN.RepPoint = RepSto;
852 if ( *ww == 0 || *(ww+*ww) != 0 ) {
853 if ( AP.lhdollarerror == 0 ) {
854 MLOCK(ErrorMessageLock);
855 MesPrint(
"&LHS must be one term");
856 MUNLOCK(ErrorMessageLock);
857 AP.lhdollarerror = 1;
859 AT.WorkPointer = OldWork;
862 m = ww; AT.WorkPointer = ww = m + *m;
863 if ( m[*m-1] < 0 ) { m[*m-1] = -m[*m-1]; }
869 if ( AT.WorkPointer < ww ) AT.WorkPointer = ww;
872 while ( w < AN.WildStop ) {
873 if ( *w == LOADDOLLAR ) numdollars++;
877 AN.RepFunList = AT.WorkPointer;
878 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
879 topje = cbuf[AT.ebufnum].numrhs;
880 if ( AT.WorkPointer >= AT.WorkTop ) {
881 MLOCK(ErrorMessageLock);
883 MUNLOCK(ErrorMessageLock);
886 AN.DisOrderFlag = ifcode[2] & SUBDISORDER;
887 switch ( ifcode[2] & (~SUBDISORDER) ) {
890 AN.UseFindOnly = 1; AN.ForFindOnly = 0;
896 t = term; newterm = r = AT.WorkPointer;
897 NCOPY(r,t,i); AT.WorkPointer = r;
899 if ( FindRest(BHEAD newterm,m) && ( AN.UsedOtherFind ||
900 FindOnly(BHEAD newterm,m) ) ) {
901 Substitute(BHEAD newterm,m,1);
903 WildDollars(BHEAD (WORD *)0);
917 t = term; newterm = r = AT.WorkPointer;
918 NCOPY(r,t,i); AT.WorkPointer = r;
921 if ( ( power = FindRest(BHEAD newterm,m) ) > 0 ) {
922 if ( ( power = FindOnce(BHEAD newterm,m) ) > 0 ) {
925 Substitute(BHEAD newterm,m,1);
927 WildDollars(BHEAD (WORD *)0);
932 }
while ( FindRest(BHEAD newterm,m) && (
933 AN.UsedOtherFind || FindOnce(BHEAD newterm,m) ) );
935 else if ( power < 0 ) {
937 Substitute(BHEAD newterm,m,1);
939 WildDollars(BHEAD (WORD *)0);
944 }
while ( FindRest(BHEAD newterm,m) );
947 else if ( power < 0 ) {
948 if ( FindOnce(BHEAD newterm,m) ) {
950 Substitute(BHEAD newterm,m,1);
952 WildDollars(BHEAD (WORD *)0);
956 }
while ( FindOnce(BHEAD newterm,m) );
967 t = term; newterm = r = AT.WorkPointer;
968 NCOPY(r,t,i); AT.WorkPointer = r;
971 if ( FindRest(BHEAD newterm,m) && ( AN.UsedOtherFind || FindOnce(BHEAD newterm,m) ) ) {
972 Substitute(BHEAD newterm,m,1);
974 WildDollars(BHEAD (WORD *)0);
983 RetVal = FindMulti(BHEAD term,m);
987 for ( i = 0; i < *term; i++ ) ww[i] = term[i];
988 while ( ( power = FindAll(BHEAD ww,m,AR.Cnumlhs,ifcode) ) != 0 ) { RetVal += power; }
991 ifcode += IDHEAD; ifcode += ifcode[1]; ifcode += *ifcode;
992 AN.UseFindOnly = 1; AN.ForFindOnly = ifcode;
993 if ( FindRest(BHEAD term,m) && ( AN.UsedOtherFind ||
994 FindOnly(BHEAD term,m) ) ) RetVal = 1;
1001 AT.WorkPointer = AN.RepFunList;
1002 cbuf[AT.ebufnum].numrhs = topje;
1011VOID DoubleIfBuffers()
1015 LONG *newheap, *newifcount;
1016 if ( AC.MaxIf == 0 ) newmax = 10;
1017 else newmax = 2*AC.MaxIf;
1018 newheap = (LONG *)Malloc1(
sizeof(LONG)*(newmax+1),
"IfHeap");
1019 newsumcheck = (WORD *)Malloc1(
sizeof(WORD)*(newmax+1),
"IfSumCheck");
1020 newifcount = (LONG *)Malloc1(
sizeof(LONG)*(newmax+1),
"IfCount");
1022 for ( i = 0; i < AC.MaxIf; i++ ) {
1023 newheap[i] = AC.IfHeap[i];
1024 newsumcheck[i] = AC.IfSumCheck[i];
1025 newifcount[i] = AC.IfCount[i];
1027 AC.IfStack = (AC.IfStack-AC.IfHeap) + newheap;
1028 M_free(AC.IfHeap,
"AC.IfHeap");
1029 M_free(AC.IfCount,
"AC.IfCount");
1030 M_free(AC.IfSumCheck,
"AC.IfSumCheck");
1033 AC.IfStack = newheap;
1035 AC.IfHeap = newheap;
1036 AC.IfSumCheck = newsumcheck;
1037 AC.IfCount = newifcount;
1048int DoSwitch(PHEAD WORD *term, WORD *lhs)
1053 WORD numdollar = lhs[2];
1054 WORD ncase = DolToNumber(BHEAD numdollar);
1056 return(
Generator(BHEAD term,swtab->value));
1064int DoEndSwitch(PHEAD WORD *term, WORD *lhs)
1066 SWITCH *sw = AC.SwitchArray+lhs[2];
1067 return(
Generator(BHEAD term,sw->endswitch.value+1));
1080 SWITCH *sw = AC.SwitchArray+nswitch;
1082 if ( sw->typetable == DENSETABLE ) {
1083 med = ncase - sw->caseoffset;
1084 if ( med >= sw->numcases || med < 0 )
return(&sw->defaultcase);
1090 if ( ncase > sw->maxcase || ncase < sw->mincase )
return(&sw->defaultcase);
1091 hi = sw->numcases-1; lo = 0;
1094 if ( ncase == sw->table[med].ncase )
break;
1095 else if ( ncase > sw->table[med].ncase ) {
1097 if ( lo > hi )
return(&sw->defaultcase);
1101 if ( hi < lo )
return(&sw->defaultcase);
1105 return(&sw->table[med]);
1113int DoubleSwitchBuffers()
1118 if ( AC.MaxSwitch == 0 ) newmax = 10;
1119 else newmax = 2*AC.MaxSwitch;
1120 newarray = (
SWITCH *)Malloc1(
sizeof(
SWITCH)*(newmax+1),
"SwitchArray");
1121 newheap = (WORD *)Malloc1(
sizeof(WORD)*(newmax+1),
"SwitchHeap");
1122 if ( AC.MaxSwitch ) {
1123 for ( i = 0; i < AC.MaxSwitch; i++ ) {
1124 newarray[i] = AC.SwitchArray[i];
1125 newheap[i] = AC.SwitchHeap[i];
1127 M_free(AC.SwitchHeap,
"AC.SwitchHeap");
1128 M_free(AC.SwitchArray,
"AC.SwitchArray");
1130 for ( i = AC.MaxSwitch; i <= newmax; i++ ) {
1131 newarray[i].table = 0;
1132 newarray[i].tablesize = 0;
1133 newarray[i].defaultcase.ncase = 0;
1134 newarray[i].defaultcase.value = 0;
1135 newarray[i].defaultcase.compbuffer = 0;
1136 newarray[i].endswitch.ncase = 0;
1137 newarray[i].endswitch.value = 0;
1138 newarray[i].endswitch.compbuffer = 0;
1139 newarray[i].typetable = 0;
1140 newarray[i].mincase = 0;
1141 newarray[i].maxcase = 0;
1142 newarray[i].numcases = 0;
1143 newarray[i].caseoffset = 0;
1144 newarray[i].iflevel = 0;
1145 newarray[i].whilelevel = 0;
1146 newarray[i].nestingsum = 0;
1149 AC.SwitchArray = newarray;
1150 AC.SwitchHeap = newheap;
1151 AC.MaxSwitch = newmax;
1166 if ( num < 2 )
return;
1168 if ( array[0].ncase > array[1].ncase ) {
1169 t = array[0]; array[0] = array[1]; array[1] = t;
1175 SwitchSplitMergeRec(array,n1,auxarray);
1176 SwitchSplitMergeRec(array+n1,n2,auxarray);
1177 if ( array[n1-1].ncase <= array[n1].ncase )
return;
1179 t1 = array; t2 = auxarray; i = n1; NCOPY(t2,t1,i);
1180 i = 0; j = n1; k = 0;
1181 while ( i < n1 && j < num ) {
1182 if ( auxarray[i].ncase <= array[j].ncase ) { array[k++] = auxarray[i++]; }
1183 else { array[k++] = array[j++]; }
1185 while ( i < n1 ) array[k++] = auxarray[i++];
1194 SwitchSplitMergeRec(array,num,auxarray);
1195 M_free(auxarray,
"SwitchSplitMerge");
LONG EndSort(PHEAD WORD *, int)
WORD Generator(PHEAD WORD *, WORD)