00001
00002
00003
00004
00005
00006
00007 #include "MALLOC.h"
00008
00009 #include "intmacr2tree.h"
00010 #include "sciprint.h"
00011
00012 static char varnames[isizt][nlgh+1];
00013
00014
00015 static int nbvars = 0;
00016
00017
00018 static int last_eol_pos = 0;
00019
00020
00021 static int CreateRecursiveIndex2List(int *data,int *index2);
00022
00023
00024 int C2F(macr2tree) _PARAMS((char *fname,unsigned long fname_len));
00025
00026
00027
00028 int C2F(macr2tree) _PARAMS((char *fname,unsigned long fname_len))
00029 {
00030
00031 int m_pgrm_tlist = 1,n_pgrm_tlist = 6;
00032 char *pgrm_tlist[] = {"program","name","outputs","inputs","statements","nblines"};
00033
00034 int *stkdata = NULL;
00035 int *data = NULL;
00036
00037 int minRhs = 1;
00038 int maxRhs = 1;
00039 int minLhs = 1;
00040 int maxLhs = 1;
00041
00042 int il = 0,ils = 0,ile = 0,ilt = 0,codelength = 0;
00043
00044 int i = 0,cod_ind = 0;
00045 int job1 = 1;
00046
00047
00048 int nblines = 1;
00049
00050
00051 char **name = NULL;
00052 int namelgth = 0;
00053
00054
00055 int nbstat = 0;
00056
00057
00058 int one = 1;
00059
00060
00061 int TopSave = 0;
00062
00063
00064 int cod_sav = 0;
00065
00066
00067 int k = 0;
00068
00069
00070 int sz = 0;
00071 int newinstr = 0;
00072
00073
00074 CheckRhs(minRhs,maxRhs);
00075
00076
00077 CheckLhs(minLhs,maxLhs);
00078
00079
00080 stkdata = (int *) stk(*Lstk(Top));
00081
00082 if (stkdata[0] > 0)
00083 {
00084 Scierror(999,"macr2tree: input argument must be a named variable\r\n");
00085 return 0;
00086 }
00087 else
00088 {
00089 stkdata = (int *) stk(stkdata[1]);
00090 }
00091
00092
00093 if(stkdata[0] != 13)
00094 {
00095 Scierror(999,"macr2tree: Wrong input type (must be a compiled macro)!\r\n");
00096 return 0;
00097 }
00098
00099
00100 if((name=CALLOC(1,sizeof(char)))==NULL)
00101 {
00102 Scierror(999,"macr2tree: No more memory available\r\n");
00103 return 0;
00104 }
00105 if((name[0]=(char *)CALLOC(1,sizeof(char)*(nlgh+1)))==NULL)
00106 {
00107 Scierror(999,"macr2tree: No more memory available\r\n");
00108 return 0;
00109 }
00110 (name[0])[nlgh]='\0';
00111
00112
00113
00114
00115 CvNameL(idstk(1,Top),name[0],&job1,&namelgth);
00116 (name[0])[namelgth]='\0';
00117
00118
00119 Top--;
00120
00121
00122 str2sci(pgrm_tlist,m_pgrm_tlist,n_pgrm_tlist);
00123
00124
00125 str2sci(name,one,one);
00126
00127 ils=il+1;
00128
00129
00130 for(i=0;i<stkdata[ils];i++)
00131 {
00132 CvNameL(&stkdata[ils+1+i*nsiz],name[0],&job1,&namelgth);
00133 (name[0])[namelgth]='\0';
00134 CreateVariableTList(name);
00135 }
00136 C2F(mklist)(&stkdata[ils]);
00137
00138 ile = ils+nsiz*stkdata[ils]+1;
00139
00140
00141 for(i=0;i<stkdata[ile];i++)
00142 {
00143 CvNameL(&stkdata[ile+1+i*nsiz],name[0],&job1,&namelgth);
00144 (name[0])[namelgth]='\0';
00145 CreateVariableTList(name);
00146 }
00147 C2F(mklist)(&stkdata[ile]);
00148
00149 ilt=ile+nsiz*stkdata[ile]+1;
00150
00151 codelength=stkdata[ilt];
00152
00153
00154
00155 if((data=(int *)CALLOC(1,sizeof(int)*(codelength+ilt+1)))==NULL)
00156 {
00157 Scierror(999,"macr2tree: No more memory available\r\n");
00158 return 0;
00159 }
00160
00161 for(k=0;k<(codelength+ilt+1);k++)
00162 data[k]=stkdata[k];
00163
00164
00165
00166
00167
00168 cod_ind = ilt + 1;
00169 nbstat = complexity(data,&ilt,&codelength);
00170
00171 Top++;
00172
00173 il = iadr(*Lstk(Top));
00174 *istk(il) = 15;
00175 *istk(il+1) = nbstat;
00176 *istk(il+2) = 1;
00177
00178 *Lstk(Top+1) = sadr(il+3+nbstat);
00179
00180
00181 if (*Lstk(Top+1) >= *Lstk(Bot)) {
00182 Scierror(17,"macr2tree: stack size exceeded (Use stacksize function to increase it)\r\n");
00183
00184
00185 FREE(name[0]);
00186 name[0]=NULL;
00187 FREE(name);
00188 name=NULL;
00189 FREE(data);
00190
00191 return 0;
00192 }
00193
00194
00195 for(k=1;k<=nbstat;k++)
00196 {
00197 newinstr = 0;
00198 TopSave=Top;
00199 while(newinstr==0)
00200 {
00201 cod_sav=data[cod_ind];
00202 GetInstruction(data,&cod_ind,&nblines,&newinstr);
00203
00204
00205 if (Err>0 || C2F(errgst).err1>0)
00206 {
00207
00208 FREE(name[0]);
00209 name[0]=NULL;
00210 FREE(name);
00211 name=NULL;
00212 FREE(data);
00213
00214 return 0;
00215 }
00216 if(cod_sav==15 && data[cod_ind+1]==29)
00217 {
00218
00219
00220
00221 Top--;
00222 last_eol_pos=-10;
00223 newinstr=0;
00224 nbstat--;
00225 }
00226 else if(cod_sav==15 && Top!=TopSave+1)
00227 newinstr=0;
00228 else if(cod_sav==15)
00229 last_eol_pos=-10;
00230
00231 cod_ind++;
00232 if(cod_ind>codelength+ilt+1)
00233 {
00234 Scierror(999,"macr2tree: Out of code\r\n");
00235
00236
00237 FREE(name[0]);
00238 name[0]=NULL;
00239 FREE(name);
00240 name=NULL;
00241 FREE(data);
00242
00243 return 0;
00244 }
00245
00246 }
00247 if(TopSave!=Top-1) {
00248 Scierror(999,"macr2tree: wrong Top value %d instead of %d\r\n",Top,TopSave+1);
00249
00250
00251 FREE(name[0]);
00252 name[0]=NULL;
00253 FREE(name);
00254 name=NULL;
00255 FREE(data);
00256
00257 return 0;
00258 }
00259
00260 sz = *Lstk(Top+1) - *Lstk(Top);
00261
00262 *istk(il+2+k) = *istk(il+1+k) + sz ;
00263
00264 Top--;
00265
00266 *Lstk(Top+1) = *Lstk(Top+2);
00267 }
00268
00269
00270 C2F(itosci)(&nblines,&one,&one);
00271
00272 C2F(mktlist)(&n_pgrm_tlist);
00273
00274
00275 FREE(name[0]);
00276 name[0]=NULL;
00277 FREE(name);
00278 name=NULL;
00279 FREE(data);
00280
00281 return 0;
00282 }
00283
00284
00285
00286
00287 static int CreateVariableTList(char **varname)
00288 {
00289 char *variable_tlist[] = {"variable","name"};
00290 int m_variable_tlist = 1;
00291 int n_variable_tlist = 2;
00292
00293 int one = 1;
00294
00295
00296 str2sci(variable_tlist,m_variable_tlist,n_variable_tlist);
00297
00298
00299 str2sci(varname,one,one);
00300
00301
00302 C2F(mktlist)(&n_variable_tlist);
00303
00304
00305 AddVar(varname[0]);
00306
00307 return 0;
00308 }
00309
00310
00311
00312
00313 static int CreateEOLList(void)
00314 {
00315 char **eol;
00316
00317 int one = 1;
00318
00319
00320 if((eol=CALLOC(1,sizeof(char)))==NULL)
00321 {
00322 Scierror(999,"CreateEOLList: No more memory available\r\n");
00323 return 0;
00324 }
00325 if((eol[0]=(char *)CALLOC(1,sizeof(char)*(strlen("EOL")+1)))==NULL)
00326 {
00327 Scierror(999,"CreateEOLList: No more memory available\r\n");
00328 return 0;
00329 }
00330 (eol[0])[3]='\0';
00331 strncpy(eol[0],"EOL",3);
00332
00333
00334 str2sci(eol,one,one);
00335
00336
00337 C2F(mklist)(&one);
00338
00339
00340 FREE(eol[0]);
00341 eol[0]=NULL;
00342 FREE(eol);
00343 eol=NULL;
00344
00345 return 0;
00346 }
00347
00348
00349
00350
00351 static int AddVar(char *name)
00352 {
00353 if(IsDefinedVar(name)==-1)
00354 {
00355 strcpy(varnames[nbvars],name);
00356 nbvars++;
00357 }
00358 return 0;
00359 }
00360
00361
00362
00363
00364 static int IsDefinedVar(char *name)
00365 {
00366 int index2 = -1;
00367 int k;
00368 int maxlgth;
00369
00370 for(k=0;k<isizt;k++)
00371 {
00372 if(strlen(name)>=strlen(varnames[k]))
00373 {
00374 maxlgth=strlen(name);
00375 }
00376 else
00377 {
00378 maxlgth=strlen(varnames[k]);
00379 }
00380 if(varnames[k][0]=='\0')
00381 {
00382 index2 = -1;
00383 break;
00384 }
00385 else if(!strncmp(name,varnames[k],maxlgth))
00386 {
00387 index2 = k;
00388 break;
00389 }
00390 }
00391 return index2;
00392 }
00393
00394
00395
00396
00397 static int GetInstruction(int *data,int *index2,int *nblines,int *addinstr)
00398 {
00399 int job1 = 1;
00400
00401 char **name;
00402 int namelgth;
00403
00404 *addinstr=0;
00405
00406
00407 if((name=CALLOC(1,sizeof(char)))==NULL)
00408 {
00409 Scierror(999,"GetInstruction: No more memory available\r\n");
00410 return 0;
00411 }
00412 if((name[0]=(char *)CALLOC(1,sizeof(char)*(nlgh+1)))==NULL)
00413 {
00414 Scierror(999,"GetInstruction: No more memory available\r\n");
00415 return 0;
00416 }
00417 (name[0])[nlgh]='\0';
00418
00419 switch(data[*index2]) {
00420 case 0:
00421
00422 *index2 += data[*index2+1];
00423 break;
00424 case 1:
00425 CreateEqualTList("code1",data,index2);
00426 *addinstr=1;
00427 break;
00428 case 2:
00429
00430 CvNameL(&data[*index2+1],name[0],&job1,&namelgth);
00431 (name[0])[namelgth]='\0';
00432 *index2 += nsiz;
00433
00434 if(data[*index2+2]==0)
00435 {
00436 CreateVariableTList(name);
00437 *index2 += 2;
00438 }
00439 else
00440 {
00441 if( (IsDefinedVar(name[0])>=0) || ( (data[*index2+1]==-3) && (data[*index2+2]!=0) ) )
00442 {
00443
00444 CreateVariableTList(name);
00445 *index2 += 2;
00446 }
00447 else
00448 {
00449
00450 data[*index2+1] = data[*index2+2];
00451 if(data[*index2+3]==5 && data[*index2+4]==3)
00452
00453 {
00454 data[*index2+2] = data[*index2+6];
00455 CreateFuncallTList("macro",data,index2);
00456 *index2 += 4;
00457 }
00458 else
00459 {
00460 data[*index2+2] = 1;
00461 CreateFuncallTList("macro",data,index2);
00462 *index2 += 4;
00463 }
00464 }
00465 }
00466 break;
00467 case 3:
00468 CreateCsteTList("string",data,index2);
00469 break;
00470 case 4:
00471 CreateCsteTList("emptymatrix",data,index2);
00472 break;
00473 case 5:
00474 if(data[*index2+2]==0)
00475 {
00476 *index2 +=3;
00477 break;
00478 }
00479 CreateOperationTList(data,index2);
00480 break;
00481 case 6:
00482 CreateCsteTList("number",data,index2);
00483 break;
00484 case 7:
00485 GetControlInstruction(data,index2,nblines);
00486 *addinstr=1;
00487 break;
00488 case 8:
00489 GetControlInstruction(data,index2,nblines);
00490 *addinstr=1;
00491 break;
00492 case 9:
00493 GetControlInstruction(data,index2,nblines);
00494 *addinstr=1;
00495 break;
00496 case 10:
00497 GetControlInstruction(data,index2,nblines);
00498 *addinstr=1;
00499 break;
00500 case 11:
00501 GetControlInstruction(data,index2,nblines);
00502 *addinstr=1;
00503 break;
00504 case 12:
00505 case 13:
00506 case 14:
00507 CreateFuncallTList("datacode",data,index2);
00508 *addinstr=1;
00509 break;
00510 case 15:
00511 (*nblines)++;
00512 CreateEOLList();
00513 last_eol_pos = Top;
00514 *addinstr=1;
00515 break;
00516 case 16:
00517
00518 (*index2)++;
00519 break;
00520 case 17:
00521 CreateFuncallTList("datacode",data,index2);
00522 *addinstr=1;
00523 break;
00524 case 18:
00525 CreateEqualTList("code18",data,index2);
00526 break;
00527 case 19:
00528 CreateRecursiveIndex2List(data,index2);
00529 break;
00530 case 20:
00531 CreateFuncallTList("datacode",data,index2);
00532 *addinstr=1;
00533 break;
00534 case 21:
00535
00536
00537 break;
00538 case 22:
00539
00540 break;
00541 case 23:
00542 CreateCsteTList("code23",data,index2);
00543 break;
00544 case 24:
00545 Scierror(999,"GetInstruction: code %d not yet implemented\r\n",data[*index2]);
00546 break;
00547 case 25:
00548
00549 *index2 += 2;
00550 break;
00551 case 26:
00552 Scierror(999,"GetInstruction: code %d not yet implemented\r\n",data[*index2]);
00553 break;
00554 case 27:
00555 Scierror(999,"GetInstruction: code %d not yet implemented\r\n",data[*index2]);
00556 break;
00557 case 28:
00558 CreateFuncallTList("datacode",data,index2);
00559 *addinstr=1;
00560 break;
00561 case 29:
00562 CreateEqualTList("code29",data,index2);
00563 *addinstr=1;
00564 break;
00565 case 30:
00566
00567 *index2 += 2;
00568 break;
00569 case 31:
00570 CreateCommentTList(data,index2);
00571 *addinstr=1;
00572 break;
00573
00574 case 99:
00575 CreateFuncallTList("datacode",data,index2);
00576 *addinstr=1;
00577 break;
00578 default:
00579 if(data[*index2]/100*100==data[*index2] && data[*index2]!=0)
00580 {
00581
00582 CreateFuncallTList("funptr",data,index2);
00583 }
00584 else
00585 {
00586 Scierror(999,"GetInstruction: unknown code %d at index2 %d \r\n",data[*index2],*index2 );
00587 return 0;
00588 }
00589 break;
00590 }
00591
00592
00593 FREE(name[0]);
00594 name[0]=NULL;
00595 FREE(name);
00596 name=NULL;
00597
00598 return 0;
00599 }
00600
00601
00602
00603
00604 static int GetControlInstruction(int *data,int *index2,int *nblines)
00605 {
00606
00607 char *trycatch_tlist[] = {"trycatch","trystat","catchstat"};
00608 int m_trycatch_tlist = 1;
00609 int n_trycatch_tlist = 3;
00610
00611
00612 char *if_tlist[] = {"ifthenelse","expression","then","elseifs","else"};
00613 int m_if_tlist = 1;
00614 int n_if_tlist = 5;
00615
00616 char *elseif_tlist[] = {"elseif","expression","then"};
00617 int m_elseif_tlist = 1;
00618 int n_elseif_tlist = 3;
00619
00620
00621 char *while_tlist[] = {"while","expression","statements"};
00622 int m_while_tlist = 1;
00623 int n_while_tlist = 3;
00624
00625
00626 char *select_tlist[] = {"selectcase","expression","cases","else"};
00627 int m_select_tlist = 1;
00628 int n_select_tlist = 4;
00629
00630 char *case_tlist[] = {"case","expression","then"};
00631 int m_case_tlist = 1;
00632 int n_case_tlist = 3;
00633
00634
00635 char *for_tlist[] = {"for","expression","statements"};
00636 int m_for_tlist = 1;
00637 int n_for_tlist = 3;
00638 char **name;
00639 int namelgth = 0;
00640
00641 int job1=1;
00642 int index20,endindex2;
00643 int codelgth;
00644 int ncase = 0,icase = 0;
00645 int TopSave = 0,TopSave_elseifsorcases=0;
00646 int nbinstr = 0;
00647 int nbelseifsorcases = 0;
00648
00649 int newinstr=0;
00650
00651
00652 if(data[*index2]==7)
00653 {
00654
00655 str2sci(for_tlist,m_for_tlist,n_for_tlist);
00656 (*index2)++;
00657 codelgth = data[*index2];
00658 endindex2 = *index2 + codelgth;
00659 (*index2)++;
00660
00661
00662 while(*index2<=endindex2)
00663 {
00664 GetInstruction(data,index2,nblines,&newinstr);
00665 (*index2)++;
00666 }
00667
00668 codelgth = data[*index2];
00669 (*index2)++;
00670
00671
00672
00673 if((name=CALLOC(1,sizeof(char)))==NULL)
00674 {
00675 Scierror(999,"GetControlInstruction: No more memory available\r\n");
00676 return 0;
00677 }
00678 if((name[0]=(char *)CALLOC(1,sizeof(char)*(nlgh+1)))==NULL)
00679 {
00680 Scierror(999,"GetControlInstruction: No more memory available\r\n");
00681 return 0;
00682 }
00683 (name[0])[nlgh]='\0';
00684
00685 CvNameL(&data[*index2],name[0],&job1,&namelgth);
00686 (name[0])[namelgth]='\0';
00687 *index2 += nsiz;
00688
00689 CreateVariableTList(name);
00690
00691
00692 CreateEqualTList("forexpr",data,index2);
00693 endindex2 = *index2 + codelgth;
00694
00695
00696 TopSave = Top;
00697 while(*index2<=endindex2)
00698 {
00699
00700 GetInstruction(data,index2,nblines,&newinstr);
00701 (*index2)++;
00702 }
00703 (*index2)--;
00704
00705 nbinstr = Top - TopSave;
00706 C2F(mklist)(&nbinstr);
00707
00708
00709 C2F(mktlist)(&n_for_tlist);
00710
00711
00712 FREE(name[0]);
00713 name[0]=NULL;
00714 FREE(name);
00715 name=NULL;
00716 }
00717
00718 else if(data[*index2]==11)
00719 {
00720 index20 = *index2;
00721
00722 str2sci(trycatch_tlist,m_trycatch_tlist,n_trycatch_tlist);
00723
00724
00725 *index2 += 3;
00726
00727 codelgth = data[index20+1];
00728 endindex2 = *index2 + codelgth - 1;
00729
00730 TopSave = Top;
00731
00732 while(*index2<=endindex2)
00733 {
00734 GetInstruction(data,index2,nblines,&newinstr);
00735 (*index2)++;
00736 }
00737
00738 nbinstr = Top - TopSave;
00739
00740
00741 C2F(mklist)(&nbinstr);
00742 last_eol_pos = -10;
00743
00744 codelgth = data[index20+2];
00745 endindex2 = *index2 + codelgth - 1;
00746
00747 TopSave = Top;
00748
00749 while(*index2<=endindex2)
00750 {
00751 GetInstruction(data,index2,nblines,&newinstr);
00752 (*index2)++;
00753 }
00754
00755 nbinstr = Top - TopSave;
00756
00757
00758 C2F(mklist)(&nbinstr);
00759
00760 (*index2)--;
00761
00762
00763 C2F(mktlist)(&n_trycatch_tlist);
00764 }
00765
00766 else
00767 {
00768 index20 = *index2;
00769
00770
00771 if( (data[*index2]==8 || data[*index2]==9) && data[*index2+1]>=0 )
00772 {
00773
00774
00775 Scierror(999,"GetControlInstruction: old version of if and while not yet implemented\r\n");
00776 return 0;
00777 }
00778 else
00779 {
00780 ncase = data[index20+2];
00781
00782
00783 if(data[index20]==8)
00784 {
00785 str2sci(if_tlist,m_if_tlist,n_if_tlist);
00786 }
00787 else if(data[index20]==9)
00788 {
00789 str2sci(while_tlist,m_while_tlist,n_while_tlist);
00790 }
00791 else if(data[index20]==10)
00792 {
00793 str2sci(select_tlist,m_select_tlist,n_select_tlist);
00794 }
00795
00796
00797 *index2 += 4;
00798
00799 codelgth = data[index20+3];
00800 endindex2 = *index2 + codelgth - 1;
00801
00802 icase = ncase + 1;
00803
00804
00805 if(data[index20]==10)
00806 {
00807 TopSave = Top;
00808 while(*index2<=endindex2)
00809 {
00810 GetInstruction(data,index2,nblines,&newinstr);
00811 (*index2)++;
00812 }
00813
00814 nbinstr = Top - TopSave;
00815
00816 C2F(mklist)(&nbinstr);
00817 last_eol_pos = -10;
00818 }
00819
00820
00821
00822
00823
00824 while(icase > 1)
00825 {
00826 icase = icase - 1;
00827
00828
00829 if(icase==ncase && data[index20]==10)
00830 TopSave_elseifsorcases = Top;
00831
00832 if(icase<ncase && data[index20]==8)
00833 {
00834
00835 str2sci(elseif_tlist,m_elseif_tlist,n_elseif_tlist);
00836 }
00837
00838 if(data[index20]==10)
00839 {
00840
00841 str2sci(case_tlist,m_case_tlist,n_case_tlist);
00842 }
00843
00844 codelgth = data[*index2];
00845 (*index2)++;
00846 endindex2 = *index2 + codelgth - 1;
00847
00848
00849 while(*index2<=endindex2)
00850 {
00851 GetInstruction(data,index2,nblines,&newinstr);
00852 (*index2)++;
00853 }
00854 last_eol_pos = -10;
00855 codelgth = data[*index2];
00856 (*index2)++;
00857 endindex2 = *index2 + codelgth - 1;
00858
00859
00860 TopSave = Top;
00861 while(*index2<=endindex2)
00862 {
00863 GetInstruction(data,index2,nblines,&newinstr);
00864 (*index2)++;
00865 }
00866 nbinstr = Top - TopSave;
00867
00868 C2F(mklist)(&nbinstr);
00869
00870 if(icase<ncase && data[index20]==8)
00871 {
00872
00873 C2F(mktlist)(&n_elseif_tlist);
00874 }
00875
00876 if(data[index20]==10)
00877 {
00878
00879 C2F(mktlist)(&n_case_tlist);
00880 }
00881
00882
00883 if(icase==ncase && data[index20]==8)
00884 TopSave_elseifsorcases = Top;
00885 }
00886
00887 nbelseifsorcases = Top - TopSave_elseifsorcases;
00888
00889
00890
00891 if(data[index20]==8 || data[index20]==10)
00892 C2F(mklist)(&nbelseifsorcases);
00893
00894
00895 (*index2)++;
00896 codelgth = data[*index2];
00897 (*index2)++;
00898
00899 if(codelgth==0)
00900 (*index2)++;
00901
00902 endindex2 = *index2 + codelgth - 1;
00903
00904
00905 TopSave = Top;
00906 while(*index2<=endindex2)
00907 {
00908 GetInstruction(data,index2,nblines,&newinstr);
00909 (*index2)++;
00910 }
00911 nbinstr = Top - TopSave;
00912
00913 if(data[index20]==8 || data[index20]==10)
00914 C2F(mklist)(&nbinstr);
00915
00916 (*index2)--;
00917
00918 if(data[index20]==8)
00919 {
00920
00921 C2F(mktlist)(&n_if_tlist);
00922 }
00923 else if(data[index20]==9)
00924 {
00925
00926 C2F(mktlist)(&n_while_tlist);
00927 }
00928 else if(data[index20]==10)
00929 {
00930
00931 C2F(mktlist)(&n_select_tlist);
00932 }
00933 }
00934 }
00935 return 0;
00936 }
00937
00938
00939
00940
00941 static int CreateCsteTList(char *type,int *data,int *index2)
00942 {
00943 char *cste_tlist[] = {"cste","value"};
00944 int m_cste_tlist = 1;
00945 int n_cste_tlist = 2;
00946
00947
00948 int littlendian = 1;
00949 char *endptr;
00950
00951
00952 double l_mat = 0;
00953 int m_mat = 0;
00954 int n_mat = 0;
00955
00956
00957 char **str;
00958 int *int_str;
00959 int strlgth = 0;
00960 int job1 = 1;
00961 int one = 1;
00962
00963
00964 double *value;
00965 int *ivalue;
00966 int i = 0;
00967
00968
00969 str2sci(cste_tlist,m_cste_tlist,n_cste_tlist);
00970
00971
00972 if(!strncmp(type,"emptymatrix",11))
00973 {
00974 C2F(dtosci)(&l_mat,&m_mat,&n_mat);
00975 }
00976 else if(!strncmp(type,"string",6))
00977 {
00978 (*index2)++;
00979 strlgth = data[*index2];
00980
00981
00982 if((str=CALLOC(1,sizeof(char)))==NULL)
00983 {
00984 Scierror(999,"CreateCsteTList: No more memory available\r\n");
00985 return 0;
00986 }
00987 if((str[0]=(char *)CALLOC(1,sizeof(char)*(strlgth+1)))==NULL)
00988 {
00989 Scierror(999,"CreateCsteTList: No more memory available\r\n");
00990 return 0;
00991 }
00992 if((int_str=(int *)CALLOC(1,sizeof(int)*(strlgth+1)))==NULL)
00993 {
00994 Scierror(999,"CreateCsteTList: No more memory available\r\n");
00995 return 0;
00996 }
00997
00998 for(i=0;i<strlgth;i++)
00999 {
01000 *index2=*index2 + 1;
01001 int_str[i]=data[*index2];
01002 }
01003 CvStr(&strlgth,int_str,str[0],&job1,strlgth);
01004 (str[0])[strlgth]='\0';
01005 str2sci(str,one,one);
01006
01007
01008 FREE(str[0]);
01009 str[0]=NULL;
01010 FREE(str);
01011 str=NULL;
01012 FREE(int_str);
01013 int_str=NULL;
01014 }
01015
01016 else if(!strncmp(type,"code23",5))
01017 {
01018 strlgth=nlgh;
01019
01020 if((str=CALLOC(1,sizeof(char)))==NULL)
01021 {
01022 Scierror(999,"CreateCsteTList: No more memory available\r\n");
01023 return 0;
01024 }
01025 if((str[0]=(char *)CALLOC(1,sizeof(char)*(strlgth+1)))==NULL)
01026 {
01027 Scierror(999,"CreateCsteTList: No more memory available\r\n");
01028 return 0;
01029 }
01030
01031
01032 CvNameL(&data[*index2+1],str[0],&job1,&strlgth);
01033 (str[0])[strlgth]='\0';
01034 *index2 += nsiz;
01035
01036
01037 str2sci(str,one,one);
01038
01039
01040 FREE(str[0]);
01041 str[0]=NULL;
01042 FREE(str);
01043 str=NULL;
01044 }
01045 else if(!strncmp(type,"number",6))
01046 {
01047
01048 if((value=(double *)CALLOC(1,sizeof(double)))==NULL)
01049 {
01050 Scierror(999,"CreateCsteTList: No more memory available\r\n");
01051 return 0;
01052 }
01053 ivalue = (int*) value;
01054
01055
01056 endptr = (char *) &littlendian;
01057 littlendian = (int) *endptr;
01058
01059
01060 if(littlendian==1)
01061 {
01062 *index2 = *index2 +1;
01063 *ivalue = data[*index2];
01064 *index2 = *index2 +1;
01065 *(ivalue+1) = data[*index2];
01066 }
01067 else
01068 {
01069 *index2 = *index2 + 1;
01070 *(ivalue+1) = data[*index2];
01071 *index2 = *index2 + 1;
01072 *ivalue = data[*index2];
01073 }
01074
01075 C2F(dtosci)(value,&one,&one);
01076
01077
01078 FREE(value);
01079 value=NULL;
01080 }
01081 else
01082 {
01083 Scierror(999,"CreateCsteTList: wrong type value %s\r\n",type);
01084 return 0;
01085 }
01086
01087
01088 C2F(mktlist)(&n_cste_tlist);
01089
01090 return 0;
01091 }
01092
01093
01094
01095
01096 static int CreateOperationTList(int *data,int *index2)
01097 {
01098 char *op_tlist[] = {"operation","operands","operator"};
01099 int m_op_tlist = 1;
01100 int n_op_tlist = 3;
01101
01102
01103 char *operators[]={"+","-","*",".*","*.",".*.","/","./","/.","./.",
01104 "\\",".\\","\\.",".\\.","^","==","<",">","<=",">=","~=",
01105 ":","rc","ins","ext","'","cc","|","&","~",".^",".'","cceol"};
01106
01107
01108 char **operator;
01109 int max_op_lgth = 5;
01110
01111 int operators_num[32]={45,46,47,98,200,149,48,99,201,150,
01112 49,100,202,151,62,50,59,60,109,110,119,
01113 44,1,2,3,53,4,57,58,61,113,104};
01114
01115 int operator_num,operator_index2=-1,nb_operands,nb_lhs;
01116
01117 int k;
01118
01119 int orig,dest;
01120
01121 int offset = 0;
01122
01123 int one = 1;
01124
01125
01126 if((operator=CALLOC(1,sizeof(char)))==NULL)
01127 {
01128 Scierror(999,"CreateOperationTList: No more memory available\r\n");
01129 return 0;
01130 }
01131 if((operator[0]=(char *)CALLOC(1,sizeof(char)*max_op_lgth+1))==NULL)
01132 {
01133 Scierror(999,"CreateOperationTList: No more memory available\r\n");
01134 return 0;
01135 }
01136 (operator[0])[max_op_lgth] = '\0';
01137
01138
01139 (*index2)++;
01140 operator_num = data[*index2];
01141 (*index2)++;
01142 nb_operands = data[*index2];
01143 (*index2)++;
01144 nb_lhs = data[*index2];
01145
01146
01147 str2sci(op_tlist,m_op_tlist,n_op_tlist);
01148
01149
01150 for(k=0;k<32;k++)
01151 {
01152 if(operators_num[k]==operator_num)
01153 {
01154 operator_index2=k;
01155 break;
01156 }
01157 }
01158 if(operator_index2<0) {
01159 Scierror(999,"CreateOperationTList: unknown operator %d\r\n",operator_num);
01160 return 0;
01161 }
01162
01163
01164
01165
01166
01167 if( (operator_index2==26) && (last_eol_pos==Top-2) )
01168 {
01169
01170 operator_index2 = 32;
01171
01172
01173 orig = last_eol_pos - 1;
01174 dest = Top + 1;
01175 VCopyObj("CreateOperationTList",&orig,&dest,20L);
01176
01177
01178 orig = last_eol_pos + 1;
01179 dest = Top + 1;
01180 VCopyObj("CreateOperationTList",&orig,&dest,20L);
01181 offset = 1;
01182 }
01183 else if(operator_index2==24)
01184 {
01185
01186 orig = Top - 1;
01187 dest = Top + 1;
01188 VCopyObj("CreateOperationTList",&orig,&dest,20L);
01189
01190
01191 for(k=nb_operands;k>1;k--)
01192 {
01193 orig = Top - nb_operands - 1;
01194 dest = Top + 1;
01195 VCopyObj("CreateOperationTList",&orig,&dest,20L);
01196 }
01197
01198 }
01199 else
01200 {
01201 for(k=nb_operands;k>0;k--)
01202 {
01203 orig = Top - nb_operands;
01204 dest = Top + 1;
01205 VCopyObj("CreateOperationTList",&orig,&dest,20L);
01206 }
01207 }
01208
01209
01210 C2F(mklist)(&nb_operands);
01211
01212
01213 strcpy(operator[0],operators[operator_index2]);
01214 (operator[0])[strlen(operators[operator_index2])]='\0';
01215 str2sci(operator,one,one);
01216
01217
01218 C2F(mktlist)(&n_op_tlist);
01219
01220
01221 orig = Top;
01222 dest = Top - nb_operands - offset;
01223 VCopyObj("CreateOperationTList",&orig,&dest,20L);
01224
01225 return 0;
01226 }
01227
01228
01229
01230
01231 static int CreateFuncallTList(char *fromwhat,int *data,int *index2)
01232 {
01233 char *fun_tlist[] = {"funcall","rhs","name","lhsnb"};
01234 int m_fun_tlist = 1;
01235 int n_fun_tlist = 4;
01236
01237
01238 int interf_num,interf_index2,funptr;
01239 int job1 = 1,job2 = 2;
01240 int id[nsiz];
01241
01242 double nblhs = 0;
01243 int nbrhs = 0;
01244
01245 char **funname;
01246 int funnamelgth = 0;
01247
01248 int one = 1;
01249
01250 int orig,dest;
01251
01252
01253 double l_mat = 0;
01254 int m_mat = 0;
01255 int n_mat = 0;
01256
01257
01258 if((funname=CALLOC(1,sizeof(char)))==NULL)
01259 {
01260 Scierror(999,"CreateFuncallTList: No more memory available\r\n");
01261 return 0;
01262 }
01263 if((funname[0]=(char *)CALLOC(1,sizeof(char)*(nlgh+1)))==NULL)
01264 {
01265 Scierror(999,"CreateFuncallTList: No more memory available\r\n");
01266 return 0;
01267 }
01268 (funname[0])[nlgh]='\0';
01269
01270 if(!strncmp(fromwhat,"funptr",6))
01271 {
01272 interf_num = data[*index2];
01273 (*index2)++;
01274 nbrhs = data[*index2];
01275 (*index2)++;
01276 nblhs = data[*index2];
01277 (*index2)++;
01278 interf_index2 = data[*index2];
01279
01280 funptr = interf_num + interf_index2;
01281
01282 C2F(funtab)(id,&funptr,&job2,"NULL_NAME",0);
01283
01284 CvNameL(id,funname[0],&job1,&funnamelgth);
01285 (funname[0])[funnamelgth]='\0';
01286 }
01287 else if(!strncmp(fromwhat,"datacode",8))
01288 {
01289 if(data[*index2]==12)
01290 {
01291 strncpy(funname[0],"pause",5);
01292 funnamelgth = 5;
01293 }
01294 else if(data[*index2]==13)
01295 {
01296 strncpy(funname[0],"break",5);
01297 funnamelgth = 5;
01298 }
01299 else if(data[*index2]==14)
01300 {
01301 strncpy(funname[0],"abort",5);
01302 funnamelgth = 5;
01303 }
01304 else if(data[*index2]==17)
01305 {
01306 strncpy(funname[0],"quit",4);
01307 funnamelgth = 4;
01308 }
01309 else if(data[*index2]==20)
01310 {
01311 strncpy(funname[0],"exit",4);
01312 funnamelgth = 4;
01313 }
01314 else if(data[*index2]==28)
01315 {
01316 strncpy(funname[0],"continue",8);
01317 funnamelgth = 8;
01318 }
01319 else if(data[*index2]==99)
01320 {
01321 strncpy(funname[0],"return",6);
01322 funnamelgth = 6;
01323 }
01324 }
01325 else if(!strncmp(fromwhat,"macro",5))
01326 {
01327 CvNameL(&data[*index2-nsiz+1],funname[0],&job1,&funnamelgth);
01328 (funname[0])[funnamelgth]='\0';
01329
01330 (*index2)++;
01331 nbrhs = data[*index2];
01332 (*index2)++;
01333 nblhs = data[*index2];
01334 }
01335 else
01336 {
01337 Scierror(999,"CreateFuncallTList: wrong fromwhat value %s\r\n",fromwhat);
01338 return 0;
01339 }
01340
01341
01342
01343 if(nbrhs==0)
01344 {
01345
01346 C2F(dtosci)(&l_mat,&m_mat,&n_mat);
01347 }
01348 else
01349 {
01350
01351
01352 if(nbrhs<0)
01353 nbrhs=0;
01354
01355 C2F(mklist)(&nbrhs);
01356 }
01357
01358
01359 str2sci(fun_tlist,m_fun_tlist,n_fun_tlist);
01360
01361
01362 orig = Top - 1;
01363 dest = Top + 1;
01364 VCopyObj("CreateFuncallTList",&orig,&dest,18L);
01365
01366
01367 str2sci(funname,one,one);
01368
01369
01370 C2F(dtosci)(&nblhs,&one,&one);
01371
01372
01373 C2F(mktlist)(&n_fun_tlist);
01374
01375
01376 orig = Top;
01377 dest = Top - 1;
01378 VCopyObj("CreateFuncallTList",&orig,&dest,18L);
01379
01380
01381 FREE(funname[0]);
01382 funname[0]=NULL;
01383 FREE(funname);
01384 funname=NULL;
01385
01386 return 0;
01387 }
01388
01389
01390
01391
01392 static int CreateEqualTList(char *fromwhat,int *data,int *index2)
01393 {
01394 char *eq_tlist[] = {"equal","expression","lhs","endsymbol"};
01395 int m_eq_tlist = 1;
01396 int n_eq_tlist = 4;
01397
01398 int nblhs = 0,nbrhs = 0;
01399
01400 int k = 0,l = 0;
01401
01402 int job1 = 1;
01403
01404 int orig,dest;
01405
01406 char **name;
01407 int namelgth = 0;
01408
01409
01410 int index2es_pos;
01411 int nb_index2es = 0;
01412 char *op_tlist[] = {"operation","operands","operator"};
01413 int m_op_tlist = 1;
01414 int n_op_tlist = 3;
01415
01416 char **operator;
01417
01418 int one = 1;
01419
01420 char **endsymbol;
01421 int symbol = 0;
01422
01423
01424 if((name=CALLOC(1,sizeof(char)))==NULL)
01425 {
01426 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01427 return 0;
01428 }
01429 if((name[0]=(char *)CALLOC(1,sizeof(char)*(nlgh+1)))==NULL)
01430 {
01431 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01432 return 0;
01433 }
01434 (name[0])[nlgh] = '\0';
01435
01436 if((operator=CALLOC(1,sizeof(char)))==NULL)
01437 {
01438 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01439 return 0;
01440 }
01441 if((operator[0]=(char *)CALLOC(1,sizeof(char)*4))==NULL)
01442 {
01443 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01444 return 0;
01445 }
01446 strcpy(operator[0],"ins");
01447 (operator[0])[3] = '\0';
01448
01449
01450 str2sci(eq_tlist,m_eq_tlist,n_eq_tlist);
01451
01452 if(!strncmp(fromwhat,"code29",6))
01453 {
01454
01455 orig = Top - 1;
01456 dest = Top + 1;
01457 VCopyObj("CreateEqualTList",&orig,&dest,16L);
01458
01459 index2es_pos = Top - 3;
01460
01461
01462 (*index2)++;
01463 nblhs = data[*index2];
01464 (*index2)++;
01465
01466
01467 symbol=data[*index2];
01468 if(symbol==43)
01469 {
01470 if((endsymbol=CALLOC(1,sizeof(char)))==NULL)
01471 {
01472 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01473 return 0;
01474 }
01475 if((endsymbol[0]=(char *)CALLOC(1,sizeof(char)*2))==NULL)
01476 {
01477 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01478 return 0;
01479 }
01480 strcpy(endsymbol[0],";");
01481 (endsymbol[0])[1] = '\0';
01482 }
01483 else if(symbol==52)
01484 {
01485 if((endsymbol=CALLOC(1,sizeof(char)))==NULL)
01486 {
01487 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01488 return 0;
01489 }
01490 if((endsymbol[0]=(char *)CALLOC(1,sizeof(char)*2))==NULL)
01491 {
01492 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01493 return 0;
01494 }
01495 strcpy(endsymbol[0],",");
01496 (endsymbol[0])[1] = '\0';
01497 }
01498 else
01499 {
01500 if((endsymbol=CALLOC(1,sizeof(char)))==NULL)
01501 {
01502 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01503 return 0;
01504 }
01505 if((endsymbol[0]=(char *)CALLOC(1,sizeof(char)*1))==NULL)
01506 {
01507 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01508 return 0;
01509 }
01510 (endsymbol[0])[0] = '\0';
01511 }
01512 for(k=0;k<nblhs;k++)
01513 {
01514 (*index2)++;
01515 CvNameL(&data[*index2],name[0],&job1,&namelgth);
01516 (name[0])[namelgth] = '\0';
01517 *index2 = *index2 + nsiz;
01518 nbrhs = data[*index2];
01519 nb_index2es = nbrhs + nb_index2es;
01520
01521 if(nbrhs==0)
01522 {
01523 CreateVariableTList(name);
01524 }
01525 else
01526 {
01527
01528 str2sci(op_tlist,m_op_tlist,n_op_tlist);
01529
01530
01531 CreateVariableTList(name);
01532
01533
01534 for(l=0;l<nbrhs;l++)
01535 {
01536 orig = index2es_pos - nbrhs + l + 1;
01537 dest = Top + 1;
01538 VCopyObj("CreateEqualTList",&orig,&dest,16L);
01539 }
01540 index2es_pos = index2es_pos - nbrhs;
01541
01542
01543 nbrhs = nbrhs + 1;
01544 C2F(mklist)(&nbrhs);
01545
01546
01547 str2sci(operator,one,one);
01548
01549
01550 C2F(mktlist)(&n_op_tlist);
01551 }
01552 }
01553
01554 for(k=0;k<nblhs;k++)
01555 {
01556 orig = Top - 2 * k;
01557 dest = Top + 1;
01558 VCopyObj("CreateEqualTList",&orig,&dest,16L);
01559 }
01560
01561
01562 C2F(mklist)(&nblhs);
01563
01564
01565 orig = Top;
01566 dest = Top - nblhs;
01567 VCopyObj("CreateEqualTList",&orig,&dest,16L);
01568
01569
01570 str2sci(endsymbol,one,one);
01571
01572
01573 C2F(mktlist)(&n_eq_tlist);
01574
01575
01576 orig = Top;
01577 dest = Top - nb_index2es - 1;
01578 VCopyObj("CreateEqualTList",&orig,&dest,16L);
01579 }
01580 else if(!strncmp(fromwhat,"code18",6))
01581 {
01582
01583 orig = Top - 1;
01584 dest = Top + 1;
01585 VCopyObj("CreateEqualTList",&orig,&dest,16L);
01586
01587 (*index2)++;
01588 nblhs++;
01589 CvNameL(&data[*index2],name[0],&job1,&namelgth);
01590 (name[0])[namelgth]='\0';
01591 CreateVariableTList(name);
01592 *index2 = *index2 + nsiz;
01593 *index2 = *index2 - 1;
01594
01595
01596 C2F(mklist)(&nblhs);
01597
01598
01599 if((endsymbol=CALLOC(1,sizeof(char)))==NULL)
01600 {
01601 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01602 return 0;
01603 }
01604 if((endsymbol[0]=(char *)CALLOC(1,sizeof(char)*1))==NULL)
01605 {
01606 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01607 return 0;
01608 }
01609 (endsymbol[0])[0] = '\0';
01610 str2sci(endsymbol,one,one);
01611
01612
01613 C2F(mktlist)(&n_eq_tlist);
01614
01615
01616 orig = Top;
01617 dest = Top - 1;
01618 VCopyObj("CreateEqualTList",&orig,&dest,16L);
01619 }
01620 else if(!strncmp(fromwhat,"code1",5))
01621 {
01622
01623 orig = Top - 1;
01624 dest = Top + 1;
01625 VCopyObj("CreateEqualTList",&orig,&dest,16L);
01626
01627 while(data[*index2]==1)
01628 {
01629 (*index2)++;
01630 nblhs++;
01631 CvNameL(&data[*index2],name[0],&job1,&namelgth);
01632 (name[0])[namelgth]='\0';
01633 CreateVariableTList(name);
01634 *index2 = *index2 + nsiz;
01635 (*index2)++;
01636 (*index2)++;
01637 }
01638
01639 C2F(mklist)(&nblhs);
01640
01641
01642 if((endsymbol=CALLOC(1,sizeof(char)))==NULL)
01643 {
01644 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01645 return 0;
01646 }
01647 if((endsymbol[0]=(char *)CALLOC(1,sizeof(char)*1))==NULL)
01648 {
01649 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01650 return 0;
01651 }
01652 (endsymbol[0])[0] = '\0';
01653 str2sci(endsymbol,one,one);
01654
01655
01656 C2F(mktlist)(&n_eq_tlist);
01657 }
01658 else if(!strncmp(fromwhat,"forexpr",7))
01659 {
01660
01661 orig = Top - 2;
01662 dest = Top + 1;
01663 VCopyObj("CreateEqualTList",&orig,&dest,16L);
01664
01665
01666 orig = Top - 2;
01667 dest = Top + 1;
01668 VCopyObj("CreateEqualTList",&orig,&dest,16L);
01669
01670 nblhs = 1;
01671
01672 C2F(mklist)(&nblhs);
01673
01674
01675 if((endsymbol=CALLOC(1,sizeof(char)))==NULL)
01676 {
01677 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01678 return 0;
01679 }
01680 if((endsymbol[0]=(char *)CALLOC(1,sizeof(char)*1))==NULL)
01681 {
01682 Scierror(999,"CreateEqualTList: No more memory available\r\n");
01683 return 0;
01684 }
01685 (endsymbol[0])[0] = '\0';
01686 str2sci(endsymbol,one,one);
01687
01688
01689 C2F(mktlist)(&n_eq_tlist);
01690
01691
01692 dest = Top - 2;
01693 orig = Top;
01694 VCopyObj("CreateEqualTList",&orig,&dest,16L);
01695 }
01696 else
01697 {
01698 Scierror(999,"CreateEqualTList: wrong fromwhat value %s\r\n",fromwhat);
01699 return 0;
01700 }
01701
01702
01703 FREE(name[0]);
01704 name[0]=NULL;
01705 FREE(name);
01706 name=NULL;
01707 FREE(operator[0]);
01708 operator[0]=NULL;
01709 FREE(operator);
01710 operator=NULL;
01711 FREE(endsymbol[0]);
01712 endsymbol[0]=NULL;
01713 FREE(endsymbol);
01714 endsymbol=0;
01715
01716 return 0;
01717 }
01718
01719
01720
01721 static int CreateCommentTList(int *data,int *index2)
01722 {
01723 char *fun_tlist[] = {"comment","text"};
01724 int m_fun_tlist = 1;
01725 int n_fun_tlist = 2;
01726
01727 int strlgth;
01728
01729 char *text=NULL;
01730 int job1 = 1;
01731
01732 int one = 1;
01733
01734
01735 str2sci(fun_tlist,m_fun_tlist,n_fun_tlist);
01736
01737
01738 (*index2)++;
01739 strlgth = data[*index2];
01740 (*index2)++;
01741
01742 if((text=(char *)CALLOC(1,sizeof(char)*(strlgth+1)))==NULL)
01743 {
01744 Scierror(999,"CreateCsteTList: No more memory available\r\n");
01745 return 0;
01746 }
01747 CvStr(&strlgth,&(data[*index2]),text,&job1,strlgth);
01748 text[strlgth]='\0';
01749 str2sci(&text,one,one);
01750 *index2 = *index2 + strlgth-1;
01751
01752 FREE(text);
01753 text=NULL;
01754
01755 C2F(mktlist)(&n_fun_tlist);
01756 return 0;
01757 }
01758
01759
01760
01761
01762 static int CreateRecursiveIndex2List(int *data,int *index2)
01763 {
01764 int m,n;
01765
01766
01767 (*index2)++;
01768 n = data[*index2];
01769 (*index2)++;
01770 m = data[*index2];
01771
01772 if(m>1)
01773 {
01774 C2F(mklist)(&m);
01775 }
01776 if(n!=0)
01777 {
01778 C2F(mklist)(&n);
01779 }
01780
01781 return 0;
01782 }
01783
01784
01785
01786
01787
01788
01789
01790
01791
01792 static int VCopyObj(char *fname,int *orig,int *dest,unsigned long fname_length)
01793 {
01794 C2F(vcopyobj)(fname,orig,dest,fname_length);
01795 Top = *dest;
01796 return 0;
01797 }
01798
01799
01800
01801
01802 int complexity(int *data,int *index2,int *lgth)
01803 {
01804 int count = 0;
01805
01806 int cur_ind = *index2+1;
01807
01808 int last_eol=0;
01809
01810 int nbop = 0;
01811
01812 while(cur_ind<=*lgth+*index2)
01813 {
01814 switch(data[cur_ind])
01815 {
01816 case 0:
01817 cur_ind = cur_ind + data[cur_ind+1] + 1;
01818 break;
01819 case 1:
01820 cur_ind = cur_ind + nsiz + 1;
01821 count++;
01822 break;
01823 case 2:
01824 cur_ind = cur_ind + nsiz + 3;
01825 nbop++;
01826 break;
01827 case 3:
01828 cur_ind = cur_ind + 2 + data[cur_ind+1];
01829 nbop++;
01830 break;
01831 case 4:
01832 cur_ind++;
01833 nbop++;
01834 break;
01835 case 5:
01836 if( (data[cur_ind+1]==4) && (last_eol==nbop-2) )
01837 {
01838 nbop--;
01839 count--;
01840 }
01841 nbop = nbop - data[cur_ind+2];
01842 cur_ind = cur_ind + 4;
01843 nbop++;
01844 break;
01845 case 6:
01846 cur_ind = cur_ind + 3;
01847 nbop++;
01848 break;
01849 case 7:
01850 cur_ind = cur_ind + data[cur_ind+1] + 2;
01851 cur_ind = cur_ind + 1 + nsiz + data[cur_ind];
01852 count++;
01853 break;
01854 case 8:
01855 if(data[cur_ind+1]>0)
01856 {
01857 cur_ind = cur_ind + 2;
01858 cur_ind = cur_ind + 3 + data[cur_ind] + data[cur_ind+1] + data[cur_ind+2];
01859 }
01860 else
01861 {
01862 cur_ind = cur_ind - data[cur_ind+1];
01863 }
01864 count++;
01865 break;
01866 case 9:
01867 if(data[cur_ind+1]>0)
01868 {
01869 cur_ind = cur_ind + 2;
01870 cur_ind = cur_ind + 3 + data[cur_ind] + data[cur_ind+1] + data[cur_ind+2];
01871 }
01872 else
01873 {
01874 cur_ind = cur_ind - data[cur_ind+1];
01875 }
01876 count++;
01877 break;
01878 case 10:
01879 cur_ind = cur_ind + data[cur_ind+1];
01880 count++;
01881 break;
01882 case 11:
01883 cur_ind = cur_ind + data[cur_ind+1] + data[cur_ind+2] + 3;
01884 count++;
01885 break;
01886 case 12:
01887 cur_ind++;
01888 count++;
01889 break;
01890 case 13:
01891 cur_ind++;
01892 count++;
01893 break;
01894 case 14:
01895 cur_ind++;
01896 count++;
01897 break;
01898 case 15:
01899 cur_ind++;
01900 last_eol = nbop;
01901 nbop++;
01902 count++;
01903 break;
01904 case 16:
01905 cur_ind = cur_ind + 2;
01906 break;
01907 case 17:
01908 cur_ind++;
01909 count++;
01910 break;
01911 case 18:
01912 cur_ind = cur_ind + 1 + nsiz;
01913 break;
01914 case 19:
01915 nbop = nbop - data[cur_ind+1] + 1;
01916 cur_ind = cur_ind + 3;
01917 break;
01918 case 20:
01919 cur_ind++;
01920 count++;
01921 break;
01922 case 21:
01923 cur_ind = cur_ind + 1;
01924 break;
01925 case 22:
01926 cur_ind = cur_ind + 2;
01927 break;
01928 case 23:
01929 cur_ind = cur_ind + 1 + nsiz;
01930 nbop++;
01931 break;
01932 case 24:
01933 cur_ind = cur_ind + 1;
01934 break;
01935 case 25:
01936 cur_ind = cur_ind + 3;
01937 break;
01938 case 26:
01939 cur_ind = cur_ind + 5 + data[cur_ind+1]*data[cur_ind+2] + data[cur_ind+4+data[cur_ind+1]*data[cur_ind+2]] - 1;
01940 break;
01941 case 27:
01942 cur_ind = cur_ind + 3 + nsiz;
01943 break;
01944 case 28:
01945 cur_ind++;
01946 count++;
01947 break;
01948 case 29:
01949 nbop = 0;
01950 cur_ind = cur_ind + 2 + (data[cur_ind+1])*(nsiz+1) + 1;
01951 count++;
01952 break;
01953 case 30:
01954
01955 cur_ind = cur_ind + 3;
01956 break;
01957 case 31:
01958 cur_ind = cur_ind + 2 + data[cur_ind+1];
01959 count++;
01960 break;
01961 case 99:
01962 cur_ind++;
01963 count++;
01964 break;
01965 default:
01966 if(data[cur_ind]/100*100==data[cur_ind])
01967 {
01968 cur_ind = cur_ind + 4;
01969 }
01970 else
01971 {
01972 sciprint("complexity: wrong code %d\r\n",data[cur_ind]);
01973 return -1;
01974 }
01975 break;
01976 }
01977 }
01978 return count;
01979
01980 }