File: ilib_gen_gateway.sci

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (94 lines) | stat: -rw-r--r-- 2,638 bytes parent folder | download | duplicates (2)
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
function ilib_gen_gateway(name,tables)
// Copyright Enpc 
//------------------------------------
// generate an interface gateway named name
// from table table taking into account 
// attributes of function i.e mex fmex or scilab interface 
// if name is a full path just extract the filename 
  k=strindex(name,['/','\'])
  if k~=[] then
    path=part(name,1:k($))
    name=part(name,k($)+1:length(name))
  else
     path=''
  end
  name=strsubst(name,'.c','')
  
  if typeof(tables)<>'list' then 
    tables= list(tables)
  end
  
  L=length(tables); 

  for itable=1:L 
    // loop on a list of tables 
    if L<> 1 then 
      tname = name +string(itable);
    else 
       tname = name ;
    end
    table = tables(itable);
    [mt,nt]=size(table);
    if nt==2 then col= "csci"; table = [table, col(ones(mt,1))];nt = 3 ; end 
    if nt<>3 then error('second argument has wrong size ');end 
    [gate,names]=new_names(table); 
    t=[ '#include <mex.h> ';
	'static int direct_gateway(char *fname,void F(void)) { F();return 0;};'
	'extern Gatefunc ' + names(:) + ';';
	'static GenericTable Tab[]={';
	'  {'+ gate(:)+','+ names(:)+',""'+table(:,1)+'""},';
	'};'
	' '
	'int C2F('+tname+')()'
	'{'
	'  Rhs = Max(0, Rhs);'
	'  (*(Tab[Fin-1].f))(Tab[Fin-1].name,Tab[Fin-1].F);'
	'  return 0;'
	'}'];
    // first chek if we already have a gateway 
    [fd,ierr]=mopen(path+tname+'.c')
    if ierr== 0 then;
      mclose(fd);
      t1=mgetl(path+tname+'.c') 
      if t1==t then 
	//	write(%io(2),'   gateway '+path+tname+'.c'+' unchanged ');
      else
	 mputl(t,path+tname+'.c')    
      end
    else
       // file does not exists we create it 
       mputl(t,path+tname+'.c')    
    end
  end
endfunction

function [gate,names]=new_names(table) 
// change names according to types 
  [mt,nt]=size(table);
  gate= "mex_gateway"; 
  gate = gate(ones(mt,1)); 
  names= " "; 
  names= names(ones(mt,1)); 
  for i=1:mt 
    select table(i,3) 
     case 'cmex' then 
      names(i) = "mex_" + table(i,2)
     case 'fmex' then 
      gate(i)="(Myinterfun)fortran_mex_gateway" 
      names(i) = "C2F(mex" + table(i,2) + ")"
     case 'Fmex' then 
      gate(i)="(Myinterfun)fortran_mex_gateway" 
      names(i) = "C2F(mex" + table(i,2) + ")"
     case 'csci'  then 
      gate(i)="(Myinterfun)sci_gateway" 
      names(i) = table(i,2)
     case 'fsci'  then 
      gate(i)="(Myinterfun)sci_gateway" 
      names(i) = "C2F(" + table(i,2) + ")"
     case 'direct'  then 
      gate(i)="(Myinterfun)direct_gateway" 
      names(i) = "C2F(" + table(i,2) + ")"
    else error(999,"wrong interface type "+table(i,3)); 
    end 
  end 
endfunction