-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_classes_from_libmatroska
90 lines (78 loc) · 2.5 KB
/
gen_classes_from_libmatroska
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
#!/bin/sh
#
# Distributed under the MIT license
# see the file COPYING for details
# or visit http://www.opensource.org/licenses/mit-license.php
#
# $Id: gen_classes_from_libmatroska 758 2004-09-08 15:52:47Z mosu $
#
# A simple script for converting classes from the
# libmatroska source code into Ruby classes useful for
# matroska.rb
#
# Written by Moritz Bunkus <moritz@bunkus.org>.
#
if [ "$MATROSKADIR" == "" ]; then
MATROSKADIR="$HOME/prog/video/libmatroska/src"
fi
if [ ! -f "$MATROSKADIR/KaxSemantic.cpp" ]; then
MATROSKADIR="$MATROSKADIR/src"
fi
if [ ! -f "$MATROSKADIR/KaxSemantic.cpp" ]; then
echo "Please set the MATROSKADIR environment variable to the libmatroska"
echo "source directory."
exit 1
fi
cat <<EOF
#!/usr/bin/ruby
#
# Distributed under the MIT license
# see the file COPYING for details
# or visit http://www.opensource.org/licenses/mit-license.php
#
# \$Id\$
#
# Classes for the "Matroska EBML doc type". Generated with
# gen_classes_from_libmatroska.
#
# Written by Moritz Bunkus <moritz@bunkus.org>.
#
# This file is generated automatically by the
# gen_classes_from_libmatroska script and should not be
# modified manually!
require "ebml"
module Matroska
EOF
DEFINE_MKX_MASTER="Ebml::Master"
DEFINE_MKX_MASTER_CONS="Ebml::Master"
DEFINE_MKX_MASTER_ORPHAN="Ebml::Master"
DEFINE_MKX_UINTEGER="Ebml::UInteger"
DEFINE_MKX_UINTEGER_DEF="Ebml::UInteger"
DEFINE_MKX_SINTEGER="Ebml::SInteger"
DEFINE_MKX_SINTEGER_DEF="Ebml::SInteger"
DEFINE_MKX_SINTEGER_CONS="Ebml::SInteger"
DEFINE_MKX_STRING="Ebml::String"
DEFINE_MKX_STRING_DEF="Ebml::String"
DEFINE_MKX_UNISTRING="Ebml::UnicodeString"
DEFINE_MKX_BINARY="Ebml::Binary"
DEFINE_MKX_BINARY_CONS="Ebml::Binary"
DEFINE_MKX_FLOAT="Ebml::Float"
DEFINE_MKX_FLOAT_DEF="Ebml::Float"
DEFINE_MKX_DATE="Ebml::Date"
CPP="$MATROSKADIR/KaxSemantic.cpp"
egrep '^DEFINE_MKX_' $CPP | (while read LINE; do
ID=`echo "$LINE" | awk -F"," '{ gsub("[ \t\"]", ""); print tolower($2) }'`
LENGTH=`echo "$LINE" | awk -F"," '{ gsub("[ \t\"]", ""); print $3 }'`
NAME=`echo "$LINE" | awk -F"[,\)]" '{ gsub("[ \t\"]", ""); print $(5) }'`
if [ "$NAME" = ";" ]; then NAME=`echo "$LINE" | awk -F"[,\)]" '{ gsub("[ \t\"]", ""); print $(4) }'`; fi
PARENT=`echo "$LINE" | awk -F"(" '{ gsub("[ \t\"]", ""); print $1 }'`
cat <<EOF
class ${NAME} < ${!PARENT}
def ${NAME}.global_id
@@id ||= Ebml::Id.new(${ID}, ${LENGTH})
return @@id
end
end
EOF
done)
echo end