1#!/bin/sh -
2#	$Id$
3#
4# Build the CSharp stat structures
5
6msgcsharp="/*-
7 * Automatically built by dist/s_java_csharp.
8 *
9 * See the file LICENSE for redistribution information.
10 *
11 * Copyright (c) 2002-2009 Oracle.  All rights reserved.
12 */"
13
14f=../csharp/Internal/StatStructs.cs
15t=AA_TEST
16#trap 'rm -f $t; exit 0' 0 1 2 3 13 15
17
18# Script to convert DB C structure declarations in CSharp declarations
19# Pull out the structure we're concerned with, strip out ifdefs and defines
20# and finally convert from C to C# types
21csclass()
22{
23    sed -n "/struct $1 {/,/^}/p" < ../dbinc/db.in |
24    sed -e "/$1/d" \
25    	-e '/^}/d' \
26	-e "/CONFIG_TEST/,/#endif/d" \
27	-e "/^#/d" \
28    	-e 's:\tchar \*:\tinternal string :' \
29	-e 's:\tdb_pgno_t:\tinternal uint:' \
30	-e 's:\tdb_seq_t:\tinternal long:' \
31	-e 's:\tdb_threadid_t:\tinternal uint:' \
32	-e 's:\tdb_timeout_t:\tinternal uint:' \
33	-e 's:\tDB_LSN:\tinternal DB_LSN_STRUCT:' \
34	-e 's:\tDB_TXN_ACTIVE \*:\tinternal IntPtr :' \
35	-e 's:\tint\s:\tinternal int :' \
36	-e 's:\tint32_t:\tinternal int:' \
37	-e 's:\tpid_t:\tinternal int:' \
38	-e 's:\troff_t:\tinternal IntPtr:' \
39	-e 's:\tsize_t:\tinternal IntPtr:' \
40	-e 's:\ttime_t:\tinternal long:' \
41    	-e 's:\tu_int32_t:\tinternal uint:' \
42        -e 's:\tuintmax_t:\tinternal ulong:' \
43	-e "s:/\*.*\*/::" \
44    	-e "/\/\*/ {
45N
46/\/\*.*\*\// {
47s:/\*.*\*/::
48P
49D
50}
51}"
52}
53
54stat_class()
55{
56	c_struct=__db_$1
57	cs_struct=$2
58
59	(cat <<EOF
60    [StructLayout(LayoutKind.Sequential)]
61    internal struct $cs_struct {
62EOF
63	 csclass $c_struct
64	 echo '    }'
65	 echo ) >> $t
66}
67
68txn_active()
69{
70    (echo "internal enum DB_TXN_ACTIVE_STATUS {"
71        sed -n "/struct __db_txn_active {/,/^}/p" < ../dbinc/db.in |
72	sed -n "/^#define/p" | awk '{print "        " $2 " = " $3 ","}'
73	echo "}"
74	echo ) >> $t
75
76    (cat <<EOF
77    [StructLayout(LayoutKind.Sequential)]
78    internal struct DB_TXN_ACTIVE {
79EOF
80
81	sed -n "/struct __db_txn_active {/,/^}/p" < ../dbinc/db.in |
82	sed -e "/__db_txn_active/d" \
83	    -e '/^}/d' \
84	    -e "/CONFIG_TEST/,/#endif/d" \
85	    -e "/^#/d" \
86	    -e "/gid\[.*\]/d" \
87	    -e "/name\[.*\]/d" \
88	    -e 's:\tchar \*:\tinternal string :' \
89	    -e 's:\tdb_pgno_t:\tinternal uint:' \
90	    -e 's:\tdb_seq_t:\tinternal long:' \
91	    -e 's:\tdb_threadid_t:\tinternal uint:' \
92	    -e 's:\tdb_timeout_t:\tinternal uint:' \
93	    -e 's:\tDB_LSN:\tinternal DB_LSN_STRUCT:' \
94	    -e 's:\tDB_TXN_ACTIVE \*:\tinternal IntPtr:' \
95	    -e 's:\tint\s:\tinternal int :' \
96	    -e 's:\tint32_t:\tinternal int:' \
97	    -e 's:\tpid_t:\tinternal int:' \
98	    -e 's:\troff_t:\tinternal IntPtr:' \
99	    -e 's:\tsize_t:\tinternal IntPtr:' \
100	    -e 's:\ttime_t:\tinternal long:' \
101	    -e 's:\tu_int32_t status:\tinternal DB_TXN_ACTIVE_STATUS status:' \
102	    -e 's:\tu_int32_t:\tinternal uint:' \
103	    -e 's:\tuintmax_t:\tinternal ulong:' \
104	    -e "s:/\*.*\*/::"
105	echo '    }'
106	echo ) >> $t
107}
108
109cat > $t <<EOF
110$msgcsharp
111
112using System;
113using System.Runtime.InteropServices;
114
115namespace BerkeleyDB.Internal {
116EOF
117
118stat_class bt_stat BTreeStatStruct
119stat_class h_stat HashStatStruct
120stat_class lock_stat LockStatStruct
121stat_class log_stat LogStatStruct
122stat_class mpool_fstat MPoolFileStatStruct
123stat_class mpool_stat MPoolStatStruct
124
125cat >>$t <<EOF
126    internal struct MempStatStruct {
127        internal MPoolStatStruct st;
128        internal MPoolFileStatStruct[] files;
129}
130
131EOF
132
133stat_class mutex_stat MutexStatStruct
134stat_class qam_stat QueueStatStruct
135stat_class bt_stat RecnoStatStruct
136stat_class repmgr_stat RepMgrStatStruct
137stat_class rep_stat ReplicationStatStruct
138stat_class seq_stat SequenceStatStruct
139stat_class txn_stat TransactionStatStruct
140
141cat >> $t <<EOF
142    internal struct DB_LSN_STRUCT {
143        internal uint file;
144        internal uint offset;
145    }
146
147EOF
148
149txn_active
150
151cat >> $t <<EOF
152    internal struct TxnStatStruct {
153        internal TransactionStatStruct st;
154        internal DB_TXN_ACTIVE[] st_txnarray;
155        internal byte[][] st_txngids;
156        internal string[] st_txnnames;
157    }
158}
159
160EOF
161
162cmp $f $t > /dev/null 2>&1 ||
163    (echo "Building $f" && rm -f $f && cp $t $f && chmod 644 $f)
164