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
|
dnl shellfuncs.m4 ... phew, a really nice m4 file containing shellfunction defs
dnl for several shell functions that I wanted to be
dnl concentrated on one point rather than spilling it over
dnl several places.
dnl
dnl is needed since most of the shellcode deals with '
dnl
dnl
dnl now write a generic header - for all files using this shellfunc (lib)
#!/bin/bash
# don't edit this file - it has been autogenerated by debian/rules
# instead edit the corresponding .in file or have a look at debian/shellfuncs
#
changequote([,])dnl
dnl
define([V], [$])dnl
define([AT], [@])dnl
define([N1], [1])dnl
define([N2], [2])dnl
define([N3], [3])dnl
define([VALL], [V()AT()])dnl
define([V1], [V()N1()])dnl
define([V2], [V()N2()])dnl
define([V3], [V()N3()])dnl
dnl
define([STRCAT],
dnl space separated value - add at the right side (string end)
dnl $ 1 = value that should be added
dnl $ 2 = ssv list
[strcat() { changequote(%,%)
if %[% -z "V2()" %]%; then changequote([,])
echo "V1()"
else
echo "V2() V1()"
fi
}])dnl
dnl
define([SSV_ADD],
[dnl space separated value - add at the left side (string start)
dnl $ 1 = value that should be added
dnl $ 2 = ssv list
ssv_add() {
echo "VALL()"
dnl | sed -e 's/ $//'
dnl | sed -ne "s/^\($1\)\(.*\)$/\1\2/p" | sed -e 's/, $//'
}])dnl
dnl
define([SSV_GET],
[dnl coma separated value - get function
dnl $ 1 = field (integer describing position)
dnl $ 2 = csv list
ssv_get() { changequote(%,%)
if [ "`echo "V2()" | grep ' '`" != "" -o "V1()" = 1 ]; then
changequote([,])dnl
echo "V2()" | cut -d" " --fields=V1()
fi
}])dnl
dnl
define([SSV_TEST],
[dnl space separated value - test function - to see if value is in the ssv list
dnl $ 1 = string to test for
dnl $ 2 = ssv list
ssv_test() { changequote(_,_)
dnl eliminate first parameter and then grep for it
if [ -n "`echo "VALL()" | sed -e "s%^V1()\ *%%;" | grep "V1()"`" ]; then
changequote([,])dnl
echo 'true'
else
echo 'false'
fi
}])dnl
dnl
define([CSV_ADD],
[dnl coma separated value - add at the left side (string start)
dnl $ 1 = value that should be added
dnl $ 2 = csv list
csv_add() {
echo "VALL()" | sed -ne "s%^\(V1()\)\(.*\)$%\1,\2%p" | sed -e 's/, $//'
}])dnl
dnl
define([CSV_ADD_RIGHT],
[dnl coma separated value - add at the right side (string end)
dnl $ 1 = value that should be added
dnl $ 2 = csv list
csv_add_right() {
echo "VALL()" | sed -ne "s/^\(V1()\) \(.*\)$/\2, \1/p" | sed -e 's/^, //'
}])dnl
dnl
define([CSV_GET],
[dnl coma separated value - get function
dnl $ 1 = field (integer describing position, starting with 1)
dnl $ 2 = csv list
csv_get() { changequote(_,_)
if [ "`echo "V2()" | grep ','`" != "" -o "V1()" = 1 ]; then
changequote([,])dnl
echo "V2()" | cut -d, --fields=V1() | sed -e 's/^ //'
fi
}])dnl
dnl
define([CSV_TEST],
[dnl coma separated value - test function - to see if value is in the csv list
dnl $ 1 = string to test for
dnl $ 2 = csv list
csv_test() { changequote(_,_)
if [ -n "`echo "VALL()" | sed -e "s/^V1() //" | grep "V1()"`" ]; then
changequote([,]) echo 'true'
else
echo 'false'
fi
}])dnl
dnl
define([CSV_RM],
[dnl coma separated value - remove function - to remove a specific value
dnl $ 1 = value to remove
dnl $ 2 = csv list
csv_rm() {
dnl CSV_LIST = $@ without $1
CSV_LIST=`echo "VALL()" | sed -e "s/^V1() //"` changequote(_,_)
dnl check if $1 is in CSV_LIST
if [ -n "`echo "$CSV_LIST" | grep "V1()"`" ]; then changequote([,])
dnl 1) remove add a ', ' to the front and a ',' to the end
dnl 2) remove entry
dnl 3) remove leading and trailing ',' and ' '
echo "VALL()" | sed -e "s/^V1() //" | sed -ne 's/^\(.*\)$/, \1,/p' | \
sed -ne "s/^\(.*\), V1(),\(.*\)$/\1,\2/p" | \
sed -e 's/^, //' | sed -e 's/,$//'
else
echo "$CSV_LIST"
fi
}])dnl
dnl
define([MCAST_ADD],
[dnl multicast helper function to add a new value
dnl $ 1 = new interface
dnl $ 2 = new value
dnl $ 3 = csv list
mcast_add() {
csv_add_right "V1()$1 V2()" "V3()"
}])dnl
dnl
define([MCAST_GET],
[dnl multicast helper function to retrieve a value
dnl $ 1 = interface to search for
dnl $ 2 = list containing all values
mcast_get() {
dnl init vars
COUNT=2
ENTRY=`csv_get "1" "V2()"`
changequote(_,_)dnl
dnl as long as entry not empty
while [ -n "$ENTRY" ]; do changequote([,])
# get the nic in front of the value
INT=`echo "$ENTRY" | cut -d"$1" -f1 | sed -ne 's/^\ *\(.*\)\ *$/\1/p'`
changequote(_,_)dnl
# when specified nic (V1()) = NIC is
if [ "$INT" = "V1()" ]; then changequote([,])
# return the value
echo "$ENTRY"| sed -e "s/$INT$1//"| sed -ne "s/^\ *\(.*\)\ *$/\1/p"
exit 0
fi
ENTRY=`csv_get "$COUNT" "V2()"`
COUNT=$(($COUNT + 1))
done
}])dnl
dnl
define([MCAST_RM],
[dnl multicast helper function to remove a value
dnl $ 1 = interface to search for
dnl $ 2 = list containing all values
mcast_rm() {
dnl init vars
COUNT=2
ENTRY=`csv_get "1" "V2()"`
NCSVLIST="" changequote(_,_)
dnl as long as entry not empty
while [ -n "$ENTRY" ]; do changequote([,])
# get the nic in front of the value
INT=`echo "$ENTRY" | cut -d$1 -f1 | sed -e 's/\ //g'` changequote(_,_)
# when specified nic ($1) != NIC is
if [ "$INT" != "V1()" ]; then changequote([,])
# return this value
NCSVLIST=`csv_add_right "$ENTRY" "$NCSVLIST"`
fi
ENTRY=`csv_get "$COUNT" "V2()"`
COUNT=$(($COUNT + 1))
done
echo "$NCSVLIST" | sed -e 's/,$//'
}])dnl
dnl
define([PRE],
[dnl writes everything from $2 til $1 occurs (while interpreting $2 with -e)
dnl $ 1 = stop when finding this at the start of a line
dnl $ 2 = text to filter (with -e)
pre() { changequote(_,_)
if [ -n "V1()" ]; then changequote([,])
echo -e "V2()" | sed -e "s/^V1().*//; t end; b fur; : end q; : fur s///;"
else
echo -e "V2()"
fi
}])dnl
dnl
define([POST],
[dnl writes everything after the first occurence of $1, but not before removing
dnl every line that starts with $1
dnl $ 1 = remove line when starting with this
dnl $ 2 = complete text (text to filter)
dnl $ 3 = PRE text (generated by pre)
post() {
LC=`echo -e "V2()" | wc -l`
PRELC=`echo -e "V3()" | wc -l`
LENGTH=$(($LC - $PRELC))
echo -e "V2()" | tail -$LENGTH | (grep -v "^V1()" || true)
}])dnl
dnl
changequote(<,_)dnl
|