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
|
#include <string.h>
#include <stdio.h>
#include "stack-c.h"
/**************************************************
* examples of an hand written interface
* Shows how to pass
* - Scilab boolean matrices as arguments
* how to create and return new boolean matrices
**************************************************/
/*-------------------------------------------------
* GetRhsVar(..,'b',...) and CreateVar(..,'b',...
*-------------------------------------------------*/
static void not __PARAMS((int * iv1,int *iv2,int size));
int intex3c_1(fname)
char *fname;
{
static int l1,m1, n1,l2;
static int minlhs=1, minrhs=1, maxlhs=1, maxrhs=1;
CheckRhs(minrhs,maxrhs) ;
CheckLhs(minlhs,maxlhs) ;
/* a boolean matrix argument */
GetRhsVar(1, "b", &m1, &n1, &l1);
/* create a new boolean matrix same size as first argument
*
* note that this is only for illustration since we could directly work
* with istk(l1) which can be modified and returned.
*/
CreateVar(2, "b",&m1,&n1,&l2);
/* fills new matrix */
not(istk(l2),istk(l1),m1*n1);
LhsVar(1) = 2; /* returns new matrix */
return 0;
}
static void not( iv1,iv2, size)
int *iv1,*iv2;
int size;
{
int i;
for ( i=0 ; i < size ; i++) iv1[i] = ! iv2[i];
}
/*---------------------------------------------
* GetRhsVar(...,'b',...)
*---------------------------------------------*/
int intex3c_2(fname)
char *fname;
{
static int l1,m1, n1;
static int minlhs=1, minrhs=1, maxlhs=1, maxrhs=1;
CheckRhs(minrhs,maxrhs) ;
CheckLhs(minlhs,maxlhs) ;
/* a boolean matrix argument */
GetRhsVar(1, "b", &m1, &n1, &l1);
/* we modify the first argument (in fact a copy of the transmited
* argument since arguments are transmited by value
*/
not(istk(l1),istk(l1),m1*n1);
LhsVar(1) = 1; /* return the modified version of argument */
return 0;
}
/*---------------------------------------------
* CreateVarFrom(...,'b',...)
*---------------------------------------------*/
int intex3c_3(fname)
char *fname;
{
static int l1,m1, n1,l2;
static int minlhs=1, minrhs=1, maxlhs=1, maxrhs=1;
CheckRhs(minrhs,maxrhs) ;
CheckLhs(minlhs,maxlhs) ;
/* a boolean matrix argument */
GetRhsVar(1, "b", &m1, &n1, &l1);
/* we make a copy of first argument
* the new array can be accessed through
* istk(l2). Again as pointed out in the first
* example this is just for illustrative purpose
* since GetRhsVar(1,..) gave us a pointer to a copy
* of transmited argument.
*/
CreateVarFrom(2,"b",&m1,&n1,&l2, &l1);
LhsVar(1) = 2; /* return the copy */
return 0;
}
|