1 %module li_cstring
2
3 %include "cstring.i"
4
5 #ifndef SWIG_CSTRING_UNIMPL
6
7 %cstring_input_binary(char *str_in, int n);
8 %cstring_bounded_output(char *out1, 512);
9 %cstring_chunk_output(char *out2, 64);
10 %cstring_bounded_mutable(char *out3, 512);
11 %cstring_mutable(char *out4, 32);
12 %cstring_output_maxsize(char *out5, int max);
13 %cstring_output_withsize(char *out6, int *size);
14
15 #ifdef __cplusplus
16 %cstring_output_allocate(char **out7, delete [] *$1);
17 %cstring_output_allocate_size(char **out8, int *size, delete [] *$1);
18 #else
19 %cstring_output_allocate(char **out7, free(*$1));
20 %cstring_output_allocate_size(char **out8, int *size, free(*$1));
21 #endif
22
23 %inline %{
24
count(char * str_in,int n,char c)25 int count(char *str_in, int n, char c) {
26 int r = 0;
27 while (n > 0) {
28 if (*str_in == c) {
29 r++;
30 }
31 str_in++;
32 --n;
33 }
34 return r;
35 }
36
test1(char * out1)37 void test1(char *out1) {
38 strcpy(out1,"Hello World");
39 }
40
test2(char * out2)41 void test2(char *out2) {
42 int i;
43 for (i = 0; i < 64; i++) {
44 *out2 = (char) i + 32;
45 out2++;
46 }
47 }
48
test3(char * out3)49 void test3(char *out3) {
50 strcat(out3,"-suffix");
51 }
52
test4(char * out4)53 void test4(char *out4) {
54 strcat(out4,"-suffix");
55 }
56
test5(char * out5,int max)57 void test5(char *out5, int max) {
58 int i;
59 for (i = 0; i < max; i++) {
60 out5[i] = 'x';
61 }
62 out5[max]='\0';
63 }
64
test6(char * out6,int * size)65 void test6(char *out6, int *size) {
66 int i;
67 for (i = 0; i < (*size/2); i++) {
68 out6[i] = 'x';
69 }
70 *size = (*size/2);
71 }
72
test7(char ** out7)73 void test7(char **out7) {
74 #ifdef __cplusplus
75 *out7 = new char[64];
76 #else
77 *out7 = malloc(64);
78 #endif
79 (*out7)[0] = 0;
80 strcat(*out7,"Hello world!");
81 }
82
test8(char ** out8,int * size)83 void test8(char **out8, int *size) {
84 int i;
85 #ifdef __cplusplus
86 *out8 = new char[64];
87 #else
88 *out8 = malloc(64);
89 #endif
90 for (i = 0; i < 64; i++) {
91 (*out8)[i] = (char) i+32;
92 }
93 *size = 64;
94 }
95
96 %}
97
98 #endif
99