Argument declaration style (Was: ANSI C prototypes)

Tapani Tarvainen tt at tarzan.jyu.fi
Wed Nov 7 22:19:29 AEST 1990


In article <BZS.90Nov6205843 at world.std.com> bzs at world.std.com (Barry Shein) writes:

> It's unfortunate that grep doesn't let you specify what is to be
> listed when a hit occurs, the perfect thing would be something like:
> 
> 	   grep ^foo( -L .-1,. *.c
> 
> which would list the previous line and the hit (thus giving you
> the type and the declaration) or even:
> 
> 	   grep ^foo( -L .-1,/^{/-1 *.c

Try this:

#!/bin/sh
# EXDEF
# extract C function definitions & declarations
# usage: exdef function file(s)
# Tapani Tarvainen 7 November 1990
f=$1
shift
sed -e '/^[a-zA-Z_]/!d' -e ':L' -e '/^[^(]*[{;]/d' -e '/(/bR' -e N -e bL \
-e :R -e '/);/!{/{/!{' -e N -e bR -e '}' -e '}' -e "/$f(/!d" $@

Then
	exdef foo *.c

should do what you want, with both old and new style.

I just wrote that and it obviously isn't perfect, e.g., certain
characters in comments within can cause trouble.
Anyway, it prints function definitions from the type up to the { and
declarations up to the semicolon, regardless of how many lines they
occupy.  If you want only definitions or only declarations it's easy
enough to change (except it doesn't distinguish function typedef's
from declarations; add -e '/^typedef/d' before $@ if you don't want
them).
--
Tapani Tarvainen    (tarvaine at jyu.fi, tarvainen at finjyu.bitnet)



More information about the Comp.lang.c mailing list