Initial revision
[official-gcc.git] / gcc / fixcpp
blob044353f3a43f5a1a18875c56a4a8761789885f7b
1 #!/bin/sh
3 # NAME:
4 # fixcpp - fix CPP errors
6 # SYNOPSIS:
7 # fixcpp [-c][-p patch_file][-b bak_dir][-n new_dir] files(s)
9 # DESCRIPTION:
10 # For each named file, use sed(1) to fixup any descriptive
11 # text after #else or #endif or that is not properly
12 # commented as this causes ANSI compilers to generate
13 # unnecessary warnings.
15 # Naturally this script is not guaranteed to be bullet
16 # proof, use of -n or -b is advisable!
18 # -c causes fixcpp to make sure that only files that
19 # needed changing are affected by returning the original
20 # file to its original location if no changes were needed.
22 # -p causes fixcpp to append to a patch file the context
23 # diffs of the changes wrought.
25 # SEE ALSO:
26 # sed(1)
28 # AMENDED:
29 # 90/08/08 22:46:32 (sjg)
31 # RELEASED:
32 # 90/08/08 22:46:34 v1.4
34 # SCCSID:
35 # @(#)fixcpp.sh 1.4 90/08/08 22:46:32 (sjg)
37 # @(#)Copyright (c) 1990 Simon J. Gerraty
39 # This is free software. It comes with NO WARRANTY.
40 # Everyone is granted permission to copy, modify and
41 # redistribute this source code provided that all
42 # recipients are given similar rights, and that the above
43 # copyright notice and this notice are preserved in all
44 # copies.
46 TMPF=/tmp/fixcpp.$$
47 NEWDIR=
48 BAKDIR=
49 PATCHF=
50 CHECK=
52 set -- `getopt "cp:b:n:" $*`
53 if [ $? != 0 ]; then
54 echo "$0 [-c][-p patch_file][-b bakup_dir][-n new_dir] file [file ...]" >&2
55 exit 1
57 for i in $*
59 case $i in
60 -c) CHECK=yes; shift;;
61 -p) PATCHF=$2; shift 2;;
62 -b) BAKDIR=$2; shift 2;;
63 -n) NEWDIR=$2; shift 2;;
64 --) shift; break;;
65 esac
66 done
67 NEWDIR=${NEWDIR:-.}
68 if [ $BAKDIR ]; then
69 if [ ! -d $BAKDIR ]; then
70 echo "$0: no such directory -- $BAKDIR" >&2
71 exit 1
77 for i in $*
79 if [ $BAKDIR ]; then
80 mv $i $BAKDIR
81 infile=$BAKDIR/$i
82 else
83 if [ "$NEWDIR" = "." ]; then
84 mv $i ${TMPF}
85 infile=${TMPF}
86 else
87 infile=$i
89 fi
90 sed -e 's;^#\([ ]*e[nl][^ ]*[ ][ ]*\)\([^/ ][^\*].*\);#\1/* \2 */;' -e 's;^#\([ ]*e[nl][^ ]*[ ][ ]*\)\([^/ ]\)$;#\1/* \2 */;' $infile >${NEWDIR}/$i
91 if [ "${CHECK}" = "yes" -o ${PATCHF} ]; then
92 if cmp -s $infile ${NEWDIR}/$i ; then
93 if [ "${CHECK}" = "yes" ]; then
94 if [ $BAKDIR ]; then
95 mv $infile ${NEWDIR}/$i
96 else
97 rm ${NEWDIR}/$i
100 else
101 if [ $PATCHF ]; then
102 diff -c $infile ${NEWDIR}/$i >> ${PATCHF}
107 done
109 rm -f ${TMPF}