Make function declarations based on function definitions
- by Clinton Blackmore
I've written a .cpp file with a number of functions in it, and now need to declare them in the header file. It occurred to me that I could grep the file for the class name, and get the declarations that way, and it would've worked well enough, too, had the complete function declaration before the definition -- return code, name, and parameters (but not function body) -- been on one line.
It seems to me that this is something that would be generally useful, and must've been solved a number of times. I am happy to edit the output and not worried about edge cases; anything that gives me results that are right 95% of the time would be great.
So, if, for example, my .cpp file had:
i2cstatus_t NXTI2CDevice::writeRegisters(
uint8_t start_register, // start of the register range
uint8_t bytes_to_write, // number of bytes to write
uint8_t* buffer = 0) // optional user-supplied buffer
{
...
}
and a number of other similar functions, getting this back:
i2cstatus_t NXTI2CDevice::writeRegisters(
uint8_t start_register, // start of the register range
uint8_t bytes_to_write, // number of bytes to write
uint8_t* buffer = 0)
for inclusion in the header file, after a little editing, would be fine.
Getting this back:
i2cstatus_t writeRegisters(
uint8_t start_register,
uint8_t bytes_to_write,
uint8_t* buffer);
or this:
i2cstatus_t writeRegisters(uint8_t start_register, uint8_t bytes_to_write, uint8_t* buffer);
would be even better.