PageRenderTime 15ms CodeModel.GetById 10ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/ruby/progargcargv.i

#
Swig | 34 lines | 20 code | 6 blank | 8 comment | 0 complexity | 320093f09f6a68a8914898f1228b4f3c MD5 | raw file
 1/*
 2int PROG_ARGC
 3char **PROG_ARGV
 4
 5    Some C function receive argc and argv from C main function.
 6    This typemap provides ignore typemap which pass Ruby ARGV contents
 7    as argc and argv to C function.
 8*/
 9
10
11
12// argc and argv
13%typemap(in,numinputs=0) int PROG_ARGC {
14    $1 = RARRAY_LEN(rb_argv) + 1;
15}
16
17%typemap(in,numinputs=0) char **PROG_ARGV {
18    int i, n;
19    VALUE ary = rb_eval_string("[$0] + ARGV");
20    n = RARRAY_LEN(ary);
21    $1 = (char **)malloc(n + 1);
22    for (i = 0; i < n; i++) {
23	VALUE v = rb_obj_as_string(RARRAY_PTR(ary)[i]);
24	$1[i] = (char *)malloc(RSTRING_LEN(v) + 1);
25	strcpy($1[i], RSTRING_PTR(v));
26    }
27}
28
29%typemap(freearg) char **PROG_ARGV {
30    int i, n = RARRAY_LEN(rb_argv) + 1;
31    for (i = 0; i < n; i++) free($1[i]);
32    free($1);
33}
34