4 extern int gcd(int x, int y);
5 extern int gcdmain(int argc, char *argv[]);
6 extern int count(char *bytes, int len, char c);
7 extern void capitalize (char *str, int len);
8 extern void circle (double cx, double cy);
9 extern int squareCubed (int n, int *OUTPUT);
15 extern int gcd(int x, int y);
17 %typemap(in) (int argc, char *argv[]) {
20 if (TYPE($input) != T_ARRAY) {
21 SWIG_exception(SWIG_ValueError, "Expected an array");
23 $1 = RARRAY($input)->len;
25 SWIG_exception(SWIG_ValueError, "List must contain at least 1 element");
27 $2 = (char **) malloc(($1+1)*sizeof(char *));
28 for (i = 0; i < $1; i++) {
29 VALUE s = rb_ary_entry($input,i);
30 if (TYPE(s) != T_STRING) {
32 SWIG_exception(SWIG_ValueError, "List items must be strings");
39 %typemap(freearg) (int argc, char *argv[]) {
43 extern int gcdmain(int argc, char *argv[]);
45 %typemap(in) (char *bytes, int len) {
46 if (TYPE($input) != T_STRING) {
47 SWIG_exception(SWIG_ValueError, "Expected a string");
49 $1 = STR2CSTR($input);
50 $2 = RSTRING($input)->len;
53 extern int count(char *bytes, int len, char c);
56 /* This example shows how to wrap a function that mutates a string */
58 %typemap(in) (char *str, int len) {
60 if (TYPE($input) != T_STRING) {
61 SWIG_exception(SWIG_ValueError,"Expected a string");
63 temp = STR2CSTR($input);
64 $2 = RSTRING($input)->len;
65 $1 = (char *) malloc($2+1);
69 /* Return the mutated string as a new object. */
71 %typemap(argout, fragment="output_helper") (char *str, int len) {
73 o = rb_str_new($1,$2);
74 $result = output_helper($result,o);
78 extern void capitalize(char *str, int len);
80 /* A multi-valued constraint. Force two arguments to lie
81 inside the unit circle */
83 %typemap(check) (double cx, double cy) {
84 double a = $1*$1 + $2*$2;
86 SWIG_exception(SWIG_ValueError,"$1_name and $2_name must be in unit circle");
90 extern void circle(double cx, double cy);