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 ( 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;
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];
415 ncoef2 = FloatFunToRat(BHEAD coef2,ifp);
420 coef2[0] = HowMany(BHEAD ifp,term);
422 if ( coef2[0] == 0 ) ncoef2 = 0;
425 acoef = CountDo(term,ifp);
426 coef2[0] = ABS(acoef);
428 if ( acoef == 0 ) ncoef2 = 0;
429 else if ( acoef < 0 ) ncoef2 = -1;
432 acoef = Lus(term,ifp[3],ifp[4],ifp[5],ifp[6],ifp[2]);
433 coef2[0] = ABS(acoef);
435 if ( acoef == 0 ) ncoef2 = 0;
436 else if ( acoef < 0 ) ncoef2 = -1;
442 cc = (UWORD *)(r - i);
443 if ( ncoef2 < 0 ) ncoef2 = (ncoef2+1)>>1;
444 else ncoef2 = (ncoef2-1)>>1;
445 i--;
for ( j = 0; j < i; j++ ) coef2[j] = cc[j];
448 ncoef2 = coef2[0] = DoIfStatement(BHEAD ifp,term);
467 int nummodopt, dtype = -1;
468 if ( AS.MultiThreaded ) {
469 for ( nummodopt = 0; nummodopt < NumModOptdollars; nummodopt++ ) {
470 if ( ifp[2] == ModOptdollars[nummodopt].number )
break;
472 if ( nummodopt < NumModOptdollars ) {
473 dtype = ModOptdollars[nummodopt].type;
474 if ( dtype == MODLOCAL ) {
475 d = ModOptdollars[nummodopt].dstruct+AT.identity;
478 LOCK(d->pthreadslock);
486 if ( ifp+3 < ifstop && ifp[3] == IFDOLLAREXTRA ) {
487 if ( d->nfactors == 0 ) {
488 MLOCK(ErrorMessageLock);
489 MesPrint(
"Attempt to use a factor of an unfactored $-variable");
490 MUNLOCK(ErrorMessageLock);
493 WORD num = GetIfDollarNum(ifp+3,ifstop);
495 while ( ifp+3 < ifstop && ifp[3] == IFDOLLAREXTRA ) ifp += 3;
496 if ( num > d->nfactors ) {
497 MLOCK(ErrorMessageLock);
498 MesPrint(
"Dollar factor number %s out of range",num);
499 MUNLOCK(ErrorMessageLock);
503 ncoef2 = 1; coef2[0] = d->nfactors; coef2[1] = 1;
506 w = d->factors[num-1].where;
508 if ( d->factors[num-1].value < 0 ) {
509 ncoef2 = -1; coef2[0] = -d->factors[num-1].value; coef2[1] = 1;
512 ncoef2 = 1; coef2[0] = d->factors[num-1].value; coef2[1] = 1;
519 if ( i == ( *w-1 ) ) {
521 if ( *r < 0 ) ncoef2 = -ncoef2;
522 i--; cc = coef2; r = w + 1;
523 while ( --i >= 0 ) *cc++ = (UWORD)(*r++);
533 if ( AC.UnsureDollarMode == 0 ) {
535 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
537 MLOCK(ErrorMessageLock);
538 MesPrint(
"$%s is undefined",AC.dollarnames->namebuffer+d->name);
539 MUNLOCK(ErrorMessageLock);
542 ncoef2 = 0; coef2[0] = 0; coef2[1] = 1;
545 ncoef2 = coef2[0] = 0; coef2[1] = 1;
548 if ( d->where[0] != INDEX || d->where[1] != 3
549 || d->where[2] < 0 || d->where[2] >= AM.OffsetIndex ) {
550 if ( AC.UnsureDollarMode == 0 ) {
552 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
554 MLOCK(ErrorMessageLock);
555 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
556 MUNLOCK(ErrorMessageLock);
559 ncoef2 = 0; coef2[0] = 0; coef2[1] = 1;
562 d->index = d->where[2];
565 if ( d->index == 0 ) {
566 ncoef2 = coef2[0] = 0; coef2[1] = 1;
568 else if ( d->index > 0 && d->index < AM.OffsetIndex ) {
569 ncoef2 = 1; coef2[0] = d->index; coef2[1] = 1;
571 else if ( AC.UnsureDollarMode == 0 ) {
573 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
575 MLOCK(ErrorMessageLock);
576 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
577 MUNLOCK(ErrorMessageLock);
580 ncoef2 = coef2[0] = 0; coef2[1] = 1;
583 if ( d->where[0] <= -FUNCTION ||
584 ( d->where[0] < 0 && d->where[2] != 0 )
585 || ( d->where[0] > 0 && d->where[d->where[0]] != 0 )
587 if ( AC.UnsureDollarMode == 0 ) {
589 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
591 MLOCK(ErrorMessageLock);
592 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
593 MUNLOCK(ErrorMessageLock);
596 ncoef2 = coef2[0] = 0; coef2[1] = 1;
601 if ( d->where[0] == -SNUMBER ) {
602 if ( d->where[1] == 0 ) {
603 ncoef2 = coef2[0] = 0;
605 else if ( d->where[1] < 0 ) {
607 coef2[0] = -d->where[1];
611 coef2[0] = d->where[1];
615 else if ( d->where[0] == -INDEX
616 && d->where[1] >= 0 && d->where[1] < AM.OffsetIndex ) {
617 if ( d->where[1] == 0 ) {
618 ncoef2 = coef2[0] = 0; coef2[1] = 1;
621 ncoef2 = 1; coef2[0] = d->where[1];
625 else if ( d->where[0] > 0
626 && d->where[ARGHEAD] == (d->where[0]-ARGHEAD)
627 && ABS(d->where[d->where[0]-1]) ==
628 (d->where[0] - ARGHEAD-1) ) {
629 i = d->where[d->where[0]-1];
630 ncoef2 = (ABS(i)-1)/2;
631 if ( i < 0 ) { ncoef2 = -ncoef2; i = -i; }
632 i--; cc = coef2; r = d->where + ARGHEAD+1;
633 while ( --i >= 0 ) *cc++ = (UWORD)(*r++);
636 if ( AC.UnsureDollarMode == 0 ) {
638 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
640 MLOCK(ErrorMessageLock);
641 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
642 MUNLOCK(ErrorMessageLock);
645 ncoef2 = 0; coef2[0] = 0; coef2[1] = 1;
650 if ( d->where[d->where[0]] == 0 ) {
651 r = d->where + d->where[0]-1;
653 if ( i == ( d->where[0]-1 ) ) {
655 if ( *r < 0 ) ncoef2 = -ncoef2;
656 i--; cc = coef2; r = d->where + 1;
657 while ( --i >= 0 ) *cc++ = (UWORD)(*r++);
662 if ( AC.UnsureDollarMode == 0 ) {
664 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
666 MLOCK(ErrorMessageLock);
667 MesPrint(
"$%s is of wrong type",AC.dollarnames->namebuffer+d->name);
668 MUNLOCK(ErrorMessageLock);
671 ncoef2 = 0; coef2[0] = 0; coef2[1] = 1;
676 if ( dtype > 0 && dtype != MODLOCAL ) { UNLOCK(d->pthreadslock); }
681 r = ifp+2; j = ifp[1] - 2; ncoef2 = 0;
683 if ( *r == AR.CurExpr ) { ncoef2 = 1;
break; }
690 r = ifp+2; j = ifp[1] - 2;
693 if ( ( Expressions[AR.CurExpr].vflags & ISFACTORIZED ) != 0 ) {
700 if ( ( Expressions[*r].vflags & ISFACTORIZED ) == 0 ) {
712 WORD *OccStop = ifp + ifp[1], *ifpp = ifp+2;
714 while ( ifpp < OccStop ) {
715 if ( FindVar(ifpp,term) == 1 ) {
718 if ( *ifpp == DOTPRODUCT ) ifp += 3;
728 if ( ( Expressions[AR.CurExpr].uflags & (1 << ifp[2]) ) != 0 )
738 if ( ifp[-2] != ORCOND && ifp[-2] != ANDCOND ) {
739 if ( ( ifp[-2] == EQUAL || ifp[-2] == NOTEQUAL ) &&
740 ( ismul2 || ismul1 ) ) {
741 if ( ismul1 && ismul2 ) {
742 if ( coef1[0] == coef2[0] ) i = 1;
748 Divvy(BHEAD coef2,&ncoef2,coef1,ncoef1);
749 cc = coef2; ncoef3 = ncoef2;
753 Divvy(BHEAD coef1,&ncoef1,coef2,ncoef2);
754 cc = coef1; ncoef3 = ncoef1;
756 if ( ncoef3 < 0 ) ncoef3 = -ncoef3;
758 if ( ifp[-2] == EQUAL ) i = 1;
761 else if ( cc[ncoef3] != 1 ) {
762 if ( ifp[-2] == EQUAL ) i = 0;
766 for ( j = 1; j < ncoef3; j++ ) {
767 if ( cc[ncoef3+j] != 0 )
break;
770 if ( ifp[-2] == EQUAL ) i = 0;
773 else if ( ifp[-2] == EQUAL ) i = 1;
779 else if ( AddRat(BHEAD coef1,ncoef1,coef2,-ncoef2,coef3,&ncoef3) ) {
780 NumberFree(coef3,
"DoIfStatement"); NumberFree(Spac1,
"DoIfStatement"); TermFree(Spac2,
"DoIfStatement");
781 MesCall(
"DoIfStatement");
return(-1);
785 if ( ncoef3 > 0 ) i = 1;
789 if ( ncoef3 >= 0 ) i = 1;
793 if ( ncoef3 < 0 ) i = 1;
797 if ( ncoef3 <= 0 ) i = 1;
801 if ( ncoef3 == 0 ) i = 1;
805 if ( ncoef3 != 0 ) i = 1;
809donemul:
if ( i ) { ncoef2 = 1; coef2 = Spac2; coef2[0] = coef2[1] = 1; }
819 for ( j = 0; j < i; j++ ) coef1[j] = coef2[j];
823 }
while ( ifp < ifstop );
825 NumberFree(coef3,
"DoIfStatement"); NumberFree(Spac1,
"DoIfStatement"); TermFree(Spac2,
"DoIfStatement");
826 if ( ncoef1 )
return(1);
840WORD HowMany(PHEAD WORD *ifcode, WORD *term)
843 WORD *m, *t, *r, *w, power, RetVal, i, topje, *newterm;
844 WORD *OldWork, *ww, *mm;
849 AN.WildValue = w = m + SUBEXPSIZE;
852 OldWork = AT.WorkPointer;
853 if ( ( ifcode[4] & 1 ) != 0 ) {
855 ww = AT.WorkPointer; i = m[0]; mm = m;
858 *ww++ = 1; *ww++ = 1; *ww++ = 3;
860 RepSto = AN.RepPoint;
863 if (
Generator(BHEAD OldWork,AR.Cnumlhs) ) {
866 AN.RepPoint = RepSto;
867 AT.WorkPointer = OldWork;
871 if (
EndSort(BHEAD ww,0) < 0 ) {}
873 AN.RepPoint = RepSto;
874 if ( *ww == 0 || *(ww+*ww) != 0 ) {
875 if ( AP.lhdollarerror == 0 ) {
876 MLOCK(ErrorMessageLock);
877 MesPrint(
"&LHS must be one term");
878 MUNLOCK(ErrorMessageLock);
879 AP.lhdollarerror = 1;
881 AT.WorkPointer = OldWork;
884 m = ww; AT.WorkPointer = ww = m + *m;
885 if ( m[*m-1] < 0 ) { m[*m-1] = -m[*m-1]; }
891 if ( AT.WorkPointer < ww ) AT.WorkPointer = ww;
894 while ( w < AN.WildStop ) {
895 if ( *w == LOADDOLLAR ) numdollars++;
899 AN.RepFunList = AT.WorkPointer;
900 AT.WorkPointer = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
901 topje = cbuf[AT.ebufnum].numrhs;
902 if ( AT.WorkPointer >= AT.WorkTop ) {
903 MLOCK(ErrorMessageLock);
905 MUNLOCK(ErrorMessageLock);
908 AN.DisOrderFlag = ifcode[2] & SUBDISORDER;
909 switch ( ifcode[2] & (~SUBDISORDER) ) {
912 AN.UseFindOnly = 1; AN.ForFindOnly = 0;
918 t = term; newterm = r = AT.WorkPointer;
919 NCOPY(r,t,i); AT.WorkPointer = r;
921 if ( FindRest(BHEAD newterm,m) && ( AN.UsedOtherFind ||
922 FindOnly(BHEAD newterm,m) ) ) {
923 Substitute(BHEAD newterm,m,1);
925 WildDollars(BHEAD (WORD *)0);
939 t = term; newterm = r = AT.WorkPointer;
940 NCOPY(r,t,i); AT.WorkPointer = r;
943 if ( ( power = FindRest(BHEAD newterm,m) ) > 0 ) {
944 if ( ( power = FindOnce(BHEAD newterm,m) ) > 0 ) {
947 Substitute(BHEAD newterm,m,1);
949 WildDollars(BHEAD (WORD *)0);
954 }
while ( FindRest(BHEAD newterm,m) && (
955 AN.UsedOtherFind || FindOnce(BHEAD newterm,m) ) );
957 else if ( power < 0 ) {
959 Substitute(BHEAD newterm,m,1);
961 WildDollars(BHEAD (WORD *)0);
966 }
while ( FindRest(BHEAD newterm,m) );
969 else if ( power < 0 ) {
970 if ( FindOnce(BHEAD newterm,m) ) {
972 Substitute(BHEAD newterm,m,1);
974 WildDollars(BHEAD (WORD *)0);
978 }
while ( FindOnce(BHEAD newterm,m) );
989 t = term; newterm = r = AT.WorkPointer;
990 NCOPY(r,t,i); AT.WorkPointer = r;
993 if ( FindRest(BHEAD newterm,m) && ( AN.UsedOtherFind || FindOnce(BHEAD newterm,m) ) ) {
994 Substitute(BHEAD newterm,m,1);
996 WildDollars(BHEAD (WORD *)0);
1005 RetVal = FindMulti(BHEAD term,m);
1009 for ( i = 0; i < *term; i++ ) ww[i] = term[i];
1010 while ( ( power = FindAll(BHEAD ww,m,AR.Cnumlhs,ifcode) ) != 0 ) { RetVal += power; }
1013 ifcode += IDHEAD; ifcode += ifcode[1]; ifcode += *ifcode;
1014 AN.UseFindOnly = 1; AN.ForFindOnly = ifcode;
1015 if ( FindRest(BHEAD term,m) && ( AN.UsedOtherFind ||
1016 FindOnly(BHEAD term,m) ) ) RetVal = 1;
1023 AT.WorkPointer = AN.RepFunList;
1024 cbuf[AT.ebufnum].numrhs = topje;
1033void DoubleIfBuffers(
void)
1037 LONG *newheap, *newifcount;
1038 if ( AC.MaxIf == 0 ) newmax = 10;
1039 else newmax = 2*AC.MaxIf;
1040 newheap = (LONG *)Malloc1(
sizeof(LONG)*(newmax+1),
"IfHeap");
1041 newsumcheck = (WORD *)Malloc1(
sizeof(WORD)*(newmax+1),
"IfSumCheck");
1042 newifcount = (LONG *)Malloc1(
sizeof(LONG)*(newmax+1),
"IfCount");
1044 for ( i = 0; i < AC.MaxIf; i++ ) {
1045 newheap[i] = AC.IfHeap[i];
1046 newsumcheck[i] = AC.IfSumCheck[i];
1047 newifcount[i] = AC.IfCount[i];
1049 AC.IfStack = (AC.IfStack-AC.IfHeap) + newheap;
1050 M_free(AC.IfHeap,
"AC.IfHeap");
1051 M_free(AC.IfCount,
"AC.IfCount");
1052 M_free(AC.IfSumCheck,
"AC.IfSumCheck");
1055 AC.IfStack = newheap;
1057 AC.IfHeap = newheap;
1058 AC.IfSumCheck = newsumcheck;
1059 AC.IfCount = newifcount;
1070int DoSwitch(PHEAD WORD *term, WORD *lhs)
1075 WORD numdollar = lhs[2];
1076 WORD ncase = DolToNumber(BHEAD numdollar);
1078 return(
Generator(BHEAD term,swtab->value));
1086int DoEndSwitch(PHEAD WORD *term, WORD *lhs)
1088 SWITCH *sw = AC.SwitchArray+lhs[2];
1089 return(
Generator(BHEAD term,sw->endswitch.value+1));
1102 SWITCH *sw = AC.SwitchArray+nswitch;
1104 if ( sw->typetable == DENSETABLE ) {
1105 med = ncase - sw->caseoffset;
1106 if ( med >= sw->numcases || med < 0 )
return(&sw->defaultcase);
1112 if ( ncase > sw->maxcase || ncase < sw->mincase )
return(&sw->defaultcase);
1113 hi = sw->numcases-1; lo = 0;
1116 if ( ncase == sw->table[med].ncase )
break;
1117 else if ( ncase > sw->table[med].ncase ) {
1119 if ( lo > hi )
return(&sw->defaultcase);
1123 if ( hi < lo )
return(&sw->defaultcase);
1127 return(&sw->table[med]);
1135int DoubleSwitchBuffers(
void)
1140 if ( AC.MaxSwitch == 0 ) newmax = 10;
1141 else newmax = 2*AC.MaxSwitch;
1142 newarray = (
SWITCH *)Malloc1(
sizeof(
SWITCH)*(newmax+1),
"SwitchArray");
1143 newheap = (WORD *)Malloc1(
sizeof(WORD)*(newmax+1),
"SwitchHeap");
1144 if ( AC.MaxSwitch ) {
1145 for ( i = 0; i < AC.MaxSwitch; i++ ) {
1146 newarray[i] = AC.SwitchArray[i];
1147 newheap[i] = AC.SwitchHeap[i];
1149 M_free(AC.SwitchHeap,
"AC.SwitchHeap");
1150 M_free(AC.SwitchArray,
"AC.SwitchArray");
1152 for ( i = AC.MaxSwitch; i <= newmax; i++ ) {
1153 newarray[i].table = 0;
1154 newarray[i].tablesize = 0;
1155 newarray[i].defaultcase.ncase = 0;
1156 newarray[i].defaultcase.value = 0;
1157 newarray[i].defaultcase.compbuffer = 0;
1158 newarray[i].endswitch.ncase = 0;
1159 newarray[i].endswitch.value = 0;
1160 newarray[i].endswitch.compbuffer = 0;
1161 newarray[i].typetable = 0;
1162 newarray[i].mincase = 0;
1163 newarray[i].maxcase = 0;
1164 newarray[i].numcases = 0;
1165 newarray[i].caseoffset = 0;
1166 newarray[i].iflevel = 0;
1167 newarray[i].whilelevel = 0;
1168 newarray[i].nestingsum = 0;
1171 AC.SwitchArray = newarray;
1172 AC.SwitchHeap = newheap;
1173 AC.MaxSwitch = newmax;
1188 if ( num < 2 )
return;
1190 if ( array[0].ncase > array[1].ncase ) {
1191 t = array[0]; array[0] = array[1]; array[1] = t;
1197 SwitchSplitMergeRec(array,n1,auxarray);
1198 SwitchSplitMergeRec(array+n1,n2,auxarray);
1199 if ( array[n1-1].ncase <= array[n1].ncase )
return;
1201 t1 = array; t2 = auxarray; i = n1; NCOPY(t2,t1,i);
1202 i = 0; j = n1; k = 0;
1203 while ( i < n1 && j < num ) {
1204 if ( auxarray[i].ncase <= array[j].ncase ) { array[k++] = auxarray[i++]; }
1205 else { array[k++] = array[j++]; }
1207 while ( i < n1 ) array[k++] = auxarray[i++];
1216 SwitchSplitMergeRec(array,num,auxarray);
1217 M_free(auxarray,
"SwitchSplitMerge");
LONG EndSort(PHEAD WORD *, int)
int Generator(PHEAD WORD *, WORD)
void LowerSortLevel(void)