This Space for Rent

New Code (2)!

Discount has been pushed up to version 1.6.6 to correct one parsing error and one defect that would make theme dump core if it tried to create an output filename from a source filename that didn’t contain a dot.

The parsing error is that I match embedded []s inside []() constructs, so I can use images as the link for a url (I do this all the time on tsfr), but I was handling escaped ]s and not handling escaped [s. This meant that a link like


would not parse, because when I encountered the \[ inside the link, I’d treat it as just another [ that I needed to match. And it would match the trailing ], and then discount would run forward trying to find another ] that it could match against.

The theme defect is a bit more stupid than this, and it’s a result of what I wrote it for. I wrote theme as a demo to show how the discount library works, of course, but I did it so I could redo my web site into markdown (and eventually write an apache content handler that dynamically generates html from markdown, but I’ve not actually gotten around to it yet :-() And how I did that was a wholescale renaming of all of my .html files into .text, which I then went over and stripped out the html and replaced it with markdown. And, as a convenience, I wrote things so that all I needed to do was give it the name of a sourcefile and it would automatically generate the html filename by removing the .text and replacing it with .html.

“But what”, you may ask, “happens if there’s no .text on the source filename to replace? Do you just append the .html?”

That’s what you’d think, but, no, theme was doing a p = strrchr(sourcefile, '.') and then, without bothering to check for teeny details like if ( p != NULL ), would just charge ahead and do strcpy(p, '.html') with the expected hilarious consequences if p was NULL.


But it’s fixed now, and this New Code! is ready for your compiling enjoyment.