00001 #include <stdio.h>
00002 #include <string.h>
00003
00004
00005
00006
00007
00008
00009 int main(int argc,char *argv[])
00010 {
00011 char nam1[256]; char nam2[256]; char generic[256]; char nam4[256];
00012 char fname[256]; char suffix;
00013 FILE *filesce,*filegat,*filei1,*filei2,*filei3,*filei4;
00014 int narg;
00015 narg=argc-1;
00016 if ((narg!=4) & (narg!=3)) return 1;
00017 if (narg==3) {
00018 if (NULL == (filesce = fopen ("startup.sce", "w"))) return 1;
00019 if (NULL == (filegat = fopen ("generic_gateway.c", "w"))) return 1;
00020 } else
00021 {
00022 strcpy(fname,argv[4]);
00023 fname[strlen(fname)]= '\0';
00027 if (NULL == (filei4=fopen(fname+1,"r"))) return 1;
00028
00029 fscanf(filei4,"%s",nam2); strcpy(nam1,nam2);strcat(nam1,".sce");
00030 fscanf(filei4,"%s",generic); strcpy(nam4,generic);strcat(nam4,"_gateway.c");
00031 fclose(filei4);
00032 if (NULL == (filesce = fopen (nam1, "w"))) return 1;
00033 if (NULL == (filegat = fopen (nam4, "w"))) return 1;
00034 }
00035 fprintf(filesce, "scilab_functions=[... \n");
00036 fprintf(filegat, "#include \"mex.h\" \n");
00037 fprintf(filegat, " \n");
00038
00039
00040 strcpy(fname,argv[3]);
00041 fname[strlen(fname)]= '\0';
00044 if (NULL == (filei3=fopen(fname+1,"r"))) return 1;
00045
00046
00047 while (1)
00048 {
00049 int j;
00050 if ( fscanf(filei3,"%s",nam1) == EOF ) break;
00051 j= strlen(nam1);
00052 suffix=nam1[j-1];
00053 while ( (j != 0) && (nam1[j] != '.')) j--;
00054 nam1[j]= '\0';
00055 if ((suffix=='c') | (suffix=='C')) fprintf(filegat, "extern Gatefunc %s;\n",nam1);
00056 if ((suffix=='f') | (suffix=='F')) fprintf(filegat, "extern Gatefunc C2F(%s);\n",nam1);
00057 }
00058 fclose(filei3);
00059
00060
00061 strcpy(fname,argv[1]);
00062 fname[strlen(fname)]= '\0';
00065
00066 if (NULL == (filei1=fopen(fname+1,"r"))) return 1;
00067
00068
00069 while (1)
00070 {
00071 if ( fscanf(filei1,"%s",nam1) == EOF ) break;
00072 fprintf(filesce, "\"%s\";\n",nam1);
00073 }
00074
00075 fprintf(filesce," ]; \n");
00076 fprintf(filesce, " \n");
00077 fclose(filei1);
00078
00079
00080 fprintf(filegat, " \n");
00081 fprintf(filegat,"static GenericTable Tab[]={ \n");
00082
00083 fprintf(filesce, " \n");
00084 fprintf(filesce,"gateway_routines=[...\n");
00085
00086 strcpy(fname,argv[3]);
00087 fname[strlen(fname)]= '\0';
00090 if (NULL == (filei3=fopen(fname+1,"r"))) return 1;
00091
00092
00093 while (1)
00094 {
00095 int j;
00096 if ( fscanf(filei3,"%s",nam1) == EOF ) break;
00097 j= strlen(nam1);
00098 suffix=nam1[j-1];
00099 while ( (j != 0) && (nam1[j] != '.')) j--;
00100 nam1[j]= '\0';
00101 if ((suffix=='c') | (suffix=='C')) fprintf(filegat, "{mex_gateway, %s,\"err msg\"},\n",nam1);
00102 if ((suffix=='f') | (suffix=='F')) fprintf(filegat, "{fortran_mex_gateway, C2F(%s),\"err msg\"},\n",nam1);
00103 fprintf(filesce, "\"%s.o\";\n",nam1);
00104 }
00105 fprintf(filegat, " }; \n");
00106 fprintf(filegat, " \n");
00107
00108 fprintf(filesce, "]; \n");
00109 fprintf(filesce, " \n");
00110
00111 fprintf(filegat, "int C2F(%s_gateway)() \n", generic);
00112 fprintf(filegat, "{ Rhs = Max(0, Rhs); \n");
00113 fprintf(filegat,"(*(Tab[Fin-1].f))(Tab[Fin-1].name,Tab[Fin-1].F); \n");
00114 fprintf(filegat,"return 0; \n");
00115 fprintf(filegat,"}; \n");
00116
00117
00118 strcpy(fname,argv[2]);
00119 fname[strlen(fname)]= '\0';
00123
00124 if (NULL == (filei2=fopen(fname+1,"r")))
00125 return 1;
00126 fprintf(filesce,"util_routines =[... \n");
00127
00128
00129 while (1)
00130 {
00131 if ( fscanf(filei2,"%s",nam1) == EOF ) break;
00132 fprintf(filesce, "\"%s\"; \n", nam1);
00133 }
00134
00135 fprintf(filesce, " ]; \n");
00136 fclose(filei2);
00137
00138
00139 fprintf(filesce,"object_files=G_make([\"%s_gateway.o\";gateway_routines;util_routines],\"%s.dll\"); \n", generic, generic);
00140
00141 fprintf(filesce,"addinter(object_files,\"%s_gateway\",scilab_functions); \n",generic);
00142
00143 fclose(filesce);
00144 fclose(filegat);
00145 return 0;
00146
00147 }
00148