File: Gengatsce.c

package info (click to toggle)
scilab 2.6-4
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 54,632 kB
  • ctags: 40,267
  • sloc: ansic: 267,851; fortran: 166,549; sh: 10,005; makefile: 4,119; tcl: 1,070; cpp: 233; csh: 143; asm: 135; perl: 130; java: 39
file content (150 lines) | stat: -rw-r--r-- 4,616 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <stdio.h>
#include <string.h>

/* 
   Gengatsce Xfilename1   Xfilename2   Xfilename3        Xfilename4
             functions     others.o      mex.c .f      startup generic
*/

int main(argc,argv)
     int argc;char *argv[];
{
  char nam1[256]; char nam2[256]; char generic[256]; char nam4[256];
  char fname[256]; char suffix;
  FILE *filesce,*filegat,*filei1,*filei2,*filei3,*filei4;
  int i=0;
  int narg;
  narg=argc-1;
  if ((narg!=4) & (narg!=3)) return 1;
  if (narg==3) {
  if (NULL == (filesce = fopen ("startup.sce", "w"))) return 1;
  if (NULL == (filegat = fopen ("generic_gateway.c", "w"))) return 1;
  } else
    {
  strcpy(fname,argv[4]);
  fname[strlen(fname)]= '\0';
  /** we use fname +1 since msvc makefile temporary filenames 
      begin whith extra @ char **/

  if (NULL == (filei4=fopen(fname+1,"r")))  return 1;
  /*  nam2 = the name;  nam1 (tmp) = nam2.sce = name of the Scilab script */
      fscanf(filei4,"%s",nam2); strcpy(nam1,nam2);strcat(nam1,".sce");
      fscanf(filei4,"%s",generic); strcpy(nam4,generic);strcat(nam4,"_gateway.c"); 
      fclose(filei4);
      if (NULL == (filesce = fopen (nam1, "w"))) return 1;
      if (NULL == (filegat = fopen (nam4, "w"))) return 1;
    }
  fprintf(filesce, "scilab_functions=[... \n");
  fprintf(filegat, "#include \"mex.h\" \n"); 
  fprintf(filegat, "      \n");


  strcpy(fname,argv[3]);
  fname[strlen(fname)]= '\0';
  /** we use fname +1 since msvc makefile temporary filenames 
      begin whith extra @ char **/
  if (NULL == (filei3=fopen(fname+1,"r")))    return 1;

  /*  loop  */
  while (1)
    {
      int j;
      if ( fscanf(filei3,"%s",nam1) == EOF ) break;
      j= strlen(nam1);
      suffix=nam1[j-1];
      while ( (j != 0) && (nam1[j] != '.')) j--; 
      nam1[j]= '\0';
      if ((suffix=='c') | (suffix=='C')) fprintf(filegat, "extern Gatefunc %s;\n",nam1);
      if ((suffix=='f') | (suffix=='F')) fprintf(filegat, "extern Gatefunc C2F(%s);\n",nam1);
    }
  fclose(filei3);

  /*   ***********Open Xfilename1*************   */
  strcpy(fname,argv[1]);
  fname[strlen(fname)]= '\0';
  /** we use fname +1 since msvc makefile temporary filenames 
      begin whith extra @ char **/
  /********* scilab_functions *************/
  if (NULL == (filei1=fopen(fname+1,"r"))) return 1;

  /* loop  */
  while (1)
    {
      if ( fscanf(filei1,"%s",nam1) == EOF ) break;
      fprintf(filesce, "\"%s\";\n",nam1);
    }
  /* end loop */
  fprintf(filesce,"                 ]; \n");
  fprintf(filesce, "      \n");
  fclose(filei1);

  /* end loop */
  fprintf(filegat, "      \n");
  fprintf(filegat,"static GenericTable Tab[]={ \n"); 

  fprintf(filesce, "      \n");
  fprintf(filesce,"gateway_routines=[...\n"); 

  strcpy(fname,argv[3]);
  fname[strlen(fname)]= '\0';
  /** we use fname +1 since msvc makefile temporary filenames 
      begin whith extra @ char **/
  if (NULL == (filei3=fopen(fname+1,"r")))    return 1;

  /*  loop  */
  while (1)
    {
      int j;
      if ( fscanf(filei3,"%s",nam1) == EOF ) break;
      j= strlen(nam1);
      suffix=nam1[j-1];
      while ( (j != 0) && (nam1[j] != '.')) j--; 
      nam1[j]= '\0';
      if ((suffix=='c') | (suffix=='C')) fprintf(filegat, "{mex_gateway, %s,\"err msg\"},\n",nam1);
      if ((suffix=='f') | (suffix=='F')) fprintf(filegat, "{fortran_mex_gateway, C2F(%s),\"err msg\"},\n",nam1);
      fprintf(filesce, "\"%s.o\";\n",nam1);
    }
  fprintf(filegat, "   }; \n");
  fprintf(filegat, "    \n");

  fprintf(filesce, "]; \n");
  fprintf(filesce, "    \n");
  
  fprintf(filegat, "int C2F(%s_gateway)() \n", generic);
  fprintf(filegat, "{  Rhs = Max(0, Rhs);   \n");
  fprintf(filegat,"(*(Tab[Fin-1].f))(Tab[Fin-1].name,Tab[Fin-1].F); \n");  
  fprintf(filegat,"return 0; \n");
  fprintf(filegat,"}; \n");


  strcpy(fname,argv[2]);
  fname[strlen(fname)]= '\0';
  /** we use fname +1 since msvc makefile temporary filenames 
      begin whith extra @ char **/

  /*     ********util_routines*************   */
  if (NULL == (filei2=fopen(fname+1,"r")))
    return 1;
fprintf(filesce,"util_routines =[...   \n");

  /*loop */
  while (1)
    {
      if ( fscanf(filei2,"%s",nam1) == EOF ) break;
      fprintf(filesce, "\"%s\";  \n", nam1);
    }
  /* end loop */
  fprintf(filesce, "             ]; \n");
  fclose(filei2);

  /*     *************G_make****************** */
fprintf(filesce,"object_files=G_make([\"%s_gateway.o\";gateway_routines;util_routines],\"%s.dll\"); \n", generic, generic);

fprintf(filesce,"addinter(object_files,\"%s_gateway\",scilab_functions); \n",generic);

  fclose(filesce);
  fclose(filegat);
  return 0;

}