LoadFunctionsTab.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------------*/
00002 /* INRIA 2006 */
00003 /* Allan CORNET */
00004 /*-----------------------------------------------------------------------------------*/
00005 #include "MALLOC.h"
00006 #include <stdlib.h>
00007 #include <stdio.h>
00008 #include <string.h>
00009 #include "machine.h"
00010 #include "hashtable_core.h"
00011 #include "getmodules.h"
00012 #include "setgetSCIpath.h"
00013 #include "LoadFunctionsTab.h"
00014 /*-----------------------------------------------------------------------------------*/  
00015 static int firstentry = 0;
00016 /*-----------------------------------------------------------------------------------*/  
00017 extern int C2F(cvname) __PARAMS((integer *,char *,integer *, unsigned long int));
00018 extern BOOL FileExist(char *filename);
00019 /*-----------------------------------------------------------------------------------*/  
00020 static int Add_a_Scilab_primitive_in_hashtable(char *str, int *dataI, int *data);
00021 static BOOL Load_primitives_from_file(char *filename);
00022 /*-----------------------------------------------------------------------------------*/  
00023 void LoadFunctionsTab(void)
00024 {
00025         struct MODULESLIST *Modules=NULL;
00026         char *SciPath=NULL;
00027         
00028         int j=0;
00029 
00030         if ( firstentry != 0 ) return;
00031 
00032         SciPath=getSCIpath();
00033         Modules=getmodules();
00034         /* je ne libere pas Modules pour accelerer le prochain appel ŕ getmodule */
00035         /* liberé dans sciquit.c */
00036 
00037         for (j=0;j<Modules->numberofModules;j++)
00038         {
00039                 #define FORMATFILENAME "%s/modules/%s/sci_gateway/%s"
00040                 char *filename_primitives_list=NULL;
00041                 int len=strlen(FORMATFILENAME)+strlen(SciPath)+strlen(Modules->ModuleList[j])*2;
00042 
00043                 filename_primitives_list=(char*)MALLOC((len+1)*sizeof(char));
00044                 sprintf(filename_primitives_list,FORMATFILENAME,SciPath,Modules->ModuleList[j],Modules->ModuleList[j]);
00045 
00046                 Load_primitives_from_file(filename_primitives_list);
00047 
00048                 if (filename_primitives_list) { FREE(filename_primitives_list);filename_primitives_list=NULL;}
00049         }
00050 
00051         if (SciPath){FREE(SciPath);SciPath=NULL;}
00052         firstentry = 1;
00053 
00054 }
00055 /*-----------------------------------------------------------------------------------*/
00056 static int Add_a_Scilab_primitive_in_hashtable(char *str, int *dataI, int *data)
00057 {
00058         int ldata;
00059         int id[nsiz];
00060         int zero=0;
00061         C2F(cvname)(id,str,&zero,strlen(str));
00062         ldata= (*dataI)*100+*data;
00063         return( action_hashtable_scilab_functions(id,str,&ldata,SCI_HFUNCTIONS_ENTER));
00064 }
00065 /*-----------------------------------------------------------------------------------*/
00066 static int Load_primitives_from_file(char *filename)
00067 {
00068         BOOL bOK=FALSE;
00069         if (FileExist(filename))
00070         {
00071                 #define LineMaxSize 1024
00072                 char Line[LineMaxSize];
00073                 FILE *pFile;
00074                 int dataI=0;
00075                 int data=0;
00076                 char namefunction[MAXLENGHTFUNCTIONNAME];
00077 
00078                 pFile=fopen(filename,"rt");
00079                 while (fgets(Line, LineMaxSize,pFile))
00080                 {
00081                         if (Line[0]!=';')
00082                         {
00083                                 int retval=0;
00084                                 retval=sscanf(Line,"%d %d %s",&dataI,&data,namefunction);
00085                                 if (retval == 3)
00086                                 {
00087                                         Add_a_Scilab_primitive_in_hashtable(namefunction,&dataI,&data);
00088                                 }
00089                         }
00090                 }
00091                 fclose(pFile);
00092                 bOK=TRUE;
00093         }
00094         return bOK;
00095 }
00096 /*-----------------------------------------------------------------------------------*/

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