diff --git a/cow/Makefile b/cow/Makefile index f43e61d..4465291 100755 --- a/cow/Makefile +++ b/cow/Makefile @@ -1,5 +1,5 @@ MAIN = cow -CFLAGS = -I/usr/include/libxml2 +CFLAGS = -I/usr/include/libxml2 -DDEBUG -pedantic -ansi -Wall LDFLAGS = $(CFLAGS) -lxml2 -lxslt SOURCES = $(wildcard *.c) OBJECTS = $(SOURCES:.c=.o) diff --git a/cow/debug.h b/cow/debug.h new file mode 100755 index 0000000..39d239b --- /dev/null +++ b/cow/debug.h @@ -0,0 +1,13 @@ +#ifndef CSC_COW_DEBUG_H +#define CSC_COW_DEBUG_H + +#include + +#ifdef DEBUG +#define DEBUG_PRINT(x) do { fprintf(stderr, "%s:%d (%s): %s\n", __FILE__, \ + __LINE__, __FUNCTION__, x); } while (0) +#else +#define DEBUG_PRINT(x) do { } while (0) +#endif + +#endif diff --git a/cow/functions.c b/cow/functions.c new file mode 100755 index 0000000..a7902bc --- /dev/null +++ b/cow/functions.c @@ -0,0 +1,55 @@ +#include "debug.h" +#include +#include +#include + +#define COW_URI ((const xmlChar *)"http://www.csclub.uwaterloo.ca/cow") + +/* return the term ({Winter,Summer,Fall} YYYY) for a date in + * YYYY-MM-DD format. + */ +void extension_cow_term(xmlXPathParserContextPtr ctxt, + int nargs) +{ + xmlChar *str, *ret; + int str_l, month; + + DEBUG_PRINT("term"); + if (nargs != 1) { + xmlXPathSetArityError(ctxt); + } + str = xmlXPathPopString(ctxt); + str_l = xmlUTF8Strlen(str); + DEBUG_PRINT(str); + + month = (str[5] - '0')*10 + (str[6] - '0'); + + ret = xmlUTF8Strndup((const xmlChar*)(month < 9 ? (month < 5 ? "Winter " : "Summer ") : "Fall "), 7); + ret = xmlStrcat(ret, xmlUTF8Strsub(str, 0, 4)); + + xmlXPathReturnString(ctxt, ret); + xmlFree(str); +} + +void *extension_init_func(xsltTransformContextPtr ctxt, + const xmlChar *URI) +{ + DEBUG_PRINT("Extension init"); + return 0; +} + +void extension_shutdown_func(xsltTransformContextPtr ctxt, + const xmlChar *URI, + void *data) +{ + DEBUG_PRINT("Extension shut down"); +} + +void init_extensions() +{ + DEBUG_PRINT("Registering extension module."); + xsltRegisterExtModule(COW_URI, + extension_init_func, extension_shutdown_func); + xsltRegisterExtModuleFunction((const xmlChar*)"term", COW_URI, + extension_cow_term); +} diff --git a/cow/main.c b/cow/main.c index 6c4a514..4bdf483 100755 --- a/cow/main.c +++ b/cow/main.c @@ -10,10 +10,14 @@ #include #include #include +#include +#include "debug.h" extern int xmlLoadExtDtdDefaultValue; -// output usage message. progname is the name of the executable. +void init_extensions(); + +/* output usage message. progname is the name of the executable. */ static void usage(const char* progname) { printf("Usage: %s [options] stylesheet input\n", progname); @@ -59,10 +63,13 @@ int main(int argc, char** argv) usage(argv[0]); return 1; } - + params[nbparams] = NULL; xmlSubstituteEntitiesDefault(1); xmlLoadExtDtdDefaultValue = 1; + + init_extensions(); + cur = xsltParseStylesheetFile((const xmlChar *)argv[argNum]); argNum++; doc = xmlParseFile(argv[argNum]); diff --git a/cscweb.xsl b/cscweb.xsl index cf8f383..9810323 100755 --- a/cscweb.xsl +++ b/cscweb.xsl @@ -1,7 +1,9 @@ + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:csc="http://www.csclub.uwaterloo.ca/cow" + extension-element-prefixes="csc"> @@ -17,6 +19,9 @@ +

+ +

@@ -207,12 +212,12 @@ -

The events for are listed here.

+

The events for are listed here.

- +

, diff --git a/default.mk.in b/default.mk.in index b018be0..b04ef3d 100755 --- a/default.mk.in +++ b/default.mk.in @@ -18,5 +18,5 @@ clean-recurse: clean clean: rm -f *.html -%.html: %.xml $(ROOT)/csc.dtd $(ROOT)/cscweb.xsl $(ROOT)/events.xml $(ROOT)/news.xml $(ROOT)/menu.xml $(ROOT)/default.mk directory.xml +%.html: %.xml $(ROOT)/csc.dtd $(ROOT)/cscweb.xsl $(ROOT)/events.xml $(ROOT)/news.xml $(ROOT)/menu.xml $(ROOT)/default.mk directory.xml $(ROOT)/cow/cow $(ROOT)/cow/cow $(XSLTARGS) $(ROOT)/cscweb.xsl $< > $@