/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk

« back to all changes in this revision

Viewing changes to parse/asm-xml-1.1/include/asm-xml.h

  • Committer: Suren A. Chilingaryan
  • Date: 2009-02-16 09:27:17 UTC
  • Revision ID: csa@dside.dyndns.org-20090216092717-wipyvaaw2srxhgns
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
*                                                                           *
 
3
* asm-xml.h                                                                 *
 
4
*                                                                           *
 
5
* Copyright (C) 2007-08 Marc Kerbiquet                                      *
 
6
*                                                                           *
 
7
****************************************************************************/
 
8
 
 
9
#ifdef WIN32
 
10
  #define ACC __cdecl
 
11
#else
 
12
  #define ACC
 
13
#endif
 
14
 
 
15
#ifdef __cplusplus
 
16
extern "C" {
 
17
#endif
 
18
 
 
19
//-----------------------------------------------------------------------------
 
20
// Error Codes
 
21
//-----------------------------------------------------------------------------
 
22
#define RC_OK                          0 // everything is ok
 
23
#define RC_MEMORY                      1 // out of memory
 
24
 
 
25
#define RC_EMPTY_NAME                 10 // name empty or not defined
 
26
#define RC_ATTR_DEFINED               11 // attribute already defined
 
27
#define RC_ELEM_DEFINED               12 // element already defined
 
28
#define RC_SCHEMA_EMPTY               13 // schema does not contains a document
 
29
#define RC_DOCUMENT_DEFINED           14 // schema contains more than one document
 
30
#define RC_UNDEFINED_CLASS            15 // can't find collection in reference
 
31
#define RC_UNDEFINED_GROUP            16 // can't find a group in include
 
32
#define RC_INVALID_ID                 17 // id is not a valid number
 
33
#define RC_INVALID_IGNORE             18 // ignore is not 'yes' or 'no'
 
34
 
 
35
#define RC_INVALID_ENTITY_REFERENCE   20 // must be amp, quot, lt, gt, or apos
 
36
#define RC_UNEXPECTED_END             21 // found last char too early
 
37
#define RC_INVALID_CHAR               22 // wrong char
 
38
#define RC_OVERFLOW                   23 // number to big in char reference
 
39
#define RC_NO_START_TAG               24 // xml does not start with a tag
 
40
#define RC_TAG_MISMATCH               25 // invalid close tag
 
41
#define RC_INVALID_TAG                26 // invalid root element
 
42
#define RC_INVALID_ATTRIBUTE          27 // unknown attribute
 
43
#define RC_INVALID_PI                 28 // invalid processing instruction (<?xml)
 
44
#define RC_INVALID_DOCTYPE            29 // duplicate doctype or after main element
 
45
#define RC_VERSION_EXPECTED           30 // version is missing in xml declaration
 
46
 
 
47
//-----------------------------------------------------------------------------
 
48
// Structures
 
49
//-----------------------------------------------------------------------------
 
50
typedef struct AXElement      AXElement       ;
 
51
typedef struct AXAttribute    AXAttribute     ;
 
52
typedef struct AXElementClass AXElementClass  ;
 
53
typedef struct AXParseContext AXParseContext  ;
 
54
typedef struct AXClassContext AXClassContext  ;
 
55
 
 
56
struct AXElementClass
 
57
{
 
58
  int               offset        ; // Offset of the element in attribute list
 
59
  char*             name          ; // Name of the element (not zero terminated)
 
60
  char*             nameLimit     ; // End of the name of the element
 
61
  unsigned int      size          ; // size in bytes of an element of this class
 
62
  unsigned int      id            ; // container, text or mixed
 
63
  unsigned int      type          ; // container, text or mixed
 
64
  unsigned int      propertyCount ; // number of attributes and text elements
 
65
  unsigned int      childCount    ; // number of child classes
 
66
  int*              attributes    ; // (internal) attribute map
 
67
  int*              elements      ; // (internal) element map
 
68
  AXElementClass**  children      ; // The list of child classes.
 
69
                                    // The order is the one defined in the class
 
70
                                    // definition file.
 
71
  int               reserved      ;
 
72
  void*             reserved2     ;
 
73
};
 
74
 
 
75
struct AXClassContext
 
76
{
 
77
  void*             base          ;
 
78
  void*             limit         ;
 
79
  void*             chunks        ;
 
80
  int               chunkSize     ;
 
81
  int               errorCode     ;
 
82
  int               line          ;
 
83
  int               column        ;
 
84
  AXElementClass**  classes       ; // all global classes
 
85
  AXElementClass*   rootClass     ; // the root class
 
86
  AXElement*        rootElement   ;
 
87
};
 
88
 
 
89
struct AXAttribute
 
90
{
 
91
  const char*       begin         ; // the value (not zero terminated)
 
92
                                    // This slot can also contain an element if
 
93
                                    // a <element> has been defined in schema;
 
94
                                    // use ax_getElement() to retrieve it.
 
95
  const char*       limit         ; // the end of the value
 
96
};
 
97
 
 
98
struct AXElement
 
99
{
 
100
  int               id            ; // the class of the element
 
101
  AXElement*        nextSibling   ; // the next sibling element
 
102
  AXElement*        firstChild    ; // the first child element
 
103
  AXElement*        lastChild     ; // the last child element
 
104
  AXAttribute       reserved      ; // do not use
 
105
  AXAttribute       attributes[1] ; // the array of attributes - there is 
 
106
                                    // no bound checking in C
 
107
};
 
108
 
 
109
struct AXParseContext
 
110
{
 
111
  void*             base          ;
 
112
  void*             limit         ;
 
113
  void*             chunks        ;
 
114
  int               chunkSize     ;
 
115
  int               errorCode     ;
 
116
  const char*       source        ;
 
117
  const char*       current       ;
 
118
  int               line          ;
 
119
  int               column        ;
 
120
  AXElement*        root          ;
 
121
  AXAttribute       version       ;
 
122
  AXAttribute       encoding      ;
 
123
  int               strict        ;
 
124
  int               reserved1     ;
 
125
  AXElement         reserved2     ;
 
126
};
 
127
 
 
128
//-----------------------------------------------------------------------------
 
129
// Functions
 
130
//-----------------------------------------------------------------------------
 
131
 
 
132
extern 
 
133
void            ACC ax_initialize            (void*             mallocFun, 
 
134
                                              void*             freeFun);
 
135
extern 
 
136
int             ACC ax_initializeParser      (AXParseContext*   context, 
 
137
                                              unsigned int      chunkSize);
 
138
extern 
 
139
int             ACC ax_releaseParser         (AXParseContext*   context);
 
140
extern 
 
141
AXElement*      ACC ax_parse                 (AXParseContext*   context, 
 
142
                                              const char*       source,
 
143
                                              AXElementClass*   type,
 
144
                                              int               strict);
 
145
extern 
 
146
int             ACC ax_initializeClassParser (AXClassContext*   context);
 
147
extern 
 
148
int             ACC ax_releaseClassParser    (AXClassContext*   context);
 
149
extern 
 
150
AXElementClass* ACC ax_classFromElement      (AXElement*        e,
 
151
                                              AXClassContext*   context);
 
152
extern 
 
153
AXElementClass* ACC ax_classFromString       (const char*       source, 
 
154
                                              AXClassContext*   context);
 
155
 
 
156
#define ax_getElement(element, index) ((AXElement*)element->attributes[index].begin)
 
157
#define ax_getAttribute(element, index) (&element->attributes[index])
 
158
 
 
159
 
 
160
#ifdef __cplusplus
 
161
}
 
162
#endif