Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
utilities.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 UTILS_UTILS_H_
31 #define UTILS_UTILS_H_
32 
42 #include <stdio.h>
43 #include "../library/lib.h"
44 #include "./objects.h"
45 
47 void vUtilApgInfo(void);
49 void vUtilSizes(void);
52 
54 void vUtilFileWrite(void* vpMem, const char* cpFileName, uint8_t* ucpData, aint uiLen);
56 void vUtilFileRead(void* vpMem, const char* cpFileName, uint8_t* ucpData, aint* uipLen);
57 abool bUtilCompareFiles(const char* cpFileL, const char* cpFileR);
58 abool bUtilCompareFileLines(void* vpMem, const char* cpFileL, const char* cpFileR);
60 
62 void vUtilPrintException(exception* spEx);
64 void vUtilPrintMemStats(const mem_stats* spStats);
65 void vUtilPrintVecStats(const vec_stats* spStats);
66 void vUtilPrintLine(line* spLine);
67 void vUtilPrintLineu(line_u* spLine);
68 char* cpUtilPrintChar(char cChar, char* cpBuf);
69 char* cpUtilPrintUChar(uint32_t uiChar, char* cpBuf);
70 const char* cpUtilUtfTypeName(aint uiType);
71 const char* cpUtilTrueFalse(luint luiTrue);
72 const char* cpUtilOpName(aint uiId);
73 void vUtilPrintParserState(parser_state* spState);
74 void vUtilPrintMsgs(void* vpMsgs);
76 
78 achar* acpUtilStrToAchar(void* vpMem, const char* cpStr, aint* uipLen);
80 const char* cpUtilAcharToStr(void* vpMem, achar* acpAchar, aint uiLen);
81 apg_phrase* spUtilStrToPhrase(void* vpMem, const char* cpStr);
82 const char* cpUtilPhraseToStr(void* vpMem, apg_phrase* spPhrase);
84 
86 uint32_t* uipUtilStrToUint32(void* vpMem, const char* cpStr, aint* uipLen);
88 const char* cpUtilUint32ToStr(void* vpMem, const uint32_t* uipUint, aint uiLen);
89 u32_phrase* spUtilStrToPhrase32(void* vpMem, const char* cpStr);
90 const char* cpUtilPhrase32ToStr(void* vpMem, u32_phrase* spPhrase);
92 
94 void vUtilIndent(FILE* spFile, aint uiIndent);
96 void vUtilCharsToAscii(FILE* spFile, const achar* acpChars, aint uiLength);
97 abool bUtilAstToXml(void* vpCtx, char* cpType, const char* cpFileName);
98 void vUtilConvertLineEnds(exception* spEx, const char *cpString, const char *cpEnd, const char *cpFileName);
100 
148 #endif /* UTILS_UTILS_H_ */
bUtilCompareFiles
abool bUtilCompareFiles(const char *cpFileL, const char *cpFileR)
Compare two files, byte for byte.
Definition: utilities.c:306
cpUtilPhraseToStr
const char * cpUtilPhraseToStr(void *vpMem, apg_phrase *spPhrase)
Convert an apg_phrase to a null-terminated ASCII string.
Definition: utilities.c:925
cpUtilPrintChar
char * cpUtilPrintChar(char cChar, char *cpBuf)
Generates a string representation for a single character.
Definition: utilities.c:504
cpUtilPhrase32ToStr
const char * cpUtilPhrase32ToStr(void *vpMem, u32_phrase *spPhrase)
Convert an u32_phrase to a null-terminated ASCII string.
Definition: utilities.c:1065
objects.h
A composite header for the utility objects.
line_u
Carries detailed information about the characters and line endings. One for each line in the input gr...
Definition: linesu.h:40
vUtilApgInfo
void vUtilApgInfo(void)
Display the current state of apg.h.
Definition: utilities.c:60
vUtilSizes
void vUtilSizes(void)
Display the APG type sizes, the compiler's C-language type sizes and a few max values.
Definition: utilities.c:153
achar
uint_fast8_t achar
achar is the type for the parser's alphabet characters.
Definition: apg.h:91
bUtilAstToXml
abool bUtilAstToXml(void *vpCtx, char *cpType, const char *cpFileName)
Convert the AST records to XML format.
Definition: utilities.c:1126
uipUtilStrToUint32
uint32_t * uipUtilStrToUint32(void *vpMem, const char *cpStr, aint *uipLen)
Convert a null-terminated ASCII string to an array of 32-bit unsigned integers.
Definition: utilities.c:963
mem_stats
Available to the user for display of memory statistics.
Definition: memory.h:45
vec_stats
Vector usage statistics.
Definition: vector.h:46
cpType
const char * cpType(aint uiId)
Convert an attribute type ID to an ASCII string.
Definition: attributes.c:484
cpUtilUtfTypeName
const char * cpUtilUtfTypeName(aint uiType)
Convert a conversion type identifier to a readable, printable ASCII string. Conversion type identifie...
Definition: utilities.c:607
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
vUtilPrintParserState
void vUtilPrintParserState(parser_state *spState)
Display the parser state in human-readable format to stdout.
Definition: utilities.c:727
aint
uint_fast32_t aint
The APG parser's unsigned integer type.
Definition: apg.h:79
vUtilPrintMemStats
void vUtilPrintMemStats(const mem_stats *spStats)
Display the memory object's statistics.
Definition: utilities.c:427
parser_state
The parser's final state.
Definition: parser.h:183
exception
A structure to describe the type and location of a caught exception.
Definition: exception.h:47
apg_phrase
Defines a pointer to an achar array plus its length. That is, a phrase as is often used by APG.
Definition: lib.h:60
vUtilCharsToAscii
void vUtilCharsToAscii(FILE *spFile, const achar *acpChars, aint uiLength)
Convert a string of alphabet characters to printable ASCII.
Definition: utilities.c:790
vUtilPrintMsgs
void vUtilPrintMsgs(void *vpMsgs)
Display the list of messages in a message object to stdout.
Definition: utilities.c:747
vUtilPrintLine
void vUtilPrintLine(line *spLine)
Display one line from a line object.
Definition: utilities.c:464
bUtilCompareFileLines
abool bUtilCompareFileLines(void *vpMem, const char *cpFileL, const char *cpFileR)
Compare two text files, line by line, without regard for the line ending characters.
Definition: utilities.c:350
luint
uintmax_t luint
luint is used to cast integers suitable for the %"PRIuMAX" printf format.
Definition: apg.h:133
vUtilPrintVecStats
void vUtilPrintVecStats(const vec_stats *spStats)
Display the vector object's statistics.
Definition: utilities.c:440
vUtilPrintException
void vUtilPrintException(exception *spEx)
Prints exception information from an exception structure.
Definition: utilities.c:415
line
Defines the characteristics of a single line.
Definition: lines.h:40
vUtilCurrentWorkingDirectory
void vUtilCurrentWorkingDirectory(void)
Display the current working directory.
Definition: utilities.c:191
acpUtilStrToAchar
achar * acpUtilStrToAchar(void *vpMem, const char *cpStr, aint *uipLen)
Convert a null-terminated ASCII string to an array of achar characters.
Definition: utilities.c:824
cpUtilUint32ToStr
const char * cpUtilUint32ToStr(void *vpMem, const uint32_t *uipUint, aint uiLen)
Convert an array of 32-bit unsigned integers to a null-terminated ASCII string.
Definition: utilities.c:997
abool
uint8_t abool
abool is the APG bool type.
Definition: apg.h:140
vUtilIndent
void vUtilIndent(FILE *spFile, aint uiIndent)
Indent by adding the given number of spaces to the output file.
Definition: utilities.c:774
vUtilPrintLineu
void vUtilPrintLineu(line_u *spLine)
Display one line from a line_u object.
Definition: utilities.c:483
cpUtilPrintUChar
char * cpUtilPrintUChar(uint32_t uiChar, char *cpBuf)
Generates a string representation for a single Unicode character.
Definition: utilities.c:539
cpUtilOpName
const char * cpUtilOpName(aint uiId)
Convert an opcode identifier to a human-readable opcode name.
Definition: utilities.c:659
spUtilStrToPhrase
apg_phrase * spUtilStrToPhrase(void *vpMem, const char *cpStr)
Convert a null-terminated ASCII string to an apg_phrase.
Definition: utilities.c:891
u32_phrase
Defines a pointer to an array of 32-bit unsigned integers plus its length. Typically needed by Unicod...
Definition: lib.h:73
vUtilFileRead
void vUtilFileRead(void *vpMem, const char *cpFileName, uint8_t *ucpData, aint *uipLen)
Read a file into the caller's data area.
Definition: utilities.c:252
vUtilConvertLineEnds
void vUtilConvertLineEnds(exception *spEx, const char *cpString, const char *cpEnd, const char *cpFileName)
Convert all line ending characters.
Definition: utilities.c:1228
cpUtilAcharToStr
const char * cpUtilAcharToStr(void *vpMem, achar *acpAchar, aint uiLen)
Convert an array of achar characters to a null-terminated ASCII string.
Definition: utilities.c:857
cpUtilTrueFalse
const char * cpUtilTrueFalse(luint luiTrue)
Return a human-readable string version of the given value in its true/false sense.
Definition: utilities.c:646
spUtilStrToPhrase32
u32_phrase * spUtilStrToPhrase32(void *vpMem, const char *cpStr)
Convert a null-terminated ASCII string to a 32-bit phrase.
Definition: utilities.c:1031
APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.