Another department at the Ft. Lauderdale Office of the Corporation is refactoring their code. Normally this wouldn't affect other groups, but this particular code requires some executables we produce, and to make it easier to install, we, or rather, I, needed to create a new repository with just these executables.
Easier said than done.
There's about a dozen small utilities, each a single C file, but unfortunately, to get the banana (the single C file) you also need the 800 pound gorilla (its dependencies). Also, these exectuables are spread through most of our projects—there's a few for “Project: Wolowizard” (which is also used for “Project: Sippy-Cup”), multiple ones for “Project: Lumbergh,” a few for “Project: Cleese” and … oh, I never even talked about this other project, so let's just call it “Project: Clean-Socks.”
So that's how I spent my time last week, working on “Project: Seymore,” rewriting a dozen small utilities to remove the 800 pounds of gorilla normally required to compile these tools. All these utilties do is transform data from format A to format B. The critical ones take a text file of lines usually in the form of “A = B” but there was one that took over a day to complete because of the input format:
A = B:foo,bar,... name1="value" name2="value" ... A = B:none
Oh, writing parsing code in C is so much fun! And as I was stuck writing this, I kept thinking just how much easier this would be with LPEG. But alas, I wanted to keep the dependencies to a minimum, so it was just grind, grind, grind until it was done.
I found that I had installed
the recursive-descent parser generator for C,
on my work machine eight years ago.
Eight years ago!
Head, meet desk.
Including the time to upgrade
the time it took me to rewrite the utility that took me nearly two days only took two hours
(most of the code among most of the utilities is the same—check options, open files, sort the data, remove duplicates, write the data;
it's only the portion that reads and converts the data that differs).
It's also shorter,
and I think easier to modify.
So memo to self: before diving into a project, check to see if I already have the right tools installed.
So if I needed to parse data in C,
why did I not use
It's pretty much standard on all Unix systems, right?
but all it does is lexical analysis.
The job of parsing requires the use of
So why didn't I use
Beacuse it doesn't do lexical analysis.
If I use
I also need to use
Why use two tools when one will suffice?
They are also both a pain to use,
so it's not like I immediately think to use them
(that, and the last time I used
lex in anger was over twenty years ago …)