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)
--- /dev/null
+#ifndef CSC_COW_DEBUG_H
+#define CSC_COW_DEBUG_H
+
+#include <stdio.h>
+
+#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
--- /dev/null
+#include "debug.h"
+#include <libxslt/extensions.h>
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+
+#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);
+}
#include <libxslt/xsltInternals.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
+#include <libxslt/extensions.h>
+#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);
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]);
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:csc="http://www.csclub.uwaterloo.ca/cow"
+ extension-element-prefixes="csc">
<xsl:output method="html" />
</style>
</head>
<body>
+<p>
+ <xsl:value-of select="csc:term($date)"/>
+</p>
<xsl:apply-templates select="biglogo"/>
<xsl:apply-templates select="header">
<xsl:with-param name="title" select="@title"/>
</xsl:template>
<xsl:template match="events-this-term">
- <p>The events for <xsl:value-of select="$term"/> are listed here.</p>
+ <p>The events for <xsl:value-of select="csc:term($date)"/> are listed here.</p>
<xsl:for-each select="document('events.xml')/eventdefs/eventitem">
<xsl:sort select="translate(@date, '-', '')"
order="ascending"
data-type="number"/>
- <xsl:if test="@term = $term">
+ <xsl:if test="@term = csc:term($date)">
<h3><xsl:value-of select="@title"/></h3>
<p>
<b><xsl:value-of select="@room"/>,
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 $< > $@