intersci-n.h

Go to the documentation of this file.
00001 /* VERSION et DATE */
00002 #define VERSION "3.0"
00003 #define DATE "SEP 2000" 
00004 
00005 /* max dimension for the array: can be modified */
00006 #define MAXARG 50
00007 #define MAXCALL 2000
00008 #define MAXEL 50
00009 #define MAXLINE 1000
00010 #define MAXNAM 128
00011 #define MAXVAR 200
00012 /* flag for generation of type and element dimension checking for lists: 
00013    can be modified */
00014 #define TESTLISTELEMENTS 1
00015 
00016 /******************************************/
00017 /* DO NOT CHANGE ANYTHING BELOW THIS LINE */
00018 /******************************************/
00019 #define MAXFUN 99 /* maximum number of SCILAB functions */
00020 
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <ctype.h>
00024 #include <stdlib.h>
00025 
00026 
00027 /* FORTRAN variable types */ 
00028 #define CHAR 1
00029 #define INT 2
00030 #define DOUBLE 3
00031 #define REAL 4
00032 #define EXTERNAL 5
00033 #define CSTRINGV 6
00034 #define LOGICAL  7
00035 #define MPOINTER 8 /* pointer to Mat */
00036 #define PREDEF  9 /* err,rhs,lhs */
00037 #define SMPOINTER 9 /* pointer to SMat */
00038 #define LPOINTER 10 /* pointer to List */
00039 #define BPOINTER 11 /* pointer to BMat */
00040 #define OPOINTER 12 /* pointer to OBJ */
00041 #define BOOLEAN     13 /* as int for boolean matrix **/
00042 
00043 /* Fortran Declaration */
00044 
00045 #define DEC_CHAR 1
00046 #define DEC_INT 2
00047 #define DEC_DOUBLE 3
00048 #define DEC_REAL 4
00049 #define DEC_LOGICAL  5
00050 #define DEC_DATA  6
00051 #define DEC_UL  7    /* unsigned long */
00052 #define DEC_INIT  8    /* initialisation x=0; etc... */
00053 #define DEC_SMAT  9  
00054 #define DEC_SPARSE 10 
00055 /* pointer declaration */
00056 #define DEC_IPTR  11
00057 #define DEC_DPTR  12
00058 #define DEC_RPTR  13
00059 #define DEC_CPTR  14
00060 #define DEC_SPARSEPTR 15
00061 
00062 
00063 /* SCILAB and extensions variable types */
00064 
00065 #define DIMFOREXT 0   /* dimension (for example of an external variable )*/
00066 #define COLUMN 1
00067 #define LIST 2
00068 #define TLIST 3
00069 #define MATRIX 4
00070 #define POLYNOM 5
00071 #define ROW 6
00072 #define SCALAR 7
00073 #define SEQUENCE 8
00074 #define STRING 9
00075 #define WORK 10
00076 #define EMPTY 11
00077 #define ANY 12
00078 #define VECTOR 13
00079 #define STRINGMAT 14
00080 #define SCIMPOINTER 15
00081 #define IMATRIX 16
00082 #define SCISMPOINTER 17
00083 #define SCILPOINTER 18
00084 #define BMATRIX 19
00085 #define SCIBPOINTER 20
00086 #define SCIOPOINTER 21
00087 #define SPARSE 22
00088 #define MLIST 23
00089 
00090 /* SCILAB optional variable types */
00091 
00092 #define NAME 1 /* {var default-name} */
00093 #define VALUE 2 /* {var default-value} */
00094 
00095 typedef int IVAR; /* variable number */
00096 
00097 /* VAR struct: informations for FORTRAN and/or SCILAB variable */
00098 
00099 
00100 typedef struct var {
00101   char *name;           /* variable name */
00102   int  vpos;            /* variable is stored in variables[vpos-1] */
00103   int type;             /* SCILAB type */
00104   int length;           /* number of el in the variable */
00105   IVAR el[MAXEL];       /* list of el IVAR (variable associated with,
00106                                             typically dimensions) */
00107   int for_type;         /* FORTRAN type */
00108   char fexternal[MAXNAM]; /* name of external function when type is
00109                               external */
00110   IVAR equal;           /* alias for variable  */
00111   int nfor_name;        /* number of for_name */
00112   int kp_state;         /* for pass dealing **/
00113   char *for_name[MAXARG]; /* list of for_name names (FORTRAN name
00114                            in generated FORTRAN code) */
00115   char *C_name[MAXARG]; /* list of C_name : i.e when a for_name is m1*n1 
00116                          * it cannot be used at C level then C_name is set to 
00117                          * m1n1 and one will have to properly set m1n1=m1*n1 
00118                          */
00119   
00120   int for_name_orig[MAXARG]; /* list of stack_position of for_name occurences */
00121   char *list_name;      /* name of the list of which the variable is an element */
00122   int list_el;          /* element number in the previous list 
00123                          0 : means that variable is not in a list */
00124   int opt_type;         /* type of optional variable */
00125   char *opt_name;       /* name or value default for optional variable */
00126   int present;          /* 1 if the variable is really present in the 
00127                            description file
00128                            0 otherwise used for list elements which might 
00129                            be not really present */
00130   int stack_position;   /* position of the variable in the stack 
00131                            1 is the first position : 
00132                            the position is : the position in the scilab 
00133                            calling list or the position in the stack for 
00134                            internal variables created inside the interface
00135                            for a variable in a list : it is the position 
00136                            of the list in the stack 
00137                            */
00138   int out_position ;    /* 
00139                            The position of the variable in the 
00140                            returned arguments 
00141                            0 if the variable is not returned 
00142                            */
00143   int is_sciarg ;          /* set to one if variable is a scilab 
00144                               argument of the interfaced function */
00145 
00146 } VAR, *VARPTR;
00147 
00148 /* BASFUN struct: informations for SCILAB function */
00149 
00150 typedef struct basfun {
00151   char *name; /* function name */
00152   int nin; /* number of arguments */
00153   int maxOpt ; /* number of potential optional arguments in function */
00154   int NewMaxOpt; /* number of new style optional arguments in function */
00155   IVAR in[MAXARG]; /* list of argument IVAR */
00156   IVAR out; /* output IVAR : i.e type of output */
00157 } BASFUN, *BASFUNPTR;
00158 
00159 /* FORSUB struct: informations for FORTRAN subroutine */
00160 
00161 typedef struct forsub {
00162   char *name; /* subroutine name */
00163   int narg; /* number of arguments */
00164   IVAR arg[MAXARG]; /* list of argument IVAR */
00165 } FORSUB, *FORSUBPTR;
00166 
00167 /* memory allocators */
00168 
00171 #ifdef __STDC__
00172 #ifndef  __PARAMS
00173 #define  __PARAMS(paramlist)            paramlist
00174 #endif
00175 #else   
00176 #ifndef  __PARAMS
00177 #define  __PARAMS(paramlist)            ()
00178 #endif
00179 #endif
00180 
00181 
00182 extern VARPTR VarAlloc  __PARAMS((void));
00183 extern BASFUNPTR BasfunAlloc  __PARAMS((void));
00184 extern FORSUBPTR ForsubAlloc  __PARAMS((void));
00185 
00186 void WriteInfoCode __PARAMS((FILE *f));
00187 int GetNumberInScilabCall __PARAMS((int ivar));
00188 int GetNumberInFortranCall __PARAMS((int ivar));
00189 char *SGetSciType __PARAMS((int type));
00190 char* SGetCDec __PARAMS((int type));
00191 char *SGetForType __PARAMS((int type));
00192 char *SGetForTypeAbrev __PARAMS((VARPTR var));
00193 char *SGetForTypeStack __PARAMS((VARPTR var));
00194 char *SGetForTypeBConvert __PARAMS((VARPTR var));
00195 void AddForName __PARAMS((IVAR ivar, char *name,char *cname,IVAR ivar1));
00196 void ChangeForName1 __PARAMS((VARPTR var, char *name));
00197 void Copyright __PARAMS((void));
00198 char *Forname2Int __PARAMS((VARPTR,int));
00199 void GenFundef __PARAMS((char *file, int interf));
00200 int GetBasType __PARAMS((char *sname));
00201 int GetForType __PARAMS((char *type));
00202 IVAR GetExistOutVar __PARAMS((void));
00203 IVAR CheckOutVar __PARAMS((void));
00204 IVAR GetExistVar __PARAMS((char *name));
00205 IVAR GetOutVar __PARAMS((char *name));
00206 IVAR GetVar __PARAMS((char *name, int p));
00207 void OptVar __PARAMS(());
00208 int ParseLine __PARAMS((char *s, char **words));
00209 int ParseScilabLine __PARAMS((char *s, char **words));
00210 int ReadListElement __PARAMS((FILE *f, char *varlistname, IVAR iivar, int nel,int));
00211 void ReadListFile __PARAMS((char *listname, char *varlistname, IVAR ivar,int));
00212 int ReadFunction __PARAMS((FILE *f));
00213 int TypeToBas __PARAMS(());
00214 void WriteArgCheck __PARAMS((FILE *f, int i));
00215 void WriteCall __PARAMS(());
00216 void WriteCallRest __PARAMS((FILE *f, IVAR ivar, int farg, char *call));
00217 void WriteCallConvertion __PARAMS((FILE *f, IVAR ivar, char *farg, char *barg, char *call));
00218 void WriteCrossCheck __PARAMS((FILE *f));
00219 void WriteEqualCheck __PARAMS((FILE *f));
00220 void WriteExternalVariableOutput __PARAMS((FILE *f, VARPTR var,  int insidelist, int nel));
00221 void WriteFortranCall __PARAMS((FILE *f));
00222 void WriteFunctionCode __PARAMS((FILE *f));
00223 void WriteHeader __PARAMS((FILE *f, char *fname0, char *fname));
00224 void WriteMainHeader __PARAMS((FILE *f, char *fname));
00225 void WriteListAnalysis __PARAMS((FILE *f, int i,char *));
00226 void WriteOutput __PARAMS((FILE *f));
00227 void WriteVariable __PARAMS((FILE *f, VARPTR var, IVAR ivar, int insidelist, int nel));
00228 void WriteVariableOutput __PARAMS((FILE *f, VARPTR var,  int convert, int insidelist, int nel));
00229 void AddForName1 __PARAMS((IVAR ivar, char *name,char *cname, IVAR ivar1));
00230 void ForNameClean __PARAMS((void));
00231 void InitDeclare  __PARAMS((void));
00232 void ResetDeclare __PARAMS((void));
00233 void WriteMain  __PARAMS((FILE *f,char *file));
00234 void FCprintf(FILE*,char *fmt,...);
00235 void Fprintf(FILE*,int,char *fmt,...);
00236 void white __PARAMS( (FILE *f, int ind));
00237 void AddDeclare __PARAMS((int type, char *declaration));
00238 void InitDeclare __PARAMS((void));
00239 void ResetDeclare __PARAMS((void));
00240 void WriteDeclaration  __PARAMS((FILE*f));
00241 void WriteCallRestCheck __PARAMS((FILE *f, VARPTR var,char *name, int iel, int flag));
00242 int CreatePredefVar __PARAMS((char *name));
00243 void Check __PARAMS((FILE *f,  VARPTR var,  int nel));
00244 void CheckSquare __PARAMS((FILE *f,  VARPTR var, char *str,char *str1));
00245 void CheckOptSquare __PARAMS((FILE *f,  VARPTR var, char *str));
00246 void CheckOptDim __PARAMS((FILE *f,  VARPTR var,  int nel));
00247 void OptvarGetSize __PARAMS((char *optvar, char *size, char *data));
00248 void WriteAddInter __PARAMS((char *file));
00249 
00250 
00251 /*** Global variables **/
00252 
00253 extern VARPTR variables[MAXVAR]; /* array of VAR structures */
00254 extern int nVariable; /* number of variables */
00255 extern BASFUNPTR basfun; /* SCILAB function structure */
00256 extern int icre;     /* incremental counter for variable creation */
00257 extern int indent; /* incremental counter for code indentation */
00258 extern int pass ;  /* flag for couting pass on code generation */
00259 extern FORSUBPTR forsub; /* FORTRAN subroutine structure */
00260 extern int nFun; /* total number of functions in "desc" file */
00261 extern char *funNames[MAXFUN]; /* array of function names */
00262 extern char target; /* langage for generation F or C */
00263 
00264 
00265 
00266 /* protos */
00267 
00268 extern void Generate __PARAMS(( char *file));
00269 extern int ShowVariables  __PARAMS((void)); 
00270 extern int FixStackPositions  __PARAMS((void)); 
00271 extern IVAR GetVar  __PARAMS((char *name, int p)); 
00272 extern IVAR GetExistVar  __PARAMS((char *name)); 
00273 extern int CreatePredefVar  __PARAMS((char *name)); 
00274 extern IVAR GetOutVar  __PARAMS((char *name)); 
00275 extern IVAR GetExistOutVar  __PARAMS((void)); 
00276 extern void AddForName  __PARAMS((IVAR ivar, char *name, char *cname, IVAR ivar1)); 
00277 extern void AddForName1  __PARAMS((IVAR ivar, char *name, char *cname, IVAR ivar1)); 
00278 extern void ForNameClean  __PARAMS((void)); 
00279 extern void ChangeForName2  __PARAMS((VARPTR var, char *format,...));
00280 extern void ChangeForName1  __PARAMS((VARPTR var, char *name)); 
00281 extern int GetBasType  __PARAMS((char *sname)); 
00282 extern char *SGetSciType  __PARAMS((int type)); 
00283 extern int GetForType  __PARAMS((char *type)); 
00284 extern char *SGetForType  __PARAMS((int type)); 
00285 extern char *SGetForTypeAbrev  __PARAMS((VARPTR var)); 
00286 extern int SGetForDec  __PARAMS((int type)); 
00287 extern char *SGetCDec  __PARAMS((int type)); 
00288 extern char *SGetForTypeStack  __PARAMS((VARPTR var)); 
00289 extern char *SGetForTypeBConvert  __PARAMS((VARPTR var)); 
00290 extern char *SGetExtForTypeAbrev  __PARAMS((VARPTR var)); 
00291 extern char *SGetExtForTypeStack  __PARAMS((VARPTR var)); 
00292 extern void StrGen  __PARAMS((char *strl, VARPTR var)); 
00293 extern void ForMATRIX  __PARAMS((VARPTR var)); 
00294 extern void ForSTRING  __PARAMS((VARPTR var)); 
00295 extern void ForIMATRIX  __PARAMS((VARPTR var)); 
00296 extern void ForSPARSE  __PARAMS((VARPTR var)); 
00297 extern void ForROW  __PARAMS((VARPTR var)); 
00298 extern void ForCOLUMN  __PARAMS((VARPTR var)); 
00299 extern void ForVECTOR  __PARAMS((VARPTR var)); 
00300 extern void ForPOLYNOM  __PARAMS((VARPTR var)); 
00301 extern void ForSCALAR  __PARAMS((VARPTR var)); 
00302 extern void ForPOINTER  __PARAMS((VARPTR var)); 
00303 extern void ForANY  __PARAMS((VARPTR var)); 
00304 extern void ForLIST  __PARAMS((VARPTR var)); 
00305 extern void ForTLIST  __PARAMS((VARPTR var)); 
00306 extern void ForSEQUENCE  __PARAMS((VARPTR var)); 
00307 extern void ForEMPTY  __PARAMS((VARPTR var)); 
00308 extern void ForWORK  __PARAMS((VARPTR var)); 
00309 extern void ForDIMFOREXT  __PARAMS((VARPTR var)); 
00310 extern int main  __PARAMS((int argc, char **argv)); 
00311 extern void Generate  __PARAMS((char *file)); 
00312 extern int FixStackPositions  __PARAMS((void));
00313 extern void FixForNames  __PARAMS(());
00314 extern void WriteMain  __PARAMS((FILE *f, char *file)); 
00315 extern void WriteAddInter  __PARAMS((char *file)); 
00316 extern void Copyright  __PARAMS((void)); 
00317 extern void WriteHeader  __PARAMS((FILE *f, char *fname0, char *fname)); 
00318 extern void WriteFunctionCode  __PARAMS((FILE *f)); 
00319 extern void WriteOptArgPhase0  __PARAMS((FILE *f, int i));
00320 extern void WriteOptArgPhase1  __PARAMS((FILE *f, int i));
00321 extern void WriteOptArgPhase2  __PARAMS((FILE *f, int i));
00322 
00323 extern void WriteInfoCode  __PARAMS((FILE *f)); 
00324 extern void WriteArgCheck  __PARAMS((FILE *f, int i)); 
00325 extern void WriteOptArg  __PARAMS((FILE *f , VARPTR var)); 
00326 extern void WriteCrossCheck  __PARAMS((FILE *f)); 
00327 extern void WriteCrossCheckExternal __PARAMS((FILE *f)); 
00328 extern void WriteEqualCheck  __PARAMS((FILE *f)); 
00329 extern void WriteListAnalysis  __PARAMS((FILE *f, int i, char *list_type)); 
00330 extern void AddDeclare1 __PARAMS((int type,char *format,...));
00331 
00332 extern void WriteFortranCall  __PARAMS((FILE *f)); 
00333 extern void WriteOutput  __PARAMS((FILE *f)); 
00334 extern void WriteVariable  __PARAMS((FILE *f, VARPTR var, IVAR ivar, int insidelist, int nel)); 
00335 extern int GetNumberInScilabCall  __PARAMS((int ivar)); 
00336 extern int GetNumberInFortranCall  __PARAMS((int ivar)); 
00337 extern char *Forname2Int  __PARAMS((VARPTR var, int i)); 
00338 extern void GenFundef  __PARAMS((char *file, int interf)); 
00339 extern void white  __PARAMS((FILE *f, int ind)); 
00340 extern VARPTR VarAlloc  __PARAMS((void)); 
00341 extern BASFUNPTR BasfunAlloc  __PARAMS((void)); 
00342 extern FORSUBPTR ForsubAlloc  __PARAMS((void)); 
00343 extern int ReadFunction  __PARAMS((FILE *f)); 
00344 extern int ParseScilabLine  __PARAMS((char *s, char **words)); 
00345 extern int ParseLine  __PARAMS((char *s, char **words)); 
00346 extern void ReadListFile  __PARAMS((char *listname, char *varlistname, IVAR ivar, int stack_position)); 
00347 extern int ReadListElement  __PARAMS((FILE *f, char *varlistname, IVAR iivar, int nel, int stack_position)); 
00348 
00349 extern int ShowVariables  __PARAMS((void)); 
00350 extern int FixStackPositions  __PARAMS((void)); 
00351 extern IVAR GetVar  __PARAMS((char *name, int p)); 
00352 extern IVAR GetExistVar  __PARAMS((char *name)); 
00353 extern int CreatePredefVar  __PARAMS((char *name)); 
00354 extern IVAR GetOutVar  __PARAMS((char *name)); 
00355 extern IVAR GetExistOutVar  __PARAMS((void)); 
00356 extern void AddForName  __PARAMS((IVAR ivar, char *name, char *cname, IVAR ivar1)); 
00357 extern void AddForName1  __PARAMS((IVAR ivar, char *name, char *cname, IVAR ivar1)); 
00358 extern void ForNameClean  __PARAMS((void)); 
00359 extern void ChangeForName1  __PARAMS((VARPTR var, char *name)); 
00360 extern int GetBasType  __PARAMS((char *sname)); 
00361 extern char *SGetSciType  __PARAMS((int type)); 
00362 extern int GetForType  __PARAMS((char *type)); 
00363 extern char *SGetForType  __PARAMS((int type)); 
00364 extern char *SGetForTypeAbrev  __PARAMS((VARPTR var)); 
00365 extern int SGetForDec  __PARAMS((int type)); 
00366 extern char *SGetCDec  __PARAMS((int type)); 
00367 extern char *SGetForTypeStack  __PARAMS((VARPTR var)); 
00368 extern char *SGetForTypeBConvert  __PARAMS((VARPTR var)); 
00369 extern char *SGetExtForTypeAbrev  __PARAMS((VARPTR var)); 
00370 extern char *SGetExtForTypeStack  __PARAMS((VARPTR var)); 
00371 extern void OutCOLUMN  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00372 extern void OutROW  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00373 extern void OutVECTOR  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00374 extern void OutMATRIX  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00375 extern void OutSCALAR  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00376 extern void OutCommon  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00377 extern void OutBMATRIX  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00378 extern void OutSTRING  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00379 extern void OutLIST  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00380 extern void OutLISTarg  __PARAMS((FILE *f, VARPTR var, VARPTR var1, int insidelist, int nel)); 
00381 extern void OutSPARSE  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00382 extern void OutIMATRIX  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00383 extern void OutPOLYNOM  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00384 extern void OutPOINTER  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00385 extern void OutSTRINGMAT  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00386 extern void OutANY  __PARAMS((FILE *f, VARPTR var, int insidelist, int nel)); 
00387 extern void WriteVariableOutput  __PARAMS((FILE *f, VARPTR var, int convert, int insidelist, int nel)); 
00388 void OptMATRIX  __PARAMS(( FILE *f, VARPTR var));
00389 void OptOpointer  __PARAMS(( FILE *f, VARPTR var));
00390 void GetDim  __PARAMS((char *str,IVAR ivar)) ;
00391 
00392 
00393 
00394 
00395 
00396 
00397 

Generated on Sun Mar 4 15:03:57 2007 for Scilab [trunk] by  doxygen 1.5.1