*BSD News Article 40597


Return to BSD News archive

Xref: sserve comp.unix.bsd:15868 comp.lang.c:89976 comp.unix.sys5.r3:2371
Newsgroups: comp.unix.bsd,comp.lang.c,comp.unix.sys5.r3
Path: sserve!newshost.anu.edu.au!munnari.oz.au!goanna.cs.rmit.edu.au!aggedor.rmit.EDU.AU!harbinger.cc.monash.edu.au!msunews!uwm.edu!cs.utexas.edu!swrinde!news.uh.edu!uuneo.neosoft.com!nmtigw!peter
From: peter@nmti.com (Peter da Silva)
Subject: Re: how to completely get rid of bcopy, bzero, bcmp?
Message-ID: <id.X38G1.148@nmti.com>
Sender: peter@nmti.com (peter da silva)
Organization: Network/development platform support, NMTI
References: <3bksus$fg4@spruce.cic.net> <3dtln1$rv8@spruce.cic.net> <3e1787$7f7@elmgate.raster.Kodak.Com> <3ebp8o$a4t@elmgate.raster.kodak.com>
Date: Fri, 6 Jan 1995 17:58:35 GMT
Lines: 46

In article <3ebp8o$a4t@elmgate.raster.kodak.com>,
W. James Colosky <wjc@raster.kodak.com> wrote:
> #!/usr/local/bin/perl
> #                                       -*-perl-*-
> while (<>) {
>         s/bcopy\((.*),(.*),(.*)/memcpy($2, $1, $3/g
>         s/bzero(.*),(.*)/memset$1, 0, $2/g; 
>         s/bcmp/memcmp/g; 
> }

	bcopy(basearray(symptr, argptr[1]), basearray(symptr, argptr[2]), LEN)

becomes

	memcpy(argptr[2]), basearray(symptr, argptr[1]), basearray(symptr, LEN)

A better (though still hazardous) solution would be to use the C preprocessor:

{
cat << \EOF
#define bcopy(a,b,c) memcpy(b,a,c)
#define bzero(a,b) memset(a,0,b)
#define bcmp memcmp
endheader;
EOF
sed '/^#/s/^/HASH/' file.c
} | /lib/cpp | sed -e 'g/^#/d' -e 's/^HASH/#/' -e '1,/endheader/d'

(off the top of my head. YOUR cpp might need other magic to hide the hash.
 See your local Imake for the things you need to do to abuse CPP like this.
 You probably need to #undef preprocessor constants like __STDC__. Your
 mileage may vary. Harmful if swallowed. Contents under pressure, do not
 puncture or expose to open flame. Haven't you read enough joke disclaimers
 already? Not valid in months with an R in it.)

Ideally you should use M4, if you have it. M4 was designed for just this
sort of task:

m4 -D'bcopy=memcpy($2,$1,$3)' \
   -D'bzero=memset($1,0,$2)' \
   -D'bcmp=memcmp($1,$2,$3)' file.bsd > file.posix
-- 
Peter da Silva                                            `-_-'
Network Management Technology Incorporated                 'U`
1601 Industrial Blvd.     Sugar Land, TX  77478  USA
+1 713 274 5180                       "Hast du heute schon deinen wolf umarmt?"