refix 1.0
Unix filter utility that maintains footnotes in a text file.
Documentation for refix.

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:

  • For each footnote, there must be exactly one reference to it in the body text. A complete rewrite of refix would be required to handle multiple references to the same footnote.
  • Even if the numbering has been disrupted, The order of the footnotes must match that of the references. If you move blocks of body text about then you must shift whatever footnotes are referenced in them in the same way. After that, run 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.

  • Only the first [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

Product : Scheme : Edit Scheme : Run : Arguments : Arguments Passed on Launch : '+'

Example of refix usage -

If you feed this to refix -

<!DOCTYPE HTML>
<html>
<head> <title> Refix Test </title> </head>
<body>
<main>
<h2> Sir Winston Leonard Spencer Churchill<sup>[4]</sup></h2>
<p> I am fond of pigs. Dogs<sup>[3]</sup> look up to us.
Cats<sup>[5]</sup> look down on us. Pigs<sup>[9]</sup>
treat us as equals.
</p>
</main>
<footer>
<dl>
<dt> [1] Churchill</dt>
<dd> British Prime Minister 1940 to 1945.</dd>
<dt> [6] Dogs</dt>
<dd> Mammals in the order Carnivora.</dd>
<dt> [8] Cats</dt>
<dd> Mammals of the subspecies Felis silvestris catus.</dd>
<dt> [3] Pigs</dt>
<dd> Animals in the genus Sus.</dd>
</dl>
<time datetime="2021-08-10T10:33:34+01:00">
Last modified: 10<sup>th</sup> Aug 2021 </time>
</footer>
</body>
</html>

then you should get back -

<!DOCTYPE HTML>
<html>
<head> <title> Refix Test </title> </head>
<body>
<main>
<h2> Sir Winston Leonard Spencer Churchill<sup>[1]</sup></h2>
<p> I am fond of pigs. Dogs<sup>[2]</sup> look up to us.
Cats<sup>[3]</sup> look down on us. Pigs<sup>[9]</sup>
treat us as equals.
</p>
</main>
<footer>
<dl>
<dt> [1] Churchill</dt>
<dd> British Prime Minister 1940 to 1945.</dd>
<dt> [2] Dogs</dt>
<dd> Mammals in the order Carnivora.</dd>
<dt> [3] Cats</dt>
<dd> Mammals of the subspecies Felis silvestris catus.</dd>
<dt> [4] Pigs</dt>
<dd> Animals in the genus Sus.</dd>
</dl>
<time datetime="2021-08-10T10:33:34+01:00">
Last modified: 10<sup>th</sup> Aug 2021 </time>
</footer>
</body>
</html>

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 -

$ g++ -std=c++20 main.cpp -o refix

It is unsafe to assume that I have been able to include no error in this code - short though it is.

Back to clarcana project list.