[comp.lang.c] ANSI C function prototype generator?

ljz@fxgrp.UUCP (Lloyd Zusman) (02/18/88)

I recently posted this query to comp.unix.questions, but it seems to
get read by many fewer people than does this newsgroup:

I am looking for a piece of software that will automatically generate
ANSI C function prototypes from "old-fashioned" (i.e., non-ANSI) C
code.

Please note the following criteria for this hypothetical piece of
software:

1)  This software MUST run under unix.  I know that the Microsoft C
    compiler for MSDOS has this capability, but this is unusable by
    me under unix.

2)  This software MUST handle the following case correctly:

    old-fashioned C function header:

    	struct
    	foo *	    	/** comment **/

    	func(a, b, c)
    	long c;
    	char *b;
    	{ ... }

    resulting ANSI C function header/prototype:

    	struct foo *func(int a, char *b, long c)
    	
    Note that the 'a' variable defaults to an 'int' since it isn't explicitly
    declared in the old-fashioned function header.  This makes the task
    rather difficult, as does the fact that the variables in the
    old-fashioned function header are not declared in the same order that
    they appear in the function declaration.  Also note that the
    'struct foo *func' is on separate lines with comments and blank
    lines interspersed ... this adds a further complication.

3)  This software should be in the public domain with source code available.

Before I start the painfully time-consuming task of hacking away at a
C compiler, I thought I'd check if someone has already solved this problem.

I already have tried a few things:

--  It was suggested that I hack at the output of lint (what the first
    pass writes to stdout), but this didn't quite do the job.  The best
    sort of thing I could get using this method was

    	struct <name-unknown> *func(int, char *, long)

    By the time lint gets around to writing its output, the name of
    the structure is lost.  Plus, since the names of the function
    arguments are lost as well, I could only use this for a function
    prototype, not a function header.

--  I tried using the output of ctags.  The best I could do with this is
    to locate the line of the function definition itself (the
    "func(a, b, c)" line in the old-fashioned example).  I still would
    have to parse backwards to the beginning of the function return type,
    and this still requires me to handle the argument types.  Plus,
    ctags tends to locate things other than function definition, making
    the parsing task even more difficult.

--  I tried various and sundry other things, such as fooling around with
    "cflow", "calls", "cb", and other related things.  All had limitations.
    I also tried using sed, awk, and lex, again with the same disappointing
    results.

I think the best hope involves hacking on pcc or gcc.  I'm prepared to do this
as a last resort, but I want to check in netland first.

Can anyone help me?

---
    Lloyd Zusman
    Master Byte Software
    Los Gatos, California		Internet:   fxgrp!ljz@ames.arpa
    "We take things well in hand."	UUCP:	    ...!ames!fxgrp!ljz