summaryrefslogtreecommitdiff
path: root/dist/s_csharp_stat
blob: 54af2ce8ff3efa57842e4880c4310a7d1ecf5ab9 (plain)
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
#!/bin/sh -
#	$Id$
#
# Build the CSharp stat structures

msgcsharp="/*-
 * Automatically built by dist/s_java_csharp.
 *
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2002-2009 Oracle.  All rights reserved.
 */"

f=../csharp/Internal/StatStructs.cs
t=AA_TEST
#trap 'rm -f $t; exit 0' 0 1 2 3 13 15

# Script to convert DB C structure declarations in CSharp declarations
# Pull out the structure we're concerned with, strip out ifdefs and defines
# and finally convert from C to C# types
csclass()
{
    sed -n "/struct $1 {/,/^}/p" < ../dbinc/db.in |
    sed -e "/$1/d" \
    	-e '/^}/d' \
	-e "/CONFIG_TEST/,/#endif/d" \
	-e "/^#/d" \
    	-e 's:\tchar \*:\tinternal string :' \
	-e 's:\tdb_pgno_t:\tinternal uint:' \
	-e 's:\tdb_seq_t:\tinternal long:' \
	-e 's:\tdb_threadid_t:\tinternal uint:' \
	-e 's:\tdb_timeout_t:\tinternal uint:' \
	-e 's:\tDB_LSN:\tinternal DB_LSN_STRUCT:' \
	-e 's:\tDB_TXN_ACTIVE \*:\tinternal IntPtr :' \
	-e 's:\tint\s:\tinternal int :' \
	-e 's:\tint32_t:\tinternal int:' \
	-e 's:\tpid_t:\tinternal int:' \
	-e 's:\troff_t:\tinternal IntPtr:' \
	-e 's:\tsize_t:\tinternal IntPtr:' \
	-e 's:\ttime_t:\tinternal long:' \
    	-e 's:\tu_int32_t:\tinternal uint:' \
        -e 's:\tuintmax_t:\tinternal ulong:' \
	-e "s:/\*.*\*/::" \
    	-e "/\/\*/ {
N
/\/\*.*\*\// {
s:/\*.*\*/::
P
D
}
}"
}

stat_class()
{
	c_struct=__db_$1
	cs_struct=$2

	(cat <<EOF
    [StructLayout(LayoutKind.Sequential)]
    internal struct $cs_struct {
EOF
	 csclass $c_struct
	 echo '    }'
	 echo ) >> $t
}

txn_active()
{
    (echo "internal enum DB_TXN_ACTIVE_STATUS {"
        sed -n "/struct __db_txn_active {/,/^}/p" < ../dbinc/db.in |
	sed -n "/^#define/p" | awk '{print "        " $2 " = " $3 ","}'
	echo "}"
	echo ) >> $t

    (cat <<EOF
    [StructLayout(LayoutKind.Sequential)]
    internal struct DB_TXN_ACTIVE {
EOF

	sed -n "/struct __db_txn_active {/,/^}/p" < ../dbinc/db.in |
	sed -e "/__db_txn_active/d" \
	    -e '/^}/d' \
	    -e "/CONFIG_TEST/,/#endif/d" \
	    -e "/^#/d" \
	    -e "/gid\[.*\]/d" \
	    -e "/name\[.*\]/d" \
	    -e 's:\tchar \*:\tinternal string :' \
	    -e 's:\tdb_pgno_t:\tinternal uint:' \
	    -e 's:\tdb_seq_t:\tinternal long:' \
	    -e 's:\tdb_threadid_t:\tinternal uint:' \
	    -e 's:\tdb_timeout_t:\tinternal uint:' \
	    -e 's:\tDB_LSN:\tinternal DB_LSN_STRUCT:' \
	    -e 's:\tDB_TXN_ACTIVE \*:\tinternal IntPtr:' \
	    -e 's:\tint\s:\tinternal int :' \
	    -e 's:\tint32_t:\tinternal int:' \
	    -e 's:\tpid_t:\tinternal int:' \
	    -e 's:\troff_t:\tinternal IntPtr:' \
	    -e 's:\tsize_t:\tinternal IntPtr:' \
	    -e 's:\ttime_t:\tinternal long:' \
	    -e 's:\tu_int32_t status:\tinternal DB_TXN_ACTIVE_STATUS status:' \
	    -e 's:\tu_int32_t:\tinternal uint:' \
	    -e 's:\tuintmax_t:\tinternal ulong:' \
	    -e "s:/\*.*\*/::"
	echo '    }'
	echo ) >> $t
}

cat > $t <<EOF
$msgcsharp

using System;
using System.Runtime.InteropServices;

namespace BerkeleyDB.Internal {
EOF

stat_class bt_stat BTreeStatStruct
stat_class h_stat HashStatStruct
stat_class lock_stat LockStatStruct
stat_class log_stat LogStatStruct
stat_class mpool_fstat MPoolFileStatStruct
stat_class mpool_stat MPoolStatStruct

cat >>$t <<EOF
    internal struct MempStatStruct {
        internal MPoolStatStruct st;
        internal MPoolFileStatStruct[] files;
}

EOF

stat_class mutex_stat MutexStatStruct
stat_class qam_stat QueueStatStruct
stat_class bt_stat RecnoStatStruct
stat_class repmgr_stat RepMgrStatStruct
stat_class rep_stat ReplicationStatStruct
stat_class seq_stat SequenceStatStruct
stat_class txn_stat TransactionStatStruct

cat >> $t <<EOF
    internal struct DB_LSN_STRUCT {
        internal uint file;
        internal uint offset;
    }

EOF

txn_active

cat >> $t <<EOF
    internal struct TxnStatStruct {
        internal TransactionStatStruct st;
        internal DB_TXN_ACTIVE[] st_txnarray;
        internal byte[][] st_txngids;
        internal string[] st_txnnames;
    }
}

EOF

cmp $f $t > /dev/null 2>&1 ||
    (echo "Building $f" && rm -f $f && cp $t $f && chmod 644 $f)