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;
169 if ( AC.OutputMode == FORTRANMODE || AC.OutputMode == PFORTRANMODE
170 || AC.OutputMode == CMODE ) {
171 if ( AO.DoubleFlag == 2 ) { AddToLine((UBYTE *)
".Q0/"); }
172 else if ( AO.DoubleFlag == 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);
185 if ( AC.OutputMode == FORTRANMODE || AC.OutputMode == PFORTRANMODE
186 || AC.OutputMode == CMODE ) {
187 if ( AO.DoubleFlag == 2 ) { AddToLine((UBYTE *)
".Q0"); }
188 else if ( AO.DoubleFlag == 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 int 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)(
'*') ) )
return(i+1);
237 int IsExponentSign(VOID)
241 if ( AO.CurrentDictionary <= 0 )
return(0);
242 dict = AO.Dictionaries[AO.CurrentDictionary-1];
243 if ( dict->characters == 0 )
return(0);
244 for ( i = dict->numelements-1; i >= 0; i-- ) {
245 if ( ( dict->elements[i]->type == DICT_SPECIALCHARACTER )
246 && ( dict->elements[i]->lhs[0] == (WORD)(
'^') ) )
return(i+1);
256 UBYTE *FindSymbol(WORD num)
258 if ( AO.CurrentDictionary > 0 ) {
259 DICTIONARY *dict = AO.Dictionaries[AO.CurrentDictionary-1];
261 if ( dict->variables > 0 && AO.CurDictVariables == DICT_DOVARIABLES ) {
262 for ( i = dict->numelements-1; i >= 0; i-- ) {
263 if ( dict->elements[i]->type == DICT_SYMBOL &&
264 dict->elements[i]->lhs[0] == num )
265 return((UBYTE *)(dict->elements[i]->rhs));
269 return(VARNAME(symbols,num));
277 UBYTE *FindVector(WORD num)
279 if ( AO.CurrentDictionary > 0 ) {
280 DICTIONARY *dict = AO.Dictionaries[AO.CurrentDictionary-1];
282 if ( dict->variables > 0 && AO.CurDictVariables == DICT_DOVARIABLES ) {
283 for ( i = dict->numelements-1; i >= 0; i-- ) {
284 if ( dict->elements[i]->type == DICT_VECTOR &&
285 dict->elements[i]->lhs[0] == num )
286 return((UBYTE *)(dict->elements[i]->rhs));
290 num -= AM.OffsetVector;
291 return(VARNAME(vectors,num));
299 UBYTE *FindIndex(WORD num)
301 if ( AO.CurrentDictionary > 0 ) {
302 DICTIONARY *dict = AO.Dictionaries[AO.CurrentDictionary-1];
304 if ( dict->variables > 0 && AO.CurDictVariables == DICT_DOVARIABLES ) {
305 for ( i = dict->numelements-1; i >= 0; i-- ) {
306 if ( dict->elements[i]->type == DICT_INDEX &&
307 dict->elements[i]->lhs[0] == num )
308 return((UBYTE *)(dict->elements[i]->rhs));
312 num -= AM.OffsetIndex;
313 return(VARNAME(indices,num));
321 UBYTE *FindFunction(WORD num)
323 if ( AO.CurrentDictionary > 0 ) {
324 DICTIONARY *dict = AO.Dictionaries[AO.CurrentDictionary-1];
326 if ( dict->variables > 0 && AO.CurDictVariables == DICT_DOVARIABLES ) {
327 for ( i = dict->numelements-1; i >= 0; i-- ) {
328 if ( dict->elements[i]->type == DICT_FUNCTION &&
329 dict->elements[i]->lhs[0] == num )
330 return((UBYTE *)(dict->elements[i]->rhs));
335 return(VARNAME(functions,num));
343 UBYTE *FindFunWithArgs(WORD *t)
345 if ( AO.CurrentDictionary > 0 ) {
346 DICTIONARY *dict = AO.Dictionaries[AO.CurrentDictionary-1];
348 if ( dict->funwith > 0
349 && AO.CurDictFunWithArgs == DICT_DOFUNWITHARGS ) {
350 for ( i = dict->numelements-1; i >= 0; i-- ) {
351 if ( dict->elements[i]->type == DICT_FUNCTION_WITH_ARGUMENTS &&
352 (WORD)(dict->elements[i]->lhs[0]) == t[0] &&
353 (WORD)(dict->elements[i]->lhs[1]) == t[1] ) {
354 for ( j = 2; j < t[1]; j++ ) {
355 if ( (WORD)(dict->elements[i]->lhs[j]) != t[j] )
break;
357 if ( j >= t[1] )
return((UBYTE *)(dict->elements[i]->rhs));
375 UBYTE *FindExtraSymbol(WORD num)
378 UBYTE *out = (UBYTE *)(AT.WorkPointer);
380 if ( AO.CurrentDictionary > 0 ) {
381 DICTIONARY *dict = AO.Dictionaries[AO.CurrentDictionary-1];
383 if ( dict->ranges > 0 && AO.CurDictVariables == DICT_DOVARIABLES ) {
384 for ( i = dict->numelements-1; i >= 0; i-- ) {
385 if ( dict->elements[i]->type == DICT_RANGE
386 && num >= dict->elements[i]->lhs[0]
387 && num <= dict->elements[i]->lhs[1] ) {
393 UBYTE *r = (UBYTE *)(dict->elements[i]->rhs);
395 if ( *r == (UBYTE)
'%' && ( r[1] == (UBYTE)
'#' 396 || r[1] == (UBYTE)
'@' ) ) {
397 if ( r[1] == (UBYTE)
'#' ) {
398 out = NumCopy(num,out);
401 out = NumCopy(num-dict->elements[i]->lhs[0]+1,out);
410 return((UBYTE *)(AT.WorkPointer));
416 out = StrCopy((UBYTE *)AC.extrasym,out);
417 if ( AC.extrasymbols == 0 ) {
418 out = NumCopy(num,out);
419 out = StrCopy((UBYTE *)
"_",out);
421 else if ( AC.extrasymbols == 1 ) {
422 out = AddArrayIndex(num,out);
424 return((UBYTE *)(AT.WorkPointer));
432 int FindDictionary(UBYTE *name)
435 for ( i = 0; i < AO.NumDictionaries; i++ ) {
436 if ( StrCmp(AO.Dictionaries[i]->name,name) == 0 )
447 int AddDictionary(UBYTE *name)
453 if ( AO.NumDictionaries >= AO.SizeDictionaries-1 ) {
456 if ( AO.SizeDictionaries <= 0 ) AO.SizeDictionaries = 10;
457 else AO.SizeDictionaries = 2*AO.SizeDictionaries;
459 for ( i = 0; i < AO.NumDictionaries; i++ ) d[i] = AO.Dictionaries[i];
460 if ( AO.Dictionaries != 0 ) M_free(AO.Dictionaries,
"Dictionaries");
467 AO.Dictionaries[AO.NumDictionaries++] = dict;
469 dict->name = strDup1(name,
"DictionaryName");
470 dict->sizeelements = 0;
471 dict->numelements = 0;
474 dict->characters = 0;
476 dict->gnumelements = 0;
479 return(AO.NumDictionaries);
489 int AddToDictionary(
DICTIONARY *dict,UBYTE *left,UBYTE *right)
492 CBUF *C = cbuf+AC.cbufnum;
493 WORD *w = AT.WorkPointer;
494 WORD *OldWork = AT.WorkPointer;
495 WORD *s, oldnumrhs = C->numrhs, oldnumlhs = C->numlhs;
496 WORD *ow, *ww, *mm, oldEside, *where = 0, type, number, range[3];
498 int error = 0, sizelhs, sizerhs, i, retcode;
501 WORD power = (WORD)(
'^'), times = (WORD)(
'*');
502 if ( ( left[0] ==
'^' && left[1] == 0 )
503 || ( left[0] ==
'*' && left[1] ==
'*' && left[2] == 0 ) ) {
504 type = DICT_SPECIALCHARACTER;
509 else if ( left[0] ==
'*' && left[1] == 0 ) {
510 type = DICT_SPECIALCHARACTER;
515 else if ( left[0] ==
'(' ) {
518 while ( FG.cTable[*r] == 1 ) x1 = 10*x1 + *r++ -
'0';
521 while ( FG.cTable[*r] == 1 ) x2 = 10*x2 + *r++ -
'0';
526 MesPrint(
"&Illegal range specification in LHS of %#add instruction.");
530 if ( x1 <= 0 || x2 <= 0 || x1 > x2 ) {
531 MesPrint(
"&Illegal range in LHS of %#add instruction.");
546 *w++ = SUBEXPRESSION;
554 AT.WorkPointer = s = w + 4*AM.MaxWildcards + 8;
558 oldcpointer =
AddLHS(AC.cbufnum) - C->Buffer;
560 if ( ( retcode = CompileAlgebra(left,LHSIDE,AC.ProtoType) ) < 0 ) { error = 1; }
561 else AC.ProtoType[2] = retcode;
563 if ( AC.NwildC &&
SortWild(w,AC.NwildC) ) error = 1;
565 OldWork[1] = AC.WildC-OldWork;
568 s = C->rhs[C->numrhs];
577 if ( !error && *s == 0 ) {
578 IllLeft:MesPrint(
"&Illegal LHS in dictionary");
582 if ( !error && *(s+*s) != 0 ) {
583 MesPrint(
"&LHS in dictionary should be one term only");
588 if ( !error ) error = 1;
591 AN.RepPoint = AT.RepCount + 1;
592 ow = (WORD *)(((UBYTE *)(AT.WorkPointer)) + AM.MaxTer);
593 mm = s; ww = ow; i = *mm;
594 while ( --i >= 0 ) *ww++ = *mm++; AT.WorkPointer = ww;
595 AC.lhdollarflag = 0; oldEside = AR.Eside; AR.Eside = LHSIDE;
596 AR.Cnumlhs = C->numlhs;
604 if ( *w == 0 || *(w+*w) != 0 ) {
605 MesPrint(
"&LHS must be one term");
611 AT.WorkPointer = w + *w;
619 C->Pointer = C->Buffer + oldcpointer;
620 C->numrhs = oldnumrhs;
621 C->numlhs = oldnumlhs;
630 if ( AC.ProtoType[1] != SUBEXPSIZE ) {
631 MesPrint(
"& Currently no wildcards allowed in dictionaries.");
634 if ( w[w[0]-1] < 0 ) {
635 MesPrint(
"& Currently no sign allowed in dictionaries.");
638 if ( w[w[0]] != 0 ) {
639 MesPrint(
"& More than one term in dictionary element.");
642 if ( w[0] == w[w[0]-1]+1 ) {
645 nsize = dsize = (w[w[0]-1]-1)/2;
648 while ( numer[nsize-1] == 0 ) nsize--;
649 while ( denom[dsize-1] == 0 ) dsize--;
650 if ( dsize == 1 && denom[0] == 1 ) {
651 type = DICT_INTEGERNUMBER;
656 type = DICT_RATIONALNUMBER;
663 if ( s[0] != 3 || s[-1] != 1 || s[-2] != 1 ) {
665 MesPrint(
"& Currently no composite objects allowed in dictionaries.");
668 if ( w[0] != w[2]+4 )
goto Compositeness;
672 if ( s[1] != 4 || s[3] != 1 )
goto Compositeness;
678 if ( s[1] != 3 )
goto Compositeness;
679 if ( s[2] < 0 ) type = DICT_VECTOR;
680 else type = DICT_INDEX;
685 if ( *s < FUNCTION ) {
686 MesPrint(
"& Illegal object in dictionary.");
689 if ( s[1] == FUNHEAD ) {
690 type = DICT_FUNCTION;
696 type = DICT_FUNCTION_WITH_ARGUMENTS;
707 if ( dict->numelements >= dict->sizeelements ) {
709 if ( dict->sizeelements <= 0 ) dict->sizeelements = 10;
710 else dict->sizeelements *= 2;
713 for ( i = 0; i < dict->numelements; i++ )
714 d[i] = dict->elements[i];
715 if ( dict->elements ) M_free(dict->elements,
"Dictionary elements");
719 sizerhs = 1; r = right;
while ( *r++ ) sizerhs++;
720 sizerhs = (sizerhs+
sizeof(WORD)-1)/
sizeof(WORD)+1;
722 +
sizeof(WORD)*(sizelhs+sizerhs),
"Dictionary element");
723 new->lhs = (WORD *)(
new+1);
724 new->rhs =
new->lhs+sizelhs;
727 for ( i = 0; i < number; i++ ) new->lhs[i] = where[i];
729 r = (UBYTE *)(
new->rhs);
731 if ( *right ==
'\\' && ( right[1] ==
'`' || right[1] ==
'\'' ) ) right++;
736 dict->elements[dict->numelements++] =
new;
739 case DICT_INTEGERNUMBER:
740 case DICT_RATIONALNUMBER:
741 dict->numbers++;
break;
746 dict->variables++;
break;
747 case DICT_FUNCTION_WITH_ARGUMENTS:
748 dict->funwith++;
break;
749 case DICT_SPECIALCHARACTER:
750 dict->characters++;
break;
752 dict->ranges++;
break;
755 AT.WorkPointer = OldWork;
764 int UseDictionary(UBYTE *name,UBYTE *options)
767 for ( i = 0; i < AO.NumDictionaries; i++ ) {
768 if ( StrCmp(AO.Dictionaries[i]->name,name) == 0 ) {
769 AO.CurrentDictionary = i+1;
770 if ( SetDictionaryOptions(options) < 0 ) {
771 AO.CurrentDictionary = 0;
779 MesPrint(
"@There is no dictionary with the name %s",name);
788 int SetDictionaryOptions(UBYTE *options)
793 AO.CurDictNumbers = DICT_ALLNUMBERS;
794 AO.CurDictVariables = DICT_DOVARIABLES;
795 AO.CurDictSpecials = DICT_DOSPECIALS;
796 AO.CurDictFunWithArgs = DICT_DOFUNWITHARGS;
797 AO.CurDictNumberWarning = 0;
798 AO.CurDictNotInFunctions= 0;
799 AO.CurDictInDollars = DICT_NOTINDOLLARS;
802 while ( *s && *s !=
',' && *s !=
' ' ) s++;
804 if ( opt[0] ==
'$' && opt[1] == 0 ) {
805 AO.CurDictInDollars = DICT_INDOLLARS;
807 else if ( StrICmp(opt,(UBYTE *)
"nonumbers") == 0 ) {
808 AO.CurDictNumbers = DICT_NONUMBERS;
810 else if ( StrICmp(opt,(UBYTE *)
"integersonly") == 0 ) {
811 AO.CurDictNumbers = DICT_INTEGERONLY;
813 else if ( StrICmp(opt,(UBYTE *)
"rationalsonly") == 0 ) {
814 AO.CurDictNumbers = DICT_RATIONALONLY;
816 else if ( StrICmp(opt,(UBYTE *)
"allnumbers") == 0 ) {
817 AO.CurDictNumbers = DICT_ALLNUMBERS;
819 else if ( StrICmp(opt,(UBYTE *)
"novariables") == 0 ) {
820 AO.CurDictVariables = DICT_NOVARIABLES;
822 else if ( StrICmp(opt,(UBYTE *)
"numbersonly") == 0 ) {
823 AO.CurDictNumbers = DICT_ALLNUMBERS;
824 AO.CurDictVariables = DICT_NOVARIABLES;
825 AO.CurDictSpecials = DICT_NOSPECIALS;
826 AO.CurDictFunWithArgs = DICT_NOFUNWITHARGS;
828 else if ( StrICmp(opt,(UBYTE *)
"variablesonly") == 0 ) {
829 AO.CurDictNumbers = DICT_NONUMBERS;
830 AO.CurDictVariables = DICT_DOVARIABLES;
831 AO.CurDictSpecials = DICT_NOSPECIALS;
832 AO.CurDictFunWithArgs = DICT_NOFUNWITHARGS;
834 else if ( StrICmp(opt,(UBYTE *)
"nospecials") == 0 ) {
835 AO.CurDictSpecials = DICT_NOSPECIALS;
837 else if ( StrICmp(opt,(UBYTE *)
"specialsonly") == 0 ) {
838 AO.CurDictNumbers = DICT_NONUMBERS;
839 AO.CurDictVariables = DICT_NOVARIABLES;
840 AO.CurDictSpecials = DICT_DOSPECIALS;
841 AO.CurDictFunWithArgs = DICT_NOFUNWITHARGS;
843 else if ( StrICmp(opt,(UBYTE *)
"nofunwithargs") == 0 ) {
844 AO.CurDictFunWithArgs = DICT_NOFUNWITHARGS;
846 else if ( StrICmp(opt,(UBYTE *)
"funwithargsonly") == 0 ) {
847 AO.CurDictNumbers = DICT_NONUMBERS;
848 AO.CurDictVariables = DICT_NOVARIABLES;
849 AO.CurDictSpecials = DICT_NOSPECIALS;
850 AO.CurDictFunWithArgs = DICT_DOFUNWITHARGS;
852 else if ( StrICmp(opt,(UBYTE *)
"warnings") == 0
853 || StrICmp(opt,(UBYTE *)
"warning") == 0 ) {
854 AO.CurDictNumberWarning = 1;
856 else if ( StrICmp(opt,(UBYTE *)
"nowarnings") == 0
857 || StrICmp(opt,(UBYTE *)
"nowarning") == 0 ) {
858 AO.CurDictNumberWarning = 0;
860 else if ( StrICmp(opt,(UBYTE *)
"infunctions") == 0 ) {
861 AO.CurDictNotInFunctions= 0;
863 else if ( StrICmp(opt,(UBYTE *)
"notinfunctions") == 0 ) {
864 AO.CurDictNotInFunctions= 1;
867 MesPrint(
"@ Unrecognized option in %#SetDictionary: %s",opt);
881 void UnSetDictionary(VOID)
883 AO.CurrentDictionary = 0;
884 AO.CurDictNumbers = -1;
885 AO.CurDictVariables = -1;
886 AO.CurDictSpecials = -1;
887 AO.CurDictFunWithArgs = -1;
888 AO.CurDictFunWithArgs = -1;
889 AO.CurDictNumberWarning = -1;
890 AO.CurDictNotInFunctions= -1;
903 if ( dict == 0 )
return;
904 for ( i = 0; i < AO.NumDictionaries; i++ ) {
905 if ( AO.Dictionaries[i] == dict ) {
906 for (i++; i < AO.NumDictionaries; i++ ) {
907 AO.Dictionaries[i-1] = AO.Dictionaries[i];
909 AO.NumDictionaries--;
913 MesPrint(
"@ Dictionary not found in RemoveDictionary");
916 for ( i = 0; i < dict->numelements; i++ )
917 M_free(dict->elements[i],
"Dictionary element");
918 for ( i = 0; i < dict->numelements; i++ ) dict->elements[i] = 0;
919 if ( dict->elements ) M_free(dict->elements,
"Dictionary elements");
921 M_free(dict->name,
"DictionaryName");
924 dict->sizeelements = 0;
925 dict->numelements = 0;
928 dict->characters = 0;
930 dict->gnumelements = 0;
945 while ( dict->numelements > dict->gnumelements ) {
947 M_free(dict->elements[dict->numelements],
"Dictionary element");
948 dict->elements[dict->numelements] = 0;
957 int DoPreOpenDictionary(UBYTE *s)
961 if ( AP.PreSwitchModes[AP.PreSwitchLevel] != EXECUTINGPRESWITCH )
return(0);
962 if ( AP.PreIfStack[AP.PreIfLevel] != EXECUTINGIF )
return(0);
963 while ( *s ==
' ' ) s++;
965 name = s; s = SkipAName(s);
966 if ( *s != 0 && *s !=
';' ) {
967 MesPrint(
"@proper syntax is #opendictionary name");
972 if ( AP.OpenDictionary > 0 ) {
973 MesPrint(
"@you cannot nest #opendictionary instructions");
974 MesPrint(
"@dictionary %s is open already",
975 AO.Dictionaries[AP.OpenDictionary-1]->name);
978 if ( AO.CurrentDictionary > 0 ) {
979 MesPrint(
"@before opening a dictionary you have to first close the selected dictionary");
985 dict = FindDictionary(name);
986 if ( dict == 0 ) dict = AddDictionary(name);
987 AP.OpenDictionary = dict;
996 int DoPreCloseDictionary(UBYTE *s)
998 if ( AP.PreSwitchModes[AP.PreSwitchLevel] != EXECUTINGPRESWITCH )
return(0);
999 if ( AP.PreIfStack[AP.PreIfLevel] != EXECUTINGIF )
return(0);
1000 while ( *s ==
' ' ) s++;
1002 if ( AP.OpenDictionary == 0 && AO.CurrentDictionary == 0 ) {
1003 MesPrint(
"@you have neither an open, nor a selected dictionary");
1007 AP.OpenDictionary = 0;
1008 AO.CurrentDictionary = 0;
1010 AO.CurDictNotInFunctions = 0;
1020 int DoPreUseDictionary(UBYTE *s)
1022 UBYTE *options, c, *ss, *sss, *name;
1023 if ( AP.PreSwitchModes[AP.PreSwitchLevel] != EXECUTINGPRESWITCH )
return(0);
1024 if ( AP.PreIfStack[AP.PreIfLevel] != EXECUTINGIF )
return(0);
1025 while ( *s ==
' ' ) s++;
1027 if ( AP.OpenDictionary > 0 ) {
1028 MesPrint(
"@before selecting a dictionary you have to first close the open dictionary");
1032 name = s; s = SkipAName(s);
1033 ss = s;
while ( *s && *s !=
'(' ) s++;
1039 options = s+1; SKIPBRA3(s)
1041 MesPrint(
"@Irregular end of %#UseDictionary instruction");
1045 s++;
while ( *s ==
' ' || *s ==
'\t' || *s ==
';' ) s++;
1048 MesPrint(
"@Irregular end of %#UseDictionary instruction");
1052 return(UseDictionary(name,options));
1065 int DoPreAdd(UBYTE *s)
1067 UBYTE *left, *right;
1069 if ( AP.PreSwitchModes[AP.PreSwitchLevel] != EXECUTINGPRESWITCH )
return(0);
1070 if ( AP.PreIfStack[AP.PreIfLevel] != EXECUTINGIF )
return(0);
1071 while ( *s ==
' ' ) s++;
1073 if ( AP.OpenDictionary == 0 ) {
1074 MesPrint(
"@there is no open dictionary to add to");
1081 while ( *s && *s !=
':' ) {
1082 if ( *s ==
'[' ) { SKIPBRA1(s) s++; }
1083 else if ( *s ==
'{' ) { SKIPBRA2(s) s++; }
1084 else if ( *s ==
'(' ) { SKIPBRA3(s) s++; }
1085 else if ( *s ==
']' || *s ==
'}' || *s ==
')' ) {
1086 MesPrint(
"@unmatched brackets in #add instruction");
1092 MesPrint(
"@Missing : in #add instruction");
1097 while ( *s ==
' ' || *s ==
'\t' ) s++;
1098 if ( *s ==
'"' && s[1] ) {
1102 while ( s[-1] !=
'"' ) s--;
1104 MesPrint(
"@Irregular use of double quotes in #add instruction");
1109 return(AddToDictionary(AO.Dictionaries[AP.OpenDictionary-1],left,right));
1117 LONG DictToBytes(
DICTIONARY *dict,UBYTE *buf)
1119 int numelements = dict->numelements, sizeelement, i, j, x;
1120 UBYTE *s1, *s2 = buf;
1130 for ( i = 0; i < numelements; i++ ) {
1131 e = dict->elements[i];
1133 s1 = (UBYTE *)e->rhs; x = 0;
1134 while ( *s1 ) { s1++; x++; }
1136 sizeelement += (x+1) *
sizeof(WORD);
1137 s1 = (UBYTE *)(&sizeelement); j =
sizeof(WORD); NCOPY(s2,s1,j)
1139 s1 = (UBYTE *)e->lhs; j = (e->size+1)*(
sizeof(WORD)); NCOPY(s2,s1,j)
1140 s1 = (UBYTE *)e->rhs; j = (x+1)*(
sizeof(WORD)); NCOPY(s2,s1,j)
1154 int i, j, sizeelement;
1160 s2 = (UBYTE *)dict; j =
sizeof(
DICTIONARY); NCOPY(s2,s1,j)
1166 for ( i = 0; i < dict->numelements; i++ ) {
1167 s2 = (UBYTE *)(&sizeelement); j =
sizeof(WORD); NCOPY(s2,s1,j)
1169 dict->elements[i] = e;
1170 j = sizeelement; s2 = (UBYTE *)e; NCOPY(s2,s1,j)
1171 e->lhs = (WORD *)(e+1);
1172 e->rhs = e->lhs + e->size+1;
WORD SortWild(WORD *, WORD)
WORD Generator(PHEAD WORD *, WORD)
LONG EndSort(PHEAD WORD *, int)