Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
callbacks.h
Go to the documentation of this file.
1 /* *************************************************************************************
2  Copyright (c) 2021, Lowell D. Thomas
3  All rights reserved.
4 
5  This file is part of APG Version 7.0.
6  APG Version 7.0 may be used under the terms of the BSD 2-Clause License.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 
14  2. Redistributions in binary form must reproduce the above copyright notice,
15  this list of conditions and the following disclaimer in the documentation
16  and/or other materials provided with the distribution.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 * *************************************************************************************/
30 #ifndef CALLBACKS_H_
31 #define CALLBACKS_H_
32 
38 #include <limits.h>
39 #include "../utilities/utilities.h"
40 #include "xmlgrammar.h"
41 #include "xml.h"
42 #include "xmlp.h"
43 
44 #define STATE_BEGIN 1
45 #define STATE_TEXT 2
46 #define STATE_WSP 3
47 #define ATT_AMP 38
48 #define ATT_HASH 35
49 #define ATT_X 120
50 #define ATT_SEMI 59
51 #define CABUF_LEN 256
52 
53 #define XML_THROW(msg) vThrowError(spXml, (msg), spData->uiParserOffset, __LINE__, __FILE__, __func__)
54 
55 // helpers
56 void vThrowError(xml* spXml, const char* cpMsg, aint uiOffset, unsigned int uiLine, const char* cpFile, const char* cpFunc);
57 void vLogMsg(xml* spXml, aint uiOffset, char* cpTitle);
58 void vPushFrame(callback_data* spData);
59 void vPopFrame(callback_data* spData);
60 uint32_t ui2byte(const achar* acpBytes);
61 uint32_t ui3byte(const achar* acpBytes);
62 uint32_t ui4byte(const achar* acpBytes);
63 abool bValidateChar(uint32_t uiChar);
64 void vMakeCDataDisplay(xml* spXml, cdata_id* spDataId, u32_phrase* spCData, aint uiOffset);
65 void vMakeCDataIdFromInput(xml* spXml, const achar* acpInput, aint uiLen, aint uiOffset, cdata_id* spCDataId);
66 cdata_id sCapturePhrase(xml* spXml, achar* acpPhrase, aint uiPhraseLength, aint uiOffset);
67 int iAttComp(const void* vpL, const void* vpR);
68 att_decl* spLeftMostElement(xml* spXml, att_decl* spAttList);
69 int iEntityComp(const void* vpL, const void* vpR);
70 void vHexValue(callback_data* spData);
71 void vDecValue(callback_data* spData);
72 uint32_t uiDecValue32(xml* spXml, aint uiOffset, uint32_t* uipChars, uint32_t uiCount);
73 uint32_t uiHexValue32(xml* spXml, aint uiOffset, uint32_t* uipChars, uint32_t uiCount);
74 abool bHasEntity(uint32_t* uipChars, uint32_t uiLen, uint32_t* uipEntityOffset, uint32_t* uipEntityLen);
75 cdata_id sNormalizeAttributeValue(xml* spXml, aint uiOffset, uint32_t* uipAttValue, uint32_t uiLength, abool bIsCDATA);
76 void vExpandEntity(xml* spXml, aint uiOffset, entity_decl* spValuei);
77 int iSortCompNames(const uint32_t* uipLName, uint32_t uiLLen, const uint32_t* uipRName, uint32_t uiRLen);
78 abool bCompNames(const uint32_t* uipLName, uint32_t uiLLen, const uint32_t* uipRName, uint32_t uiRLen);
79 entity_decl* spEntityNameLookup(xml* spXml, aint uiOffset, uint32_t* uipName, uint32_t uiNameLen);
80 void vConvertParsedData(xml* spXml, const achar* acpData, aint uiDataLen, uint32_t* uipOffset, uint32_t* uipLength);
81 int iCompNames(const uint32_t* uipLName, uint32_t uiLLen, const uint32_t* uipRName, uint32_t uiRLen);
82 
83 // callbacks
84 void vDocument(callback_data* spData);
85 void vXmlDeclOpen(callback_data* spData);
86 void vXmlDeclClose(callback_data* spData);
87 void vEncDef(callback_data* spData);
88 void vVersionNum(callback_data* spData);
89 void vVersionInfo(callback_data* spData);
90 void vVersionNum(callback_data* spData);
91 void vEncDef(callback_data* spData);
92 void vEncName(callback_data* spData);
93 void vSDeclOther(callback_data* spData);
94 void vSDeclYes(callback_data* spData);
95 void vSDeclNo(callback_data* spData);
96 void vDtdOpen(callback_data* spData);
97 void vDtdName(callback_data* spData);
98 void vDtdClose(callback_data* spData);
99 void vExtSubset(callback_data* spData);
100 void vExternalID(callback_data* spData);
101 void vNExternalID(callback_data* spData);
102 void vPEDeclOpen(callback_data* spData);
103 void vPEDeclClose(callback_data* spData);
104 void vPEReference(callback_data* spData);
105 void vPERefError(callback_data* spData);
106 void vGEDeclName(callback_data* spData);
107 void vGEPERef(callback_data* spData);
108 void vGEDefEx(callback_data* spData);
109 void vGEDeclClose(callback_data* spData);
110 void vCloseQuote(callback_data* spData);
111 void vEntityChar(callback_data* spData);
112 void vGERef(callback_data* spData);
113 void vAttlistOpen(callback_data* spData);
114 void vAttName(callback_data* spData);
115 void vAttType(callback_data* spData);
116 void vAttlistValue(callback_data* spData);
117 void vAttDef(callback_data* spData);
118 void vAttlistClose(callback_data* spData);
119 void vNotationOpen(callback_data* spData);
120 void vNotationDef(callback_data* spData);
121 void vNotationClose(callback_data* spData);
122 void vDvalue(callback_data* spData);
123 void vDChar(callback_data* spData);
124 void vEntityRef(callback_data* spData);
125 void vElementOpen(callback_data* spData);
126 void vElementClose(callback_data* spData);
127 void vETagClose(callback_data* spData);
128 
129 
130 void vEOpen(callback_data* spData);
131 void vEStart(callback_data* spData);
132 void vEReserved(callback_data* spData);
133 void vEmptyClose(callback_data* spData);
134 void vSTagClose(callback_data* spData);
135 void vAttValue(callback_data* spData);
136 void vElAttName(callback_data* spData);
137 void vCharData(callback_data* spData);
138 void vCDSectEnd(callback_data* spData);
139 void vCDEnd(callback_data* spData);
140 void vCDRb(callback_data* spData);
141 void vCD2Rb(callback_data* spData);
142 void vRefClose(callback_data* spData);
143 //void u_vCommentClose(callback_data* spData);
144 void vComment(callback_data* spData);
145 void vDoubleh(callback_data* spData);
146 void vPIClose(callback_data* spData);
147 void vPITarget(callback_data* spData);
148 void vPIInfo(callback_data* spData);
149 void vPIInfoq(callback_data* spData);
150 void vPIInfoa(callback_data* spData);
151 void vPIForbidden(callback_data* spData);
152 void vPIReserved(callback_data* spData);
153 void vAscii(callback_data* spData);
154 void vUtf82(callback_data* spData);
155 void vUtf83(callback_data* spData);
156 void vUtf84(callback_data* spData);
157 //void vAmp(callback_data* spData);
158 //void vLt(callback_data* spData);
159 //void vGt(callback_data* spData);
160 //void vApos(callback_data* spData);
161 //void vQuot(callback_data* spData);
162 void vName(callback_data* spData);
163 void vNameStartChar(callback_data* spData);
164 void vNameOtherChar(callback_data* spData);
165 
166 #endif /* CALLBACKS_H_ */
vGEDefEx
void vGEDefEx(callback_data *spData)
Definition: declarations.c:447
vGEDeclClose
void vGEDeclClose(callback_data *spData)
Definition: declarations.c:454
vPITarget
void vPITarget(callback_data *spData)
Definition: basics.c:346
vNotationClose
void vNotationClose(callback_data *spData)
Definition: declarations.c:710
sCapturePhrase
cdata_id sCapturePhrase(xml *spXml, achar *acpPhrase, aint uiPhraseLength, aint uiOffset)
Definition: basics.c:192
vThrowError
void vThrowError(xml *spXml, const char *cpMsg, aint uiOffset, unsigned int uiLine, const char *cpFile, const char *cpFunc)
Definition: basics.c:47
vAttlistClose
void vAttlistClose(callback_data *spData)
Definition: declarations.c:666
vRefClose
void vRefClose(callback_data *spData)
Definition: declarations.c:737
vXmlDeclOpen
void vXmlDeclOpen(callback_data *spData)
Definition: declarations.c:69
vUtf84
void vUtf84(callback_data *spData)
Definition: basics.c:420
vGERef
void vGERef(callback_data *spData)
Definition: declarations.c:513
bCompNames
abool bCompNames(const uint32_t *uipLName, uint32_t uiLLen, const uint32_t *uipRName, uint32_t uiRLen)
Definition: basics.c:676
vName
void vName(callback_data *spData)
Definition: basics.c:426
vDvalue
void vDvalue(callback_data *spData)
Definition: elements.c:194
vEncName
void vEncName(callback_data *spData)
Definition: declarations.c:180
vDChar
void vDChar(callback_data *spData)
Definition: elements.c:200
bValidateChar
abool bValidateChar(uint32_t uiChar)
Definition: basics.c:124
vSDeclNo
void vSDeclNo(callback_data *spData)
Definition: declarations.c:207
vDoubleh
void vDoubleh(callback_data *spData)
Definition: basics.c:267
vAttType
void vAttType(callback_data *spData)
Definition: declarations.c:575
xml
This is the encapsulated data for the xml component. The component context or handle is an opaque poi...
vUtf83
void vUtf83(callback_data *spData)
Definition: basics.c:414
vSDeclOther
void vSDeclOther(callback_data *spData)
Definition: declarations.c:194
vHexValue
void vHexValue(callback_data *spData)
Definition: elements.c:259
iSortCompNames
int iSortCompNames(const uint32_t *uipLName, uint32_t uiLLen, const uint32_t *uipRName, uint32_t uiRLen)
uiHexValue32
uint32_t uiHexValue32(xml *spXml, aint uiOffset, uint32_t *uipChars, uint32_t uiCount)
Definition: basics.c:544
achar
uint_fast8_t achar
achar is the type for the parser's alphabet characters.
Definition: apg.h:91
vCharData
void vCharData(callback_data *spData)
Definition: elements.c:341
vGEDeclName
void vGEDeclName(callback_data *spData)
Definition: declarations.c:417
vDecValue
void vDecValue(callback_data *spData)
Definition: elements.c:229
entity_decl
Provides the offset into the general 32-bit vector and length of a name and value pair.
Definition: xmlp.h:80
vDtdName
void vDtdName(callback_data *spData)
Definition: declarations.c:233
vVersionNum
void vVersionNum(callback_data *spData)
Definition: declarations.c:158
xml.h
Public header file for the APG XML parser API..
vAscii
void vAscii(callback_data *spData)
Definition: basics.c:402
vSDeclYes
void vSDeclYes(callback_data *spData)
Definition: declarations.c:200
vXmlDeclClose
void vXmlDeclClose(callback_data *spData)
Definition: declarations.c:86
vVersionInfo
void vVersionInfo(callback_data *spData)
Definition: declarations.c:152
vMakeCDataIdFromInput
void vMakeCDataIdFromInput(xml *spXml, const achar *acpInput, aint uiLen, aint uiOffset, cdata_id *spCDataId)
Definition: basics.c:167
vPEDeclOpen
void vPEDeclOpen(callback_data *spData)
Definition: declarations.c:390
vNameOtherChar
void vNameOtherChar(callback_data *spData)
Definition: basics.c:503
vPIClose
void vPIClose(callback_data *spData)
Definition: basics.c:332
aint
uint_fast32_t aint
The APG parser's unsigned integer type.
Definition: apg.h:79
vDocument
void vDocument(callback_data *spData)
Definition: declarations.c:51
vCloseQuote
void vCloseQuote(callback_data *spData)
Definition: declarations.c:501
vEStart
void vEStart(callback_data *spData)
Definition: elements.c:50
vConvertParsedData
void vConvertParsedData(xml *spXml, const achar *acpData, aint uiDataLen, uint32_t *uipOffset, uint32_t *uipLength)
Converts parsed UTF-8 data to UTF-32 code points.
Definition: basics.c:234
vPEReference
void vPEReference(callback_data *spData)
Definition: declarations.c:402
vAttName
void vAttName(callback_data *spData)
Definition: declarations.c:557
xmlp.h
Private header for the APG XML parser's component context. Not needed by application programs.
ui2byte
uint32_t ui2byte(const achar *acpBytes)
Definition: basics.c:101
vCDEnd
void vCDEnd(callback_data *spData)
Definition: elements.c:375
vExtSubset
void vExtSubset(callback_data *spData)
Definition: declarations.c:367
vEncDef
void vEncDef(callback_data *spData)
Definition: declarations.c:174
vAttValue
void vAttValue(callback_data *spData)
Definition: elements.c:176
vPopFrame
void vPopFrame(callback_data *spData)
Definition: basics.c:86
vCDSectEnd
void vCDSectEnd(callback_data *spData)
Definition: elements.c:347
vPERefError
void vPERefError(callback_data *spData)
Definition: declarations.c:408
vElementOpen
void vElementOpen(callback_data *spData)
Definition: declarations.c:717
vExternalID
void vExternalID(callback_data *spData)
Definition: declarations.c:375
vExpandEntity
void vExpandEntity(xml *spXml, aint uiOffset, entity_decl *spValuei)
Definition: basics.c:855
callback_data
The data struct passed to each callback function.
Definition: parser.h:134
vCDRb
void vCDRb(callback_data *spData)
Definition: elements.c:381
vEOpen
void vEOpen(callback_data *spData)
Definition: elements.c:74
vNameStartChar
void vNameStartChar(callback_data *spData)
Definition: basics.c:432
ui4byte
uint32_t ui4byte(const achar *acpBytes)
Definition: basics.c:116
vNotationOpen
void vNotationOpen(callback_data *spData)
Definition: declarations.c:675
vETagClose
void vETagClose(callback_data *spData)
Definition: elements.c:120
xmlgrammar.h
bHasEntity
abool bHasEntity(uint32_t *uipChars, uint32_t uiLen, uint32_t *uipEntityOffset, uint32_t *uipEntityLen)
Definition: basics.c:946
vElementClose
void vElementClose(callback_data *spData)
Definition: declarations.c:724
vPIInfoa
void vPIInfoa(callback_data *spData)
Definition: basics.c:376
vAttlistValue
void vAttlistValue(callback_data *spData)
Definition: declarations.c:600
iCompNames
int iCompNames(const uint32_t *uipLName, uint32_t uiLLen, const uint32_t *uipRName, uint32_t uiRLen)
Definition: basics.c:969
vAttlistOpen
void vAttlistOpen(callback_data *spData)
Definition: declarations.c:535
vPIReserved
void vPIReserved(callback_data *spData)
Definition: basics.c:389
vPushFrame
void vPushFrame(callback_data *spData)
Definition: basics.c:77
vElAttName
void vElAttName(callback_data *spData)
Definition: elements.c:157
vGEPERef
void vGEPERef(callback_data *spData)
Definition: declarations.c:440
iAttComp
int iAttComp(const void *vpL, const void *vpR)
Definition: basics.c:808
vCD2Rb
void vCD2Rb(callback_data *spData)
Definition: elements.c:388
vNotationDef
void vNotationDef(callback_data *spData)
Definition: declarations.c:697
vComment
void vComment(callback_data *spData)
Definition: basics.c:273
vSTagClose
void vSTagClose(callback_data *spData)
Definition: elements.c:103
vDtdOpen
void vDtdOpen(callback_data *spData)
Definition: declarations.c:221
abool
uint8_t abool
abool is the APG bool type.
Definition: apg.h:140
vLogMsg
void vLogMsg(xml *spXml, aint uiOffset, char *cpTitle)
Definition: basics.c:61
vDtdClose
void vDtdClose(callback_data *spData)
Definition: declarations.c:241
ui3byte
uint32_t ui3byte(const achar *acpBytes)
Definition: basics.c:108
vPEDeclClose
void vPEDeclClose(callback_data *spData)
Definition: declarations.c:396
vPIInfo
void vPIInfo(callback_data *spData)
Definition: basics.c:360
vEntityRef
void vEntityRef(callback_data *spData)
Definition: elements.c:209
uiDecValue32
uint32_t uiDecValue32(xml *spXml, aint uiOffset, uint32_t *uipChars, uint32_t uiCount)
Definition: basics.c:581
vEmptyClose
void vEmptyClose(callback_data *spData)
Definition: elements.c:92
vEReserved
void vEReserved(callback_data *spData)
Definition: elements.c:85
vAttDef
void vAttDef(callback_data *spData)
Definition: declarations.c:614
spEntityNameLookup
entity_decl * spEntityNameLookup(xml *spXml, aint uiOffset, uint32_t *uipName, uint32_t uiNameLen)
Find the left-most occurrence of the given entity name.
Definition: basics.c:645
vPIInfoq
void vPIInfoq(callback_data *spData)
Definition: basics.c:367
u32_phrase
Defines a pointer to an array of 32-bit unsigned integers plus its length. Typically needed by Unicod...
Definition: lib.h:73
vEntityChar
void vEntityChar(callback_data *spData)
Definition: declarations.c:507
att_decl
Identifies the element name, attribute name and default attribute value of attribute list declaration...
Definition: xmlp.h:60
sNormalizeAttributeValue
cdata_id sNormalizeAttributeValue(xml *spXml, aint uiOffset, uint32_t *uipAttValue, uint32_t uiLength, abool bIsCDATA)
Definition: basics.c:682
iEntityComp
int iEntityComp(const void *vpL, const void *vpR)
Definition: basics.c:832
vNExternalID
void vNExternalID(callback_data *spData)
Definition: declarations.c:382
cdata_id
Parsed character data definition.
Definition: xmlp.h:42
spLeftMostElement
att_decl * spLeftMostElement(xml *spXml, att_decl *spAttList)
Definition: basics.c:606
vPIForbidden
void vPIForbidden(callback_data *spData)
Definition: basics.c:383
vMakeCDataDisplay
void vMakeCDataDisplay(xml *spXml, cdata_id *spDataId, u32_phrase *spCData, aint uiOffset)
Definition: basics.c:156
vUtf82
void vUtf82(callback_data *spData)
Definition: basics.c:408
APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.