scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

0012-delete.sh (1646B)


      1 #!/bin/sh
      2 
      3 
      4 set -e
      5 
      6 trap "rm -f file.a; exit" 0 2 3
      7 
      8 ############################################################################
      9 #delete one member
     10 
     11 cp master.a file.a
     12 
     13 ar -dv file.a file2
     14 
     15 if ar -tv file.a file2
     16 then
     17 	echo file-2 was not deleted >&2
     18 	exit 1
     19 fi
     20 
     21 
     22 ############################################################################
     23 #delete two members, 1st and 2nd
     24 
     25 cp master.a file.a
     26 
     27 ar -dv file.a file1 file2
     28 
     29 if ar -tv file.a file1 file2
     30 then
     31 	echo file-1 or file-2 were not deleted >&2
     32 	exit 1
     33 fi
     34 
     35 
     36 ############################################################################
     37 #delete two members, 2nd and 3rd
     38 
     39 cp master.a file.a
     40 ar -dv  file.a file2 file3
     41 
     42 if ar -tv file.a file2 file3
     43 then
     44 	echo file-2 file-3 were not deleted >&2
     45 	exit 1
     46 fi
     47 
     48 ############################################################################
     49 #remove all the members
     50 
     51 cp master.a file.a
     52 ar -dv file.a file1 file2 file3
     53 
     54 if ar -tv file.a file2 file3
     55 then
     56 	echo file-1 file2 file were not deleted >&2
     57 	exit 1
     58 fi
     59 
     60 if test `ar -t file.a | wc -l` -ne 0
     61 then
     62 	echo file.a is not empty after deleting all the members >&2
     63 	exit 1
     64 fi
     65 
     66 ############################################################################
     67 #special cases
     68 
     69 #no members
     70 cp master.a file.a
     71 
     72 last=`ls -l file.a | awk '{print $6,$7,$8}'`
     73 
     74 if ! ar -dv file.a
     75 then
     76 	echo ar returned with error when no members
     77 	exit 1
     78 fi
     79 
     80 now=`ls -l file.a | awk '{print $6,$7,$8}'`
     81 if test "$now" != "$last"
     82 then
     83 	echo empty ar -d modified the archive >&2
     84 	exit 1
     85 fi
     86 
     87 #delete not existing member
     88 cp master.a file.a
     89 
     90 if ar -dv file.a badfile
     91 then
     92 	echo ar returned ok deleting a not existing member >&2
     93 	exit 1
     94 fi