"Fossies" - the Fresh Open Source Software Archive

Member "sip-0.12.1/config/my_ilib_gen_gateway.sci" (22 Feb 2012, 2756 Bytes) of package /linux/privat/sip-0.12.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Scilab source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "my_ilib_gen_gateway.sci": 0.5.6_vs_0.12.1.

    1 function my_ilib_gen_gateway(name,tables)
    2 //------------------------------------
    3 // generate an interface gateway named name
    4 // from table table taking into account 
    5 // attributes of function i.e mex fmex or scilab interface 
    6 // if name is a full path just extract the filename 
    7   k=strindex(name,['/','\'])
    8   if k~=[] then
    9     path=part(name,1:k($))
   10     name=part(name,k($)+1:length(name))
   11   else
   12      path=''
   13   end
   14   name=strsubst(name,'.c','')
   15   
   16   if typeof(tables)<>'list' then 
   17     tables= list(tables)
   18   end
   19   
   20   L=length(tables); 
   21 
   22   for itable=1:L 
   23     // loop on a list of tables 
   24     if L<> 1 then 
   25       tname = name +string(itable);
   26     else 
   27        tname = name ;
   28     end
   29     table = tables(itable);
   30     [mt,nt]=size(table);
   31     if nt==2 then col= "csci"; table = [table, col(ones(mt,1))];nt = 3 ; end 
   32     if nt<>3 then error('second argument has wrong size ');end 
   33     [gate,names]=new_names(table); 
   34     t=['#include ""sip_common.h""';
   35    '#include <mex.h> ';
   36    '#ifdef SIP_HAVE_SCI_GATEWAY_H';
   37    '  #include <sci_gateway.h> ';
   38    '#endif';
   39     'static int direct_gateway(char *fname,void F(void)) { F();return 0;};'
   40     'SipExport extern Gatefunc ' + names(:) + ';';
   41     'static GenericTable Tab[]={';
   42     '  {'+ gate(:)+','+ names(:)+',""'+table(:,1)+'""},';
   43     '};'
   44     ' '
   45     'SipExport int C2F('+tname+')()'
   46     '{'
   47     '  Rhs = Max(0, Rhs);'
   48     '  (*(Tab[Fin-1].f))(Tab[Fin-1].name,Tab[Fin-1].F);'
   49     '  return 0;'
   50     '}'];
   51     // first chek if we already have a gateway 
   52     [fd,ierr]=mopen(path+tname+'.c')
   53     if ierr== 0 then;
   54       mclose(fd);
   55       t1=mgetl(path+tname+'.c') 
   56       if t1==t then 
   57     //  write(%io(2),'   gateway '+path+tname+'.c'+' unchanged ');
   58       else
   59      mputl(t,path+tname+'.c')    
   60       end
   61     else
   62        // file does not exists we create it 
   63        mputl(t,path+tname+'.c')    
   64     end
   65   end
   66 endfunction
   67 
   68 function [gate,names]=new_names(table) 
   69 // change names according to types 
   70   [mt,nt]=size(table);
   71   gate= "mex_gateway"; 
   72   gate = gate(ones(mt,1)); 
   73   names= " "; 
   74   names= names(ones(mt,1)); 
   75   for i=1:mt 
   76     select table(i,3) 
   77      case 'cmex' then 
   78       names(i) = "mex_" + table(i,2)
   79      case 'fmex' then 
   80       gate(i)="(Myinterfun)fortran_mex_gateway" 
   81       names(i) = "C2F(mex" + table(i,2) + ")"
   82      case 'Fmex' then 
   83       gate(i)="(Myinterfun)fortran_mex_gateway" 
   84       names(i) = "C2F(mex" + table(i,2) + ")"
   85      case 'csci'  then 
   86       gate(i)="(Myinterfun)sci_gateway" 
   87       names(i) = table(i,2)
   88      case 'fsci'  then 
   89       gate(i)="(Myinterfun)sci_gateway" 
   90       names(i) = "C2F(" + table(i,2) + ")"
   91      case 'direct'  then 
   92       gate(i)="(Myinterfun)direct_gateway" 
   93       names(i) = "C2F(" + table(i,2) + ")"
   94     else error(999,"wrong interface type "+table(i,3)); 
   95     end 
   96   end 
   97 endfunction