48603f9e0e8959102fdbd6ed8fe817f50a8f2c2e
[platform/upstream/lsof.git] / tests / Add2TestDB
1 #!/bin/sh
2 #
3 # Add2TestDB -- add the current test to the lsof test suite DB
4 #
5 # This script saves the current TestDB file in TestDB.old and adds
6 # the words in config.cflags to it.  "-D" prefixes on the words are
7 # removed, the words are sorted, and they are joint in a single
8 # line that is catenated to TestDB if it isn't already there.
9 #
10 # $Id: Add2TestDB,v 1.2 2002/04/19 11:53:37 abe Exp $
11
12 # Check for config.flags.
13
14 if test ! -r config.cflags
15 then
16   echo "$0: no ./config.cflags file"
17   exit 1
18 fi
19
20 # Check for a current data base file.
21
22 if test ! -r TestDB
23 then
24   echo "$0: no ./TestDB file"
25   exit 1
26 fi
27
28 # Form a new data base line.
29
30 new=""
31 for i in `sort < config.cflags`
32 do
33   w=`echo $i | sed 's/^-D//'`
34   if test "X$new" = "X"
35   then
36     new=$w
37   else
38     new="$new $w"
39   fi
40 done
41
42 # See if the new line is already in the data base.
43
44 grep "$new" TestDB > /dev/null 2>&1
45 if test $? -eq 0
46 then
47   echo "\"$new\" is already in TestDB."
48   exit 1
49 fi
50
51 # Build a new data base file.
52
53 if test ! -w TestDB
54 then
55   echo "$0: can't write the following to the end of TestDB:"
56   echo  "    \"$new\""
57   exit 1
58 fi
59 rm -f TestDB.new
60 cp TestDB TestDB.new
61 chmod 644 TestDB.new
62 echo "$new" >> TestDB.new
63
64 # Archive the current data base file, if possible.
65
66 if test -d OLD
67 then
68   dt=`date`
69   dtm="========== $dt =========="
70   if test -r OLD/TestDB
71   then
72     echo "$dtm" >> OLD/TestDB
73   else
74     echo "$dtm" > OLD/TestDB
75   fi
76   cat TestDB >> OLD/TestDB
77 fi
78
79 # Put the new data base file in place.
80
81 mv TestDB.new TestDB
82 echo "\"$new\" added to TestDB."
83 exit 0