Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
format.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 * *************************************************************************************/
55 #define MAX_INDENT 80
57 #define LINE_LEN 16
58 #define LINE_LEN4 4
59 #define LINE_LEN8 8
60 #define LINE_LEN12 12
61 #define FMT_BUFLEN (128+MAX_INDENT)
62 #define FILE_END ((uint64_t)-1)
63 
65 static const void* s_vpMagicNumber = (void*)"format";
66 
67 #include <stdio.h>
68 #include <limits.h>
69 #include "../library/lib.h"
70 #include "./objects.h"
71 
77 typedef struct fmt_tag{
78  const void* vpValidate;
80  void* vpMem;
82  FILE* spFile;
83  uint8_t* ucpBuf8;
84  uint32_t* uipBuf32;
85  char* cpFmtBuf;
86  const uint8_t* ucpChars8;
87  const uint32_t* uipChars32;
88  int iStyle;
90  int iIndent;
91  uint64_t (*pfnFill)(struct fmt_tag*);
92  void (*pfnFmt)(struct fmt_tag*, uint64_t);
93  uint64_t uiFillLineLen;
95  uint64_t uiDisplayOffset;
96  uint64_t uiLastOffset;
97  uint64_t uiNextOffset;
98  uint64_t uiDisplayEnd;
100 } fmt;
101 
102 static char* cpNext(fmt* spCtx);
103 static void vFmtBuf8Hex(fmt* spCtx, uint64_t uiChars);
104 static void vFmtBuf8Hex2(fmt* spCtx, uint64_t uiChars);
105 static void vFmtBuf8Ascii(fmt* spCtx, uint64_t uiChars);
106 static void vFmtBuf8Canonical(fmt* spCtx, uint64_t uiChars);
107 static void vFmtBufUnicode(fmt* spCtx, uint64_t uiChars);
108 static uint64_t uiFillBytes(fmt* spCtx);
109 static uint64_t uiFillFile(fmt* spCtx);
110 static uint64_t uiFillUnicode(fmt* spCtx);
111 static void vReset(fmt* spCtx);
112 
118 void* vpFmtCtor(exception* spEx) {
119  if(bExValidate(spEx)){
120  fmt* spCtx;
121  void* vpMem = vpMemCtor(spEx);
122  spCtx = (fmt*) vpMemAlloc(vpMem, sizeof(fmt));
123  memset((void*) spCtx, 0, sizeof(fmt));
124  spCtx->ucpBuf8 = (uint8_t*) vpMemAlloc(vpMem, (LINE_LEN * sizeof(uint8_t)));
125  spCtx->uipBuf32 = (uint32_t*) vpMemAlloc(vpMem, (LINE_LEN * sizeof(uint32_t)));
126  spCtx->cpFmtBuf = (char*) vpMemAlloc(vpMem, FMT_BUFLEN);
127  spCtx->vpMem = vpMem;
128  spCtx->spException = spEx;
129  spCtx->vpValidate = s_vpMagicNumber;
130  return (void*) spCtx;
131  }else{
132  vExContext();
133  }
134  return NULL;
135 }
136 
146 void vFmtDtor(void* vpCtx) {
147  if (vpCtx) {
148  fmt* spCtx = (fmt*) vpCtx;
149  if (spCtx->vpValidate == s_vpMagicNumber) {
150  if (spCtx->spFile) {
151  fclose(spCtx->spFile);
152  }
153  void* vpMem = spCtx->vpMem;
154  memset(vpCtx, 0, sizeof(fmt));
155  vMemDtor(vpMem);
156  }else{
157  vExContext();
158  }
159  }
160 }
161 
167 abool bFmtValidate(void* vpCtx){
168  fmt* spCtx = (fmt*) vpCtx;
169  if (vpCtx && (spCtx->vpValidate == s_vpMagicNumber)) {
170  return APG_TRUE;
171  }
172  return APG_FALSE;
173 }
174 
181 void vFmtIndent(void* vpCtx, int iIndent) {
182  fmt* spCtx = (fmt*) vpCtx;
183  if (vpCtx && (spCtx->vpValidate == s_vpMagicNumber)) {
184  if (iIndent > 0) {
185  if (iIndent > MAX_INDENT) {
186  spCtx->iIndent = MAX_INDENT;
187  } else {
188  spCtx->iIndent = iIndent;
189  }
190  } else {
191  spCtx->iIndent = 0;
192  }
193  }else{
194  vExContext();
195  }
196 }
197 
210 const char* cpFmtFirstBytes(void* vpCtx, const uint8_t* ucpBytes, uint64_t uiLength,
211  int iStyle, uint64_t uiOffset, uint64_t uiLimit) {
212  fmt* spCtx = (fmt*) vpCtx;
213  if (vpCtx && (spCtx->vpValidate == s_vpMagicNumber)) {
214  if(ucpBytes == NULL){
215  XTHROW(spCtx->spException, "ucpBytes: input cannot be NULL");
216  }
217  if(uiLength <= 0){
218  XTHROW(spCtx->spException, "uiLength: input length must be > 0");
219  }
220  vReset(spCtx);
221  spCtx->iStyle = FMT_HEX;
222  spCtx->pfnFmt = vFmtBuf8Hex;
223  switch (iStyle) {
224  case FMT_HEX2:
225  spCtx->iStyle = FMT_HEX2;
226  spCtx->pfnFmt = vFmtBuf8Hex2;
227  break;
228  case FMT_ASCII:
229  spCtx->iStyle = FMT_ASCII;
230  spCtx->pfnFmt = vFmtBuf8Ascii;
231  break;
232  case FMT_CANONICAL:
233  spCtx->iStyle = FMT_CANONICAL;
234  spCtx->pfnFmt = vFmtBuf8Canonical;
235  break;
236  }
237  spCtx->pfnFill = uiFillBytes;
238  spCtx->uiFillLineLen = LINE_LEN;
239  spCtx->ucpChars8 = ucpBytes;
240  if(uiOffset){
241  spCtx->uiDisplayOffset = (uiOffset > uiLength) ? uiLength : uiOffset;
242  }
243  spCtx->uiNextOffset = spCtx->uiDisplayOffset;
244  if (uiLimit == 0L) {
245  spCtx->uiDisplayEnd = uiLength;
246  } else {
247  spCtx->uiDisplayEnd = spCtx->uiDisplayOffset + uiLimit;
248  if (spCtx->uiDisplayEnd > uiLength) {
249  spCtx->uiDisplayEnd = uiLength;
250  }
251  }
252  return cpNext(spCtx);
253  }else{
254  vExContext();
255  }
256  return NULL;
257 }
258 
271 const char* cpFmtFirstFile(void* vpCtx, const char* cpFileName, int iStyle, uint64_t uiOffset, uint64_t uiLimit) {
272  char* cpReturn = NULL;
273  fmt* spCtx = (fmt*) vpCtx;
274  if (vpCtx && (spCtx->vpValidate == s_vpMagicNumber)) {
275  if(cpFileName == NULL || (cpFileName[0] == 0)){
276  XTHROW(spCtx->spException, "cpFileName: cannot be NULL or empty");
277  }
278  char caBuf[PATH_MAX + 128];
279  size_t uiBufSize = PATH_MAX + 128;
280  vReset(spCtx);
281  spCtx->spFile = fopen(cpFileName, "rb");
282  if (!spCtx->spFile) {
283  snprintf(caBuf, uiBufSize, "can't open file: %s", cpFileName);
284  XTHROW(spCtx->spException, caBuf);
285  }
286  spCtx->iStyle = FMT_HEX;
287  spCtx->pfnFmt = vFmtBuf8Hex;
288  switch (iStyle) {
289  case FMT_HEX2:
290  spCtx->iStyle = FMT_HEX2;
291  spCtx->pfnFmt = vFmtBuf8Hex2;
292  break;
293  case FMT_ASCII:
294  spCtx->iStyle = FMT_ASCII;
295  spCtx->pfnFmt = vFmtBuf8Ascii;
296  break;
297  case FMT_CANONICAL:
298  spCtx->iStyle = FMT_CANONICAL;
299  spCtx->pfnFmt = vFmtBuf8Canonical;
300  break;
301  }
302  spCtx->pfnFill = uiFillFile;
303  spCtx->uiFillLineLen = LINE_LEN;
304  spCtx->iStyle = iStyle;
305  spCtx->uiNextOffset = 0L;
306  if(uiOffset){
307  int iChar;
308  while(spCtx->uiNextOffset < uiOffset){
309  iChar = fgetc(spCtx->spFile);
310  if (iChar == EOF) {
311  break;
312  }
313  spCtx->uiNextOffset++;
314  }
315  }
316  spCtx->uiDisplayOffset = spCtx->uiNextOffset;
317  spCtx->uiDisplayEnd = FILE_END;
318  if (uiLimit > 0L) {
319  spCtx->uiDisplayEnd = spCtx->uiDisplayOffset + uiLimit;
320  }
321  return cpNext(spCtx);
322  }else{
323  vExContext();
324  }
325  return cpReturn;
326 }
327 
341 const char* cpFmtFirstUnicode(void* vpCtx, const uint32_t* uipChars, uint64_t uiLength, uint64_t uiOffset,
342  uint64_t uiLimit) {
343  char* cpReturn = NULL;
344  fmt* spCtx = (fmt*) vpCtx;
345  if (vpCtx && (spCtx->vpValidate == s_vpMagicNumber)) {
346  while (1) {
347  vReset(spCtx);
348  if(uipChars == NULL){
349  XTHROW(spCtx->spException, "uipChars: input cannot be NULL");
350  }
351  if(uiLength <= 0){
352  XTHROW(spCtx->spException, "uiLength: input length must be > 0");
353  }
354  spCtx->pfnFmt = vFmtBufUnicode;
355  spCtx->pfnFill = uiFillUnicode;
356  spCtx->uiFillLineLen = LINE_LEN8;
357  spCtx->iStyle = FMT_UNICODE;
358  spCtx->uipChars32 = uipChars;
359  if(uiOffset){
360  spCtx->uiDisplayOffset = (uiOffset > uiLength) ? uiLength : uiOffset;
361  }
362  if (uiLimit == 0L) {
363  spCtx->uiDisplayEnd = uiLength;
364  } else {
365  spCtx->uiDisplayEnd = spCtx->uiDisplayOffset + uiLimit;
366  if (spCtx->uiDisplayEnd > uiLength) {
367  spCtx->uiDisplayEnd = uiLength;
368  }
369  }
370  spCtx->uiNextOffset = spCtx->uiDisplayOffset;
371  cpReturn = cpNext(spCtx);
372  break;
373  }
374  }else{
375  vExContext();
376  }
377  return cpReturn;
378 }
379 
386 const char* cpFmtNext(void* vpCtx) {
387  const char* cpReturn = NULL;
388  fmt* spCtx = (fmt*) vpCtx;
389  if (vpCtx && (spCtx->vpValidate == s_vpMagicNumber)) {
390  if(spCtx->bDone){
391  return NULL;
392  }else{
393  cpReturn = cpNext(spCtx);
394  }
395  }else{
396  vExContext();
397  }
398  return cpReturn;
399 }
400 
401 // static functions
402 static char* cpNext(fmt* spCtx) {
403  uint64_t uiChars = spCtx->pfnFill(spCtx);
404  spCtx->pfnFmt(spCtx, uiChars);
405  if (uiChars == 0) {
406  spCtx->bDone = APG_TRUE;
407  }
408  return spCtx->cpFmtBuf;
409 }
410 
411 static uint64_t uiFillBytes(fmt* spCtx) {
412  uint64_t uiDst = 0L;
413  spCtx->uiLastOffset = spCtx->uiNextOffset;
414  while ((uiDst < spCtx->uiFillLineLen) && (spCtx->uiNextOffset < spCtx->uiDisplayEnd)) {
415  spCtx->ucpBuf8[uiDst++] = spCtx->ucpChars8[spCtx->uiNextOffset++];
416  }
417  return uiDst;
418 }
419 
420 static uint64_t uiFillFile(fmt* spCtx) {
421  int iChar;
422  uint64_t uiDst = 0L;
423  spCtx->uiLastOffset = spCtx->uiNextOffset;
424  while ((uiDst < spCtx->uiFillLineLen) && (spCtx->uiNextOffset < spCtx->uiDisplayEnd)) {
425  iChar = fgetc(spCtx->spFile);
426  if (iChar == EOF) {
427  break;
428  }
429  spCtx->uiNextOffset++;
430  spCtx->ucpBuf8[uiDst++] = (uint8_t) iChar;
431  }
432  return uiDst;
433 }
434 
435 static uint64_t uiFillUnicode(fmt* spCtx) {
436  uint64_t uiDst = 0L;
437  spCtx->uiLastOffset = spCtx->uiNextOffset;
438  while ((uiDst < spCtx->uiFillLineLen) && (spCtx->uiNextOffset < spCtx->uiDisplayEnd)) {
439  spCtx->uipBuf32[uiDst++] = spCtx->uipChars32[spCtx->uiNextOffset++];
440  }
441  return uiDst;
442 }
443 
444 static void vFmtBufUnicode(fmt* spCtx, uint64_t uiChars) {
445  uint64_t ui = 0;
446  int n = 0;
447  if (spCtx->iIndent > 0) {
448  for (; n < spCtx->iIndent; n++) {
449  spCtx->cpFmtBuf[n] = 32;
450  }
451  }
452  n += sprintf(&spCtx->cpFmtBuf[n], "%08"PRIxMAX" ", spCtx->uiLastOffset);
453  if(uiChars > 0){
454  for (; ui < uiChars; ui++) {
455  if (ui == LINE_LEN4) {
456  n += sprintf(&spCtx->cpFmtBuf[n], " ");
457  }
458  n += sprintf(&spCtx->cpFmtBuf[n], " %06X", spCtx->uipBuf32[ui]);
459  }
460  if (uiChars < LINE_LEN8) {
461  for (; ui < LINE_LEN8; ui++) {
462  if (ui == LINE_LEN4) {
463  n += sprintf(&spCtx->cpFmtBuf[n], " ");
464  }
465  n += sprintf(&spCtx->cpFmtBuf[n], " ");
466  }
467  }
468  n += sprintf(&spCtx->cpFmtBuf[n], " |");
469  for (ui = 0; ui < uiChars; ui++) {
470  if ((spCtx->uipBuf32[ui] >= 32) && (spCtx->uipBuf32[ui] <= 126)) {
471  n += sprintf(&spCtx->cpFmtBuf[n], "%c", (char) spCtx->uipBuf32[ui]);
472  } else {
473  n += sprintf(&spCtx->cpFmtBuf[n], ".");
474  }
475  }
476  n += sprintf(&spCtx->cpFmtBuf[n], "|");
477  }
478  spCtx->cpFmtBuf[n++] = 10;
479  spCtx->cpFmtBuf[n] = 0;
480 }
481 
482 static void vFmtBuf8Hex(fmt* spCtx, uint64_t uiChars) {
483  uint64_t ui;
484  int n = 0;
485  if (spCtx->iIndent > 0) {
486  for (; n < spCtx->iIndent; n++) {
487  spCtx->cpFmtBuf[n] = 32;
488  }
489  }
490  n += sprintf(&spCtx->cpFmtBuf[n], "%08"PRIxMAX" ", spCtx->uiLastOffset);
491  if(uiChars > 0){
492  for (ui = 0; ui < uiChars; ui++) {
493  if (ui == LINE_LEN8) {
494  n += sprintf(&spCtx->cpFmtBuf[n], " ");
495  }
496  n += sprintf(&spCtx->cpFmtBuf[n], " %02x", spCtx->ucpBuf8[ui]);
497  }
498  }
499  spCtx->cpFmtBuf[n++] = 10;
500  spCtx->cpFmtBuf[n] = 0;
501 }
502 
503 static void vFmtBuf8Hex2(fmt* spCtx, uint64_t uiChars) {
504  uint64_t ui;
505  uint64_t uiCount;
506  int n = 0;
507  int j = 0;
508  uint16_t ui16 = 0;
509  uint16_t* uip16 = (uint16_t*)spCtx->ucpBuf8;
510  if (spCtx->iIndent > 0) {
511  for (; n < spCtx->iIndent; n++) {
512  spCtx->cpFmtBuf[n] = 32;
513  }
514  }
515  n += sprintf(&spCtx->cpFmtBuf[n], "%08"PRIxMAX"", spCtx->uiLastOffset);
516  if(uiChars > 0){
517  uiCount = uiChars;
518  if(uiChars % 2){
519  ui16 = (uint16_t)spCtx->ucpBuf8[uiChars - 1];
520  uiCount--;
521  }
522  for (ui = 0; ui < uiCount; ui += 2) {
523  n += sprintf(&spCtx->cpFmtBuf[n], " %04x", uip16[j++]);
524  }
525  if(uiCount < uiChars){
526  n += sprintf(&spCtx->cpFmtBuf[n], " %04x", ui16);
527  }
528  }
529  spCtx->cpFmtBuf[n++] = 10;
530  spCtx->cpFmtBuf[n] = 0;
531 }
532 
533 static void vFmtBuf8Ascii(fmt* spCtx, uint64_t uiChars) {
534  uint64_t ui = 0;
535  int n = 0;
536  int iChar;
537  if (spCtx->iIndent > 0) {
538  for (; n < spCtx->iIndent; n++) {
539  spCtx->cpFmtBuf[n] = 32;
540  }
541  }
542  n += sprintf(&spCtx->cpFmtBuf[n], "%08"PRIxMAX" ", spCtx->uiLastOffset);
543  if(uiChars > 0){
544  for (; ui < uiChars; ui++) {
545  iChar = (int)spCtx->ucpBuf8[ui];
546  if(iChar == 9){
547  n += sprintf(&spCtx->cpFmtBuf[n], " \\t");
548  }else if(iChar == 10){
549  n += sprintf(&spCtx->cpFmtBuf[n], " \\n");
550  }else if(iChar == 13){
551  n += sprintf(&spCtx->cpFmtBuf[n], " \\r");
552  }else if(iChar >= 32 && iChar <= 126){
553  n += sprintf(&spCtx->cpFmtBuf[n], " %c", (char)iChar);
554  }else{
555  n += sprintf(&spCtx->cpFmtBuf[n], " %03d", iChar);
556  }
557  }
558  }
559  spCtx->cpFmtBuf[n++] = 10;
560  spCtx->cpFmtBuf[n] = 0;
561 }
562 
563 static void vFmtBuf8Canonical(fmt* spCtx, uint64_t uiChars) {
564  uint64_t ui = 0;
565  int n = 0;
566  if (spCtx->iIndent > 0) {
567  for (; n < spCtx->iIndent; n++) {
568  spCtx->cpFmtBuf[n] = 32;
569  }
570  }
571  n += sprintf(&spCtx->cpFmtBuf[n], "%08"PRIxMAX" ", spCtx->uiLastOffset);
572  if(uiChars > 0){
573  for (; ui < uiChars; ui++) {
574  if (ui == LINE_LEN8) {
575  n += sprintf(&spCtx->cpFmtBuf[n], " ");
576  }
577  n += sprintf(&spCtx->cpFmtBuf[n], " %02x", spCtx->ucpBuf8[ui]);
578  }
579  if (uiChars < LINE_LEN) {
580  for (; ui < LINE_LEN; ui++) {
581  if (ui == LINE_LEN8) {
582  n += sprintf(&spCtx->cpFmtBuf[n], " ");
583  }
584  n += sprintf(&spCtx->cpFmtBuf[n], " ");
585  }
586  }
587  n += sprintf(&spCtx->cpFmtBuf[n], " |");
588  for (ui = 0; ui < uiChars; ui++) {
589  if ((spCtx->ucpBuf8[ui] >= 32) && (spCtx->ucpBuf8[ui] <= 126)) {
590  n += sprintf(&spCtx->cpFmtBuf[n], "%c", (char) spCtx->ucpBuf8[ui]);
591  } else {
592  n += sprintf(&spCtx->cpFmtBuf[n], ".");
593  }
594  }
595  n += sprintf(&spCtx->cpFmtBuf[n], "|");
596  }
597  spCtx->cpFmtBuf[n++] = 10;
598  spCtx->cpFmtBuf[n] = 0;
599 }
600 
601 static void vReset(fmt* spCtx) {
602  if (spCtx->spFile) {
603  fclose(spCtx->spFile);
604  spCtx->spFile = NULL;
605  }
606  spCtx->ucpChars8 = NULL;
607  spCtx->uipChars32 = NULL;
608  spCtx->uiDisplayOffset = 0;
609  spCtx->uiDisplayEnd = 0;
610  spCtx->uiNextOffset = 0;
611  spCtx->bDone = APG_FALSE;
612 }
613 
FILE_END
#define FILE_END
Definition: format.c:62
fmt_tag::ucpBuf8
uint8_t * ucpBuf8
Pointer to a byte buffer for formatting the next byte-stream line.
Definition: format.c:83
vMemDtor
void vMemDtor(void *vpCtx)
Destroys a Memory component. Frees all memory allocated.
Definition: memory.c:141
fmt_tag::vpMem
void * vpMem
Pointer to a memory object for allocating all memory associated with this object.
Definition: format.c:81
objects.h
A composite header for the utility objects.
fmt_tag
The context for the format object.
Definition: format.c:77
cpFmtFirstBytes
const char * cpFmtFirstBytes(void *vpCtx, const uint8_t *ucpBytes, uint64_t uiLength, int iStyle, uint64_t uiOffset, uint64_t uiLimit)
Initiate the iterator over an array of 8-bit byte data.
Definition: format.c:210
bFmtValidate
abool bFmtValidate(void *vpCtx)
Validate a format context pointer.
Definition: format.c:167
fmt_tag::uipChars32
const uint32_t * uipChars32
Pointer to the 32-bit Unicode code points to be formatted, if any. Otherwise, NULL.
Definition: format.c:87
fmt_tag::cpFmtBuf
char * cpFmtBuf
Pointer to a temporary, working buffer for formatting the data in the data buffers.
Definition: format.c:85
LINE_LEN8
#define LINE_LEN8
Definition: format.c:59
vExContext
void vExContext()
Handles bad context pointers.
Definition: exception.c:126
FMT_CANONICAL
#define FMT_CANONICAL
Display lines with both FMT_HEX and FMT_ASCII formats.
Definition: format.h:55
cpFmtNext
const char * cpFmtNext(void *vpCtx)
Formats the next line of data.
Definition: format.c:386
fmt_tag::bDone
abool bDone
True if there are no more lines to display. False otherwise.
Definition: format.c:99
fmt_tag::iStyle
int iStyle
The display style identifier. One of these..
Definition: format.c:89
cpFmtFirstUnicode
const char * cpFmtFirstUnicode(void *vpCtx, const uint32_t *uipChars, uint64_t uiLength, uint64_t uiOffset, uint64_t uiLimit)
Initiate the iterator over an array of 32-bit Unicode code points.
Definition: format.c:341
XTHROW
#define XTHROW(ctx, msg)
Exception throw macro.
Definition: exception.h:67
fmt_tag::uiLastOffset
uint64_t uiLastOffset
Keeps the offset to the previous line displayed.
Definition: format.c:96
LINE_LEN4
#define LINE_LEN4
Definition: format.c:58
cpFmtFirstFile
const char * cpFmtFirstFile(void *vpCtx, const char *cpFileName, int iStyle, uint64_t uiOffset, uint64_t uiLimit)
Initiate the iterator over file of 8-bit byte data.
Definition: format.c:271
fmt_tag::ucpChars8
const uint8_t * ucpChars8
Pointer to the array of 8-bit bytes to be formatted, if any. Otherwise, NULL.
Definition: format.c:86
MAX_INDENT
#define MAX_INDENT
Definition: format.c:56
LINE_LEN
#define LINE_LEN
Definition: format.c:57
vpMemAlloc
void * vpMemAlloc(void *vpCtx, aint uiBytes)
Allocates memory.
Definition: memory.c:196
FMT_HEX2
#define FMT_HEX2
Display lines of 16-bit hexadecimal integers.
Definition: format.h:45
exception
A structure to describe the type and location of a caught exception.
Definition: exception.h:47
fmt_tag::pfnFill
uint64_t(* pfnFill)(struct fmt_tag *)
Function pointer for filling the temp byte or code point buffer.
Definition: format.c:91
fmt_tag::uiNextOffset
uint64_t uiNextOffset
Keeps the offset to the next byte or code point to display next.
Definition: format.c:97
bExValidate
abool bExValidate(exception *spException)
Test an exception structure for validity.
Definition: exception.c:70
FMT_HEX
#define FMT_HEX
Display lines of single 8-bit hexadecimal bytes.
Definition: format.h:42
exception::vpValidate
const void * vpValidate
Used by the memory object to validate the exception structure.
Definition: exception.h:48
vpMemCtor
void * vpMemCtor(exception *spException)
Construct a memory component.
Definition: memory.c:121
fmt_tag::uiDisplayOffset
uint64_t uiDisplayOffset
The offset to the first byte or code point to display.
Definition: format.c:95
fmt_tag::uiDisplayEnd
uint64_t uiDisplayEnd
The last byte or code point to display.
Definition: format.c:98
fmt_tag::vpValidate
const void * vpValidate
A "magic number" used to validate the context.
Definition: format.c:78
APG_TRUE
#define APG_TRUE
Definition: apg.h:291
FMT_UNICODE
#define FMT_UNICODE
Display lines of 24-bit integers.
Definition: format.h:59
abool
uint8_t abool
abool is the APG bool type.
Definition: apg.h:140
fmt_tag::spFile
FILE * spFile
Pointer to an open file, if the data is from a file byte stream. Otherwise NULL.
Definition: format.c:82
fmt_tag::iIndent
int iIndent
The number of spaces to indent before displaying data.
Definition: format.c:90
fmt_tag::uiFillLineLen
uint64_t uiFillLineLen
formatting the data in the byte or code point buffer.
Definition: format.c:94
fmt_tag::spException
exception * spException
Pointer to an exception structure to report fatal errors back to the application's catch block.
Definition: format.c:79
FMT_BUFLEN
#define FMT_BUFLEN
Definition: format.c:61
vFmtDtor
void vFmtDtor(void *vpCtx)
The object destructor.
Definition: format.c:146
fmt_tag::uipBuf32
uint32_t * uipBuf32
Pointer to a 32-bit buffer for formatting the next Unicode line.
Definition: format.c:84
vFmtIndent
void vFmtIndent(void *vpCtx, int iIndent)
Set the an indentation for the display.
Definition: format.c:181
FMT_ASCII
#define FMT_ASCII
Display lines of single 8-bit characters.
Definition: format.h:51
vpFmtCtor
void * vpFmtCtor(exception *spEx)
The object constructor.
Definition: format.c:118
APG_FALSE
#define APG_FALSE
Definition: apg.h:292
fmt_tag::pfnFmt
void(* pfnFmt)(struct fmt_tag *, uint64_t)
Function pointer for.
Definition: format.c:92
APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.