usbmodeswitch: Updated to v.1.2.6 from shibby's branch.
[tomato.git] / release / src / router / www / remcoms2.sh
blob5925ac268356673cd8ac9c374a2b6a00c7b3062e
1 #! /bin/sh
2 # Strip C comments
3 # by Stewart Ravenhall <stewart.ravenhall@ukonline.co.uk> -- 4 October 2000
4 # Un-Korn-ized by Paolo Bonzini <bonzini@gnu.org> -- 24 November 2000
6 # Strip everything between /* and */ inclusive
8 # Copes with multi-line comments,
9 # disassociated end comment symbols,
10 # disassociated start comment symbols,
11 # multiple comments per line
13 # Check given file exists
14 program=`echo $0|sed -e 's:.*/::'`
15 if [ "$#" != 3 ] && [ "$1" != "-" ] && [ ! -f "$1" ]; then
16 print "$program: $1 does not exist"
17 exit 2
20 # Create shell variables for ASCII 1 (control-a)
21 # and ASCII 2 (control-b)
22 a="`echo | tr '\012' '\001'`"
23 b="`echo | tr '\012' '\002'`"
25 # The script is updated to strip both c and html comments
26 # The original was taken here: http://sed.sourceforge.net/grabbag/scripts/remccoms2.sh.txt
27 if [ $2 = "c" ] ; then
28 p1="\/\*"
29 p2="/\*"
30 p3="\*/"
31 p4="/*"
32 p5="*/"
33 else
34 p1="<!--"
35 p2="<!--"
36 p3="-->"
37 p4="<!--"
38 p5="-->"
41 sed -ri '
42 # If no start comment then go to end of script
43 /'"$p1"'/!b
45 s:'"$p2"':'"$a"':g
46 s:'"$p3"':'"$b"':g
48 # If no end comment
49 /'"$b"'/!{
52 # If not last line then read in next one
53 $!{
58 # If last line then remove from start
59 # comment to end of line
60 # then go to end of script
61 s:'"$a[^$b]"'*$::
65 # Remove comments
66 '"s:$a[^$b]*$b"'::g
67 /'"$a"'/ bb
70 s:'"$a"':'"$p4"':g
71 s:'"$b"':'"$p5"':g
72 ' $1
74 sed -i $1 -e "/^$/d"