Subject: Re: misc/908: Comments after DEFINES
To: John F. Woods <jfw@jfwhome.funhouse.com>
From: Simon J. Gerraty <sjg@zen.void.oz.au>
List: current-users
Date: 03/28/1995 09:03:40
John F. Woods wrote,
> But while we're whining about comments, I noticed recently that the name
> daemon source is filled with
> 
> 	#endif PREPROCESSOR_SYMBOL
> 
> misdirectives.  Assuming there are any architectures on which GCC does not
> run :-), there might be some portability gain in changing those to honest
> comments...

many years ago I got sick of porting such code to a machine with an
ANSI compiler - the important error messages got lost in all the noise...
So I wrote a little script to fix C preprocessor directives...

These days I use a generic sedem script (run sed, check for change if
so save old file etc) and a simple file containing the sed command
from the earlier script.

Since I find sedem very useful for many bulk editing tasks, others
might too, so here it is...

--sjg

#!/bin/sh
# This is a shell archive.
# remove everything above the "#!/bin/sh" line
# and feed to /bin/sh
# Use -c option to overwrite existing files
#
# Contents: 
#	sedem.1
#	sedem.sh
#	cpp.sed
#
# packed by: <sjg@zen.void.oz.au> on Tue Mar 28 08:51:44 EST 1995
#
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f sedem.1 -a x$1 != x-c ; then
  echo shar: Will not over-write existing file \"sedem.1\"
else
  echo shar: Extracting \"sedem.1\" \(523 characters\)
  sed 's/^X//' >sedem.1 << '!EOF'
X.\" extracted from sedem.sh 28 March 1995 by cmt2doc.pl
X.TH SEDEM L "28 March 1995" "FreeWare" "LOCAL COMMANDS"
X.PD .8v
X.SH NAME
X.nf
Xsedem.sh \- sed a bunch of files.
X.fi
X
X.SH SYNOPSIS
X.nf
X\fBsedem\fR.sh \fIargs\fR < \fIlist\fR
X.fi
X
X.SH DESCRIPTION
X
XThis script is used to apply \fBsed\fR \fIargs\fR to a list of files
Xread from stdin.
XIf the edit affects a \fIfile\fR then the original is renamed to
X\fIfile\fR.bak otherwise it is left untouched.
X
X.SH "SEE ALSO"
X
Xsed(1)
X
X.SH AUTHOR
X
XSimon J. Gerraty <sjg@zen.void.oz.au>
!EOF
  if test 523 -ne `wc -c < sedem.1`; then
    echo shar: \"sedem.1\" unpacked with wrong size!
  fi
  
fi
if test -f sedem.sh -a x$1 != x-c ; then
  echo shar: Will not over-write existing file \"sedem.sh\"
else
  echo shar: Extracting \"sedem.sh\" \(1184 characters\)
  sed 's/^X//' >sedem.sh << '!EOF'
X:
X# NAME:
X#	sedem.sh - sed a bunch of files.
X#
X# SYNOPSIS:
X#	sedem.sh "args" < "list"
X#
X# DESCRIPTION:
X#	This script is used to apply 'sed' "args" to a list of files
X#	read from stdin.
X#	If the edit affects a "file" then the original is renamed to
X#	"file".bak otherwise it is left untouched.
X#
X# SEE ALSO:
X#	sed(1)
X#	
X# AUTHOR:
X#	Simon J. Gerraty <sjg@zen.void.oz.au>
X
X# RCSid:
X#	$Id: sedem.sh,v 1.2 1995/01/03 21:35:57 sjg Exp $
X#
X#	@(#) Copyright (c) 1992 Simon J. Gerraty
X#
X#	This file is provided in the hope that it will
X#	be of use.  There is absolutely NO WARRANTY.
X#	Permission to copy, redistribute or otherwise
X#	use this file is hereby granted provided that 
X#	the above copyright notice and this notice are
X#	left intact. 
X#      
X#	Please send copies of changes and bug-fixes to:
X#	sjg@zen.void.oz.au
X#
X
X[ $# -gt 0 ] || { echo "sedit sedargs < list" >&2; exit 1; }
X  
Xwhile read file
Xdo
X  sed "$@" $file > $file.$$ || { rm -f $file.$$; exit 1; }
X  if cmp -s $file $file.$$; then
X    # they're the same, skip rest
X    rm -f $file.$$
X  else
X    # sed command above checked that we can write in the directory...
X    mv $file $file.bak && mv $file.$$ $file
X  fi
Xdone
Xexit 0
!EOF
  if test 1184 -ne `wc -c < sedem.sh`; then
    echo shar: \"sedem.sh\" unpacked with wrong size!
  fi
  chmod +x sedem.sh
fi
if test -f cpp.sed -a x$1 != x-c ; then
  echo shar: Will not over-write existing file \"cpp.sed\"
else
  echo shar: Extracting \"cpp.sed\" \(162 characters\)
  sed 's/^X//' >cpp.sed << '!EOF'
X# sed script to turn text after #endif etc into comments
X# use with sedem.sh to do a bunch of files...
Xs;^#\([ 	]*e[nl][^ 	]*[ 	][ 	]*\)\([^/ 	].*\);#\1/* \2 */;
!EOF
  if test 162 -ne `wc -c < cpp.sed`; then
    echo shar: \"cpp.sed\" unpacked with wrong size!
  fi
  
fi
exit 0