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);
280int 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 ( DollarLocalCopy(dtype) ) {
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;
369 if ( ( Expressions[AR.CurExpr].uflags & (1 << ifp[2]) ) != 0 )
376 if ( ifp[3] == ( ifp[1] + 3 ) )
return(DoIfStatement(BHEAD ifp,term));
377 ifstop = ifp + ifp[1];
385 coef3 = NumberMalloc(
"DoIfStatement");
386 Spac1 = NumberMalloc(
"DoIfStatement");
387 Spac2 = (UWORD *)(TermMalloc(
"DoIfStatement"));
388 ncoef1 = 0; first = 1; ismul1 = 0;
392 if ( ifp[-2] == ORCOND && ncoef1 ) {
394 ncoef1 = 1; coef1[0] = coef1[1] = 1;
397 if ( ifp[-2] == ANDCOND && !ncoef1 )
goto SkipCond;
406 cc = (UWORD *)(ifp + 3);
407 for ( i = 0; i < j; i++ ) coef2[i] = cc[i];
416 ncoef2 = FloatFunToRat(BHEAD coef2,ifp);
422 coef2[0] = HowMany(BHEAD ifp,term);
424 if ( coef2[0] == 0 ) ncoef2 = 0;
427 acoef = CountDo(term,ifp);
428 coef2[0] = ABS(acoef);
430 if ( acoef == 0 ) ncoef2 = 0;
431 else if ( acoef < 0 ) ncoef2 = -1;
434 acoef = Lus(term,ifp[3],ifp[4],ifp[5],ifp[6],ifp[2]);
435 coef2[0] = ABS(acoef);
437 if ( acoef == 0 ) ncoef2 = 0;
438 else if ( acoef < 0 ) ncoef2 = -1;
444 cc = (UWORD *)(r - i);
445 if ( ncoef2 < 0 ) ncoef2 = (ncoef2+1)>>1;
446 else ncoef2 = (ncoef2-1)>>1;
447 i--;
for ( j = 0; j < i; j++ ) coef2[j] = cc[j];
450 ncoef2 = coef2[0] = DoIfStatement(BHEAD ifp,term);
469 int nummodopt, dtype = -1;
470 if ( AS.MultiThreaded ) {
471 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
472 if ( ifp[2] == ModOptdollars[nummodopt].number )
break;
474 if ( nummodopt < NumModOptdollars ) {
475 dtype = ModOptdollars[nummodopt].type;
476 if ( DollarLocalCopy(dtype) ) {
477 d = ModOptdollars[nummodopt].dstruct+AT.identity;
480 LOCK(d->pthreadslock);
488 if ( ifp+3 < ifstop && ifp[3] == IFDOLLAREXTRA ) {
489 if ( d->nfactors == 0 ) {
490 MLOCK(ErrorMessageLock);
491 MesPrint(
"Attempt to use a factor of an unfactored $-variable");
492 MUNLOCK(ErrorMessageLock);
495 WORD num = GetIfDollarNum(ifp+3,ifstop);
497 while ( ifp+3 < ifstop && ifp[3] == IFDOLLAREXTRA ) ifp += 3;
498 if ( num > d->nfactors ) {
499 MLOCK(ErrorMessageLock);
500 MesPrint(
"Dollar factor number %s out of range",num);
501 MUNLOCK(ErrorMessageLock);
505 ncoef2 = 1; coef2[0] = d->nfactors; coef2[1] = 1;
508 w = d->factors[num-1].where;
510 if ( d->factors[num-1].value < 0 ) {
511 ncoef2 = -1; coef2[0] = -d->factors[num-1].value; coef2[1] = 1;
514 ncoef2 = 1; coef2[0] = d->factors[num-1].value; coef2[1] = 1;
521 if ( i == ( *w-1 ) ) {
523 if ( *r < 0 ) ncoef2 = -ncoef2;
524 i--; cc = coef2; r = w + 1;
525 while ( --i >= 0 ) *cc++ = (UWORD)(*r++);
535 if ( AC.UnsureDollarMode == 0 ) {
537 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) {
538 UNLOCK(d->pthreadslock);
541 MLOCK(ErrorMessageLock);
542 MesPrint(
"$%s is undefined",AC.dollarnames->namebuffer+d->name);
543 MUNLOCK(ErrorMessageLock);
546 ncoef2 = 0; coef2[0] = 0; coef2[1] = 1;
549 ncoef2 = coef2[0] = 0; coef2[1] = 1;
552 if ( d->where[0] != INDEX || d->where[1] != 3
553 || d->where[2] < 0 || d->where[2] >= AM.OffsetIndex ) {
554 if ( AC.UnsureDollarMode == 0 ) {
556 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) {
557 UNLOCK(d->pthreadslock);
560 MLOCK(ErrorMessageLock);
561 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
562 MUNLOCK(ErrorMessageLock);
565 ncoef2 = 0; coef2[0] = 0; coef2[1] = 1;
568 d->index = d->where[2];
571 if ( d->index == 0 ) {
572 ncoef2 = coef2[0] = 0; coef2[1] = 1;
574 else if ( d->index > 0 && d->index < AM.OffsetIndex ) {
575 ncoef2 = 1; coef2[0] = d->index; coef2[1] = 1;
577 else if ( AC.UnsureDollarMode == 0 ) {
579 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) {
580 UNLOCK(d->pthreadslock);
583 MLOCK(ErrorMessageLock);
584 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
585 MUNLOCK(ErrorMessageLock);
588 ncoef2 = coef2[0] = 0; coef2[1] = 1;
591 if ( d->where[0] <= -FUNCTION ||
592 ( d->where[0] < 0 && d->where[2] != 0 )
593 || ( d->where[0] > 0 && d->where[d->where[0]] != 0 )
595 if ( AC.UnsureDollarMode == 0 ) {
597 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) {
598 UNLOCK(d->pthreadslock);
601 MLOCK(ErrorMessageLock);
602 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
603 MUNLOCK(ErrorMessageLock);
606 ncoef2 = coef2[0] = 0; coef2[1] = 1;
611 if ( d->where[0] == -SNUMBER ) {
612 if ( d->where[1] == 0 ) {
613 ncoef2 = coef2[0] = 0;
615 else if ( d->where[1] < 0 ) {
617 coef2[0] = -d->where[1];
621 coef2[0] = d->where[1];
625 else if ( d->where[0] == -INDEX
626 && d->where[1] >= 0 && d->where[1] < AM.OffsetIndex ) {
627 if ( d->where[1] == 0 ) {
628 ncoef2 = coef2[0] = 0; coef2[1] = 1;
631 ncoef2 = 1; coef2[0] = d->where[1];
635 else if ( d->where[0] > 0
636 && d->where[ARGHEAD] == (d->where[0]-ARGHEAD)
637 && ABS(d->where[d->where[0]-1]) ==
638 (d->where[0] - ARGHEAD-1) ) {
639 i = d->where[d->where[0]-1];
640 ncoef2 = (ABS(i)-1)/2;
641 if ( i < 0 ) { ncoef2 = -ncoef2; i = -i; }
642 i--; cc = coef2; r = d->where + ARGHEAD+1;
643 while ( --i >= 0 ) *cc++ = (UWORD)(*r++);
646 if ( AC.UnsureDollarMode == 0 ) {
648 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) {
649 UNLOCK(d->pthreadslock);
652 MLOCK(ErrorMessageLock);
653 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
654 MUNLOCK(ErrorMessageLock);
657 ncoef2 = 0; coef2[0] = 0; coef2[1] = 1;
662 if ( d->where[d->where[0]] == 0 ) {
663 r = d->where + d->where[0]-1;
665 if ( i == ( d->where[0]-1 ) ) {
667 if ( *r < 0 ) ncoef2 = -ncoef2;
668 i--; cc = coef2; r = d->where + 1;
669 while ( --i >= 0 ) *cc++ = (UWORD)(*r++);
674 if ( AC.UnsureDollarMode == 0 ) {
676 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) {
677 UNLOCK(d->pthreadslock);
680 MLOCK(ErrorMessageLock);
681 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
682 MUNLOCK(ErrorMessageLock);
685 ncoef2 = 0; coef2[0] = 0; coef2[1] = 1;
690 if ( dtype > 0 && ! DollarLocalCopy(dtype) ) {
691 UNLOCK(d->pthreadslock);
697 r = ifp+2; j = ifp[1] - 2; ncoef2 = 0;
699 if ( *r == AR.CurExpr ) { ncoef2 = 1;
break; }
706 r = ifp+2; j = ifp[1] - 2;
709 if ( ( Expressions[AR.CurExpr].vflags & ISFACTORIZED ) != 0 ) {
716 if ( ( Expressions[*r].vflags & ISFACTORIZED ) == 0 ) {
728 WORD *OccStop = ifp + ifp[1], *ifpp = ifp+2;
730 while ( ifpp < OccStop ) {
731 if ( FindVar(ifpp,term) == 1 ) {
734 if ( *ifpp == DOTPRODUCT ) ifp += 3;
744 if ( ( Expressions[AR.CurExpr].uflags & (1 << ifp[2]) ) != 0 )
754 if ( ifp[-2] != ORCOND && ifp[-2] != ANDCOND ) {
755 if ( ( ifp[-2] == EQUAL || ifp[-2] == NOTEQUAL ) &&
756 ( ismul2 || ismul1 ) ) {
757 if ( ismul1 && ismul2 ) {
758 if ( coef1[0] == coef2[0] ) i = 1;
764 Divvy(BHEAD coef2,&ncoef2,coef1,ncoef1);
765 cc = coef2; ncoef3 = ncoef2;
769 Divvy(BHEAD coef1,&ncoef1,coef2,ncoef2);
770 cc = coef1; ncoef3 = ncoef1;
772 if ( ncoef3 < 0 ) ncoef3 = -ncoef3;
774 if ( ifp[-2] == EQUAL ) i = 1;
777 else if ( cc[ncoef3] != 1 ) {
778 if ( ifp[-2] == EQUAL ) i = 0;
782 for ( j = 1; j < ncoef3; j++ ) {
783 if ( cc[ncoef3+j] != 0 )
break;
786 if ( ifp[-2] == EQUAL ) i = 0;
789 else if ( ifp[-2] == EQUAL ) i = 1;
795 else if ( AddRat(BHEAD coef1,ncoef1,coef2,-ncoef2,coef3,&ncoef3) ) {
796 NumberFree(coef3,
"DoIfStatement"); NumberFree(Spac1,
"DoIfStatement"); TermFree(Spac2,
"DoIfStatement");
797 MesCall(
"DoIfStatement");
return(-1);
801 if ( ncoef3 > 0 ) i = 1;
805 if ( ncoef3 >= 0 ) i = 1;
809 if ( ncoef3 < 0 ) i = 1;
813 if ( ncoef3 <= 0 ) i = 1;
817 if ( ncoef3 == 0 ) i = 1;
821 if ( ncoef3 != 0 ) i = 1;
825donemul:
if ( i ) { ncoef2 = 1; coef2 = Spac2; coef2[0] = coef2[1] = 1; }
835 for ( j = 0; j < i; j++ ) coef1[j] = coef2[j];
839 }
while ( ifp < ifstop );
841 NumberFree(coef3,
"DoIfStatement"); NumberFree(Spac1,
"DoIfStatement"); TermFree(Spac2,
"DoIfStatement");
842 if ( ncoef1 )
return(1);
856WORD HowMany(PHEAD WORD *ifcode, WORD *term)
859 WORD *m, *t, *r, *w, power, RetVal, i, topje, *newterm;
860 WORD *OldWork, *ww, *mm;
865 AN.WildValue = w = m + SUBEXPSIZE;
868 OldWork = AT.WorkPointer;
869 if ( ( ifcode[4] & 1 ) != 0 ) {
871 ww = AT.WorkPointer; i = m[0]; mm = m;
874 *ww++ = 1; *ww++ = 1; *ww++ = 3;
876 RepSto = AN.RepPoint;
879 if (
Generator(BHEAD OldWork,AR.Cnumlhs) ) {
882 AN.RepPoint = RepSto;
883 AT.WorkPointer = OldWork;
887 if (
EndSort(BHEAD ww,0) < 0 ) {}
889 AN.RepPoint = RepSto;
890 if ( *ww == 0 || *(ww+*ww) != 0 ) {
891 if ( AP.lhdollarerror == 0 ) {
892 MLOCK(ErrorMessageLock);
893 MesPrint(
"&LHS must be one term");
894 MUNLOCK(ErrorMessageLock);
895 AP.lhdollarerror = 1;
897 AT.WorkPointer = OldWork;
900 m = ww; AT.WorkPointer = ww = m + *m;
901 if ( m[*m-1] < 0 ) { m[*m-1] = -m[*m-1]; }
907 if ( AT.WorkPointer < ww ) AT.WorkPointer = ww;
910 while ( w < AN.WildStop ) {
911 if ( *w == LOADDOLLAR ) numdollars++;
915 AN.RepFunList = AT.WorkPointer;
916 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
917 topje = cbuf[AT.ebufnum].numrhs;
918 if ( AT.WorkPointer >= AT.WorkTop ) {
919 MLOCK(ErrorMessageLock);
921 MUNLOCK(ErrorMessageLock);
924 AN.DisOrderFlag = ifcode[2] & SUBDISORDER;
925 switch ( ifcode[2] & (~SUBDISORDER) ) {
928 AN.UseFindOnly = 1; AN.ForFindOnly = 0;
934 t = term; newterm = r = AT.WorkPointer;
935 NCOPY(r,t,i); AT.WorkPointer = r;
937 if ( FindRest(BHEAD newterm,m) && ( AN.UsedOtherFind ||
938 FindOnly(BHEAD newterm,m) ) ) {
939 Substitute(BHEAD newterm,m,1);
941 WildDollars(BHEAD (WORD *)0);
955 t = term; newterm = r = AT.WorkPointer;
956 NCOPY(r,t,i); AT.WorkPointer = r;
959 if ( ( power = FindRest(BHEAD newterm,m) ) > 0 ) {
960 if ( ( power = FindOnce(BHEAD newterm,m) ) > 0 ) {
963 Substitute(BHEAD newterm,m,1);
965 WildDollars(BHEAD (WORD *)0);
970 }
while ( FindRest(BHEAD newterm,m) && (
971 AN.UsedOtherFind || FindOnce(BHEAD newterm,m) ) );
973 else if ( power < 0 ) {
975 Substitute(BHEAD newterm,m,1);
977 WildDollars(BHEAD (WORD *)0);
982 }
while ( FindRest(BHEAD newterm,m) );
985 else if ( power < 0 ) {
986 if ( FindOnce(BHEAD newterm,m) ) {
988 Substitute(BHEAD newterm,m,1);
990 WildDollars(BHEAD (WORD *)0);
994 }
while ( FindOnce(BHEAD newterm,m) );
1005 t = term; newterm = r = AT.WorkPointer;
1006 NCOPY(r,t,i); AT.WorkPointer = r;
1009 if ( FindRest(BHEAD newterm,m) && ( AN.UsedOtherFind || FindOnce(BHEAD newterm,m) ) ) {
1010 Substitute(BHEAD newterm,m,1);
1012 WildDollars(BHEAD (WORD *)0);
1021 RetVal = FindMulti(BHEAD term,m);
1025 for ( i = 0; i < *term; i++ ) ww[i] = term[i];
1026 while ( ( power = FindAll(BHEAD ww,m,AR.Cnumlhs,ifcode) ) != 0 ) { RetVal += power; }
1029 ifcode += IDHEAD; ifcode += ifcode[1]; ifcode += *ifcode;
1030 AN.UseFindOnly = 1; AN.ForFindOnly = ifcode;
1031 if ( FindRest(BHEAD term,m) && ( AN.UsedOtherFind ||
1032 FindOnly(BHEAD term,m) ) ) RetVal = 1;
1039 AT.WorkPointer = AN.RepFunList;
1040 cbuf[AT.ebufnum].numrhs = topje;
1049void DoubleIfBuffers(
void)
1053 LONG *newheap, *newifcount;
1054 if ( AC.MaxIf == 0 ) newmax = 10;
1055 else newmax = 2*AC.MaxIf;
1056 newheap = (LONG *)Malloc1(
sizeof(LONG)*(newmax+1),
"IfHeap");
1057 newsumcheck = (WORD *)Malloc1(
sizeof(WORD)*(newmax+1),
"IfSumCheck");
1058 newifcount = (LONG *)Malloc1(
sizeof(LONG)*(newmax+1),
"IfCount");
1060 for ( i = 0; i < AC.MaxIf; i++ ) {
1061 newheap[i] = AC.IfHeap[i];
1062 newsumcheck[i] = AC.IfSumCheck[i];
1063 newifcount[i] = AC.IfCount[i];
1065 AC.IfStack = (AC.IfStack-AC.IfHeap) + newheap;
1066 M_free(AC.IfHeap,
"AC.IfHeap");
1067 M_free(AC.IfCount,
"AC.IfCount");
1068 M_free(AC.IfSumCheck,
"AC.IfSumCheck");
1071 AC.IfStack = newheap;
1073 AC.IfHeap = newheap;
1074 AC.IfSumCheck = newsumcheck;
1075 AC.IfCount = newifcount;
1086int DoSwitch(PHEAD WORD *term, WORD *lhs)
1091 WORD numdollar = lhs[2];
1092 WORD ncase = DolToNumber(BHEAD numdollar);
1094 return(
Generator(BHEAD term,swtab->value));
1102int DoEndSwitch(PHEAD WORD *term, WORD *lhs)
1104 SWITCH *sw = AC.SwitchArray+lhs[2];
1105 return(
Generator(BHEAD term,sw->endswitch.value+1));
1118 SWITCH *sw = AC.SwitchArray+nswitch;
1120 if ( sw->typetable == DENSETABLE ) {
1121 med = ncase - sw->caseoffset;
1122 if ( med >= sw->numcases || med < 0 )
return(&sw->defaultcase);
1128 if ( ncase > sw->maxcase || ncase < sw->mincase )
return(&sw->defaultcase);
1129 hi = sw->numcases-1; lo = 0;
1132 if ( ncase == sw->table[med].ncase )
break;
1133 else if ( ncase > sw->table[med].ncase ) {
1135 if ( lo > hi )
return(&sw->defaultcase);
1139 if ( hi < lo )
return(&sw->defaultcase);
1143 return(&sw->table[med]);
1151int DoubleSwitchBuffers(
void)
1156 if ( AC.MaxSwitch == 0 ) newmax = 10;
1157 else newmax = 2*AC.MaxSwitch;
1158 newarray = (
SWITCH *)Malloc1(
sizeof(
SWITCH)*(newmax+1),
"SwitchArray");
1159 newheap = (WORD *)Malloc1(
sizeof(WORD)*(newmax+1),
"SwitchHeap");
1160 if ( AC.MaxSwitch ) {
1161 for ( i = 0; i < AC.MaxSwitch; i++ ) {
1162 newarray[i] = AC.SwitchArray[i];
1163 newheap[i] = AC.SwitchHeap[i];
1165 M_free(AC.SwitchHeap,
"AC.SwitchHeap");
1166 M_free(AC.SwitchArray,
"AC.SwitchArray");
1168 for ( i = AC.MaxSwitch; i <= newmax; i++ ) {
1169 newarray[i].table = 0;
1170 newarray[i].tablesize = 0;
1171 newarray[i].defaultcase.ncase = 0;
1172 newarray[i].defaultcase.value = 0;
1173 newarray[i].defaultcase.compbuffer = 0;
1174 newarray[i].endswitch.ncase = 0;
1175 newarray[i].endswitch.value = 0;
1176 newarray[i].endswitch.compbuffer = 0;
1177 newarray[i].typetable = 0;
1178 newarray[i].mincase = 0;
1179 newarray[i].maxcase = 0;
1180 newarray[i].numcases = 0;
1181 newarray[i].caseoffset = 0;
1182 newarray[i].iflevel = 0;
1183 newarray[i].whilelevel = 0;
1184 newarray[i].nestingsum = 0;
1187 AC.SwitchArray = newarray;
1188 AC.SwitchHeap = newheap;
1189 AC.MaxSwitch = newmax;
1204 if ( num < 2 )
return;
1206 if ( array[0].ncase > array[1].ncase ) {
1207 t = array[0]; array[0] = array[1]; array[1] = t;
1213 SwitchSplitMergeRec(array,n1,auxarray);
1214 SwitchSplitMergeRec(array+n1,n2,auxarray);
1215 if ( array[n1-1].ncase <= array[n1].ncase )
return;
1217 t1 = array; t2 = auxarray; i = n1; NCOPY(t2,t1,i);
1218 i = 0; j = n1; k = 0;
1219 while ( i < n1 && j < num ) {
1220 if ( auxarray[i].ncase <= array[j].ncase ) { array[k++] = auxarray[i++]; }
1221 else { array[k++] = array[j++]; }
1223 while ( i < n1 ) array[k++] = auxarray[i++];
1232 SwitchSplitMergeRec(array,num,auxarray);
1233 M_free(auxarray,
"SwitchSplitMerge");
LONG EndSort(PHEAD WORD *, int)
int Generator(PHEAD WORD *, WORD)
void LowerSortLevel(void)