1
dnl shellfuncs.m4 ... phew, a really nice m4 file containing shellfunction defs
2
dnl for several shell functions that I wanted to be
3
dnl concentrated on one point rather than spilling it over
6
dnl is needed since most of the shellcode deals with '
9
dnl now write a generic header - for all files using this shellfunc (lib)
11
# don't edit this file - it has been autogenerated by debian/rules
12
# instead edit the corresponding .in file or have a look at debian/shellfuncs
21
define([VALL], [V()AT()])dnl
22
define([V1], [V()N1()])dnl
23
define([V2], [V()N2()])dnl
24
define([V3], [V()N3()])dnl
27
dnl space separated value - add at the right side (string end)
28
dnl $ 1 = value that should be added
30
[strcat() { changequote(%,%)
31
if %[% -z "V2()" %]%; then changequote([,])
39
[dnl space separated value - add at the left side (string start)
40
dnl $ 1 = value that should be added
45
dnl | sed -ne "s/^\($1\)\(.*\)$/\1\2/p" | sed -e 's/, $//'
49
[dnl coma separated value - get function
50
dnl $ 1 = field (integer describing position)
52
ssv_get() { changequote(%,%)
53
if [ "`echo "V2()" | grep ' '`" != "" -o "V1()" = 1 ]; then
55
echo "V2()" | cut -d" " --fields=V1()
60
[dnl space separated value - test function - to see if value is in the ssv list
61
dnl $ 1 = string to test for
63
ssv_test() { changequote(_,_)
64
dnl eliminate first parameter and then grep for it
65
if [ -n "`echo "VALL()" | sed -e "s%^V1()\ *%%;" | grep "V1()"`" ]; then
74
[dnl coma separated value - add at the left side (string start)
75
dnl $ 1 = value that should be added
78
echo "VALL()" | sed -ne "s%^\(V1()\)\(.*\)$%\1,\2%p" | sed -e 's/, $//'
81
define([CSV_ADD_RIGHT],
82
[dnl coma separated value - add at the right side (string end)
83
dnl $ 1 = value that should be added
86
echo "VALL()" | sed -ne "s/^\(V1()\) \(.*\)$/\2, \1/p" | sed -e 's/^, //'
90
[dnl coma separated value - get function
91
dnl $ 1 = field (integer describing position, starting with 1)
93
csv_get() { changequote(_,_)
94
if [ "`echo "V2()" | grep ','`" != "" -o "V1()" = 1 ]; then
96
echo "V2()" | cut -d, --fields=V1() | sed -e 's/^ //'
101
[dnl coma separated value - test function - to see if value is in the csv list
102
dnl $ 1 = string to test for
104
csv_test() { changequote(_,_)
105
if [ -n "`echo "VALL()" | sed -e "s/^V1() //" | grep "V1()"`" ]; then
106
changequote([,]) echo 'true'
113
[dnl coma separated value - remove function - to remove a specific value
114
dnl $ 1 = value to remove
117
dnl CSV_LIST = $@ without $1
118
CSV_LIST=`echo "VALL()" | sed -e "s/^V1() //"` changequote(_,_)
119
dnl check if $1 is in CSV_LIST
120
if [ -n "`echo "$CSV_LIST" | grep "V1()"`" ]; then changequote([,])
121
dnl 1) remove add a ', ' to the front and a ',' to the end
123
dnl 3) remove leading and trailing ',' and ' '
124
echo "VALL()" | sed -e "s/^V1() //" | sed -ne 's/^\(.*\)$/, \1,/p' | \
125
sed -ne "s/^\(.*\), V1(),\(.*\)$/\1,\2/p" | \
126
sed -e 's/^, //' | sed -e 's/,$//'
133
[dnl multicast helper function to add a new value
134
dnl $ 1 = new interface
138
csv_add_right "V1()$1 V2()" "V3()"
142
[dnl multicast helper function to retrieve a value
143
dnl $ 1 = interface to search for
144
dnl $ 2 = list containing all values
148
ENTRY=`csv_get "1" "V2()"`
151
dnl as long as entry not empty
152
while [ -n "$ENTRY" ]; do changequote([,])
153
# get the nic in front of the value
154
INT=`echo "$ENTRY" | cut -d"$1" -f1 | sed -ne 's/^\ *\(.*\)\ *$/\1/p'`
156
# when specified nic (V1()) = NIC is
157
if [ "$INT" = "V1()" ]; then changequote([,])
159
echo "$ENTRY"| sed -e "s/$INT$1//"| sed -ne "s/^\ *\(.*\)\ *$/\1/p"
162
ENTRY=`csv_get "$COUNT" "V2()"`
163
COUNT=$(($COUNT + 1))
168
[dnl multicast helper function to remove a value
169
dnl $ 1 = interface to search for
170
dnl $ 2 = list containing all values
174
ENTRY=`csv_get "1" "V2()"`
175
NCSVLIST="" changequote(_,_)
177
dnl as long as entry not empty
178
while [ -n "$ENTRY" ]; do changequote([,])
179
# get the nic in front of the value
180
INT=`echo "$ENTRY" | cut -d$1 -f1 | sed -e 's/\ //g'` changequote(_,_)
181
# when specified nic ($1) != NIC is
182
if [ "$INT" != "V1()" ]; then changequote([,])
184
NCSVLIST=`csv_add_right "$ENTRY" "$NCSVLIST"`
186
ENTRY=`csv_get "$COUNT" "V2()"`
187
COUNT=$(($COUNT + 1))
189
echo "$NCSVLIST" | sed -e 's/,$//'
193
[dnl writes everything from $2 til $1 occurs (while interpreting $2 with -e)
194
dnl $ 1 = stop when finding this at the start of a line
195
dnl $ 2 = text to filter (with -e)
196
pre() { changequote(_,_)
197
if [ -n "V1()" ]; then changequote([,])
198
echo -e "V2()" | sed -e "s/^V1().*//; t end; b fur; : end q; : fur s///;"
205
[dnl writes everything after the first occurence of $1, but not before removing
206
dnl every line that starts with $1
207
dnl $ 1 = remove line when starting with this
208
dnl $ 2 = complete text (text to filter)
209
dnl $ 3 = PRE text (generated by pre)
211
LC=`echo -e "V2()" | wc -l`
212
PRELC=`echo -e "V3()" | wc -l`
213
LENGTH=$(($LC - $PRELC))
214
echo -e "V2()" | tail -$LENGTH | (grep -v "^V1()" || true)