Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
parser-get-init.c
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 * *************************************************************************************/
37 #include "./lib.h"
38 #include "./parserp.h"
39 
43 aint uiGetAcharTable(parser_init* spParserInit, achar* acpAcharTable){
44  aint ui;
45  aint uiLen = spParserInit->uiAcharTableLength;
46  if(spParserInit->uiSizeofAchar == 1){
47  uint8_t* ucpTable = (uint8_t*)spParserInit->vpAcharTable;
48  for(ui = 0; ui < uiLen; ui += 1){
49  acpAcharTable[ui] = (achar)ucpTable[ui];
50  }
51  return APG_SUCCESS;
52  }
53  if(spParserInit->uiSizeofAchar == 2){
54  uint16_t* usipTable = (uint16_t*)spParserInit->vpAcharTable;
55  for(ui = 0; ui < uiLen; ui += 1){
56  acpAcharTable[ui] = (achar)usipTable[ui];
57  }
58  return APG_SUCCESS;
59  }
60  if(spParserInit->uiSizeofAchar == 4){
61  uint32_t* uipTable = (uint32_t*)spParserInit->vpAcharTable;
62  for(ui = 0; ui < uiLen; ui += 1){
63  acpAcharTable[ui] = (achar)uipTable[ui];
64  }
65  return APG_SUCCESS;
66  }
67  if(spParserInit->uiSizeofAchar == 8){
68  uint64_t* ulipTable = (uint64_t*)spParserInit->vpAcharTable;
69  for(ui = 0; ui < uiLen; ui += 1){
70  acpAcharTable[ui] = (achar)ulipTable[ui];
71  }
72  return APG_SUCCESS;
73  }
74  return APG_FAILURE;
75 }
76 
80 abool bGetParserInitData(parser_init* spParserInit, luint* luipParserInit){
81  aint ui;
82  aint uiLen = spParserInit->uiParserInitLength;
83  const void* vpData = spParserInit->vpParserInit;
84  if(spParserInit->uiSizeofUint == 1){
85  uint8_t* ucpTable = (uint8_t*)vpData;
86  for(ui = 0; ui < uiLen; ui += 1){
87  if((signed char)ucpTable[ui] == -1){
88  luipParserInit[ui] = (luint)-1;
89  }else{
90  luipParserInit[ui] = (luint)ucpTable[ui];
91  }
92  }
93  return APG_SUCCESS;
94  }
95  if(spParserInit->uiSizeofUint == 2){
96  uint16_t* usipTable = (uint16_t*)vpData;
97  for(ui = 0; ui < uiLen; ui += 1){
98  if((signed short int)usipTable[ui] == -1){
99  luipParserInit[ui] = (luint)-1;
100  }else{
101  luipParserInit[ui] = (luint)usipTable[ui];
102  }
103  }
104  return APG_SUCCESS;
105  }
106  if(spParserInit->uiSizeofUint == 4){
107  uint32_t* uipTable = (uint32_t*)vpData;
108  for(ui = 0; ui < uiLen; ui += 1){
109  if((signed int)uipTable[ui] == -1){
110  luipParserInit[ui] = (luint)-1;
111  }else{
112  luipParserInit[ui] = (luint)uipTable[ui];
113  }
114  }
115  return APG_SUCCESS;
116  }
117  if(spParserInit->uiSizeofUint == 8){
118  uint64_t* ulipTable = (uint64_t*)vpData;
119  for(ui = 0; ui < uiLen; ui += 1){
120  luipParserInit[ui] = ulipTable[ui];
121  }
122  return APG_SUCCESS;
123  }
124  return APG_FAILURE;
125 }
126 
130 void vGetChildListTable(init_hdr* spInitHdr, aint* uipList) {
131  aint ui;
132  luint* uipTable = (luint*) spInitHdr + spInitHdr->uiChildListOffset;
133  for (ui = 0; ui < spInitHdr->uiChildListLength; ui += 1) {
134  uipList[ui] = (aint) uipTable[ui];
135  }
136 }
lib.h
This header "#include"s all publid lib headers and other standard headers needed by most objects.
APG_FAILURE
#define APG_FAILURE
Definition: apg.h:308
parser_init::uiSizeofUint
uint32_t uiSizeofUint
Minimum size, in bytes, required for the basic parser unsigned integer, aint.
Definition: parserp.h:48
parserp.h
Private header for the SABNF parser.
init_hdr::uiChildListOffset
luint uiChildListOffset
Offset from the beginning of the initialization data to the list of ALT and CAT child node opcode ind...
Definition: parserp.h:85
parser_init::uiAcharTableLength
uint32_t uiAcharTableLength
Length of this data's alphabet character table.
Definition: parserp.h:50
achar
uint_fast8_t achar
achar is the type for the parser's alphabet characters.
Definition: apg.h:91
vGetChildListTable
void vGetChildListTable(init_hdr *spInitHdr, aint *uipList)
Extract the child index list from the initialization data.
Definition: parser-get-init.c:130
uiGetAcharTable
aint uiGetAcharTable(parser_init *spParserInit, achar *acpAcharTable)
Extract the alphabet character table from the initialization data.
Definition: parser-get-init.c:43
bGetParserInitData
abool bGetParserInitData(parser_init *spParserInit, luint *luipParserInit)
Re-size the initialization data to the required integer size.
Definition: parser-get-init.c:80
parser_init::uiSizeofAchar
uint32_t uiSizeofAchar
Minimum size, in bytes, required for the alphabet characters, achar.
Definition: parserp.h:47
parser_init::uiParserInitLength
uint32_t uiParserInitLength
Length of the parser initialization data.
Definition: parserp.h:52
parser_init
The initialization information generated by APG.
Definition: parserp.h:46
parser_init::vpAcharTable
const void * vpAcharTable
Pointer to the alphabet character table or NULL if none. (Possible for small grammars....
Definition: parserp.h:55
aint
uint_fast32_t aint
The APG parser's unsigned integer type.
Definition: apg.h:79
APG_SUCCESS
#define APG_SUCCESS
Definition: apg.h:307
luint
uintmax_t luint
luint is used to cast integers suitable for the %"PRIuMAX" printf format.
Definition: apg.h:133
init_hdr::uiChildListLength
luint uiChildListLength
The number of integers in the child index list.
Definition: parserp.h:87
abool
uint8_t abool
abool is the APG bool type.
Definition: apg.h:140
init_hdr
Header for the parser initialization data.
Definition: parserp.h:69
parser_init::vpParserInit
const void * vpParserInit
Pointer to the parser's initialization data.
Definition: parserp.h:56
APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.