Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
main.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 * *************************************************************************************/
82 #include <limits.h>
83 #include "../../json/json.h"
84 
85 #include "source.h"
86 
87 static const char* cpMakeFileName(char* cpBuffer, const char* cpBase, const char* cpDivider, const char* cpName){
88  strcpy(cpBuffer, cpBase);
89  strcat(cpBuffer, cpDivider);
90  strcat(cpBuffer, cpName);
91  return cpBuffer;
92 }
93 
94 static char s_caBuf[PATH_MAX];
95 static char s_caBufOut[5*PATH_MAX];
96 
97 static char* s_cpDescription =
98  "Illustrate the JSON object for parsing and building JSON files.";
99 
100 static char* s_cppCases[] = {
101  "Display application information.",
102  "Illustrate a simple case of reading and parsing a JSON file.",
103  "Illustrate finding keys in the tree of JSON values.",
104  "Illustrate walking a sub-tree and the siblings of a sub-root explicitly with the iterator.",
105  "Illustrate writing a JSON file from a value tree of parsed JSON values.",
106  "Illustrate building a JSON file.",
107 };
108 static long int s_iCaseCount = (long int)(sizeof(s_cppCases) / sizeof(s_cppCases[0]));
109 
110 static int iHelp(void){
111  long int i = 0;
113  printf("description: %s\n", s_cpDescription);
114  printf(" usage: ex-api arg\n");
115  printf(" arg = n, 1 <= n <= %ld\n", s_iCaseCount);
116  printf(" execute case number n\n");
117  printf(" arg = anthing else\n");
118  printf(" print this help screen\n");
119  printf("\n");
120  for(; i < s_iCaseCount; i++){
121  printf("case %ld %s\n", (i + 1), s_cppCases[i]);
122  }
123  return EXIT_SUCCESS;
124 }
125 
126 static int iApp() {
127  // print the current working directory
129  printf("\n");
130 
131  // display the current APG sizes and macros
132  vUtilApgInfo();
133  return EXIT_SUCCESS;
134 }
135 
136 static int iSimpleParse() {
137  int iReturn = EXIT_SUCCESS;
138  static void* vpMem = NULL;
139  static void* vpJson = NULL;
140  json_value* spRoot;
141  void* vpIn;
142  exception e;
143  XCTOR(e);
144  if(e.try){
145  // try block
146  vpMem = vpMemCtor(&e);
147  vpJson = vpJsonCtor(&e);
148  const char* cpInput = cpMakeFileName(s_caBuf, SOURCE_DIR, "/../input/", "json-parse.json");
149 
150  // display the information header
151  char* cpHeader =
152  "This example case illustrates a simple parse and display of a JSON file.\n"
153  "The file has many non-printing ASCII characters.\n";
154  printf("\n%s", cpHeader);
155 
156  // read the file
157  vpIn = vpJsonReadFile(vpJson, cpInput);
158 
159  // display the input file
160  printf("\nThe Input File (with line numbers)\n");
161  vJsonDisplayInput(vpJson, APG_TRUE);
162 
163  // display the JSON values
164  printf("\nThe JSON Values\n");
165  spRoot = spJsonIteratorFirst(vpIn);
166  vJsonDisplayValue(vpJson, spRoot, 0);
167 
168  }else{
169  // catch block - display the exception location and message
171  iReturn = EXIT_FAILURE;
172  }
173 
174  // clean up resources
175  vJsonDtor(vpJson);
176  vMemDtor(vpMem);
177  return iReturn;
178 }
179 
180 static int iFindKeys() {
181  int iReturn = EXIT_SUCCESS;
182  static void* vpMem = NULL;
183  static void* vpJson = NULL;
184  json_value* spRoot, *spValue;
185  void* vpIn, *vpIt;
186  u32_phrase* spKey32;
187  exception e;
188  XCTOR(e);
189  if(e.try){
190  // try block
191  vpMem = vpMemCtor(&e);
192  vpJson = vpJsonCtor(&e);
193  const char* cpInput = cpMakeFileName(s_caBuf, SOURCE_DIR, "/../input/", "json-parse.json");
194 
195  // display the information header
196  char* cpHeader =
197  "This example case illustrates finding keys in a parsed JSON file.\n";
198  printf("\n%s", cpHeader);
199 
200  // read the file
201  vpIn = vpJsonReadFile(vpJson, cpInput);
202  spRoot = spJsonIteratorFirst(vpIn);
203 
204  // display the input file
205  printf("\nThe Input File (with line numbers)\n");
206  vJsonDisplayInput(vpJson, APG_TRUE);
207 
208  // find the numbers key
209  printf("\nFind the \"numbers\" Key\n");
210  vpIt = vpJsonFindKeyA(vpJson, "numbers", spRoot);
211  if(vpIt){
212  spValue = spJsonIteratorFirst(vpIt);
213  while(spValue){
214  vJsonDisplayValue(vpJson, spValue, 0);
215  spValue = spJsonIteratorNext(vpIt);
216  }
217  }else{
218  XTHROW(&e, "numbers key not found");
219  }
220 
221  // find all ctrl keys
222  printf("\nFind the \"ctrl\" Keys\n");
223  vpIt = vpJsonFindKeyA(vpJson, "ctrl", spRoot);
224  if(vpIt){
225  spValue = spJsonIteratorFirst(vpIt);
226  while(spValue){
227  vJsonDisplayValue(vpJson, spValue, 0);
228  spValue = spJsonIteratorNext(vpIt);
229  }
230  }else{
231  XTHROW(&e, "ctrl key not found");
232  }
233 
234  // find the numbers key
235  printf("\nFind the Non-ASCII Key\n");
236  spKey32 = spUtilStrToPhrase32(vpMem, "odd-\xFF-key");
237  vpIt = vpJsonFindKeyU(vpJson, spKey32->uipPhrase, spKey32->uiLength, spRoot);
238  if(vpIt){
239  spValue = spJsonIteratorFirst(vpIt);
240  while(spValue){
241  vJsonDisplayValue(vpJson, spValue, 0);
242  spValue = spJsonIteratorNext(vpIt);
243  }
244  }else{
245  XTHROW(&e, "non-ascii key not found");
246  }
247 
248  }else{
249  // catch block - display the exception location and message
251  iReturn = EXIT_FAILURE;
252  }
253 
254  // clean up resources
255  vJsonDtor(vpJson);
256  vMemDtor(vpMem);
257  return iReturn;
258 }
259 
260 static int iWalker() {
261  int iReturn = EXIT_SUCCESS;
262  static void* vpMem = NULL;
263  static void* vpJson = NULL;
264  json_value* spRoot, *spValue;
265  void* vpIn, *vpIt, *vpIt2;
266  exception e;
267  XCTOR(e);
268  if(e.try){
269  // try block
270  vpMem = vpMemCtor(&e);
271  vpJson = vpJsonCtor(&e);
272  const char* cpInput = cpMakeFileName(s_caBuf, SOURCE_DIR, "/../input/", "json-parse.json");
273 
274  // display the information header
275  char* cpHeader =
276  "This example case illustrates walking a tree, depth-first from any value as root\n"
277  "or horizontally across children of a specific node.\n";
278  printf("\n%s", cpHeader);
279 
280  // read the file
281  vpIn = vpJsonReadFile(vpJson, cpInput);
282  spRoot = spJsonIteratorFirst(vpIn);
283 
284  // display the input file
285  printf("\nThe Input File (with line numbers)\n");
286  vJsonDisplayInput(vpJson, APG_TRUE);
287 
288  // walk the children of the root node
289  printf("\nWalk the Children of the Root Node\n");
290  vpIt = vpJsonChildren(vpJson, spRoot);
291  if(vpIt){
292  spValue = spJsonIteratorFirst(vpIt);
293  while(spValue){
294  vJsonDisplayValue(vpJson, spValue, 1);
295  spValue = spJsonIteratorNext(vpIt);
296  }
297  }else{
298  XTHROW(&e, "no children of the root node found");
299  }
300 
301  // walk the sub-tree with the "unsigned" node as the root node
302  printf("\nWalk the Sub-Tree of the \"unsigned\" Node as the Root Node\n");
303  vpIt = vpJsonFindKeyA(vpJson, "unsigned", spRoot);
304  if(vpIt){
305  vpIt2 = vpJsonTree(vpJson, spJsonIteratorFirst(vpIt));
306  spValue = spJsonIteratorFirst(vpIt2);
307  while(spValue){
308  vJsonDisplayValue(vpJson, spValue, 1);
309  spValue = spJsonIteratorNext(vpIt2);
310  }
311  }else{
312  XTHROW(&e, "signed key not found");
313  }
314 
315  }else{
316  // catch block - display the exception location and message
318  iReturn = EXIT_FAILURE;
319  }
320 
321  // clean up resources
322  vJsonDtor(vpJson);
323  vMemDtor(vpMem);
324  return iReturn;
325 }
326 
327 static int iWriter() {
328  int iReturn = EXIT_SUCCESS;
329  static void* vpMem = NULL;
330  static void* vpJson = NULL;
331  json_value* spRoot, *spValue;
332  void* vpIn, *vpIt;
333  char* cpaKeys[] = {
334  "text",
335  "unicode",
336  "numbers",
337  "odd-\xFF-key",
338  };
339  const char* cpaOutFile[] = {
340  cpMakeFileName(&s_caBufOut[0], SOURCE_DIR, "/../output/", "text.json"),
341  cpMakeFileName(&s_caBufOut[PATH_MAX], SOURCE_DIR, "/../output/", "unicode.json"),
342  cpMakeFileName(&s_caBufOut[2*PATH_MAX], SOURCE_DIR, "/../output/", "numbers.json"),
343  cpMakeFileName(&s_caBufOut[3*PATH_MAX], SOURCE_DIR, "/../output/", "odd.json"),
344  cpMakeFileName(&s_caBufOut[4*PATH_MAX], SOURCE_DIR, "/../output/", "root.json"),
345  };
346  uint8_t* ucpOutput;
347  aint uiOutputLen;
348  aint ui;
349  exception e;
350  XCTOR(e);
351  if(e.try){
352  // try block
353  vpMem = vpMemCtor(&e);
354  vpJson = vpJsonCtor(&e);
355  const char* cpInput = cpMakeFileName(s_caBuf, SOURCE_DIR, "/../input/", "json-parse.json");
356 
357  // display the information header
358  char* cpHeader =
359  "This example case illustrates writing JSON files from trees of values.\n"
360  "JSON files are generated for a series of tree values a root node.\n"
361  "The generated files are written in the current working directory.\n";
362  printf("\n%s", cpHeader);
363 
364  // read the file
365  vpIn = vpJsonReadFile(vpJson, cpInput);
366  spRoot = spJsonIteratorFirst(vpIn);
367 
368  // display the input file
369  printf("\nThe Input File (with line numbers)\n");
370  vJsonDisplayInput(vpJson, APG_TRUE);
371 
372  printf("\nWrite JSON Files\n");
373  printf("For the JSON file with the named key as root node view these files.\n");
374  for(ui = 0; ui < 4; ui++){
375  vpIt = vpJsonFindKeyA(vpJson, cpaKeys[ui], spRoot);
376  if(!vpIt){
377  XTHROW(&e, "expected to find key");
378  }
379  spValue = spJsonIteratorFirst(vpIt);
380  if(!spValue){
381  XTHROW(&e, "expected to get value");
382  }
383  ucpOutput = ucpJsonWrite(vpJson, spValue, &uiOutputLen);
384  vUtilFileWrite(vpMem, cpaOutFile[ui], ucpOutput, uiOutputLen);
385  printf("%s\n", cpaOutFile[ui]);
386  }
387  ucpOutput = ucpJsonWrite(vpJson, spRoot, &uiOutputLen);
388  vUtilFileWrite(vpMem, cpaOutFile[4], ucpOutput, uiOutputLen);
389  printf("\nThe root node\n%s\n", cpaOutFile[4]);
390 
391  }else{
392  // catch block - display the exception location and message
394  iReturn = EXIT_FAILURE;
395  }
396 
397  // clean up resources
398  vJsonDtor(vpJson);
399  vMemDtor(vpMem);
400  return iReturn;
401 }
402 
403 static int iBuilder() {
404  int iReturn = EXIT_SUCCESS;
405  static void* vpMem = NULL;
406  static void* vpBld = NULL;
407  static void* vpJson = NULL;
408  json_value* spValue;
409  void* vpIt;
410  typedef struct{
411  aint uiIndex;
412  char* cpKey;
413  const char* cpFileName;
414  } file_def;
415  file_def saFiles[] = {
416  {0, "single", cpMakeFileName(&s_caBufOut[0], SOURCE_DIR, "/../output/", "builder-single-value.json")},
417  {1, "text", cpMakeFileName(&s_caBufOut[PATH_MAX], SOURCE_DIR, "/../output/", "builder-text.json")},
418  {2, "unicode", cpMakeFileName(&s_caBufOut[2*PATH_MAX], SOURCE_DIR, "/../output/", "builder-unicode.json")},
419  {3, "numbers", cpMakeFileName(&s_caBufOut[3*PATH_MAX], SOURCE_DIR, "/../output/", "builder-numbers.json")},
420  {4, "root", cpMakeFileName(&s_caBufOut[4*PATH_MAX], SOURCE_DIR, "/../output/", "builder-root.json")},
421  };
422  uint8_t* ucpOutput;
423  aint uiOutputLen;
424  aint uiSingle, uiText, uiUnicode, uiNumbers, uiRoot, uiTemp;
425  exception e;
426  XCTOR(e);
427  if(e.try){
428  // try block
429  vpMem = vpMemCtor(&e);
430  vpJson = vpJsonCtor(&e);
431  vpBld = vpJsonBuildCtor(vpJson);
432 
433  // display the information header
434  char* cpHeader =
435  "This example case illustrates building JSON files from scratch.\n"
436  "For simple ASCII files, this is most easily done with a text editor.\n"
437  "However, when working with Unicode data a more general method is needed.\n"
438  "This JSON builder works by creating root nodes (objects or arrays) and adding children to them.\n";
439  printf("\n%s", cpHeader);
440 
441  printf("\nBuild a single-value JSON file.\n");
442  uiSingle = uiJsonBuildMakeStringA(vpBld, "the quick brown fox jumps over the lazy dog");
443  vpIt = vpJsonBuild(vpBld, uiSingle);
444  spValue = spJsonIteratorFirst(vpIt);
445  ucpOutput = ucpJsonWrite(vpJson, spValue, &uiOutputLen);
446  vUtilFileWrite(vpMem, saFiles[0].cpFileName, ucpOutput, uiOutputLen);
447  printf("%s node written to file %s\n", saFiles[0].cpKey, saFiles[0].cpFileName);
448  vJsonDisplayValue(vpJson, spValue, 0);
449 
450  printf("\nBuild the text node.\n");
451  vJsonBuildClear(vpBld);
452  uiText = uiJsonBuildMakeObject(vpBld);
453  uiJsonBuildAddToObject(vpBld, uiText,
454  uiJsonBuildMakeStringA(vpBld, "simple"),
455  uiJsonBuildMakeStringA(vpBld, "the quick brown fox jumps over the lazy dog"));
456  uiJsonBuildAddToObject(vpBld, uiText,
457  uiJsonBuildMakeStringA(vpBld, "ctrl"),
458  uiJsonBuildMakeStringA(vpBld, "text with control characters: \\\\/\\\"\\b\\f\\n\\r\\tabc"));
459  vpIt = vpJsonBuild(vpBld, uiText);
460  spValue = spJsonIteratorFirst(vpIt);
461  ucpOutput = ucpJsonWrite(vpJson, spValue, &uiOutputLen);
462  vUtilFileWrite(vpMem, saFiles[1].cpFileName, ucpOutput, uiOutputLen);
463  printf("%s node written to file %s\n", saFiles[1].cpKey, saFiles[1].cpFileName);
464  vJsonDisplayValue(vpJson, spValue, 0);
465  vJsonIteratorDtor(vpIt);
466 
467  printf("\nBuild the unicode node.\n");
468  uiUnicode = uiJsonBuildMakeObject(vpBld);
469  uiJsonBuildAddToObject(vpBld, uiUnicode,
470  uiJsonBuildMakeStringA(vpBld, "text"),
471  uiJsonBuildMakeStringA(vpBld, "simple"));
472  uiJsonBuildAddToObject(vpBld, uiUnicode,
473  uiJsonBuildMakeStringA(vpBld, "ctrl"),
474  uiJsonBuildMakeStringA(vpBld, "abc\\tdef\\nghi"));
475  uiJsonBuildAddToObject(vpBld, uiUnicode,
476  uiJsonBuildMakeStringA(vpBld, "escaped"),
477  uiJsonBuildMakeStringA(vpBld, "\\u0000\\u00ff\\ud800\\udc00\\udbff\\udfff"));
478  uint32_t uiaBuf[] = {255, 939, 10348};
479  uiJsonBuildAddToObject(vpBld, uiUnicode,
480  uiJsonBuildMakeStringA(vpBld, "ctrl"),
481  uiJsonBuildMakeStringU(vpBld, uiaBuf, 3));
482  vpIt = vpJsonBuild(vpBld, uiUnicode);
483  spValue = spJsonIteratorFirst(vpIt);
484  ucpOutput = ucpJsonWrite(vpJson, spValue, &uiOutputLen);
485  vUtilFileWrite(vpMem, saFiles[2].cpFileName, ucpOutput, uiOutputLen);
486  printf("%s node written to file %s\n", saFiles[2].cpKey, saFiles[2].cpFileName);
487  vJsonDisplayValue(vpJson, spValue, 0);
488  vJsonIteratorDtor(vpIt);
489 
490  printf("\nBuild the numbers node.\n");
491  uiNumbers = uiJsonBuildMakeObject(vpBld);
492  uiTemp = uiJsonBuildMakeArray(vpBld);
493  uiJsonBuildAddToArray(vpBld, uiTemp, uiJsonBuildMakeNumberS(vpBld, -1));
494  uiJsonBuildAddToArray(vpBld, uiTemp, uiJsonBuildMakeNumberS(vpBld, -2));
495  uiJsonBuildAddToArray(vpBld, uiTemp, uiJsonBuildMakeNumberS(vpBld, -9223372036854775807));
496  uiJsonBuildAddToObject(vpBld, uiNumbers, uiJsonBuildMakeStringA(vpBld, "signed"), uiTemp);
497  uiTemp = uiJsonBuildMakeArray(vpBld);
498  uiJsonBuildAddToArray(vpBld, uiTemp, uiJsonBuildMakeNumberU(vpBld, 1));
499  uiJsonBuildAddToArray(vpBld, uiTemp, uiJsonBuildMakeNumberU(vpBld, 255));
500  uiJsonBuildAddToArray(vpBld, uiTemp, uiJsonBuildMakeNumberU(vpBld, 65535));
501  uiJsonBuildAddToArray(vpBld, uiTemp, uiJsonBuildMakeNumberU(vpBld, 4294967295));
502  uiJsonBuildAddToArray(vpBld, uiTemp, uiJsonBuildMakeNumberU(vpBld, 18446744073709551615U));
503  uiJsonBuildAddToObject(vpBld, uiNumbers, uiJsonBuildMakeStringA(vpBld, "unsigned"), uiTemp);
504  uiTemp = uiJsonBuildMakeArray(vpBld);
505  uiJsonBuildAddToArray(vpBld, uiTemp, uiJsonBuildMakeNumberF(vpBld, 2.2250738585072014e-308));
506  uiJsonBuildAddToArray(vpBld, uiTemp, uiJsonBuildMakeNumberF(vpBld, 2.2250738585072014e307));
507  uiJsonBuildAddToArray(vpBld, uiTemp, uiJsonBuildMakeNumberF(vpBld, -1.1));
508  uiJsonBuildAddToArray(vpBld, uiTemp, uiJsonBuildMakeNumberF(vpBld, 2.3));
509  uiJsonBuildAddToArray(vpBld, uiTemp, uiJsonBuildMakeNumberF(vpBld, -0.001e-10));
510  uiJsonBuildAddToObject(vpBld, uiNumbers, uiJsonBuildMakeStringA(vpBld, "floating point"), uiTemp);
511  vpIt = vpJsonBuild(vpBld, uiNumbers);
512  spValue = spJsonIteratorFirst(vpIt);
513  ucpOutput = ucpJsonWrite(vpJson, spValue, &uiOutputLen);
514  vUtilFileWrite(vpMem, saFiles[3].cpFileName, ucpOutput, uiOutputLen);
515  printf("%s node written to file %s\n", saFiles[3].cpKey, saFiles[3].cpFileName);
516  vJsonDisplayValue(vpJson, spValue, 0);
517  vJsonIteratorDtor(vpIt);
518 
519  printf("\nAdd all keyed nodes to a single, parent root.\n");
520  uiRoot = uiJsonBuildMakeObject(vpBld);
521  uiJsonBuildAddToObject(vpBld, uiRoot, uiJsonBuildMakeStringA(vpBld, "text"), uiText);
522  uiJsonBuildAddToObject(vpBld, uiRoot, uiJsonBuildMakeStringA(vpBld, "unicode"), uiUnicode);
523  uiJsonBuildAddToObject(vpBld, uiRoot, uiJsonBuildMakeStringA(vpBld, "numbers"), uiNumbers);
524  uiJsonBuildAddToObject(vpBld, uiRoot, uiJsonBuildMakeStringA(vpBld, "odd-\\u00FF\xc3\xbf-key"), uiJsonBuildMakeStringA(vpBld, "how do you like this key?"));
525  vpIt = vpJsonBuild(vpBld, uiRoot);
526  spValue = spJsonIteratorFirst(vpIt);
527  ucpOutput = ucpJsonWrite(vpJson, spValue, &uiOutputLen);
528  vUtilFileWrite(vpMem, saFiles[4].cpFileName, ucpOutput, uiOutputLen);
529  printf("%s node written to file %s\n", saFiles[4].cpKey, saFiles[4].cpFileName);
530  vJsonDisplayValue(vpJson, spValue, 0);
531  vJsonIteratorDtor(vpIt);
532 
533  }else{
534  // catch block - display the exception location and message
536  iReturn = EXIT_FAILURE;
537  }
538 
539  // clean up resources
540  vJsonDtor(vpJson); // deletes iterators and builders
541  vMemDtor(vpMem);
542  return iReturn;
543 }
544 
552 int main(int argc, char **argv) {
553  long int iCase = 0;
554  if(argc > 1){
555  iCase = atol(argv[1]);
556  }
557  if((iCase > 0) && (iCase <= s_iCaseCount)){
558  printf("%s\n", s_cppCases[iCase -1]);
559  }
560  switch(iCase){
561  case 1:
562  return iApp();
563  case 2:
564  return iSimpleParse();
565  case 3:
566  return iFindKeys();
567  case 4:
568  return iWalker();
569  case 5:
570  return iWriter();
571  case 6:
572  return iBuilder();
573  default:
574  return iHelp();
575  }
576 }
577 
XCTOR
#define XCTOR(e)
This macro will initialize an exception structure and prepare entry to the "try" block.
Definition: exception.h:77
vpJsonChildren
void * vpJsonChildren(void *vpCtx, json_value *spValue)
Initialize the iterator over the children of the given value as the parent node.
Definition: json.c:530
vMemDtor
void vMemDtor(void *vpCtx)
Destroys a Memory component. Frees all memory allocated.
Definition: memory.c:141
exception::try
abool try
True for the try block, false for the catch block.
Definition: exception.h:49
vpJsonFindKeyA
void * vpJsonFindKeyA(void *vpCtx, const char *cpKey, json_value *spValue)
Find JSON values with a specified ASCII key.
Definition: json.c:434
uiJsonBuildMakeNumberF
aint uiJsonBuildMakeNumberF(void *vpBuildCtx, double dNumber)
Make a JSON floating point number value.
Definition: builder.c:336
vpJsonReadFile
void * vpJsonReadFile(void *vpCtx, const char *cpFileName)
The JSON file reader.
Definition: json.c:207
u32_phrase::uiLength
uint32_t uiLength
The number of integers in the array.
Definition: lib.h:75
vJsonDisplayInput
void vJsonDisplayInput(void *vpCtx, abool bShowLines)
Display the input JSON byte stream.
Definition: json.c:365
uiJsonBuildMakeNumberU
aint uiJsonBuildMakeNumberU(void *vpBuildCtx, uint64_t uiNumber)
Make a JSON unsigned integer number value.
Definition: builder.c:383
u32_phrase::uipPhrase
const uint32_t * uipPhrase
Pointer to an array of 32-bit unsigned integers.
Definition: lib.h:74
XTHROW
#define XTHROW(ctx, msg)
Exception throw macro.
Definition: exception.h:67
vpJsonFindKeyU
void * vpJsonFindKeyU(void *vpCtx, const uint32_t *uipKey, aint uiLength, json_value *spValue)
Find JSON values with the specified 32-bit Unicode key.
Definition: json.c:474
aint
uint_fast32_t aint
The APG parser's unsigned integer type.
Definition: apg.h:79
uiJsonBuildMakeStringA
aint uiJsonBuildMakeStringA(void *vpBuildCtx, const char *cpString)
Make a string value from a null-terminated ASCII string.
Definition: builder.c:283
main
int main(int argc, char **argv)
The executable from this main function is the ABNF Parser Generator application, APG.
Definition: main.c:61
vJsonDisplayValue
void vJsonDisplayValue(void *vpCtx, json_value *spValue, aint uiDepth)
Display a value and optionally the values in the branch below, if any.
Definition: json.c:412
exception
A structure to describe the type and location of a caught exception.
Definition: exception.h:47
uiJsonBuildMakeObject
aint uiJsonBuildMakeObject(void *vpBuildCtx)
Make a JSON object value.
Definition: builder.c:445
ucpJsonWrite
uint8_t * ucpJsonWrite(void *vpCtx, json_value *spValue, aint *uipCount)
Converts a sub-tree of values into UTF-8 byte stream of JSON text.
Definition: json.c:329
vpJsonBuild
void * vpJsonBuild(void *vpBuildCtx, aint uiRoot)
Build the JSON object.
Definition: builder.c:603
uiJsonBuildMakeStringU
aint uiJsonBuildMakeStringU(void *vpBuildCtx, const uint32_t *uipData, aint uiLength)
Make a string value from UTF-32 code points.
Definition: builder.c:223
uiJsonBuildAddToObject
aint uiJsonBuildAddToObject(void *vpBuildCtx, aint uiObject, aint uiKey, aint uiAdd)
Add a child value to a parent object value.
Definition: builder.c:479
spJsonIteratorFirst
json_value * spJsonIteratorFirst(void *vpIteratorCtx)
Find the first value in the list represented by this iterator.
Definition: json.c:613
vJsonBuildClear
void vJsonBuildClear(void *vpBuildCtx)
Clears all memory associated with this builder object.
Definition: builder.c:184
vpMemCtor
void * vpMemCtor(exception *spException)
Construct a memory component.
Definition: memory.c:121
spJsonIteratorNext
json_value * spJsonIteratorNext(void *vpIteratorCtx)
Find the next value in the list represented by this iterator.
Definition: json.c:647
APG_TRUE
#define APG_TRUE
Definition: apg.h:291
uiJsonBuildMakeArray
aint uiJsonBuildMakeArray(void *vpBuildCtx)
Makea JSON array value.
Definition: builder.c:459
uiJsonBuildAddToArray
aint uiJsonBuildAddToArray(void *vpBuildCtx, aint uiArray, aint uiAdd)
Add a child value to a parent array value.
Definition: builder.c:550
vJsonIteratorDtor
void vJsonIteratorDtor(void *vpIteratorCtx)
The JSON iterator destructor.
Definition: json.c:591
vUtilFileWrite
void vUtilFileWrite(void *vpMem, const char *cpFileName, uint8_t *ucpData, aint uiLen)
Write from the caller's data area to the given file name.
Definition: utilities.c:210
vUtilApgInfo
void vUtilApgInfo(void)
Display the current state of apg.h.
Definition: utilities.c:60
vpJsonCtor
void * vpJsonCtor(exception *spEx)
The JSON constructor.
Definition: json.c:115
vJsonDtor
void vJsonDtor(void *vpCtx)
The JSON Parser component destructor.
Definition: json.c:165
uiJsonBuildMakeNumberS
aint uiJsonBuildMakeNumberS(void *vpBuildCtx, int64_t iNumber)
Make a JSON signed integer number value.
Definition: builder.c:358
u32_phrase
Defines a pointer to an array of 32-bit unsigned integers plus its length. Typically needed by Unicod...
Definition: lib.h:73
vpJsonTree
void * vpJsonTree(void *vpCtx, json_value *spValue)
Initialize the iterator to walk a value tree.
Definition: json.c:501
vUtilPrintException
void vUtilPrintException(exception *spEx)
Prints exception information from an exception structure.
Definition: utilities.c:415
vUtilCurrentWorkingDirectory
void vUtilCurrentWorkingDirectory(void)
Display the current working directory.
Definition: utilities.c:191
spUtilStrToPhrase32
u32_phrase * spUtilStrToPhrase32(void *vpMem, const char *cpStr)
Convert a null-terminated ASCII string to a 32-bit phrase.
Definition: utilities.c:1031
vpJsonBuildCtor
void * vpJsonBuildCtor(void *vpJsonCtx)
The builder object constructor.
Definition: builder.c:124
APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.