| radwin.org -> Michael J. Radwin -> Projects -> stubgen -> stubgen 1.11 | Search |
I don't like C++, in part because of the repetition between header files and the actual code. But I use C++. So I wrote stubgen.
Back in '95, when I was coding some of those C++ projects for cs032, I realized I needed the C++ equivalent of EdsScript (written by the infamous Ed Bielawa). The result of my efforts is a perl script (residing in /cs/bin/stubgen). While you're here, you can peek at the source.
stubgen was formerly known as expandC, but I didn't like that capital "C" at the end, so I changed the name when I made it a cs project.
For those of you who are unfamiliar with what EdsScript for OOPas did, stubgen takes a C++ header (.H or .h) file, finds member function prototypes, and expands those prototypes into member function definiton stubs to a code (.C or .cc) file of the same name. stubgen isn't as bug-free as EdsScript was, but it works well enough to be usable.
I make no guarantees. It seems to work rather well for me, and I've found it useful for C++ projects of any size, so I figured I'd make it available. It appends to whatever code file you have around, so you won't accidentally clobber your existing code files.
Features I hope to add:
template<class T>)
usage: stubgen [-hqlxricdvVfsjpn] infiles
GENERAL OPTIONS
-h Display usage information.
-q Quiet mode, no status information while generating code.
-l Generate source files with a lowercase (.cc) extension.
-x Generate source files with a .cxx extension.
-r Make RCS-style file headers
-i Don't put the #include "my_file.H" directive in my_file.C
DEBUGGING OUTPUT OPTIONS (prints "class::function" in body of function)
-c Use cerrs and iostream.h
-d Use cs169-style dprintf's and Debug.H
METHOD HEADER STYLES
-v Verbose method headers, similar style to the cs032
method headers you get from the emacs mode. (default)
-V Really verbose method headers, true cs032 style because
each line both begins and ends the comment. Code by dp.
-f Full method headers, a cross between -p and -v.
-s Simple method headers.
-j Java-style method headers.
-p Plain headers, just the name of the function.
-n No method headers.
I'd run this command:
% stubgen Foo.H
and the file Foo.C would be produced.
Using the -c option for cerr debugging
% stubgen -c Foo.H
produces functions that look like this:
/*************************************************************************
* Function Name: Foo::toto
* Parameters: double &d, int i
* Returns: double
* Effects:
*************************************************************************/
double
Foo::toto(double &d, int i)
{
cerr << "Foo::toto" << endl;
}
Using the -d option for cs169-style dprintf debugging (relies on both Debug.H and Debug.C)
% stubgen -d Foo.H
produces functions that look like this:
/*************************************************************************
* Function Name: Foo::toto
* Parameters: double &d, int i
* Returns: double
* Effects:
*************************************************************************/
double
Foo::toto(double &d, int i)
{
dprintf(("Foo::toto\n"));
}
Using the -r option gives you RCS-style file headers
% stubgen -r Foo.H
produces file headers that look like this:
/* * FILE: Foo.C * AUTH: Michael John Radwin <mjr> * * DESC: * * DATE: Thu Apr 18 14:23:30 1996 * $Id$ * * Modification history: * $Log$ * */
You can even combine options, like: plain method headers and cerr debugging
% stubgen -cp Foo.H
produces functions that look like this:
/*
* Foo::toto
*/
double
Foo::toto(double &d, int i)
{
cerr << "Foo::toto" << endl;
}
---------------------------- revision 1.8 date: 1997/02/07 00:48:16; author: mjr; state: Exp; lines: +7 -4 -x option ---------------------------- revision 1.7 date: 1996/06/12 17:31:18; author: mjr; state: Exp; lines: +2 -2 fixed the defined() paren mismatch ---------------------------- revision 1.6 date: 1996/06/06 17:22:00; author: mjr; state: Exp; lines: +19 -7 revised comments at the top ---------------------------- revision 1.5 date: 1996/05/02 15:44:40; author: mjr; state: Exp; lines: +9 -7 added STUBGEN_DOM environment variable check to append to the author's email address. Cleaned up the -V option so it has the same width as -v Put the Returns: void line back in ---------------------------- revision 1.4 date: 1996/04/22 17:51:12; author: mjr; state: Exp; lines: +7 -8 cleaned up nest handling a little and also checks for undefined NAME and USER variables instead of just '' values ---------------------------- revision 1.3 date: 1996/04/19 17:08:48; author: mjr; state: Exp; lines: +4 -3 added -i option to not #include "file.H" in file.C per request of djh ---------------------------- revision 1.2 date: 1996/04/17 00:23:09; author: mjr; state: Exp; lines: +7 -6 function(s) based on # expanded -- cosmetic ---------------------------- revision 1.1 date: 1996/04/16 23:25:42; author: mjr; state: Exp; Initial revision
----------------------------
revision 1.19
date: 1996/04/15 15:19:18; author: mjr; state: Exp; lines: +1 -1
made constructors and destructors print the blank line again
so that the signature matching isn't broken anymore
----------------------------
revision 1.18
date: 1996/04/15 13:49:25; author: mjr; state: Exp; lines: +33 -8
-r for rcs-style file headers
added USER lookup in case the environment var is not set
----------------------------
revision 1.17
date: 1996/04/15 05:41:33; author: mjr; state: Exp; lines: +14 -5
added -f for full headers (per request of knr)
don't print ret_type if it's blank (i.e. constructors, destructors)
----------------------------
revision 1.16
date: 1996/04/15 01:26:10; author: mjr; state: Exp; lines: +41 -29
added -q, cleaned up status output with inform_user
doesn't restrict input files to .[hH]
new usage format
----------------------------
revision 1.15
date: 1996/04/12 05:40:57; author: mjr; state: Exp; lines: +24 -13
checks for existence of .cc or .C to override -l flag
if one or the other exists already.
----------------------------
revision 1.14
date: 1996/04/12 02:43:48; author: mjr; state: Exp; lines: +4 -2
revised some output messages
----------------------------
revision 1.13
date: 1996/04/12 00:12:41; author: mjr; state: Exp; lines: +5 -3
added -l option for lowercase (.cc) extensions for files
----------------------------
revision 1.12
date: 1996/04/11 05:39:49; author: mjr; state: Exp; lines: +3 -2
fixed the regexp for previous-op-overload
----------------------------
revision 1.11
date: 1996/04/11 05:20:16; author: mjr; state: Exp; lines: +2 -0
added operator-overloading to the previous_sigs function
----------------------------
revision 1.10
date: 1996/04/11 03:39:04; author: mjr; state: Exp; lines: +61 -5
added signature matching so you can run it multiple times
----------------------------
revision 1.9
date: 1996/04/10 02:28:33; author: mjr; state: Exp; lines: +2 -0
fixed the fwd decl prob
----------------------------
Wed Feb 28 13:34:24 EST 1996
cleaned up the ENV{'NAME'} lookup a little
Sat Feb 24 22:35:06 EST 1996
doesn't create a .C file if it finds no member functions
Wed Feb 21 22:29:36 EST 1996
added pw-lookup for ENV{'NAME'} in case it's not set
Tue Feb 20 14:07:39 EST 1996
switched to getopts.pl, added java-style comments, made comment
styles a little more uniform, added dprintf support
Sun Oct 22 23:33:23 EDT 1995
fixed what apparently broke with $class:: to $class\:\:
Tue May 2 12:39:22 EDT 1995
now ignores nested classes, structs, enums and unions
Mon May 1 15:05:23 EDT 1995
really cleaned up the general function rule, which allowed the
elimination of the extra rule for templates. Much smarter.
also added parameter lists to limit the use of globals.
also cleaned up usage info and command-line options.
outFile writes to current directory, not full path of infile
Tue Apr 25 16:41:57 EDT 1995
added cerr support, allows comments following functions
Tue Apr 4 18:43:55 EDT 1995
moved usage message after commandline stuff
Mon Apr 3 16:44:00 EDT 1995
added support for **&, etc; sub PrintMethod introduced to handle
the various command line options
Mon Mar 13 20:30:18 EST 1995
cleaned it up a lot, functional but limited