/usr/bin/gtstemplate is in libgts-bin 0.7.6+darcs110121-1.1build1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | #! /bin/sh
usage()
{
cat <<EOF
Usage: gtstemplate [OPTIONS] Class ParentClass
Options:
[--no-extra-data]
[--no-extra-method]
[--overload=METHOD]
EOF
exit $1
}
form_name()
{
echo $1 | sed 's/[ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_&/g' | awk '{
if (substr ($1, 1, 1) == "_")
print tolower(substr ($1, 2));
else
print tolower($1);}'
}
if test $# -lt 2; then
usage 1 1>&2
fi
while test $# -gt 0; do
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case $1 in
--no-extra-data)
no_extra_data=yes
;;
--no-extra-method)
no_extra_method=yes
;;
--overload=*)
methods="$methods $optarg"
;;
--*)
usage 1 1>&2
;;
*)
if test -z "$Object"; then
Object=$1
elif test -z "$ParentObject"; then
ParentObject=$1
else
usage 1 1>&2
fi
;;
esac
shift
done
if test -z "$Object" -o -z "$ParentObject"; then
usage 1 1>&2
fi
object=`form_name $Object`
ObjectName=$Object
if test "$no_extra_data" = "yes"; then
Object=$ParentObject
fi
OBJECT=`echo $object | awk '{print toupper ($1)}'`
if test "$no_extra_method" = "yes"; then
ObjectClass=$ParentObject"Class"
else
ObjectClass=$ObjectName"Class"
OBJECT_CLASS=$OBJECT"_CLASS"
fi
parent_object=`form_name $ParentObject`
parent_object_class=$parent_object"_class"
ParentObjectClass=$ParentObject"Class"
object_class=$object"_class"
cat <<EOF
/* $ObjectName: Header */
EOF
if test "$no_extra_data" != "yes"; then
cat <<EOF
typedef struct _$Object $Object;
struct _$Object {
/*< private >*/
$ParentObject parent;
/*< public >*/
/* add extra data here (if public) */
};
EOF
fi
if test "$no_extra_method" != "yes"; then
cat <<EOF
typedef struct _$ObjectClass $ObjectClass;
struct _$ObjectClass {
/*< private >*/
$ParentObjectClass parent_class;
/*< public >*/
/* add extra methods here */
};
EOF
fi
if test "$no_extra_data" != "yes"; then
cat <<EOF
#define $OBJECT(obj) GTS_OBJECT_CAST (obj,\\
$Object,\\
$object_class ())
EOF
fi
if test "$no_extra_method" != "yes"; then
cat <<EOF
#define $OBJECT_CLASS(klass) GTS_OBJECT_CLASS_CAST (klass,\\
$ObjectClass,\\
$object_class())
EOF
fi
cat <<EOF
#define IS_$OBJECT(obj) (gts_object_is_from_class (obj,\\
$object_class ()))
$ObjectClass * $object_class (void);
EOF
if test "$no_extra_data" != "yes"; then
object_new=$object"_new"
cat <<EOF
$Object * $object_new ($ObjectClass * klass);
EOF
fi
cat <<EOF
/* $ObjectName: Object */
EOF
for method in $methods; do
case $method in
destroy)
object_destroy=$object"_destroy"
cat <<EOF
static void $object_destroy (GtsObject * object)
{
/* do object-specific cleanup here */
/* do not forget to call destroy method of the parent */
(* GTS_OBJECT_CLASS ($object_class ())->parent_class->destroy)
(object);
}
EOF
;;
read)
object_read=$object"_read"
cat <<EOF
static void $object_read (GtsObject ** o, GtsFile * fp)
{
/* call read method of parent */
if (GTS_OBJECT_CLASS ($object_class ())->parent_class->read)
(* GTS_OBJECT_CLASS ($object_class ())->parent_class->read)
(o, fp);
if (fp->type == GTS_ERROR)
return;
/* do object-specific read here */
/* do not forget to prepare for next read */
gts_file_next_token (fp);
}
EOF
;;
write)
object_write=$object"_write"
cat <<EOF
static void $object_write (GtsObject * o, FILE * fp)
{
/* call write method of parent */
if (GTS_OBJECT_CLASS ($object_class ())->parent_class->write)
(* GTS_OBJECT_CLASS ($object_class ())->parent_class->write)
(o, fp);
/* do object specific write here */
}
EOF
;;
color)
object_color=$object"_color"
cat <<EOF
static GtsColor $object_color (GtsObject * o)
{
GtsColor c = { 1., 1., 1. }; /* white */
return c;
}
EOF
;;
event)
object_event=$object"_event"
cat <<EOF
static gboolean $object_event (GfsEvent * event, GfsSimulation * sim)
{
if ((* GFS_EVENT_CLASS (GTS_OBJECT_CLASS ($object_class ())->parent_class)->event) (event, sim)) {
/* do object-specific event here */
return TRUE;
}
return FALSE;
}
EOF
;;
*)
echo "gtstemplate: unknown method '$method'"
exit 1;
;;
esac
done
if test -n "$methods" -o "$no_extra_method" != "yes"; then
object_class_init=$object_class"_init"
cat <<EOF
static void $object_class_init ($ObjectClass * klass)
{
/* define new methods and overload inherited methods here */
EOF
if test -n "$object_event"; then
cat <<EOF
GFS_EVENT_CLASS (klass)->event = $object_event;
EOF
fi
if test -n "$object_read"; then
cat <<EOF
GTS_OBJECT_CLASS (klass)->read = $object_read;
EOF
fi
if test -n "$object_write"; then
cat <<EOF
GTS_OBJECT_CLASS (klass)->write = $object_write;
EOF
fi
if test -n "$object_color"; then
cat <<EOF
GTS_OBJECT_CLASS (klass)->color = $object_color;
EOF
fi
if test -n "$object_destroy"; then
cat <<EOF
GTS_OBJECT_CLASS (klass)->destroy = $object_destroy;
EOF
fi
cat <<EOF
}
EOF
else
object_class_init=NULL
fi
if test "$no_extra_data" != "yes"; then
object_init=$object"_init"
cat <<EOF
static void $object_init ($Object * object)
{
/* initialize object here */
}
EOF
else
object_init=NULL
fi
object_info=$object"_info"
cat <<EOF
$ObjectClass * $object_class (void)
{
static $ObjectClass * klass = NULL;
if (klass == NULL) {
GtsObjectClassInfo $object_info = {
"$ObjectName",
sizeof ($Object),
sizeof ($ObjectClass),
(GtsObjectClassInitFunc) $object_class_init,
(GtsObjectInitFunc) $object_init,
(GtsArgSetFunc) NULL,
(GtsArgGetFunc) NULL
};
klass = gts_object_class_new (GTS_OBJECT_CLASS ($parent_object_class ()),
&$object_info);
}
return klass;
}
EOF
if test -n "$object_new"; then
cat <<EOF
$Object * $object_new ($ObjectClass * klass)
{
$Object * object;
object = $OBJECT (gts_object_new (GTS_OBJECT_CLASS (klass)));
return object;
}
EOF
fi
|