File: makeoctfilewrapper

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (108 lines) | stat: -rwxr-xr-x 2,767 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#! /bin/sh

# This program is granted to the public domain

# 2003-01-03 Paul Kienzle <pkienzle@users.sf.net>
# * eliminate sed --- use direct string interpolation for variables
# * define both the C and fortran names for mexFunction in the oct-file.
# 2001-06-20 Paul Kienzle <pkienzle@users.sf.net>
# * eliminate $(arg:0:1) since it is not available in all sh versions
# 2001-09-20 Paul Kienzle <pkienzle@users.sf.net>
# * use config-like syntax to set the name of mkoctfile and the path to mex

test $# -lt 1 && echo usage: mex2oct -options file.c && exit 1

first=""
for arg in $*; do
    case "$arg" in -c) compileonly=1 ;; -*) ;; *) first="$arg"; break ;; esac
done

# default the name of the octave function from the first filename
dir=`dirname $first`
first=`basename $first`
#echo "first= $first"
ext=`echo $first | sed 's;.*\.;.;g'`
#echo "ext= $ext"
name=`basename $first $ext`
#echo "name=$name ext=$ext"

case "$ext" in
  f*|F*)
    invoke=Fortran_mex
    otherfn=mexFunction
  ;;
  *)
    invoke=C_mex
    otherfn="F77_FUNC(mexfunction,MEXFUNCTION)"
  ;;
esac

# search for a .m file which will be used for the help string
# in the mex function.
if test -f $dir/$name.m ; then
	mfile=$dir/$name.m
elif test -f ./$name.m ; then
	mfile=./$name.m
elif test -f $dir/../../../Psychtoolbox/PsychBasic/$name.m ; then
	mfile=$dir/../../../Psychtoolbox/PsychBasic/$name.m
else
	mfile=""
fi

cat <<EOF > Octave/$name.cc
// This C++ file is the interface between GNU/Octave and Psychtoolbox
// module $name. It defines the entry-point function F$name and the online
// help for $name. The function itself (see bottom of file) is just a
// wrapper around octFunction(), the real command dispatcher defined in
// the PsychScriptingGlue.cc file.
// This file is autogenerated, please do not edit!
//

#ifdef PTBOCTAVE
#define PTBMODULE_$name
#include <octave/oct.h>

extern "C" {
  // mex.cc names both mexFunction (c) and MEXFUNCTION (Fortran)
  // but the mex file only defines one of them, so define the other
  // here just to keep the linker happy, but don't ever call it.
  void $otherfn() {}
  const char *mexFunctionName = "$name";
} ;

DEFUN_DLD($name, args, nargout,
EOF

if test "X$mfile" = "X" ; then
	cat <<EOF >> Octave/$name.cc
"\
$name not directly documented. Try the following:\n\
   type(file_in_loadpath('$name.m'))\n\
")

EOF
else
	gawk 'BEGIN{print "\"\\";printing=0;} 
		/^[ \t]*[%#]/ {printing=1;
		gsub(/^[ \t]*[%#]*/,""); 
		gsub(/\\/,"\\\\"); 
		gsub(/"/,"\\\""); 
		print $0 "\\n\\"; next}
		{if (printing) exit;}
		END{print "\")"}' \
		$mfile >> Octave/$name.cc

EOF

fi

cat <<EOF >> Octave/$name.cc
{
  octave_value_list octFunction(const octave_value_list &, const int);
  return octFunction(args, nargout);
}
#endif

EOF

echo Done.