71 VOID TransformRational(UWORD *a, WORD na)
74 WORD i, j, nb, i1, i2; UWORD *b;
75 if ( AO.CurrentDictionary <= 0 )
goto NoAction;
76 dict = AO.Dictionaries[AO.CurrentDictionary-1];
77 if ( na < 0 ) na = -na;
78 switch ( AO.CurDictNumbers ) {
81 case DICT_INTEGERONLY:
82 if ( a[na] != 1 )
goto NoAction;
84 for ( i = 1; i < na; i++ ) {
85 if ( a[na+i] != 0 )
goto NoAction;
89 for ( i = dict->numelements-1; i >= 0; i-- ) {
90 if ( dict->elements[i]->type == DICT_INTEGERNUMBER ) {
91 if ( dict->elements[i]->size == na ) {
92 for ( j = 0; j < na; j++ ) {
93 if ( (UWORD)(dict->elements[i]->lhs[j]) != a[j] )
break;
96 TokenToLine((UBYTE *)(dict->elements[i]->rhs));
103 case DICT_RATIONALONLY:
105 for ( i = dict->numelements-1; i >= 0; i-- ) {
106 if ( dict->elements[i]->type == DICT_RATIONALNUMBER ) {
107 if ( dict->elements[i]->size == nb+2 ) {
108 for ( j = 0; j < nb; j++ ) {
109 if ( (UWORD)(dict->elements[i]->lhs[j+1]) != a[j] )
break;
112 TokenToLine((UBYTE *)(dict->elements[i]->rhs));
119 case DICT_ALLNUMBERS:
124 for ( i = dict->numelements-1; i >= 0; i-- ) {
125 if ( dict->elements[i]->type == DICT_RATIONALNUMBER ) {
126 if ( dict->elements[i]->size == nb+2 ) {
127 for ( j = 0; j < nb; j++ ) {
128 if ( (UWORD)(dict->elements[i]->lhs[j+1]) != a[j] )
break;
131 TokenToLine((UBYTE *)(dict->elements[i]->rhs));
141 while ( b[nb-1] == 0 ) nb--;
142 if ( nb == 1 && b[0] == 1 )
goto Numeratoronly;
143 while ( a[na-1] == 0 ) na--;
144 for ( i1 = dict->numelements-1; i1 >= 0; i1-- ) {
145 if ( dict->elements[i1]->type == DICT_INTEGERNUMBER ) {
146 if ( dict->elements[i1]->size == na ) {
147 for ( j = 0; j < na; j++ ) {
148 if ( (UWORD)(dict->elements[i1]->lhs[j]) != a[j] )
break;
150 if ( j == na )
break;
154 for ( i2 = dict->numelements-1; i2 >= 0; i2-- ) {
155 if ( dict->elements[i2]->type == DICT_INTEGERNUMBER ) {
156 if ( dict->elements[i2]->size == nb ) {
157 for ( j = 0; j < nb; j++ ) {
158 if ( (UWORD)(dict->elements[i2]->lhs[j]) != b[j] )
break;
160 if ( j == nb )
break;
165 if ( i2 < 0 )
goto NotFound;
168 if ( na > 1 || ( AO.DoubleFlag & 4 ) == 4 ) {
169 if ( AC.OutputMode == FORTRANMODE || AC.OutputMode == PFORTRANMODE
170 || AC.OutputMode == CMODE ) {
171 if ( ( AO.DoubleFlag & 2 ) == 2 ) { AddToLine((UBYTE *)
".Q0/"); }
172 else if ( ( AO.DoubleFlag & 1 ) == 1 ) { AddToLine((UBYTE *)
".D0/"); }
173 else { AddToLine((UBYTE *)
"/"); }
176 else AddToLine((UBYTE *)(
"/"));
177 TokenToLine((UBYTE *)(dict->elements[i2]->rhs));
181 TokenToLine((UBYTE *)(dict->elements[i1]->rhs));
182 AddToLine((UBYTE *)(
"/"));
183 LongToLine((UWORD *)(b),nb);
184 if ( nb > 1 || ( AO.DoubleFlag & 4 ) == 4 ) {
185 if ( AC.OutputMode == FORTRANMODE || AC.OutputMode == PFORTRANMODE
186 || AC.OutputMode == CMODE ) {
187 if ( ( AO.DoubleFlag & 2 ) == 2 ) { AddToLine((UBYTE *)
".Q0"); }
188 else if ( ( AO.DoubleFlag & 1 ) == 1 ) { AddToLine((UBYTE *)
".D0"); }
193 TokenToLine((UBYTE *)(dict->elements[i1]->rhs));
194 AddToLine((UBYTE *)(
"/"));
195 TokenToLine((UBYTE *)(dict->elements[i2]->rhs));
199 MesPrint(
"Illegal code in TransformRational: %d",AO.CurDictNumbers);
204 if ( na != 1 || a[1] != 1 ) {
205 if ( AO.CurDictNumberWarning ) {
206 MesPrint(
">>>>>>>>Could not translate coefficient with dictionary %s<<<<<<<<<<<<",dict->name);
218 UBYTE *IsMultiplySign(VOID)
222 if ( AO.CurrentDictionary <= 0 )
return(0);
223 dict = AO.Dictionaries[AO.CurrentDictionary-1];
224 if ( dict->characters == 0 )
return(0);
225 for ( i = dict->numelements-1; i >= 0; i-- ) {
226 if ( ( dict->elements[i]->type == DICT_SPECIALCHARACTER )
227 && ( dict->elements[i]->lhs[0] == (WORD)(
'*') ) )
228 return((UBYTE *)(dict->elements[i]->rhs));
238 UBYTE *IsExponentSign(VOID)
242 if ( AO.CurrentDictionary <= 0 )
return(0);
243 dict = AO.Dictionaries[AO.CurrentDictionary-1];
244 if ( dict->characters == 0 )
return(0);
245 for ( i = dict->numelements-1; i >= 0; i-- ) {
246 if ( ( dict->elements[i]->type == DICT_SPECIALCHARACTER )
247 && ( dict->elements[i]->lhs[0] == (WORD)(
'^') ) )
248 return((UBYTE *)(dict->elements[i]->rhs));
258 UBYTE *FindSymbol(WORD num)
260 if ( AO.CurrentDictionary > 0 ) {
261 DICTIONARY *dict = AO.Dictionaries[AO.CurrentDictionary-1];
263 if ( dict->variables > 0 && AO.CurDictVariables == DICT_DOVARIABLES ) {
264 for ( i = dict->numelements-1; i >= 0; i-- ) {
265 if ( dict->elements[i]->type == DICT_SYMBOL &&
266 dict->elements[i]->lhs[0] == num )
267 return((UBYTE *)(dict->elements[i]->rhs));
271 return(VARNAME(symbols,num));
279 UBYTE *FindVector(WORD num)
281 if ( AO.CurrentDictionary > 0 ) {
282 DICTIONARY *dict = AO.Dictionaries[AO.CurrentDictionary-1];
284 if ( dict->variables > 0 && AO.CurDictVariables == DICT_DOVARIABLES ) {
285 for ( i = dict->numelements-1; i >= 0; i-- ) {
286 if ( dict->elements[i]->type == DICT_VECTOR &&
287 dict->elements[i]->lhs[0] == num )
288 return((UBYTE *)(dict->elements[i]->rhs));
292 num -= AM.OffsetVector;
293 return(VARNAME(vectors,num));
301 UBYTE *FindIndex(WORD num)
303 if ( AO.CurrentDictionary > 0 ) {
304 DICTIONARY *dict = AO.Dictionaries[AO.CurrentDictionary-1];
306 if ( dict->variables > 0 && AO.CurDictVariables == DICT_DOVARIABLES ) {
307 for ( i = dict->numelements-1; i >= 0; i-- ) {
308 if ( dict->elements[i]->type == DICT_INDEX &&
309 dict->elements[i]->lhs[0] == num )
310 return((UBYTE *)(dict->elements[i]->rhs));
314 num -= AM.OffsetIndex;
315 return(VARNAME(indices,num));
323 UBYTE *FindFunction(WORD num)
325 if ( AO.CurrentDictionary > 0 ) {
326 DICTIONARY *dict = AO.Dictionaries[AO.CurrentDictionary-1];
328 if ( dict->variables > 0 && AO.CurDictVariables == DICT_DOVARIABLES ) {
329 for ( i = dict->numelements-1; i >= 0; i-- ) {
330 if ( dict->elements[i]->type == DICT_FUNCTION &&
331 dict->elements[i]->lhs[0] == num )
332 return((UBYTE *)(dict->elements[i]->rhs));
337 return(VARNAME(functions,num));
345 UBYTE *FindFunWithArgs(WORD *t)
347 if ( AO.CurrentDictionary > 0 ) {
348 DICTIONARY *dict = AO.Dictionaries[AO.CurrentDictionary-1];
350 if ( dict->funwith > 0
351 && AO.CurDictFunWithArgs == DICT_DOFUNWITHARGS ) {
352 for ( i = dict->numelements-1; i >= 0; i-- ) {
353 if ( dict->elements[i]->type == DICT_FUNCTION_WITH_ARGUMENTS &&
354 (WORD)(dict->elements[i]->lhs[0]) == t[0] &&
355 (WORD)(dict->elements[i]->lhs[1]) == t[1] ) {
356 for ( j = 2; j < t[1]; j++ ) {
357 if ( (WORD)(dict->elements[i]->lhs[j]) != t[j] )
break;
359 if ( j >= t[1] )
return((UBYTE *)(dict->elements[i]->rhs));
377 UBYTE *FindExtraSymbol(WORD num)
380 UBYTE *out = (UBYTE *)(AT.WorkPointer);
382 if ( AO.CurrentDictionary > 0 ) {
383 DICTIONARY *dict = AO.Dictionaries[AO.CurrentDictionary-1];
385 if ( dict->ranges > 0 && AO.CurDictVariables == DICT_DOVARIABLES ) {
386 for ( i = dict->numelements-1; i >= 0; i-- ) {
387 if ( dict->elements[i]->type == DICT_RANGE
388 && num >= dict->elements[i]->lhs[0]
389 && num <= dict->elements[i]->lhs[1] ) {
395 UBYTE *r = (UBYTE *)(dict->elements[i]->rhs);
397 if ( *r == (UBYTE)
'%' && ( r[1] == (UBYTE)
'#' 398 || r[1] == (UBYTE)
'@' ) ) {
399 if ( r[1] == (UBYTE)
'#' ) {
400 out = NumCopy(num,out);
403 out = NumCopy(num-dict->elements[i]->lhs[0]+1,out);
412 return((UBYTE *)(AT.WorkPointer));
418 out = StrCopy((UBYTE *)AC.extrasym,out);
419 if ( AC.extrasymbols == 0 ) {
420 out = NumCopy(num,out);
421 out = StrCopy((UBYTE *)
"_",out);
423 else if ( AC.extrasymbols == 1 ) {
424 out = AddArrayIndex(num,out);
426 return((UBYTE *)(AT.WorkPointer));
434 int FindDictionary(UBYTE *name)
437 for ( i = 0; i < AO.NumDictionaries; i++ ) {
438 if ( StrCmp(AO.Dictionaries[i]->name,name) == 0 )
449 int AddDictionary(UBYTE *name)
455 if ( AO.NumDictionaries >= AO.SizeDictionaries-1 ) {
458 if ( AO.SizeDictionaries <= 0 ) AO.SizeDictionaries = 10;
459 else AO.SizeDictionaries = 2*AO.SizeDictionaries;
461 for ( i = 0; i < AO.NumDictionaries; i++ ) d[i] = AO.Dictionaries[i];
462 if ( AO.Dictionaries != 0 ) M_free(AO.Dictionaries,
"Dictionaries");
469 AO.Dictionaries[AO.NumDictionaries++] = dict;
471 dict->name = strDup1(name,
"DictionaryName");
472 dict->sizeelements = 0;
473 dict->numelements = 0;
476 dict->characters = 0;
478 dict->gnumelements = 0;
481 return(AO.NumDictionaries);
491 int AddToDictionary(
DICTIONARY *dict,UBYTE *left,UBYTE *right)
494 CBUF *C = cbuf+AC.cbufnum;
495 WORD *w = AT.WorkPointer;
496 WORD *OldWork = AT.WorkPointer;
497 WORD *s, oldnumrhs = C->numrhs, oldnumlhs = C->numlhs;
498 WORD *ow, *ww, *mm, oldEside, *where = 0, type, number, range[3];
500 int error = 0, sizelhs, sizerhs, i, retcode;
503 WORD power = (WORD)(
'^'), times = (WORD)(
'*');
504 if ( ( left[0] ==
'^' && left[1] == 0 )
505 || ( left[0] ==
'*' && left[1] ==
'*' && left[2] == 0 ) ) {
506 type = DICT_SPECIALCHARACTER;
511 else if ( left[0] ==
'*' && left[1] == 0 ) {
512 type = DICT_SPECIALCHARACTER;
517 else if ( left[0] ==
'(' ) {
520 while ( FG.cTable[*r] == 1 ) x1 = 10*x1 + *r++ -
'0';
523 while ( FG.cTable[*r] == 1 ) x2 = 10*x2 + *r++ -
'0';
528 MesPrint(
"&Illegal range specification in LHS of %#add instruction.");
532 if ( x1 <= 0 || x2 <= 0 || x1 > x2 ) {
533 MesPrint(
"&Illegal range in LHS of %#add instruction.");
548 *w++ = SUBEXPRESSION;
556 AT.WorkPointer = s = w + 4*AM.MaxWildcards + 8;
560 oldcpointer =
AddLHS(AC.cbufnum) - C->Buffer;
562 if ( ( retcode = CompileAlgebra(left,LHSIDE,AC.ProtoType) ) < 0 ) { error = 1; }
563 else AC.ProtoType[2] = retcode;
565 if ( AC.NwildC &&
SortWild(w,AC.NwildC) ) error = 1;
567 OldWork[1] = AC.WildC-OldWork;
570 s = C->rhs[C->numrhs];
579 if ( !error && *s == 0 ) {
580 IllLeft:MesPrint(
"&Illegal LHS in dictionary");
584 if ( !error && *(s+*s) != 0 ) {
585 MesPrint(
"&LHS in dictionary should be one term only");
590 if ( !error ) error = 1;
593 AN.RepPoint = AT.RepCount + 1;
594 ow = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
595 mm = s; ww = ow; i = *mm;
596 while ( --i >= 0 ) *ww++ = *mm++; AT.WorkPointer = ww;
597 AC.lhdollarflag = 0; oldEside = AR.Eside; AR.Eside = LHSIDE;
598 AR.Cnumlhs = C->numlhs;
606 if ( *w == 0 || *(w+*w) != 0 ) {
607 MesPrint(
"&LHS must be one term");
613 AT.WorkPointer = w + *w;
621 C->Pointer = C->Buffer + oldcpointer;
622 C->numrhs = oldnumrhs;
623 C->numlhs = oldnumlhs;
632 if ( AC.ProtoType[1] != SUBEXPSIZE ) {
633 MesPrint(
"& Currently no wildcards allowed in dictionaries.");
636 if ( w[w[0]-1] < 0 ) {
637 MesPrint(
"& Currently no sign allowed in dictionaries.");
640 if ( w[w[0]] != 0 ) {
641 MesPrint(
"& More than one term in dictionary element.");
644 if ( w[0] == w[w[0]-1]+1 ) {
647 nsize = dsize = (w[w[0]-1]-1)/2;
650 while ( numer[nsize-1] == 0 ) nsize--;
651 while ( denom[dsize-1] == 0 ) dsize--;
652 if ( dsize == 1 && denom[0] == 1 ) {
653 type = DICT_INTEGERNUMBER;
658 type = DICT_RATIONALNUMBER;
665 if ( s[0] != 3 || s[-1] != 1 || s[-2] != 1 ) {
667 MesPrint(
"& Currently no composite objects allowed in dictionaries.");
670 if ( w[0] != w[2]+4 )
goto Compositeness;
674 if ( s[1] != 4 || s[3] != 1 )
goto Compositeness;
680 if ( s[1] != 3 )
goto Compositeness;
681 if ( s[2] < 0 ) type = DICT_VECTOR;
682 else type = DICT_INDEX;
687 if ( *s < FUNCTION ) {
688 MesPrint(
"& Illegal object in dictionary.");
691 if ( s[1] == FUNHEAD ) {
692 type = DICT_FUNCTION;
698 type = DICT_FUNCTION_WITH_ARGUMENTS;
709 if ( dict->numelements >= dict->sizeelements ) {
711 if ( dict->sizeelements <= 0 ) dict->sizeelements = 10;
712 else dict->sizeelements *= 2;
715 for ( i = 0; i < dict->numelements; i++ )
716 d[i] = dict->elements[i];
717 if ( dict->elements ) M_free(dict->elements,
"Dictionary elements");
721 sizerhs = 1; r = right;
while ( *r++ ) sizerhs++;
722 sizerhs = (sizerhs+
sizeof(WORD)-1)/
sizeof(WORD)+1;
724 +
sizeof(WORD)*(sizelhs+sizerhs),
"Dictionary element");
725 new->lhs = (WORD *)(
new+1);
726 new->rhs =
new->lhs+sizelhs;
729 for ( i = 0; i < number; i++ ) new->lhs[i] = where[i];
731 r = (UBYTE *)(
new->rhs);
733 if ( *right ==
'\\' && ( right[1] ==
'`' || right[1] ==
'\'' ) ) right++;
738 dict->elements[dict->numelements++] =
new;
741 case DICT_INTEGERNUMBER:
742 case DICT_RATIONALNUMBER:
743 dict->numbers++;
break;
748 dict->variables++;
break;
749 case DICT_FUNCTION_WITH_ARGUMENTS:
750 dict->funwith++;
break;
751 case DICT_SPECIALCHARACTER:
752 dict->characters++;
break;
754 dict->ranges++;
break;
757 AT.WorkPointer = OldWork;
766 int UseDictionary(UBYTE *name,UBYTE *options)
769 for ( i = 0; i < AO.NumDictionaries; i++ ) {
770 if ( StrCmp(AO.Dictionaries[i]->name,name) == 0 ) {
771 AO.CurrentDictionary = i+1;
772 if ( SetDictionaryOptions(options) < 0 ) {
773 AO.CurrentDictionary = 0;
781 MesPrint(
"@There is no dictionary with the name %s",name);
790 int SetDictionaryOptions(UBYTE *options)
795 AO.CurDictNumbers = DICT_ALLNUMBERS;
796 AO.CurDictVariables = DICT_DOVARIABLES;
797 AO.CurDictSpecials = DICT_DOSPECIALS;
798 AO.CurDictFunWithArgs = DICT_DOFUNWITHARGS;
799 AO.CurDictNumberWarning = 0;
800 AO.CurDictNotInFunctions= 0;
801 AO.CurDictInDollars = DICT_NOTINDOLLARS;
804 while ( *s && *s !=
',' && *s !=
' ' ) s++;
806 if ( opt[0] ==
'$' && opt[1] == 0 ) {
807 AO.CurDictInDollars = DICT_INDOLLARS;
809 else if ( StrICmp(opt,(UBYTE *)
"nonumbers") == 0 ) {
810 AO.CurDictNumbers = DICT_NONUMBERS;
812 else if ( StrICmp(opt,(UBYTE *)
"integersonly") == 0 ) {
813 AO.CurDictNumbers = DICT_INTEGERONLY;
815 else if ( StrICmp(opt,(UBYTE *)
"rationalsonly") == 0 ) {
816 AO.CurDictNumbers = DICT_RATIONALONLY;
818 else if ( StrICmp(opt,(UBYTE *)
"allnumbers") == 0 ) {
819 AO.CurDictNumbers = DICT_ALLNUMBERS;
821 else if ( StrICmp(opt,(UBYTE *)
"novariables") == 0 ) {
822 AO.CurDictVariables = DICT_NOVARIABLES;
824 else if ( StrICmp(opt,(UBYTE *)
"numbersonly") == 0 ) {
825 AO.CurDictNumbers = DICT_ALLNUMBERS;
826 AO.CurDictVariables = DICT_NOVARIABLES;
827 AO.CurDictSpecials = DICT_NOSPECIALS;
828 AO.CurDictFunWithArgs = DICT_NOFUNWITHARGS;
830 else if ( StrICmp(opt,(UBYTE *)
"variablesonly") == 0 ) {
831 AO.CurDictNumbers = DICT_NONUMBERS;
832 AO.CurDictVariables = DICT_DOVARIABLES;
833 AO.CurDictSpecials = DICT_NOSPECIALS;
834 AO.CurDictFunWithArgs = DICT_NOFUNWITHARGS;
836 else if ( StrICmp(opt,(UBYTE *)
"nospecials") == 0 ) {
837 AO.CurDictSpecials = DICT_NOSPECIALS;
839 else if ( StrICmp(opt,(UBYTE *)
"specialsonly") == 0 ) {
840 AO.CurDictNumbers = DICT_NONUMBERS;
841 AO.CurDictVariables = DICT_NOVARIABLES;
842 AO.CurDictSpecials = DICT_DOSPECIALS;
843 AO.CurDictFunWithArgs = DICT_NOFUNWITHARGS;
845 else if ( StrICmp(opt,(UBYTE *)
"nofunwithargs") == 0 ) {
846 AO.CurDictFunWithArgs = DICT_NOFUNWITHARGS;
848 else if ( StrICmp(opt,(UBYTE *)
"funwithargsonly") == 0 ) {
849 AO.CurDictNumbers = DICT_NONUMBERS;
850 AO.CurDictVariables = DICT_NOVARIABLES;
851 AO.CurDictSpecials = DICT_NOSPECIALS;
852 AO.CurDictFunWithArgs = DICT_DOFUNWITHARGS;
854 else if ( StrICmp(opt,(UBYTE *)
"warnings") == 0
855 || StrICmp(opt,(UBYTE *)
"warning") == 0 ) {
856 AO.CurDictNumberWarning = 1;
858 else if ( StrICmp(opt,(UBYTE *)
"nowarnings") == 0
859 || StrICmp(opt,(UBYTE *)
"nowarning") == 0 ) {
860 AO.CurDictNumberWarning = 0;
862 else if ( StrICmp(opt,(UBYTE *)
"infunctions") == 0 ) {
863 AO.CurDictNotInFunctions= 0;
865 else if ( StrICmp(opt,(UBYTE *)
"notinfunctions") == 0 ) {
866 AO.CurDictNotInFunctions= 1;
869 MesPrint(
"@ Unrecognized option in %#SetDictionary: %s",opt);
883 void UnSetDictionary(VOID)
885 AO.CurrentDictionary = 0;
886 AO.CurDictNumbers = -1;
887 AO.CurDictVariables = -1;
888 AO.CurDictSpecials = -1;
889 AO.CurDictFunWithArgs = -1;
890 AO.CurDictFunWithArgs = -1;
891 AO.CurDictNumberWarning = -1;
892 AO.CurDictNotInFunctions= -1;
905 if ( dict == 0 )
return;
906 for ( i = 0; i < AO.NumDictionaries; i++ ) {
907 if ( AO.Dictionaries[i] == dict ) {
908 for (i++; i < AO.NumDictionaries; i++ ) {
909 AO.Dictionaries[i-1] = AO.Dictionaries[i];
911 AO.NumDictionaries--;
915 MesPrint(
"@ Dictionary not found in RemoveDictionary");
918 for ( i = 0; i < dict->numelements; i++ )
919 M_free(dict->elements[i],
"Dictionary element");
920 for ( i = 0; i < dict->numelements; i++ ) dict->elements[i] = 0;
921 if ( dict->elements ) M_free(dict->elements,
"Dictionary elements");
923 M_free(dict->name,
"DictionaryName");
926 dict->sizeelements = 0;
927 dict->numelements = 0;
930 dict->characters = 0;
932 dict->gnumelements = 0;
947 while ( dict->numelements > dict->gnumelements ) {
949 M_free(dict->elements[dict->numelements],
"Dictionary element");
950 dict->elements[dict->numelements] = 0;
959 int DoPreOpenDictionary(UBYTE *s)
963 if ( AP.PreSwitchModes[AP.PreSwitchLevel] != EXECUTINGPRESWITCH )
return(0);
964 if ( AP.PreIfStack[AP.PreIfLevel] != EXECUTINGIF )
return(0);
965 while ( *s ==
' ' ) s++;
967 name = s; s = SkipAName(s);
968 if ( *s != 0 && *s !=
';' ) {
969 MesPrint(
"@proper syntax is #opendictionary name");
974 if ( AP.OpenDictionary > 0 ) {
975 MesPrint(
"@you cannot nest #opendictionary instructions");
976 MesPrint(
"@dictionary %s is open already",
977 AO.Dictionaries[AP.OpenDictionary-1]->name);
980 if ( AO.CurrentDictionary > 0 ) {
981 MesPrint(
"@before opening a dictionary you have to first close the selected dictionary");
987 dict = FindDictionary(name);
988 if ( dict == 0 ) dict = AddDictionary(name);
989 AP.OpenDictionary = dict;
998 int DoPreCloseDictionary(UBYTE *s)
1000 if ( AP.PreSwitchModes[AP.PreSwitchLevel] != EXECUTINGPRESWITCH )
return(0);
1001 if ( AP.PreIfStack[AP.PreIfLevel] != EXECUTINGIF )
return(0);
1002 while ( *s ==
' ' ) s++;
1004 if ( AP.OpenDictionary == 0 && AO.CurrentDictionary == 0 ) {
1005 MesPrint(
"@you have neither an open, nor a selected dictionary");
1009 AP.OpenDictionary = 0;
1010 AO.CurrentDictionary = 0;
1012 AO.CurDictNotInFunctions = 0;
1022 int DoPreUseDictionary(UBYTE *s)
1024 UBYTE *options, c, *ss, *sss, *name;
1025 if ( AP.PreSwitchModes[AP.PreSwitchLevel] != EXECUTINGPRESWITCH )
return(0);
1026 if ( AP.PreIfStack[AP.PreIfLevel] != EXECUTINGIF )
return(0);
1027 while ( *s ==
' ' ) s++;
1029 if ( AP.OpenDictionary > 0 ) {
1030 MesPrint(
"@before selecting a dictionary you have to first close the open dictionary");
1034 name = s; s = SkipAName(s);
1035 ss = s;
while ( *s && *s !=
'(' ) s++;
1041 options = s+1; SKIPBRA3(s)
1043 MesPrint(
"@Irregular end of %#UseDictionary instruction");
1047 s++;
while ( *s ==
' ' || *s ==
'\t' || *s ==
';' ) s++;
1050 MesPrint(
"@Irregular end of %#UseDictionary instruction");
1054 return(UseDictionary(name,options));
1067 int DoPreAdd(UBYTE *s)
1069 UBYTE *left, *right;
1071 if ( AP.PreSwitchModes[AP.PreSwitchLevel] != EXECUTINGPRESWITCH )
return(0);
1072 if ( AP.PreIfStack[AP.PreIfLevel] != EXECUTINGIF )
return(0);
1073 while ( *s ==
' ' ) s++;
1075 if ( AP.OpenDictionary == 0 ) {
1076 MesPrint(
"@there is no open dictionary to add to");
1083 while ( *s && *s !=
':' ) {
1084 if ( *s ==
'[' ) { SKIPBRA1(s) s++; }
1085 else if ( *s ==
'{' ) { SKIPBRA2(s) s++; }
1086 else if ( *s ==
'(' ) { SKIPBRA3(s) s++; }
1087 else if ( *s ==
']' || *s ==
'}' || *s ==
')' ) {
1088 MesPrint(
"@unmatched brackets in #add instruction");
1094 MesPrint(
"@Missing : in #add instruction");
1099 while ( *s ==
' ' || *s ==
'\t' ) s++;
1100 if ( *s ==
'"' && s[1] ) {
1104 while ( s[-1] !=
'"' ) s--;
1106 MesPrint(
"@Irregular use of double quotes in #add instruction");
1111 return(AddToDictionary(AO.Dictionaries[AP.OpenDictionary-1],left,right));
1119 LONG DictToBytes(
DICTIONARY *dict,UBYTE *buf)
1121 int numelements = dict->numelements, sizeelement, i, j, x;
1122 UBYTE *s1, *s2 = buf;
1132 for ( i = 0; i < numelements; i++ ) {
1133 e = dict->elements[i];
1135 s1 = (UBYTE *)e->rhs; x = 0;
1136 while ( *s1 ) { s1++; x++; }
1138 sizeelement += (x+1) *
sizeof(WORD);
1139 s1 = (UBYTE *)(&sizeelement); j =
sizeof(WORD); NCOPY(s2,s1,j)
1141 s1 = (UBYTE *)e->lhs; j = (e->size+1)*(
sizeof(WORD)); NCOPY(s2,s1,j)
1142 s1 = (UBYTE *)e->rhs; j = (x+1)*(
sizeof(WORD)); NCOPY(s2,s1,j)
1156 int i, j, sizeelement;
1162 s2 = (UBYTE *)dict; j =
sizeof(
DICTIONARY); NCOPY(s2,s1,j)
1168 for ( i = 0; i < dict->numelements; i++ ) {
1169 s2 = (UBYTE *)(&sizeelement); j =
sizeof(WORD); NCOPY(s2,s1,j)
1171 dict->elements[i] = e;
1172 j = sizeelement; s2 = (UBYTE *)e; NCOPY(s2,s1,j)
1173 e->lhs = (WORD *)(e+1);
1174 e->rhs = e->lhs + e->size+1;
WORD SortWild(WORD *, WORD)
WORD Generator(PHEAD WORD *, WORD)
LONG EndSort(PHEAD WORD *, int)