The Boston Diaries

The ongoing saga of a programmer who doesn't live in Boston, nor does he even like Boston, but yet named his weblog/journal “The Boston Diaries.”

Go figure.

Wednesday, April 26, 2000

Woo hoo! Bug free the first time through …

It's always nice when code I write works the first time.

mod_blog advancing yet some more. I was going to embed the HTML within the module, but when I wrote some sample code (to make the archives on the current site) it just got real messy real quick and I didn't even bother finishing it up.

Instead, I quickly wrote code to process template files. This side works pretty much like I think I'm going to end up doing it. I set up a subdirectory containing the templates, each file containing just a portion of a much larger page. In effect, each file is a chunk of HTML code that is processed. During the processing, anything between double hash signs is taken as the name of a callback function.

So for example, in the HTML code I have:


<html>
<head>

  <title>##title## - The Boston Diaries - Captain Napalm<title>

</head>

And the callbacks are currently defined in C as such:


static void archive_callback(FILE *fpout,void *data)
{
  struct tm *ptm = data;
  char       date[BUFSIZ];

  strftime(date,BUFSIZ,"%B %Y",ptm);
  fprintf(fpout,"%s",date);
}

/***************************************************/

void do_archive(
		  FILE *fpout,
                  int   year,
		  int   month,
                  int   stday,
                  int   endday)
{
  static struct chunk_callback cb 
    = { "title" , archive_callback };
  struct tm thisday;

  /* code to set thisday properly snipped */

  ChunkProcess(fpout,"archivehead",&cb,1,&thisday);
  ChunkProcess(fpout,"bostontitle",NULL,0,NULL);
  ChunkProcess(fpout,"bartitle",&cb,1,&thisday);
  
  /* code to generate links for each day */

  ChunkProcess(fpout,"end",NULL,0,NULL);
}

The call to ChunkProcess() takes an output file, the name of the chunk to display, a structure declaring the callbacks, the size of that array, and an extra pointer that is passed to the callback, in this case, to a struct tm * to the date we're processing.

The only thing I may change is the way callbacks are registered, but the mechanics certainly work.

Obligatory Picture

[It's the most wonderful time of the year!]

Obligatory Links

Obligatory Miscellaneous

You have my permission to link freely to any entry here. Go ahead, I won't bite. I promise.

The dates are the permanent links to that day's entries (or entry, if there is only one entry). The titles are the permanent links to that entry only. The format for the links are simple: Start with the base link for this site: http://boston.conman.org/, then add the date you are interested in, say 2000/08/01, so that would make the final URL:

http://boston.conman.org/2000/08/01

You can also specify the entire month by leaving off the day portion. You can even select an arbitrary portion of time.

You may also note subtle shading of the links and that's intentional: the “closer” the link is (relative to the page) the “brighter” it appears. It's an experiment in using color shading to denote the distance a link is from here. If you don't notice it, don't worry; it's not all that important.

It is assumed that every brand name, slogan, corporate name, symbol, design element, et cetera mentioned in these pages is a protected and/or trademarked entity, the sole property of its owner(s), and acknowledgement of this status is implied.

Copyright © 1999-2019 by Sean Conner. All Rights Reserved.