Skip to content

Commit 34221f2

Browse files
committed
Add Octave argcargv.i
Signed-off-by: Erez Geva <[email protected]>
1 parent 96337b2 commit 34221f2

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Examples/test-suite/argcargvtest.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%module argcargvtest
22

3-
#if !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGGO) && !defined(SWIGGUILE) && !defined(SWIGJAVA) && !defined(SWIGJAVASCRIPT) && !defined(SWIGMZSCHEME) && !defined(SWIGOCTAVE) && !defined(SWIGR) && !defined(SWIGSCILAB)
3+
#if !defined(SWIGCSHARP) && !defined(SWIGD) && !defined(SWIGGO) && !defined(SWIGGUILE) && !defined(SWIGJAVA) && !defined(SWIGJAVASCRIPT) && !defined(SWIGMZSCHEME) && !defined(SWIGR) && !defined(SWIGSCILAB)
44
%include <argcargv.i>
55

66
%apply (int ARGC, char **ARGV) { (size_t argc, const char **argv) }

Lib/octave/argcargv.i

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* ------------------------------------------------------------
2+
* SWIG library containing argc and argv multi-argument typemaps
3+
* ------------------------------------------------------------ */
4+
5+
%typemap(in) (int ARGC, char **ARGV) {
6+
if ($input.is_scalar_type()) {
7+
$1 = 0; $2 = NULL;
8+
%argument_fail(SWIG_TypeError, "'int ARGC, char **ARGV' is not a list", $symname, $argnum);
9+
}
10+
octave_value_list list = $input.list_value();
11+
int i, len = list.length();
12+
$1 = ($1_ltype) len;
13+
$2 = (char **) malloc((len+1)*sizeof(char *));
14+
for (i = 0; i < len; i++) {
15+
if(!list(i).is_string()) {
16+
$1 = 0;
17+
%argument_fail(SWIG_TypeError, "'int ARGC, char **ARGV' use a non-string", $symname, $argnum);
18+
}
19+
$2[i] = (char *)list(i).string_value().c_str();
20+
}
21+
$2[i] = NULL;
22+
}
23+
24+
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) {
25+
const octave_value& ov = $input;
26+
$1 = !ov.is_scalar_type();
27+
}
28+
29+
%typemap(freearg) (int ARGC, char **ARGV) {
30+
if ($2 != NULL) {
31+
free((void *)$2);
32+
}
33+
}

0 commit comments

Comments
 (0)