PageRenderTime 45ms CodeModel.GetById 18ms 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
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /*
  2. int PROG_ARGC
  3. char **PROG_ARGV
  4. Some C function receive argc and argv from C main function.
  5. This typemap provides ignore typemap which pass Ruby ARGV contents
  6. as argc and argv to C function.
  7. */
  8. // argc and argv
  9. %typemap(in,numinputs=0) int PROG_ARGC {
  10. $1 = RARRAY_LEN(rb_argv) + 1;
  11. }
  12. %typemap(in,numinputs=0) char **PROG_ARGV {
  13. int i, n;
  14. VALUE ary = rb_eval_string("[$0] + ARGV");
  15. n = RARRAY_LEN(ary);
  16. $1 = (char **)malloc(n + 1);
  17. for (i = 0; i < n; i++) {
  18. VALUE v = rb_obj_as_string(RARRAY_PTR(ary)[i]);
  19. $1[i] = (char *)malloc(RSTRING_LEN(v) + 1);
  20. strcpy($1[i], RSTRING_PTR(v));
  21. }
  22. }
  23. %typemap(freearg) char **PROG_ARGV {
  24. int i, n = RARRAY_LEN(rb_argv) + 1;
  25. for (i = 0; i < n; i++) free($1[i]);
  26. free($1);
  27. }