]> gcc.gnu.org Git - gcc.git/blob - gcc/fixcpp
cpplib.c (macroexpand): Correct off-by-one error in handling of escapes.
[gcc.git] / gcc / fixcpp
1 #!/bin/sh
2 #
3 # NAME:
4 # fixcpp - fix CPP errors
5 #
6 # SYNOPSIS:
7 # fixcpp [-c][-p patch_file][-b bak_dir][-n new_dir] files(s)
8 #
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.
14 #
15 # Naturally this script is not guaranteed to be bullet
16 # proof, use of -n or -b is advisable!
17 #
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.
21 #
22 # -p causes fixcpp to append to a patch file the context
23 # diffs of the changes wrought.
24 #
25 # SEE ALSO:
26 # sed(1)
27 #
28 # AMENDED:
29 # 90/08/08 22:46:32 (sjg)
30 #
31 # RELEASED:
32 # 90/08/08 22:46:34 v1.4
33 #
34 # SCCSID:
35 # @(#)fixcpp.sh 1.4 90/08/08 22:46:32 (sjg)
36 #
37 # @(#)Copyright (c) 1990 Simon J. Gerraty
38 #
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.
45
46 TMPF=/tmp/fixcpp.$$
47 NEWDIR=
48 BAKDIR=
49 PATCHF=
50 CHECK=
51
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
56 fi
57 for i in $*
58 do
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
72 fi
73 fi
74
75
76
77 for i in $*
78 do
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
88 fi
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
98 fi
99 fi
100 else
101 if [ $PATCHF ]; then
102 diff -c $infile ${NEWDIR}/$i >> ${PATCHF}
103 fi
104 fi
105 fi
106
107 done
108
109 rm -f ${TMPF}
This page took 0.044822 seconds and 5 git commands to generate.