#include "MALLOC.h"#include "intmacr2tree.h"#include "sciprint.h"Include dependency graph for intmacr2tree.c:

Go to the source code of this file.
Functions | |
| static int | CreateRecursiveIndex2List (int *data, int *index2) |
| int | C2F (macr2tree) |
| static int | CreateVariableTList (char **varname) |
| static int | CreateEOLList (void) |
| static int | AddVar (char *name) |
| static int | IsDefinedVar (char *name) |
| static int | GetInstruction (int *data, int *index2, int *nblines, int *addinstr) |
| static int | GetControlInstruction (int *data, int *index2, int *nblines) |
| static int | CreateCsteTList (char *type, int *data, int *index2) |
| static int | CreateOperationTList (int *data, int *index2) |
| static int | CreateFuncallTList (char *fromwhat, int *data, int *index2) |
| static int | CreateEqualTList (char *fromwhat, int *data, int *index2) |
| static int | CreateCommentTList (int *data, int *index2) |
| static int | VCopyObj (char *fname, int *orig, int *dest, unsigned long fname_length) |
| int | complexity (int *data, int *index2, int *lgth) |
Variables | |
| static char | varnames [isizt][nlgh+1] |
| static int | nbvars = 0 |
| static int | last_eol_pos = 0 |
| static int AddVar | ( | char * | name | ) | [static] |
Definition at line 351 of file intmacr2tree.c.
References IsDefinedVar(), nbvars, and varnames.
00352 { 00353 if(IsDefinedVar(name)==-1) 00354 { 00355 strcpy(varnames[nbvars],name); 00356 nbvars++; 00357 } 00358 return 0; 00359 }
Here is the call graph for this function:

| int C2F | ( | macr2tree | ) |
Definition at line 24 of file intmacr2tree.c.
References Bot, C2F, CALLOC, CheckLhs, CheckRhs, complexity(), CreateVariableTList(), CvNameL, data, Err, err1, FREE, GetInstruction(), i, iadr, idstk, istk, itosci(), last_eol_pos, Lstk, mklist(), mktlist(), name, nlgh, nsiz, NULL, sadr, stk, str2sci(), sz, and Top.
00026 : macr2tree 00027 ****************************************************************/ 00028 int C2F(macr2tree) _PARAMS((char *fname,unsigned long fname_len)) 00029 { 00030 /* Returned value parameters */ 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; /* Pointeur to rhs arguments */ 00035 int *data = NULL; /* Macro integer vector (pointer to copy of rhs argument) */ 00036 00037 int minRhs = 1; /* Minimum number of RHS arguments */ 00038 int maxRhs = 1; /* Maximum number of RHS arguments */ 00039 int minLhs = 1; /* Minimum number of LHS arguments */ 00040 int maxLhs = 1; /* Maximum number of LHS arguments */ 00041 00042 int il = 0,ils = 0,ile = 0,ilt = 0,codelength = 0; 00043 00044 int i = 0,cod_ind = 0; /* Loop index */ 00045 int job1 = 1; /* Used when job passed as a pointer to a function */ 00046 00047 /* Number of lines */ 00048 int nblines = 1; 00049 00050 /* Name (character string used to store function/lhs/rhs names */ 00051 char **name = NULL; 00052 int namelgth = 0; 00053 00054 /* Number of statements in macro */ 00055 int nbstat = 0; 00056 00057 /* Generic variables */ 00058 int one = 1; 00059 00060 /* Save Top */ 00061 int TopSave = 0; 00062 00063 /* Save last code interpreted */ 00064 int cod_sav = 0; 00065 00066 /* Loop index */ 00067 int k = 0; 00068 00069 /* Used for statements list creation */ 00070 int sz = 0; /* Size */ 00071 int newinstr = 0; /* flag used to know if a new instruction has been created (1->TRUE) */ 00072 00073 /* Verify number of RHS arguments */ 00074 CheckRhs(minRhs,maxRhs); 00075 00076 /* Verify number of LHS arguments */ 00077 CheckLhs(minLhs,maxLhs); 00078 00079 /* Read all data */ 00080 stkdata = (int *) stk(*Lstk(Top)); 00081 00082 if (stkdata[0] > 0) /* Not a reference to variable */ 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 /* Verify good type for input: must be a compiled macro (type 13) */ 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 /* Memory allocation */ 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 /* Get function name: variable name on top of idstk */ 00113 /* Must be done before writing anything on stack or else we have to save Top when entering this program */ 00114 00115 CvNameL(idstk(1,Top),name[0],&job1,&namelgth); 00116 (name[0])[namelgth]='\0'; 00117 00118 /* Input variable is no more useful */ 00119 Top--; 00120 00121 /* Write 'program' tlist first element on stack */ 00122 str2sci(pgrm_tlist,m_pgrm_tlist,n_pgrm_tlist); 00123 00124 /* Write function name on stack */ 00125 str2sci(name,one,one); 00126 00127 ils=il+1; /* stkdata[ils] = number of outputs */ 00128 00129 /* Read output parameters names */ 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; /* stkdata[ile] = number of outputs */ 00139 00140 /* Read input parameters names */ 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 /* Make a copy variable passed as reference */ 00154 /* Memory allocation */ 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 /* Copy */ 00161 for(k=0;k<(codelength+ilt+1);k++) 00162 data[k]=stkdata[k]; 00163 00164 /* List header */ 00165 /* Considering Top is pointing last occupied place */ 00166 00167 /* Number of elements in list */ 00168 cod_ind = ilt + 1; 00169 nbstat = complexity(data,&ilt,&codelength); 00170 00171 Top++; /* First free place */ 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 /* Error handling (S. Steer */ 00181 if (*Lstk(Top+1) >= *Lstk(Bot)) { 00182 Scierror(17,"macr2tree: stack size exceeded (Use stacksize function to increase it)\r\n"); 00183 00184 /* Free memory */ 00185 FREE(name[0]); 00186 name[0]=NULL; 00187 FREE(name); 00188 name=NULL; 00189 FREE(data); 00190 00191 return 0; 00192 } 00193 00194 /* Fill list */ 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 /* Error handling (S. Steer) */ 00205 if (Err>0 || C2F(errgst).err1>0) 00206 { 00207 /* Free memory */ 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) /* EOL as the last component of a column concatenation */ 00217 { 00218 /* a = ['a' 00219 'b' 00220 ] */ 00221 Top--; /* EOL is erased */ 00222 last_eol_pos=-10; /* EOL position is erased */ 00223 newinstr=0; /* No new instruction created */ 00224 nbstat--; /* One statement deleted */ 00225 } 00226 else if(cod_sav==15 && Top!=TopSave+1) /* Column catenation with EOL after semi-colon */ 00227 newinstr=0; 00228 else if(cod_sav==15) /* If EOL is not after semi-colon in catenation, it is ignored */ 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 /* Free memory */ 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 /* Free memory */ 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 /* Number of lines */ 00270 C2F(itosci)(&nblines,&one,&one); 00271 00272 C2F(mktlist)(&n_pgrm_tlist); 00273 00274 /* Free memory */ 00275 FREE(name[0]); 00276 name[0]=NULL; 00277 FREE(name); 00278 name=NULL; 00279 FREE(data); 00280 00281 return 0; 00282 }
Here is the call graph for this function:

Definition at line 1802 of file intmacr2tree.c.
References count, nsiz, and sciprint().
Referenced by C2F().
01803 { 01804 int count = 0; 01805 01806 int cur_ind = *index2+1; 01807 01808 int last_eol=0; 01809 01810 int nbop = 0; /* Number of value stored on stack */ 01811 01812 while(cur_ind<=*lgth+*index2) 01813 { 01814 switch(data[cur_ind]) 01815 { 01816 case 0: /* Deleted operation */ 01817 cur_ind = cur_ind + data[cur_ind+1] + 1; 01818 break; 01819 case 1: /* Stack put (Obsolete) */ 01820 cur_ind = cur_ind + nsiz + 1; 01821 count++; 01822 break; 01823 case 2: /* Stack get */ 01824 cur_ind = cur_ind + nsiz + 3; 01825 nbop++; 01826 break; 01827 case 3: /* String */ 01828 cur_ind = cur_ind + 2 + data[cur_ind+1]; 01829 nbop++; 01830 break; 01831 case 4: /* Empty matrix */ 01832 cur_ind++; 01833 nbop++; 01834 break; 01835 case 5: /* Operations */ 01836 if( (data[cur_ind+1]==4) && (last_eol==nbop-2) ) /* rc with a EOL */ 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: /* Number */ 01846 cur_ind = cur_ind + 3; 01847 nbop++; 01848 break; 01849 case 7: /* 'for' control instruction */ 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: /* 'if-then-else' control instruction */ 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: /* 'while' control instruction */ 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: /* 'select-case' control instruction */ 01879 cur_ind = cur_ind + data[cur_ind+1]; 01880 count++; 01881 break; 01882 case 11: /* 'try-catch' control instruction */ 01883 cur_ind = cur_ind + data[cur_ind+1] + data[cur_ind+2] + 3; 01884 count++; 01885 break; 01886 case 12: /* pause */ 01887 cur_ind++; 01888 count++; 01889 break; 01890 case 13: /* break */ 01891 cur_ind++; 01892 count++; 01893 break; 01894 case 14: /* abort */ 01895 cur_ind++; 01896 count++; 01897 break; 01898 case 15: /* EOL */ 01899 cur_ind++; 01900 last_eol = nbop; 01901 nbop++; 01902 count++; 01903 break; 01904 case 16: /* Set line number */ 01905 cur_ind = cur_ind + 2; 01906 break; 01907 case 17: /* quit (Should never append) */ 01908 cur_ind++; 01909 count++; 01910 break; 01911 case 18: /* Mark named variable */ 01912 cur_ind = cur_ind + 1 + nsiz; 01913 break; 01914 case 19: /* Form recursive index2 list */ 01915 nbop = nbop - data[cur_ind+1] + 1; 01916 cur_ind = cur_ind + 3; 01917 break; 01918 case 20: /* exit */ 01919 cur_ind++; 01920 count++; 01921 break; 01922 case 21: /* Beginning of rhs */ 01923 cur_ind = cur_ind + 1; 01924 break; 01925 case 22: /* Set print mode (ignored ?) */ 01926 cur_ind = cur_ind + 2; 01927 break; 01928 case 23: /* Create variable from name */ 01929 cur_ind = cur_ind + 1 + nsiz; 01930 nbop++; 01931 break; 01932 case 24: /* Create an object with type 0 */ 01933 cur_ind = cur_ind + 1; 01934 break; 01935 case 25: /* Compute profiling data */ 01936 cur_ind = cur_ind + 3; 01937 break; 01938 case 26: /* Vector of strings */ 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: /* varfunptr ??? */ 01942 cur_ind = cur_ind + 3 + nsiz; 01943 break; 01944 case 28: /* continue */ 01945 cur_ind++; 01946 count++; 01947 break; 01948 case 29: /* Affectation */ 01949 nbop = 0; 01950 cur_ind = cur_ind + 2 + (data[cur_ind+1])*(nsiz+1) + 1; 01951 count++; 01952 break; 01953 case 30: /* Expression evaluation short circuiting */ 01954 /* This code is ignored */ 01955 cur_ind = cur_ind + 3; 01956 break; 01957 case 31: /* comment */ 01958 cur_ind = cur_ind + 2 + data[cur_ind+1]; 01959 count++; 01960 break; 01961 case 99: /* return */ 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 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1721 of file intmacr2tree.c.
References C2F, CALLOC, CvStr, FREE, mktlist(), NULL, and str2sci().
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 /* First item of returned list */ 01735 str2sci(fun_tlist,m_fun_tlist,n_fun_tlist); 01736 01737 /* Create data to write in field 'text' */ 01738 (*index2)++; 01739 strlgth = data[*index2]; 01740 (*index2)++; 01741 /* Memory allocation */ 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 /* Free memory */ 01752 FREE(text); 01753 text=NULL; 01754 01755 C2F(mktlist)(&n_fun_tlist); 01756 return 0; 01757 }
Here is the call graph for this function:

Definition at line 941 of file intmacr2tree.c.
References C2F, CALLOC, CvNameL, CvStr, dtosci(), FREE, i, int, mktlist(), nlgh, nsiz, NULL, str, str2sci(), and value.
00942 { 00943 char *cste_tlist[] = {"cste","value"}; 00944 int m_cste_tlist = 1; 00945 int n_cste_tlist = 2; 00946 00947 /* Used to get endian */ 00948 int littlendian = 1; 00949 char *endptr; 00950 00951 /* Used when type=="emptymatrix" */ 00952 double l_mat = 0; 00953 int m_mat = 0; 00954 int n_mat = 0; 00955 00956 /* Used when type=="string" */ 00957 char **str; 00958 int *int_str; 00959 int strlgth = 0; 00960 int job1 = 1; 00961 int one = 1; 00962 00963 /* Used when type=="number" */ 00964 double *value; 00965 int *ivalue; 00966 int i = 0; /* Loop index2 */ 00967 00968 /* First item of returned list */ 00969 str2sci(cste_tlist,m_cste_tlist,n_cste_tlist); 00970 00971 /* Create data to write in field 'value' */ 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 /* Memory allocation */ 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 /* Fill int_str */ 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 /* Free memory */ 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 /* Memory allocation */ 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 /* Read name */ 01032 CvNameL(&data[*index2+1],str[0],&job1,&strlgth); 01033 (str[0])[strlgth]='\0'; 01034 *index2 += nsiz; 01035 01036 /* Write on stack */ 01037 str2sci(str,one,one); 01038 01039 /* Free memory */ 01040 FREE(str[0]); 01041 str[0]=NULL; 01042 FREE(str); 01043 str=NULL; 01044 } 01045 else if(!strncmp(type,"number",6)) 01046 { 01047 /* Memory allocation */ 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 /* Get endian */ 01056 endptr = (char *) &littlendian; 01057 littlendian = (int) *endptr; 01058 01059 /* Read values in data */ 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 /* Free memory */ 01078 FREE(value); 01079 value=NULL; 01080 } 01081 else /* Should never happen */ 01082 { 01083 Scierror(999,"CreateCsteTList: wrong type value %s\r\n",type); 01084 return 0; 01085 } 01086 01087 /* Create returned list */ 01088 C2F(mktlist)(&n_cste_tlist); 01089 01090 return 0; 01091 }
Here is the call graph for this function:

| static int CreateEOLList | ( | void | ) | [static] |
Definition at line 313 of file intmacr2tree.c.
References C2F, CALLOC, eol, FREE, mklist(), NULL, and str2sci().
00314 { 00315 char **eol; 00316 00317 int one = 1; 00318 00319 /* Memory allocation */ 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 /* Add eol to stack */ 00334 str2sci(eol,one,one); 00335 00336 /* Create list */ 00337 C2F(mklist)(&one); 00338 00339 /* Free memory */ 00340 FREE(eol[0]); 00341 eol[0]=NULL; 00342 FREE(eol); 00343 eol=NULL; 00344 00345 return 0; 00346 }
Here is the call graph for this function:

Definition at line 1392 of file intmacr2tree.c.
References C2F, CALLOC, CreateVariableTList(), CvNameL, FREE, L, l, mklist(), mktlist(), name, nlgh, nsiz, NULL, str2sci(), Top, and VCopyObj().
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; /* Loop index2es */ 01401 01402 int job1 = 1; 01403 01404 int orig,dest; /* Used when copy objects */ 01405 01406 char **name; 01407 int namelgth = 0; 01408 01409 /* Used for lhs which are insertion operations */ 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 /* Memory allocation */ 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 /* Add tlist items names to stack */ 01450 str2sci(eq_tlist,m_eq_tlist,n_eq_tlist); 01451 01452 if(!strncmp(fromwhat,"code29",6)) /* A code 29 was found in data */ 01453 { 01454 /* Copy expression */ 01455 orig = Top - 1; 01456 dest = Top + 1; 01457 VCopyObj("CreateEqualTList",&orig,&dest,16L); 01458 01459 index2es_pos = Top - 3; 01460 01461 /* Create list of lhs */ 01462 (*index2)++; /* Code 29 is passed */ 01463 nblhs = data[*index2]; 01464 (*index2)++; 01465 01466 /* Symbol which ends the line: ; , or nothing */ 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 /* Nothing */ 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) /* Variable affectation */ 01522 { 01523 CreateVariableTList(name); 01524 } 01525 else /* Insertion */ 01526 { 01527 /* Write tlist items names */ 01528 str2sci(op_tlist,m_op_tlist,n_op_tlist); 01529 01530 /* Name of variable where data will be inserted */ 01531 CreateVariableTList(name); 01532 01533 /* Index2es for insertion */ 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 /* Create list of operands */ 01543 nbrhs = nbrhs + 1; 01544 C2F(mklist)(&nbrhs); 01545 01546 /* Add operator */ 01547 str2sci(operator,one,one); 01548 01549 /* Create operation tlist */ 01550 C2F(mktlist)(&n_op_tlist); 01551 } 01552 } 01553 /* Reverse order of lhs */ 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 /* Create list of lhs */ 01562 C2F(mklist)(&nblhs); 01563 01564 /* Copy lhs list to first free place */ 01565 orig = Top; 01566 dest = Top - nblhs; 01567 VCopyObj("CreateEqualTList",&orig,&dest,16L); 01568 01569 /* Symbol */ 01570 str2sci(endsymbol,one,one); 01571 01572 /* Create equal tlist */ 01573 C2F(mktlist)(&n_eq_tlist); 01574 01575 /* Copy tlist to first free place */ 01576 orig = Top; 01577 dest = Top - nb_index2es - 1; 01578 VCopyObj("CreateEqualTList",&orig,&dest,16L); 01579 } 01580 else if(!strncmp(fromwhat,"code18",6)) /* A code 18 was found in data */ 01581 { 01582 /* Copy expression */ 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 /* Create list of lhs */ 01596 C2F(mklist)(&nblhs); 01597 01598 /* Symbol */ 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 /* Create equal tlist */ 01613 C2F(mktlist)(&n_eq_tlist); 01614 01615 /* Copy equal tlist */ 01616 orig = Top; 01617 dest = Top - 1; 01618 VCopyObj("CreateEqualTList",&orig,&dest,16L); 01619 } 01620 else if(!strncmp(fromwhat,"code1",5)) /* A code 1 was found in data (should no more exist) */ 01621 { 01622 /* Copy expression */ 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)++; /* Code 22 (print mode) is ignored */ 01636 (*index2)++; /* Code 99 is ignored */ 01637 } 01638 /* Create list of lhs */ 01639 C2F(mklist)(&nblhs); 01640 01641 /* Symbol */ 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 /* Create equal tlist */ 01656 C2F(mktlist)(&n_eq_tlist); 01657 } 01658 else if(!strncmp(fromwhat,"forexpr",7)) 01659 { 01660 /* Copy expression */ 01661 orig = Top - 2; 01662 dest = Top + 1; 01663 VCopyObj("CreateEqualTList",&orig,&dest,16L); 01664 01665 /* Copy variable after tlist items */ 01666 orig = Top - 2; 01667 dest = Top + 1; 01668 VCopyObj("CreateEqualTList",&orig,&dest,16L); 01669 01670 nblhs = 1; 01671 /* Create list of lhs */ 01672 C2F(mklist)(&nblhs); 01673 01674 /* Symbol */ 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 /* Create equal tlist */ 01689 C2F(mktlist)(&n_eq_tlist); 01690 01691 /* Copy tlist to first free place */ 01692 dest = Top - 2; 01693 orig = Top; 01694 VCopyObj("CreateEqualTList",&orig,&dest,16L); 01695 } 01696 else /* Should not happen */ 01697 { 01698 Scierror(999,"CreateEqualTList: wrong fromwhat value %s\r\n",fromwhat); 01699 return 0; 01700 } 01701 01702 /* Free memory */ 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 }
Here is the call graph for this function:

Definition at line 1231 of file intmacr2tree.c.
References C2F, CALLOC, CvNameL, dtosci(), FREE, funname, funtab(), L, mklist(), mktlist(), nlgh, nsiz, NULL, str2sci(), Top, and VCopyObj().
01232 { 01233 char *fun_tlist[] = {"funcall","rhs","name","lhsnb"}; 01234 int m_fun_tlist = 1; 01235 int n_fun_tlist = 4; 01236 01237 /* Used when fromwhat=="funptr" */ 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; /* Used when copy objects */ 01251 01252 /* Used for empty matrix creation when rhsnb==0 (function called as a command) */ 01253 double l_mat = 0; 01254 int m_mat = 0; 01255 int n_mat = 0; 01256 01257 /* Memory allocation */ 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 /* Should never happen */ 01336 { 01337 Scierror(999,"CreateFuncallTList: wrong fromwhat value %s\r\n",fromwhat); 01338 return 0; 01339 } 01340 01341 /* rhs==0 then function called as a command */ 01342 /* In funcall tree, rhs=[] */ 01343 if(nbrhs==0) 01344 { 01345 /* Create an empty matrix on stack */ 01346 C2F(dtosci)(&l_mat,&m_mat,&n_mat); 01347 } 01348 else 01349 { 01350 /* rhs==-1 then function called with no rhs */ 01351 /* In funcall tree, rhs=list() */ 01352 if(nbrhs<0) 01353 nbrhs=0; 01354 /* Create rhs list */ 01355 C2F(mklist)(&nbrhs); 01356 } 01357 01358 /* Add tlist items names to stack */ 01359 str2sci(fun_tlist,m_fun_tlist,n_fun_tlist); 01360 01361 /* Copy rhs list */ 01362 orig = Top - 1; 01363 dest = Top + 1; 01364 VCopyObj("CreateFuncallTList",&orig,&dest,18L); 01365 01366 /* Add funname to stack */ 01367 str2sci(funname,one,one); 01368 01369 /* Add nblhs to stack */ 01370 C2F(dtosci)(&nblhs,&one,&one); 01371 01372 /* Create 'funcall' tlist */ 01373 C2F(mktlist)(&n_fun_tlist); 01374 01375 /* Copy tlist to first free place in stack */ 01376 orig = Top; 01377 dest = Top - 1; 01378 VCopyObj("CreateFuncallTList",&orig,&dest,18L); 01379 01380 /* Free memory */ 01381 FREE(funname[0]); 01382 funname[0]=NULL; 01383 FREE(funname); 01384 funname=NULL; 01385 01386 return 0; 01387 }
Here is the call graph for this function:

Definition at line 1096 of file intmacr2tree.c.
References C2F, CALLOC, L, last_eol_pos, mklist(), mktlist(), NULL, offset, str2sci(), Top, and VCopyObj().
01097 { 01098 char *op_tlist[] = {"operation","operands","operator"}; 01099 int m_op_tlist = 1; 01100 int n_op_tlist = 3; 01101 01102 /* Operators table */ 01103 char *operators[]={"+","-","*",".*","*.",".*.","/","./","/.","./.", 01104 "\\",".\\","\\.",".\\.","^","==","<",">","<=",">=","~=", 01105 ":","rc","ins","ext","'","cc","|","&","~",".^",".'","cceol"}; 01106 /* cceol: special operator for column concatenation followed by EOL (initialisation made on more than one line... */ 01107 01108 char **operator; 01109 int max_op_lgth = 5; /* strlen("cceol") */ 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; /* Loop index2 */ 01118 01119 int orig,dest; /* Used when copy objects */ 01120 01121 int offset = 0; 01122 01123 int one = 1; 01124 01125 /* Memory allocation */ 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 /* Read useful data */ 01139 (*index2)++; /* Pass index2 corresponding to 5 */ 01140 operator_num = data[*index2]; 01141 (*index2)++; 01142 nb_operands = data[*index2]; /* One or two */ 01143 (*index2)++; 01144 nb_lhs = data[*index2]; /* Always one */ 01145 01146 /* Write tlist items names */ 01147 str2sci(op_tlist,m_op_tlist,n_op_tlist); 01148 01149 /* Search operator index2 */ 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 /* Move all operands to next place in stack */ 01164 /* Special case for column concatenation followed by a EOL */ 01165 /* Example: a=[1,2; 01166 3,4] */ 01167 if( (operator_index2==26) && (last_eol_pos==Top-2) ) 01168 { 01169 /* Change operator */ 01170 operator_index2 = 32; 01171 01172 /* First operand is placed before EOL */ 01173 orig = last_eol_pos - 1; 01174 dest = Top + 1; 01175 VCopyObj("CreateOperationTList",&orig,&dest,20L); 01176 01177 /* Second operand is placed after EOL */ 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) /* For extraction: variable is moved to be the first operand */ 01184 { 01185 /* Move variable */ 01186 orig = Top - 1; 01187 dest = Top + 1; 01188 VCopyObj("CreateOperationTList",&orig,&dest,20L); 01189 01190 /* Move all indices */ 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 /* Create list of operands */ 01210 C2F(mklist)(&nb_operands); 01211 01212 /* Add operator to stack */ 01213 strcpy(operator[0],operators[operator_index2]); 01214 (operator[0])[strlen(operators[operator_index2])]='\0'; 01215 str2sci(operator,one,one); 01216 01217 /* Create operation tlist */ 01218 C2F(mktlist)(&n_op_tlist); 01219 01220 /* Move resulting list to first free place in stack */ 01221 orig = Top; 01222 dest = Top - nb_operands - offset; 01223 VCopyObj("CreateOperationTList",&orig,&dest,20L); 01224 01225 return 0; 01226 }
Here is the call graph for this function:

Definition at line 1762 of file intmacr2tree.c.
References C2F, m, mklist(), and n.
Referenced by GetInstruction().
01763 { 01764 int m,n; 01765 01766 /* Get infos in data */ 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 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static int CreateVariableTList | ( | char ** | varname | ) | [static] |
Definition at line 287 of file intmacr2tree.c.
References AddVar(), C2F, mktlist(), and str2sci().
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 /* Add 'variable' tlist items to stack */ 00296 str2sci(variable_tlist,m_variable_tlist,n_variable_tlist); 00297 00298 /* Add variable name to stack */ 00299 str2sci(varname,one,one); 00300 00301 /* Create tlist */ 00302 C2F(mktlist)(&n_variable_tlist); 00303 00304 /* Add variable to known variables table */ 00305 AddVar(varname[0]); 00306 00307 return 0; 00308 }
Here is the call graph for this function:

Definition at line 604 of file intmacr2tree.c.
References C2F, CALLOC, CreateEqualTList(), CreateVariableTList(), CvNameL, FREE, GetInstruction(), last_eol_pos, mklist(), mktlist(), name, nlgh, nsiz, NULL, str2sci(), and Top.
00605 { 00606 /* try-catch */ 00607 char *trycatch_tlist[] = {"trycatch","trystat","catchstat"}; 00608 int m_trycatch_tlist = 1; 00609 int n_trycatch_tlist = 3; 00610 00611 /* if */ 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 /* while */ 00621 char *while_tlist[] = {"while","expression","statements"}; 00622 int m_while_tlist = 1; 00623 int n_while_tlist = 3; 00624 00625 /* select */ 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 /* for */ 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; /* Used to call GetInstruction with enough parameters */ 00650 00651 /* FOR */ 00652 if(data[*index2]==7) 00653 { 00654 /* Write list items */ 00655 str2sci(for_tlist,m_for_tlist,n_for_tlist); 00656 (*index2)++; 00657 codelgth = data[*index2]; 00658 endindex2 = *index2 + codelgth; 00659 (*index2)++; 00660 00661 /* Get expression */ 00662 while(*index2<=endindex2) 00663 { 00664 GetInstruction(data,index2,nblines,&newinstr); 00665 (*index2)++; 00666 } 00667 00668 codelgth = data[*index2]; 00669 (*index2)++; 00670 00671 /* Get loop variable */ 00672 /* Memory allocation */ 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 /* Create a variable tlist with name */ 00689 CreateVariableTList(name); 00690 00691 /* variable = expression */ 00692 CreateEqualTList("forexpr",data,index2); 00693 endindex2 = *index2 + codelgth; 00694 00695 /* Get all instructions */ 00696 TopSave = Top; 00697 while(*index2<=endindex2) 00698 { 00699 /* Get all instructions */ 00700 GetInstruction(data,index2,nblines,&newinstr); 00701 (*index2)++; 00702 } 00703 (*index2)--; 00704 /* Make list of instructions */ 00705 nbinstr = Top - TopSave; 00706 C2F(mklist)(&nbinstr); 00707 00708 /* Create FOR tlist */ 00709 C2F(mktlist)(&n_for_tlist); 00710 00711 /* Free memory */ 00712 FREE(name[0]); 00713 name[0]=NULL; 00714 FREE(name); 00715 name=NULL; 00716 } 00717 /* TRYCATCH */ 00718 else if(data[*index2]==11) 00719 { 00720 index20 = *index2; 00721 00722 str2sci(trycatch_tlist,m_trycatch_tlist,n_trycatch_tlist); 00723 00724 /* index2 now point to first code to use as an instruction code */ 00725 *index2 += 3; 00726 00727 codelgth = data[index20+1]; 00728 endindex2 = *index2 + codelgth - 1; 00729 00730 TopSave = Top; 00731 /* Get try instructions */ 00732 while(*index2<=endindex2) 00733 { 00734 GetInstruction(data,index2,nblines,&newinstr); 00735 (*index2)++; 00736 } 00737 00738 nbinstr = Top - TopSave; 00739 00740 /* Create list of try instructions */ 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 /* Get catch instructions */ 00749 while(*index2<=endindex2) 00750 { 00751 GetInstruction(data,index2,nblines,&newinstr); 00752 (*index2)++; 00753 } 00754 00755 nbinstr = Top - TopSave; 00756 00757 /* Create list of catch instructions */ 00758 C2F(mklist)(&nbinstr); 00759 00760 (*index2)--; 00761 00762 /* Create trycatch tlist */ 00763 C2F(mktlist)(&n_trycatch_tlist); 00764 } 00765 /* IF - WHILE - SELECT */ 00766 else 00767 { 00768 index20 = *index2; 00769 00770 /* if or while of Scilab version < 3 */ 00771 if( (data[*index2]==8 || data[*index2]==9) && data[*index2+1]>=0 ) 00772 { 00773 /* This part will not be written */ 00774 /* No more used */ 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]; /* Number of elseif + number of else = number of elseif + 1 */ 00781 00782 /* Write first tlist item (tlist fields) */ 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 /* index2 now point to first code to use as an instruction code */ 00797 *index2 += 4; 00798 00799 codelgth = data[index20+3]; 00800 endindex2 = *index2 + codelgth - 1; 00801 00802 icase = ncase + 1; 00803 00804 /* If control instruction is a select, I get expression */ 00805 if(data[index20]==10) 00806 { 00807 TopSave = Top; 00808 while(*index2<=endindex2) 00809 { 00810 GetInstruction(data,index2,nblines,&newinstr); 00811 (*index2)++; 00812 } 00813 /* Create a list for expression because can be expression+EOL */ 00814 nbinstr = Top - TopSave; 00815 /* Create list of then instructions */ 00816 C2F(mklist)(&nbinstr); 00817 last_eol_pos = -10; 00818 } 00819 00820 00821 /* select: for all cases */ 00822 /* if: 1rst pass gives expression and then instructions */ 00823 /* others passes give expression and then instructions for elseifs */ 00824 while(icase > 1) 00825 { 00826 icase = icase - 1; 00827 00828 /* For a select: on first pass save position on stack to get the number of cases */ 00829 if(icase==ncase && data[index20]==10) 00830 TopSave_elseifsorcases = Top; /* Saved to know how many cases have been written */ 00831 00832 if(icase<ncase && data[index20]==8) /* For a if (if loop already executed one time): found a elseif */ 00833 { 00834 /* Write tlist items */ 00835 str2sci(elseif_tlist,m_elseif_tlist,n_elseif_tlist); 00836 } 00837 00838 if(data[index20]==10) /* For a select: found a case */ 00839 { 00840 /* Write tlist items */ 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 /* Get expression */ 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 /* Get then instructions */ 00860 TopSave = Top; /* Position on stack saved to get the number of instructions */ 00861 while(*index2<=endindex2) 00862 { 00863 GetInstruction(data,index2,nblines,&newinstr); 00864 (*index2)++; 00865 } 00866 nbinstr = Top - TopSave; 00867 /* Create list of then instructions */ 00868 C2F(mklist)(&nbinstr); 00869 00870 if(icase<ncase && data[index20]==8) /* IF: create elseif tlist */ 00871 { 00872 /* Create elseif tlist */ 00873 C2F(mktlist)(&n_elseif_tlist); 00874 } 00875 00876 if(data[index20]==10) /* SELECT: create case tlist */ 00877 { 00878 /* Create case tlist */ 00879 C2F(mktlist)(&n_case_tlist); 00880 } 00881 00882 /* IF: after first pass, save position on stack to get the number of elseifs */ 00883 if(icase==ncase && data[index20]==8) 00884 TopSave_elseifsorcases = Top; /* Saved to know how many elseifs have been written */ 00885 } 00886 00887 nbelseifsorcases = Top - TopSave_elseifsorcases; 00888 00889 /* IF: create list of elseifs */ 00890 /* SELECT: create list of cases */ 00891 if(data[index20]==8 || data[index20]==10) 00892 C2F(mklist)(&nbelseifsorcases); 00893 00894 /* else (if there is one) (not used for WHILE) */ 00895 (*index2)++; 00896 codelgth = data[*index2]; 00897 (*index2)++; 00898 00899 if(codelgth==0) /* When no else in IF or SELECT and when a WHILE */ 00900 (*index2)++; 00901 00902 endindex2 = *index2 + codelgth - 1; 00903 00904 /* Get else instructions */ 00905 TopSave = Top; 00906 while(*index2<=endindex2) 00907 { 00908 GetInstruction(data,index2,nblines,&newinstr); 00909 (*index2)++; 00910 } 00911 nbinstr = Top - TopSave; 00912 /* Create list of else instructions */ 00913 if(data[index20]==8 || data[index20]==10) 00914 C2F(mklist)(&nbinstr); 00915 00916 (*index2)--; /* Index2 is decremented because is incremented when going back to intmacr2tree() */ 00917 00918 if(data[index20]==8) 00919 { 00920 /* Create if tlist */ 00921 C2F(mktlist)(&n_if_tlist); 00922 } 00923 else if(data[index20]==9) 00924 { 00925 /* Create while tlist */ 00926 C2F(mktlist)(&n_while_tlist); 00927 } 00928 else if(data[index20]==10) 00929 { 00930 /* Create select tlist */ 00931 C2F(mktlist)(&n_select_tlist); 00932 } 00933 } 00934 } 00935 return 0; 00936 }
Here is the call graph for this function:

Definition at line 397 of file intmacr2tree.c.
References CALLOC, CreateCommentTList(), CreateCsteTList(), CreateEOLList(), CreateEqualTList(), CreateFuncallTList(), CreateOperationTList(), CreateRecursiveIndex2List(), CreateVariableTList(), CvNameL, FREE, GetControlInstruction(), IsDefinedVar(), last_eol_pos, name, nlgh, nsiz, NULL, and Top.
00398 { 00399 int job1 = 1; 00400 00401 char **name; 00402 int namelgth; 00403 00404 *addinstr=0; 00405 00406 /* Memory allocation */ 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: /* Deleted operation */ 00421 /* This code is ignored */ 00422 *index2 += data[*index2+1]; 00423 break; 00424 case 1: /* Stack put (Obsolete) */ 00425 CreateEqualTList("code1",data,index2); 00426 *addinstr=1; 00427 break; 00428 case 2: /* Stack get */ 00429 /* Read name */ 00430 CvNameL(&data[*index2+1],name[0],&job1,&namelgth); 00431 (name[0])[namelgth]='\0'; 00432 *index2 += nsiz; 00433 00434 if(data[*index2+2]==0) /* stack get (rhs=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 /* Stack get for extraction from variable */ 00444 CreateVariableTList(name); 00445 *index2 += 2; 00446 } 00447 else 00448 { 00449 /* Macro call */ 00450 data[*index2+1] = data[*index2+2]; 00451 if(data[*index2+3]==5 && data[*index2+4]==3) /* 3=code for extraction */ 00452 /* If next instruction is an extraction, it is ignored */ 00453 { 00454 data[*index2+2] = data[*index2+6]; /* Replace number of lhs for macro call by the one of extraction */ 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: /* String */ 00468 CreateCsteTList("string",data,index2); 00469 break; 00470 case 4: /* Empty matrix */ 00471 CreateCsteTList("emptymatrix",data,index2); 00472 break; 00473 case 5: /* Operations */ 00474 if(data[*index2+2]==0) 00475 { 00476 *index2 +=3; 00477 break; 00478 } 00479 CreateOperationTList(data,index2); 00480 break; 00481 case 6: /* Number */ 00482 CreateCsteTList("number",data,index2); 00483 break; 00484 case 7: /* 'for' control instruction */ 00485 GetControlInstruction(data,index2,nblines); 00486 *addinstr=1; 00487 break; 00488 case 8: /* 'if-then-else' control instruction */ 00489 GetControlInstruction(data,index2,nblines); 00490 *addinstr=1; 00491 break; 00492 case 9: /* 'while' control instruction */ 00493 GetControlInstruction(data,index2,nblines); 00494 *addinstr=1; 00495 break; 00496 case 10: /* 'select-case' control instruction */ 00497 GetControlInstruction(data,index2,nblines); 00498 *addinstr=1; 00499 break; 00500 case 11: /* 'try-catch' control instruction */ 00501 GetControlInstruction(data,index2,nblines); 00502 *addinstr=1; 00503 break; 00504 case 12: /* pause */ 00505 case 13: /* break */ 00506 case 14: /* abort */ 00507 CreateFuncallTList("datacode",data,index2); 00508 *addinstr=1; 00509 break; 00510 case 15: /* EOL */ 00511 (*nblines)++; 00512 CreateEOLList(); 00513 last_eol_pos = Top; 00514 *addinstr=1; 00515 break; 00516 case 16: /* Set line number */ 00517 /* This code is ignored */ 00518 (*index2)++; 00519 break; 00520 case 17: /* quit (Should never append) */ 00521 CreateFuncallTList("datacode",data,index2); 00522 *addinstr=1; 00523 break; 00524 case 18: /* Mark named variable */ 00525 CreateEqualTList("code18",data,index2); 00526 break; 00527 case 19: /* Form recursive index2 list */ 00528 CreateRecursiveIndex2List(data,index2); 00529 break; 00530 case 20: /* exit */ 00531 CreateFuncallTList("datacode",data,index2); 00532 *addinstr=1; 00533 break; 00534 case 21: /* Beginning of rhs */ 00535 /* This code is ignored */ 00536 /* Code also ignored in CreateEqualTList with fromwhat=="code1" */ 00537 break; 00538 case 22: /* Set print mode (ignored ?) */ 00539 /* This code is ignored */ 00540 break; 00541 case 23: /* Create variable from name */ 00542 CreateCsteTList("code23",data,index2); 00543 break; 00544 case 24: /* Create an object with type 0 */ 00545 Scierror(999,"GetInstruction: code %d not yet implemented\r\n",data[*index2]); 00546 break; 00547 case 25: /* Compute profiling data */ 00548 /* This code is ignored */ 00549 *index2 += 2; 00550 break; 00551 case 26: /* Vector of strings */ 00552 Scierror(999,"GetInstruction: code %d not yet implemented\r\n",data[*index2]); 00553 break; 00554 case 27: /* varfunptr */ 00555 Scierror(999,"GetInstruction: code %d not yet implemented\r\n",data[*index2]); 00556 break; 00557 case 28: /* continue */ 00558 CreateFuncallTList("datacode",data,index2); 00559 *addinstr=1; 00560 break; 00561 case 29: /* Affectation */ 00562 CreateEqualTList("code29",data,index2); 00563 *addinstr=1; 00564 break; 00565 case 30: /* Expression evaluation short circuiting */ 00566 /* This code is ignored */ 00567 *index2 += 2; 00568 break; 00569 case 31: /* comment */ 00570 CreateCommentTList(data,index2); 00571 *addinstr=1; 00572 break; 00573 00574 case 99: /* return */ 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 /* funptr */ 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 /* Free memory */ 00593 FREE(name[0]); 00594 name[0]=NULL; 00595 FREE(name); 00596 name=NULL; 00597 00598 return 0; 00599 }
Here is the call graph for this function:

| static int IsDefinedVar | ( | char * | name | ) | [static] |
Definition at line 364 of file intmacr2tree.c.
References isizt, and varnames.
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 }
Definition at line 1792 of file intmacr2tree.c.
References C2F, Top, and vcopyobj().
01793 { 01794 C2F(vcopyobj)(fname,orig,dest,fname_length); 01795 Top = *dest; 01796 return 0; 01797 }
Here is the call graph for this function:

int last_eol_pos = 0 [static] |
Definition at line 18 of file intmacr2tree.c.
Referenced by C2F(), CreateOperationTList(), GetControlInstruction(), and GetInstruction().
char varnames[isizt][nlgh+1] [static] |
1.5.1