My gcc installation had neither cproto nor mkproto. But I did have Vim and I figured out a global substitute to do this one parameter at a time...
:%s/^\(\%(\w\+\%(\s*\*\+\s*\|\s\+\)\)\+\)\(\w\+\)\s*(\@=\(.\{-}\)\([(,)]\)\s*\(\w\+\)\s*\([,)].*\)\n\s*\(.\{-}\)\5\([^;]*\);/\1\2\3\4\7\5\8\6/
where the recorded subexpressions are:
- the function return type
- the function name
- the already-prototyped parameters (if any)
- the delimiter before the next K&R parameter to fix - '(' or ','
- the next K&R parameter to fix
- the following delimiter - ',' or ')' followed by any remaining (unprocessed) K&R parameter identifiers and closing ')'
- the parameter's type
- the parameter's post-identifier characters (e.g., brackets)
Repeat until no more matches in the file. Note, the pattern presumes the K&R function declaration is on one line, followed by individual parameter declarations on successive lines.
Two applications of this substitute successfully processes:
int main(argc,argv)
int argc;
char *argv[];
{
printf("Hello world!\n");
return 0;
}
into:
int main(int argc,char *argv[])
{
printf("Hello world!\n");
return 0;
}