I need to create ANSI C function prototypes.

Chris R. Lewis clewis at spectrix.UUCP
Sat Feb 13 08:47:22 AEST 1988


In article <2273 at cognos.UUCP> brianc at cognos.UUCP (Brian Campbell) writes:
>In article <201 at fxgrp.UUCP> fxgrp!ljz at ames.arpa (Lloyd Zusman) writes:
>! I'm looking for a program that will take old-fashioned C code and
>! produce ANSI C function prototypes.
>! ...
>! This program would produce something similar to the following:
>! 
>! 	char *foo(char *a, int b, int c);

This is probably not to hard to do with awk.  Swallow a whole function
definition until the leading brace and then rewrite it.  With YACC (this
will probably work much better): find a yacc grammar for C.  In the
parameter declaration portion, insert actions to reformat the text and
spit it out.  Don't emit anything else.

>I tried to do this once before.  I failed.  I wanted to have lint
>create a lint-library for each source file, but lint libraries are not
>particularly readable (they're not textual).

An easy hack:

Take the lint shell file.  Make a copy.  Modify it so that it saves
the output of the "lint1" pass.  Delete the lint2 pass.  Run it on
the sources you want to have lint libraries for.  Viola!  The stuff
you saved is the lint library.  Only one idiosyncrasy: if any of the
library routines have lint errors, you'll see these lint errors on
every invocation lint you use these new lint libraries on.  And, I
expect that the libraries would be bigger than they could be.

Or, use my first suggestion, except that you'll have to emit the
function declaration in the order it comes in (rather than make it
look like ANSI) plus replace the body with:

	{	return(<dummy variable of the function's type>);	}
-- 
Chris Lewis, Spectrix Microsystems Inc,
UUCP: {uunet!mnetor, utcsri!utzoo, lsuc, yunexus}!spectrix!clewis
Phone: (416)-474-1955



More information about the Comp.unix.questions mailing list