refix 1.0
Unix filter utility that maintains footnotes in a text file.
|
refix
is a 'filter' utility that automates the maintenance of either a text or html document containing numbered footnotes in the footer, or near the end of the document, and references to those notes scattered throughout the body text.
A problem ensues when the author wishes to add a new note or delete an existing one. All the subsequent footnotes, and all subsequent references to them, must then be renumbered to preserve the monotonic sequence a reader prefers.
To keep the code simple, so must be the reference system in use:
refix
to straighten out the numbering.The character sequence
[nnn]
is used both for footnotes and for references. A different sequence could be used by modifying the regex pattern. nnn
is any string of decimal numbers of at least one digit. The first footnote must be made
[1]
The first reference will be converted to [1]
. Leading zeros will be stripped out.
[nnn]
on each line will be processed. Subsequent ones are ignored. This is alterable without great effort.The first sequence on a line will be treated as a reference even if you intend it for a section number or some other purpose, or enclose it in a comment. Sequences may be hidden from refix
by adding a non-decimal before or after the number -
[ 42 ]
or
[+42]
refix
will change none of the text except the footnote numbers inside []
.refix
appears to work with UTF-8 input. Wider characters may yield, er, unexpected results. refix
may be used as a free standing filter, as any other, from the command line or in a script. I use it as a BBEdit 'Text Filter', that is BBEdit passes the entire text of its front document, or a selection, if such there be, to this program. refix
then reads that text with cin
, processes it and then outputs modified text on cout
which is then read back by BBEdit and used to replace the original text with the modified content.
For BBEdit to recognize refix
as a filter it must be installed as -
/Users/yourUname/Library/Application\ Support/BBEdit/Text\ Filters/refix
After compilation, the executable will be left in your Library folder. Copy it to the Filters folder, or symlink -
ln -s /Users/yourUname/Library/Developer/Xcode/DerivedData/refix-avznsfyyvrexnbcwvwngkjsgkhoy/Build/Products/Debug/refix refix
If refix
is invoked without command line arguments then it will take input from stdin
. If you specify argument -t
then refix goes into 'test mode' and tries to open a file test.txt
sitting in the same directory, and processes that instead of stdin
.
To persuade Xcode to pass command line arguments to refix
, hit
Example of refix
usage -
If you feed this to refix
-
then you should get back -
There is no make
or Xcode
project file. The code consists only of the main
function, which you can copy and paste from the main.cpp
File Reference listing you access from the menu here at top.
Try -
It is unsafe to assume that I have been able to include no error in this code - short though it is.