# fixcpp - fix CPP errors
# fixcpp [-c][-p patch_file][-b bak_dir][-n new_dir] files(s)
# For each named file, use sed(1) to fixup any descriptive
# text after #else or #endif or that is not properly
# commented as this causes ANSI compilers to generate
# Naturally this script is not guaranteed to be bullit
# proof, use of -n or -b is advisable!
# -c causes fixcpp to make sure that only files that
# needed changing are affected by returning the original
# file to its original location if no changes were needed.
# -p causes fixcpp to append to a patch file the context
# diffs of the changes wraught.
# 90/08/08 22:46:32 (sjg)
# @(#)fixcpp.sh 1.4 90/08/08 22:46:32 (sjg)
# @(#)Copyright (c) 1990 Simon J. Gerraty
# This is free software. It comes with NO WARRANTY.
# Everyone is granted permission to copy, modify and
# redistribute this source code provided that all
# recipients are given similar rights, and that the above
# copyright notice and this notice are preserved in all
set -- `getopt "cp:b:n:" $*`
echo "$0 [-c][-p patch_file][-b bakup_dir][-n new_dir] file [file ...]" >&2
if [ ! -d $BAKDIR ]; then
echo "$0: no such directory -- $BAKDIR" >&2
if [ "$NEWDIR" = "." ]; then
sed -e 's;^#\([ ]*e[nl][^ ]*[ ][ ]*\)\([^/ ][^\*].*\);#\1/* \2 */;' -e 's;^#\([ ]*e[nl][^ ]*[ ][ ]*\)\([^/ ]\)$;#\1/* \2 */;' $infile >${NEWDIR}/$i
if [ "${CHECK}" = "yes" -o ${PATCHF} ]; then
if cmp -s $infile ${NEWDIR}/$i ; then
if [ "${CHECK}" = "yes" ]; then
diff -c $infile ${NEWDIR}/$i >> ${PATCHF}