5x12 pentomino tiling
«

Luckily I am not a C programmer

»

We use htmldoc, a program which converts an HTML document into Adobe/PDF format, for a variety of reasons the most significant of which is that we use it to generate the PDF versions of our walks on WalkLakes so when we recently upgraded to a server running Ubuntu 14.04 I installed the latest htmldoc from the distribution. Not a good idea. Here's how step 2 looked on the first walk processed via htmldoc:

Sample from broken PDF showing borked map

That block on the right is meant to be a map rendered from a PNG but htmldoc has screwed it up squashing it to the left.

Looking back on the old server I saw I'd built htmldoc from source. Fair enough, let's do that again, how hard can it be ...

Well the first problem was a fatal error complaining about an "int to boolean" conversion error in image.cxx line 1385:

  cinfo.quantize_colors = 0;

Beth, who'd wandered in by then, suggesting simply changing the 0 to FALSE (and that was also suggested by a poster on the htmldoc site) so I did that and set it off again.

Then it complained about gnutls so we turned that off with:

  ./configure --enable-gnutls=no

More errors, this time relating to SSL. Again we don't need SSL for this, we're trying to simply generate very simple PDFs so we disabled this too thus:

  ./configure --enable-gnutls=no --enable-ssl=no --enable-openssl=no

And still it complained, this time that errno wasn't defined in this code in http-addrlist.c:

  if (!sock)
  {
#ifdef WIN32
    errno = WSAEINVAL;
#else
    errno = EINVAL;
#endif /* WIN32 */
 
    return (NULL);

At this point Beth gave up and wandered off muttering about how crap the code was. At the time I didn't really understand why but went back to Googling about for solutions, without success. In the end I went back to the code with the error and here, not being a C programmer helped me1. I've been coding a lot in PHP (which is syntactically sort of similar) and looking at the code, which was inside a function, errno clearly wasn't been returned and wasn't being declared as a global (something you need to do inside a function in PHP) so perhaps I could simply comment references to it out so I did so thus:

  if (!sock)
  {
/*
#ifdef WIN32
    errno = WSAEINVAL;
#else
    errno = EINVAL;
#endif */ /* WIN32 */
 
    return (NULL);
  }

and it compiled and runs and, if you look at A very short walk to Hard Knott and Border End (which is what I was trying to render before) you'll see that all the maps, including step 2, are now fine.

Of course the reality, as I now know, is that errno is a global so presumably should be set, having been declared by a #include (errno.h perhaps?) but ignorance is bliss on this occasion: it works and that'll do me.

Anyway blogged, both as an object lesson in how being ignorant can occasionally help but also to give some pointers to people going this way in future (who can hopefully find a better solution to the final problem).

  1. You have to remember that I'm old, when I did my CompSci degree it was before the days of C and we mainly used Algol and BCPL.

Written 15/10/14

Comment on this article

«
You can follow these posts on Twitter at @Wibblings
»
I am currently reading:

Scotland: The Autobiography by Rosemary Goring Hopjoy Was Here by Colin Watson

(?)
Word of the Day:
mazer