preparing 1.0.14 updated rebuilt implemented the IN_LIBXSLT and
[platform/upstream/libxslt.git] / libexslt / common.c
1 #define IN_LIBEXSLT
2 #include "libexslt/libexslt.h"
3
4 #if defined(WIN32) && !defined (__CYGWIN__)
5 #include <win32config.h>
6 #else
7 #include "config.h"
8 #endif
9
10 #include <libxml/tree.h>
11 #include <libxml/xpath.h>
12 #include <libxml/xpathInternals.h>
13
14 #include <libxslt/xsltconfig.h>
15 #include <libxslt/xsltutils.h>
16 #include <libxslt/xsltInternals.h>
17 #include <libxslt/extensions.h>
18 #include <libxslt/transform.h>
19 #include <libxslt/extra.h>
20 #include <libxslt/preproc.h>
21
22 #include "exslt.h"
23
24 static void
25 exsltNodeSetFunction (xmlXPathParserContextPtr ctxt, int nargs) {
26     xmlChar *strval;
27     xmlNodePtr retNode;
28     xmlXPathObjectPtr ret;
29
30     if (nargs != 1) {
31         xmlXPathSetArityError(ctxt);
32         return;
33     }
34
35     if (xmlXPathStackIsNodeSet (ctxt)) {
36         xsltFunctionNodeSet (ctxt, nargs);
37         return;
38     }
39
40     strval = xmlXPathPopString (ctxt);
41     retNode = xmlNewDocText (NULL, strval);
42     ret = xmlXPathNewValueTree (retNode);
43     ret->type = XPATH_NODESET;
44
45     if (strval != NULL)
46         xmlFree (strval);
47
48     valuePush (ctxt, ret);
49 }
50
51 static void
52 exsltObjectTypeFunction (xmlXPathParserContextPtr ctxt, int nargs) {
53     xmlXPathObjectPtr obj, ret;
54
55     if (nargs != 1) {
56         xmlXPathSetArityError(ctxt);
57         return;
58     }
59
60     obj = valuePop(ctxt);
61
62     switch (obj->type) {
63     case XPATH_STRING:
64         ret = xmlXPathNewCString("string");
65         break;
66     case XPATH_NUMBER:
67         ret = xmlXPathNewCString("number");
68         break;
69     case XPATH_BOOLEAN:
70         ret = xmlXPathNewCString("boolean");
71         break;
72     case XPATH_NODESET:
73         ret = xmlXPathNewCString("node-set");
74         break;
75     case XPATH_XSLT_TREE:
76         ret = xmlXPathNewCString("RTF");
77         break;
78     case XPATH_USERS:
79         ret = xmlXPathNewCString("external");
80         break;
81     default:
82         xsltGenericError(xsltGenericErrorContext,
83                 "object-type() invalid arg\n");
84         ctxt->error = XPATH_INVALID_TYPE;
85         xmlXPathFreeObject(obj);
86         return;
87     }
88     xmlXPathFreeObject(obj);
89     valuePush(ctxt, ret);
90 }
91
92
93 /**
94  * exsltCommonRegister:
95  *
96  * Registers the EXSLT - Common module
97  */
98
99 void
100 exsltCommonRegister (void) {
101     xsltRegisterExtModuleFunction((const xmlChar *) "node-set",
102                                   EXSLT_COMMON_NAMESPACE,
103                                   exsltNodeSetFunction);
104     xsltRegisterExtModuleFunction((const xmlChar *) "object-type",
105                                   EXSLT_COMMON_NAMESPACE,
106                                   exsltObjectTypeFunction);
107     xsltRegisterExtModuleElement((const xmlChar *) "document",
108                                  EXSLT_COMMON_NAMESPACE,
109                                  (xsltPreComputeFunction) xsltDocumentComp,
110                                  (xsltTransformFunction) xsltDocumentElem);
111 }