PostFilt:
A Utility that Processes Source Code for Publication and/or Usenet
News Group Postings
by Leor Zolman and Arthur J. O'Dwyer
Open Source Freeware in C++ (well, sort of)
Click here to download the ZIP
archive, or here for a .tar file
[updated June 2, 2004]
Description:
PostFilt began as a simple de-tabifier and source code cleaner-upper
named plist.c that I wrote for use while on the editorial/technical
staff at The C/C++
User's Journal. It has sat pretty much unused for years. Recently,
while participating in Usenet news groups (alt.comp.lang.learn.c-c++,
specifically), the issue of tabs in source code came up (as it does
on a regular basis on the various groups). I posted the old plist.c
program as a stopgap for folks to use if they want to eliminate
tabs from their code ("detabify") without changing the
apparent column alignment.
Arthur J. O'Dwyer, a longtime regular on the news groups, then
posted a link to a utility he wrote, usenetify.c,
that nicely wraps long lines, preserving C and C++'s semantics.
But Usenetify didn't address the tabs issue.
I made a tongue-in-cheek suggestion that we'd inaugurated a "detabifier/line-wrapper
arms race". Immediately upon examination of Arthur's program,
however, I realized he'd done something very useful that would nicely
dovetail with some of plist's functionality. With his blessing and
support, I incorporated the heart of usenetify.c into my program,
and renamed the resulting utility pf (less to type, and it does
not conflict with a Microsoft utility named plist.exe that has come
onto the scene since my plist was originally written.)
Both plist.c and usenetify.c are written in pure C, but I decided
to use C++ for the new, combined utility. The primary reason for
this was to use C++'s iostream facilities for reading lines of arbitrary
length from a file (or the standard input) without having to worry
about buffer length management. As it turns out, in order to interface
with Arthur's wrapping function, I ended up having to do a bit of
manual dynamic memory management anyway, but overall I think the
program holds up pretty well considering the input side uses iostreams
and the output side relies solely on stdio facilities. It's a strange
marriage ;-)
Some useful things to know:
- pf -? or -h gives a usage summary. pf with no arguments reads
from stdin and writes to stdout.
- Command-line options and filenames may be intermixed. Options
apply to subsequent filenames until overridden.
- Boolean option flags toggle their state; defaults are configurable
by changing the #defines in the source.
- Field width may be specified with or without the 'w' (e.g.,
-70 is the same as -w70).
- The -e option is kinda cool. See below.
- The goal is for the Usenetify option to preserve all C/C++
semantics, and it is close... close enough that I judged this
package worthy of release. But it isn't perfect (for example,
there's a problem with multi-line macros and strings in certain
contexts.) For the time being, it would be a Good Idea to be sure
and test code produced by pf (and Arthur's usenetify program)
for validity before posting it. [Of course, the output will only
be valid C or C++ if the input also was ;-) ]
Installation:
- This is just a command-line utility. Tailor to suit (as per
some of the items below, for example), compile it and put is somewhere
useful, like in a directory in your PATH.
- If you do not want a leading forward slash to be recognized
as an option prefix (equivalent to '-'), be sure to go into the
source and comment out the #define SLASH_OPTS line.
- The '-e' option forces output files to be written (as with '-o'),
but in addition, it brings each output file up in your text editor
of choice (configure the command line for the editor by setting
the value of the FAVE_EDITOR #define.) The idea is that you can
then simply copy-and-paste whatever you need out of your editor
and into, say, a news group posting.
Feedback (bugs, suggestions, whatever) is always appreciated --
contact leor@bdsoft.com.
Home |
Courses |
Tools |
Resources
Clients |
Successes |
Contact |
Site Map |
Links |
About Us
All text and images on this website are Copyright © 2001-2003 BD Software. All rights reserved.
|
 |