proto(1)

NAME
proto - build ANSI-C prototypes from ANSI or K&R C source code.

SYNOPSIS
proto [-f|-s] inputfile [outputfile]

DESCRIPTION
By default, PROTO builds a list of ANSI-C prototypes (external declarations that declare the parameter types) for all the public functions in a given C source file - whether the function headers are in the new ANSI C style or the old K&R C style.

You can then incorporate the file generated into your .h files.

If you omit the output file from the command line, the standard output will be used.

OPTIONS
If you give PROTO the -s flag, it will generate prototypes of all the private (static) functions in the file, instead of the public ones. This list is suitable for embedding into a C source file, above all the function definitions..

If you give PROTO the -f flag, it will copy the entire file, changing any K&R style function headers it sees into the ANSI style. Thus, it acts as a useful (but simplistic) K&R -> ANSI C converter. PROTO doesn't care whether it is given a .c or a .h filename - it still reads the .c file! Why? I have a vi macro set up which pipes the next paragraph into proto and replaces it with the result. I run this when editing the run proto on the corresponding .c file! This allows me to keep the prototypes up to date with very little effort. I have another vi macro (invoking proto -s) to regenerate the static function prototypes.

PORTABILITY
PROTO should work fine on any system with a C compiler. If it doesn't, please let me know!

AUTHOR
Duncan White, Dept of Computing, Imperial College London UK.
Email: d.white@imperial.ac.uk

LIMITATIONS
Rather than implement a full C grammar, PROTO uses a very simple strategy for identifying the functions in your C file: it takes each line separately, and attempts to recognise it as a function heading. Lines that fail (the vast majority, of course!) are silently ignored, whereas any line that looks like a function has a prototype emitted.

This approach means that the entire function declaration, including the types of all the parameters, must reside on a single line for it to be recognised.

The grammar used for parsing lines is **not** complete: types (both the return type and parameter types) are restricted to roughly ['struct'|'union'] identifier ['*']*' Anything more complex, eg. "int (*fred)()" or even "int fred[]" will not be recognised. To use PROTO successfully, you will need to disguise all such complex types as typedef's (but then, I'd always recommend doing this anyway!)