This parsing tool converts C #define
'ed constants into
Java interfaces containing those constants. It will handle most simple
expressions and scanning through out-of-order #include files. It will
not handle macros. It will only read but not execute casts. It does
do a reasonably good job, parsing over 97% of the Windows non-macro
constants.
You must give it input files consisting only of #define lines, with no other intervening whitespace or code. Its output is a large interface containing all of your constants and an alphabetically split up set of interfaces. The alphabetical breakdown should perform slightly better than the huge interface on a large number of constants (~10K or more).
If you have a particular macro that you'd like the program to support,
your best chance is to edit it to handle it. There are a few hacks for
about 3 common macros that only pass a number through (no changes
whatsoever) which would be trivial to adapt for your own trivial macros.
If you're interested, most of your edits will be in parseWords
.
grep
, sed
, tcsh
, and other
Unix command line utilities are strongly recommended but not strictly necessary
Create .def
files for your constants. For each of your
header files, grep for #define
in your code. Any
#define
directives that span multiple lines are considered
unparsible. If you have tcsh
and a few command line
utilities, this tcsh command should work:
foreach i (*.h)
grep ^#define $i > `echo $i | sed "s/\.h$/\.def$/"`
end
The echo and sed command just converts the header file name to a def file,
changing your_header.h
into your_header.def
, so
you can do this by hand without needing a copy of sed
.
/*
without a corresponding */
on that same
line. You can do that with this command:
grep \/\* *.def | grep -v \*\/
Fix up any lines that grep
outputs. Edit the def file and get
rid of those comments.
Edit defscan source code, if needed. You can change the behavior for strings, the default package, and output directory.
.def
files. You can pass them in as
command line parameters, but if you have a lot of them, you'd be better off
listing them in a text file, files.txt
. List them one per
line. Run defscan as:
jview defscan [your .def files]