parent
9abc317387
commit
b5c49e1863
@ -0,0 +1,13 @@ |
||||
#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 |
@ -0,0 +1,55 @@ |
||||
#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); |
||||
} |
Loading…
Reference in new issue