PageRenderTime 74ms CodeModel.GetById 24ms app.highlight 35ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/rel-1-3-15/SWIG/Examples/mzscheme/multimap/example.i

#
Swig | 81 lines | 60 code | 16 blank | 5 comment | 0 complexity | ee30c6f12ed6b4f8a536769e845cfa55 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
 1/* File : example.i */
 2%module example
 3%include exception.i
 4%include typemaps.i
 5
 6extern int    gcd(int x, int y);
 7
 8%typemap(mzscheme,in) (int argc, char *argv[]) {
 9  int i;
10  Scheme_Object **elms;
11  if (!SCHEME_VECTORP($input)) {
12    scheme_wrong_type("$name","vector",$argnum,argc,argv);
13  }
14  $1 = SCHEME_VEC_SIZE($input);
15  elms = SCHEME_VEC_ELS($input);
16  if ($1 == 0) {
17    scheme_wrong_type("$name","vector",$argnum,argc,argv);
18  }
19  $2 = (char **) malloc(($1+1)*sizeof(char *));
20  for (i = 0; i < $1; i++) {
21    if (!SCHEME_STRINGP(elms[i])) {
22      free($2);
23      scheme_wrong_type("$name","vector",$argnum,argc,argv);      
24    }
25    $2[i] = SCHEME_STR_VAL(elms[i]);
26  }
27  $2[i] = 0;
28}
29
30%typemap(mzscheme,freear) (int argc, char *argv[]) {
31  free($2);
32}
33extern int gcdmain(int argc, char *argv[]);
34
35%typemap(mzscheme,in) (char *bytes, int len) {
36  if (!SCHEME_STRINGP($input)) {
37     scheme_wrong_type("$name","string",1,argc,argv);
38  }	
39  $1 = SCHEME_STR_VAL($input);
40  $2 = SCHEME_STRLEN_VAL($input);
41}
42
43extern int count(char *bytes, int len, char c);
44
45
46/* This example shows how to wrap a function that mutates a string */
47
48%typemap(mzscheme,in) (char *str, int len) {
49  if (!SCHEME_STRINGP($input)) {
50     scheme_wrong_type("$name","string",1,argc,argv);
51  }	
52  $2 = SCHEME_STRLEN_VAL($input);
53  $1 = (char *) malloc($2+1);
54  memmove($1,SCHEME_STR_VAL($input),$2);
55}
56
57/* Return the mutated string as a new object.  */
58
59%typemap(mzscheme,argout) (char *str, int len) {
60   Scheme_Object *s;
61   s = scheme_make_sized_string($1,$2,1);
62   SWIG_APPEND_VALUE(s);
63   free($1);
64}   
65
66extern void capitalize(char *str, int len);
67
68/* A multi-valued constraint.  Force two arguments to lie
69   inside the unit circle */
70
71%typemap(check) (double cx, double cy) {
72   double a = $1*$1 + $2*$2;
73   if (a > 1.0) {
74	SWIG_exception(SWIG_ValueError,"$1_name and $2_name must be in unit circle");
75        return NULL;
76   }
77}
78
79extern void circle(double cx, double cy);
80
81