File: insert-packet.sh

package info (click to toggle)
resiprocate 1%3A1.11.0~beta1-3%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 37,944 kB
  • sloc: cpp: 206,325; xml: 12,515; sh: 12,418; ansic: 6,973; makefile: 2,315; php: 1,150; python: 355; sql: 142; objc: 91; perl: 21; csh: 5
file content (54 lines) | stat: -rwxr-xr-x 1,094 bytes parent folder | download | duplicates (5)
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
#!/bin/sh
#
# Insert a test packet into a unit test.
#   ./insert-packet.sh <plaintext packet file> <C++ source>
#
# searches for the initNetwork() line and inserts just below that
#

function die() {
	echo "$1" >&2;
	exit 1;
}

test ! -z "$1" -a ! -z "$2" || die "usage: $0 input output";

quoted=`sed -e 's/\"/\\\"/g' \
            -e 's/^/         \"/' \
	    -e $'s/\r$//g' -e 's/$/\\\\r\\\\n\"/g' <$1`;

# Figure out where we want to insert this.
line=`egrep -n 'initNetwork\(\)\;$' <$2 | sed -e 's/:/ /' | awk '{print $1}'`;

total=`wc -l $2 | awk '{print $1}'`;

head -n ${line} $2 >.tmp;

cat >>.tmp <<EOF

   {
      Data txt(
${quoted}
      );

      std::auto_ptr<SipMessage> message(TestSupport::makeMessage(txt));

      try
      {
         (void)message->header(h_From);
      }
      catch (ParseException&)
      {
         std::cerr << "uh, failed to parse message: "
	           << __FILE__ << ':' << __LINE__
		   << std::endl;
         assert(false);
      }
   }
EOF

tail -n `expr ${total} - ${line}` $2 >>.tmp;

mv .tmp $2;

echo "inserted at line `expr ${line} + 1`";