35 #include "../api/api.h"
36 #include "../api/apip.h"
37 #include "../api/attributes.h"
38 #include "../library/parserp.h"
78 #define OUTPUT_LINE_LENGTH 30
83 #define LUINT_MAX(x,y) if(((x) < (y)) && ((y) != (luint)-1))x = (y)
85 static const char* s_cpUchar =
"uint8_t";
86 static const char* s_cpUshort =
"uint16_t";
87 static const char* s_cpUint =
"uint32_t";
88 static const char* s_cpUlong =
"uint64_t";
89 static char* s_cpLicenseNotice =
90 "/* *************************************************************************************\n"
91 " Copyright (c) 2021, Lowell D. Thomas\n"
92 " All rights reserved.\n"
94 " This file was generated by and is part of APG Version 7.0.\n"
95 " APG Version 7.0 may be used under the terms of the BSD 2-Clause License.\n"
97 " Redistribution and use in source and binary forms, with or without\n"
98 " modification, are permitted provided that the following conditions are met:\n"
100 " 1. Redistributions of source code must retain the above copyright notice, this\n"
101 " list of conditions and the following disclaimer.\n"
103 " 2. Redistributions in binary form must reproduce the above copyright notice,\n"
104 " this list of conditions and the following disclaimer in the documentation\n"
105 " and/or other materials provided with the distribution.\n"
107 " THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n"
108 " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n"
109 " IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n"
110 " DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n"
111 " FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n"
112 " DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n"
113 " SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n"
114 " CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n"
115 " OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
116 " OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
118 "* *************************************************************************************/\n\n";
120 static aint uiLastChar(
char cCharToFind,
const char* cpString);
121 static abool bGetFileName(
const char* cpPathName,
char* cpBuffer,
aint uiBufferLength);
122 static abool bSetFileExtension(
const char* cpPathName,
const char* cpExt,
char* cpBuffer,
aint uiBufferLength);
123 static abool bNameToCaps(
const char* cpPrefix,
const char* cpName,
char* cpBuffer,
aint uiBufferLength);
124 static abool bNameToCamelCase(
const char* cpPrefix,
const char* cpName,
char* cpBuffer,
aint uiBufferLength);
125 static void vOutputHeader(
api* spApi,
const char* cpName, FILE* spOut);
126 static void vOutputSource(
api* spApi,
const char* cpName, FILE* spOut);
127 static void* vpOutputParser(
api* spApi);
128 static int iCompRule(
const void* vpL,
const void* vpR);
129 static int iCompUdt(
const void* vpL,
const void* vpR);
130 static char cToUpper(
char cChar);
131 static char cToLower(
char cChar);
132 static abool bIsLetter(
char cLetter);
133 static void vPrintChars(FILE* spOut,
const uint8_t* ucpChars,
aint uiLength);
134 static void vPrintLongs(FILE* spOut,
const luint* luiVals,
aint uiLength);
136 static const char* cpGetType(
luint luiVal);
137 static void* vpMakeParserInit(
api* spApi,
luint luiUintMax,
luint* luipData,
aint uiLen);
138 static void* vpMakeAcharTable(
api* spApi,
luint luiAcharMax,
luint* luipTable,
aint uiLen);
139 static luint* luipMakeInitData(
api* spApi);
142 static void vTestNames();
156 api* spApi = (
api*) vpCtx;
157 FILE* spHeader = NULL;
158 FILE* spSource = NULL;
159 char caName[PATH_MAX];
160 char caFileName[PATH_MAX];
161 size_t uiErrorSize = PATH_MAX + 128;
162 char caErrorBuf[uiErrorSize];
173 "attempted output but opcodes have not been constructed and validated");
177 if(!bGetFileName(cpOutput, caName, PATH_MAX)){
178 snprintf(caErrorBuf, uiErrorSize,
"unable to extract file name from output parameter: '%s'", cpOutput);
183 if(!bSetFileExtension(cpOutput,
"h", caFileName, PATH_MAX)){
184 snprintf(caErrorBuf, uiErrorSize,
"unable to set file extension on output parameter: '%s'", cpOutput);
187 spHeader = fopen(caFileName,
"wb");
189 snprintf(caErrorBuf, uiErrorSize,
"unable to open header file \"%s\"", caFileName);
192 vOutputHeader(spApi, caName, spHeader);
195 if(!bSetFileExtension(cpOutput,
"c", caFileName, PATH_MAX)){
196 snprintf(caErrorBuf, uiErrorSize,
"unable to set file extension on output parameter: '%s'", cpOutput);
199 spSource = fopen(caFileName,
"wb");
201 snprintf(caErrorBuf, uiErrorSize,
"unable to open source file \"%s\"", caFileName);
204 vOutputSource(spApi, caName, spSource);
221 api* spApi = (
api*) vpCtx;
231 XTHROW(spApi->
spException,
"attempted output but opcodes have not been constructed and validated");
235 return vpOutputParser(spApi);
238 static void vOutputHeader(
api* spApi,
const char* cpName, FILE* spOut){
239 aint uiBufSize = PATH_MAX;
240 char caDefine[PATH_MAX];
241 char caWork[PATH_MAX];
242 char caRuleCount[PATH_MAX];
243 char caUdtCount[PATH_MAX];
248 fprintf(spOut,
"//\n");
249 fprintf(spOut,
"// This C-language parser header was generated by APG Version 7.0.\n");
250 fprintf(spOut,
"// User modifications may cause unpredictable results.\n");
251 fprintf(spOut,
"//\n");
252 fprintf(spOut,
"%s",s_cpLicenseNotice);
254 bNameToCaps(
"", cpName, caWork, uiBufSize);
257 strcat(caDefine, caWork);
258 strcat(caDefine,
"_H_");
261 fprintf(spOut,
"#ifndef %s\n", caDefine);
262 fprintf(spOut,
"#define %s\n", caDefine);
266 saRules[ui] = spApi->
spRules[ui];
271 fprintf(spOut,
"\n");
272 fprintf(spOut,
"// rule ids\n");
274 bNameToCaps(cpName, saRules[ui].cpName, caWork, uiBufSize);
275 fprintf(spOut,
"#define %s %"PRIuMAX
"\n", caWork, (
luint)saRules[ui].uiIndex);
277 bNameToCaps(
"RULE_COUNT", cpName, caRuleCount, uiBufSize);
278 fprintf(spOut,
"#define %s %"PRIuMAX
"\n", caRuleCount, (
luint)spApi->
uiRuleCount);
283 saUdts[ui] = spApi->
spUdts[ui];
288 fprintf(spOut,
"\n");
289 fprintf(spOut,
"// UDT ids\n");
291 bNameToCaps(cpName, saUdts[ui].cpName, caWork, uiBufSize);
292 fprintf(spOut,
"#define %s %"PRIuMAX
"\n", caWork, (
luint)saUdts[ui].uiIndex);
294 bNameToCaps(
"UDT_COUNT", cpName, caUdtCount, uiBufSize);
295 fprintf(spOut,
"#define %s %"PRIuMAX
"\n", caUdtCount, (
luint)spApi->
uiUdtCount);
299 bNameToCamelCase(
"vp", cpName, caWork, uiBufSize);
300 strcat(caWork,
"Init");
301 fprintf(spOut,
"\n");
302 fprintf(spOut,
"// pointer to parser initialization data\n");
303 fprintf(spOut,
"extern void* %s;\n", caWork);
306 fprintf(spOut,
"\n");
307 fprintf(spOut,
"// Helper function(s) for setting rule/UDT name callbacks.\n");
308 fprintf(spOut,
"// Un-comment and replace named NULL with pointer to the appropriate callback function.\n");
309 fprintf(spOut,
"// NOTE: This can easily be modified for setting AST callback functions:\n");
310 fprintf(spOut,
"// Replace parser_callback with ast_callback and\n");
311 fprintf(spOut,
"// vParserSetRuleCallback(vpParserCtx) with vAstSetRuleCallback(vpAstCtx) and\n");
312 fprintf(spOut,
"// vParserSetUdtCallback(vpParserCtx) with vAstSetUdtCallback(vpAstCtx).\n");
313 fprintf(spOut,
"/****************************************************************\n");
314 bNameToCamelCase(
"v", cpName, caWork, uiBufSize);
315 strcat(caWork,
"RuleCallbacks");
316 fprintf(spOut,
"void %s(void* vpParserCtx){\n", caWork);
317 fprintf(spOut,
" aint ui;\n");
318 fprintf(spOut,
" parser_callback cb[%s];\n", caRuleCount);
320 bNameToCaps(cpName, saRules[ui].cpName, caWork, uiBufSize);
321 fprintf(spOut,
" cb[%s] = NULL;\n", caWork);
323 fprintf(spOut,
" for(ui = 0; ui < (aint)%s; ui++){\n", caRuleCount);
324 fprintf(spOut,
" vParserSetRuleCallback(vpParserCtx, ui, cb[ui]);\n");
325 fprintf(spOut,
" }\n");
326 fprintf(spOut,
"}\n");
328 bNameToCamelCase(
"v", cpName, caWork, uiBufSize);
329 strcat(caWork,
"UdtCallbacks");
330 fprintf(spOut,
"void %s(void* vpParserCtx){\n", caWork);
331 fprintf(spOut,
" aint ui;\n");
332 fprintf(spOut,
" parser_callback cb[%s];\n", caUdtCount);
334 bNameToCaps(cpName, saUdts[ui].cpName, caWork, uiBufSize);
335 fprintf(spOut,
" cb[%s] = NULL;\n", caWork);
337 fprintf(spOut,
" for(ui = 0; ui < (aint)%s; ui++){\n", caUdtCount);
338 fprintf(spOut,
" vParserSetUdtCallback(vpParserCtx, ui, cb[ui]);\n");
339 fprintf(spOut,
" }\n");
340 fprintf(spOut,
"}\n");
342 fprintf(spOut,
"****************************************************************/\n");
345 fprintf(spOut,
"\n");
346 fprintf(spOut,
"#endif /* %s */\n", caDefine);
348 static void vOutputSource(
api* spApi,
const char* cpName, FILE* spOut){
349 luint* luipInit = NULL;
350 char* cpLineBuffer = NULL;
353 char caBuf[PATH_MAX];
361 spApi->
luipInit = luipMakeInitData(spApi);
364 memset((
void*)&uiaOpCounts[0], 0,
sizeof(uiaOpCounts));
366 uiaOpCounts[spOp->
uiId]++;
370 fprintf(spOut,
"//\n");
371 fprintf(spOut,
"// This C-language parser code was generated by APG Version 7.0.\n");
372 fprintf(spOut,
"// User modifications may cause unpredictable results.\n");
373 fprintf(spOut,
"//\n");
374 fprintf(spOut,
"%s",s_cpLicenseNotice);
375 fprintf(spOut,
"#include <stdint.h>\n");
376 fprintf(spOut,
"\n");
381 fprintf(spOut,
"};\n");
382 fprintf(spOut,
"\n");
386 fprintf(spOut,
"static const uint8_t ucaPpptTable[%"PRIuMAX
"] = {\n", spApi->
luiPpptTableLength);
388 fprintf(spOut,
"};\n");
389 fprintf(spOut,
"\n");
394 fprintf(spOut,
"static const %s aAcharTable[%"PRIuMAX
"] = {\n",
397 fprintf(spOut,
"};\n");
398 fprintf(spOut,
"\n");
403 fprintf(spOut,
"static const %s aParserInit[%"PRIuMAX
"] = {\n", cpGetType(spHdr->
luiUintMax), spHdr->
luiSizeInInts);
405 fprintf(spOut,
"};\n");
406 fprintf(spOut,
"\n");
409 fprintf(spOut,
"static struct {\n");
410 fprintf(spOut,
" uint32_t uiSizeofAchar;\n");
411 fprintf(spOut,
" uint32_t uiSizeofUint;\n");
412 fprintf(spOut,
" uint32_t uiStringTableLength;\n");
413 fprintf(spOut,
" uint32_t uiAcharTableLength;\n");
414 fprintf(spOut,
" uint32_t uiPpptTableLength;\n");
415 fprintf(spOut,
" uint32_t uiParserInitLength;\n");
416 fprintf(spOut,
" const char* cpStringTable;\n");
417 fprintf(spOut,
" const uint8_t* ucpPpptTable;\n");
418 fprintf(spOut,
" const void* vpAcharTable;\n");
419 fprintf(spOut,
" const void* vpParserInit;\n");
420 fprintf(spOut,
"} s_parser_init = {\n");
427 fprintf(spOut,
" caStringTable,\n");
429 fprintf(spOut,
" ucaPpptTable,\n");
431 fprintf(spOut,
" (const uint8_t*)0,\n");
434 fprintf(spOut,
" (const void*)aAcharTable,\n");
436 fprintf(spOut,
" (const void*)0,\n");
438 fprintf(spOut,
" (const void*)aParserInit\n");
439 fprintf(spOut,
"};\n");
440 fprintf(spOut,
"\n");
441 fprintf(spOut,
"// void pointer to the parser initialization data\n");
442 bNameToCamelCase(
"vp", cpName, caBuf, PATH_MAX);
443 fprintf(spOut,
"void* %sInit = (void*)&s_parser_init;\n", caBuf);
444 fprintf(spOut,
"\n");
447 fprintf(spOut,
"// ALPHABET\n");
448 fprintf(spOut,
"// achar min = %"PRIuMAX
"\n", spHdr->
luiAcharMin);
449 fprintf(spOut,
"// achar max = %"PRIuMAX
"\n", spHdr->
luiAcharMax);
450 fprintf(spOut,
"// aint max = %"PRIuMAX
"\n", spHdr->
luiUintMax);
451 fprintf(spOut,
"\n");
453 fprintf(spOut,
"// PPPT\n");
455 fprintf(spOut,
"// PPPT (not used)\n");
458 fprintf(spOut,
"// map size = %"PRIuMAX
" (bytes)\n", spApi->
luiPpptMapSize);
464 fprintf(spOut,
"\n");
465 fprintf(spOut,
"// GRAMMAR\n");
469 fprintf(spOut,
"// --- ABNF original opcodes\n");
470 fprintf(spOut,
"// ALT = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_ALT]);
471 fprintf(spOut,
"// CAT = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_CAT]);
472 fprintf(spOut,
"// REP = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_REP]);
473 fprintf(spOut,
"// RNM = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_RNM]);
474 fprintf(spOut,
"// TRG = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_TRG]);
475 fprintf(spOut,
"// TLS = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_TLS]);
476 fprintf(spOut,
"// TBS = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_TBS]);
477 fprintf(spOut,
"// --- SABNF opcodes\n");
478 fprintf(spOut,
"// UDT = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_UDT]);
479 fprintf(spOut,
"// AND = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_AND]);
480 fprintf(spOut,
"// NOT = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_NOT]);
481 fprintf(spOut,
"// BKR = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_BKR]);
482 fprintf(spOut,
"// BKA = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_BKA]);
483 fprintf(spOut,
"// BKN = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_BKN]);
484 fprintf(spOut,
"// ABG = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_ABG]);
485 fprintf(spOut,
"// AEN = %"PRIuMAX
"\n", (
luint)uiaOpCounts[
ID_AEN]);
486 fprintf(spOut,
"\n");
489 fprintf(spOut,
"// ;original grammar\n");
507 cpLineBuffer[0] =
'/';
508 cpLineBuffer[1] =
'/';
509 cpLineBuffer[2] =
' ';
514 fprintf(spOut,
"%s\n", cpLineBuffer);
517 fprintf(spOut,
"\n");
520 static void* vpOutputParser(
api* spApi){
521 luint* luipInit = NULL;
525 spApi->
luipInit = luipMakeInitData(spApi);
550 static luint* luipMakeInitData(
api* spApi){
551 luint* luipUdts = NULL;
552 luint* luipRules = NULL;
553 luint* luipOpcodes = NULL;
554 luint* luipInit = NULL;
556 luint lui, luiLen, luiUdtLen, luiRuleLen, luiOpLen;
567 memset((
void*)&uiaOpCounts[0], 0,
sizeof(uiaOpCounts));
590 for(ui = 0; ui < spApi->
uiUdtCount; ui++, spUdt++){
600 for(ui = 0; ui < uiRuleCount; ui++, spRule++){
606 luipRules[luiRuleLen++] = (
luint)spAttrs[ui].bEmpty;
612 for(ui = 0; ui < uiOpcodeCount; ui++, spOp++){
613 luipOpcodes[luiOpLen++] = spOp->
uiId;
614 uiaOpCounts[spOp->
uiId]++;
615 switch (spOp->
uiId) {
625 luipOpcodes[luiOpLen++] = spOp->
luiMin;
626 luipOpcodes[luiOpLen++] = spOp->
luiMax;
701 for(lui = 0; lui < luiUdtLen; lui++){
705 for(lui = 0; lui < luiRuleLen; lui++){
708 for(lui = 0; lui < luiOpLen; lui++){
744 for(lui = 0; lui < luiRuleLen; lui++){
745 luipInit[luiLen++] = luipRules[lui];
747 for(lui = 0; lui < luiUdtLen; lui++){
748 luipInit[luiLen++] = luipUdts[lui];
750 for(lui = 0; lui < luiOpLen; lui++){
751 luipInit[luiLen++] = luipOpcodes[lui];
759 "sanity check - calculated and actual parser initialization lengths not equal");
767 static aint uiLastChar(
char cCharToFind,
const char* cpString) {
770 aint uiLen = (
aint) strlen(cpString);
771 for (; ui < uiLen; ui++) {
772 if (cpString[ui] == cCharToFind) {
778 static abool bSetFileExtension(
const char* cpPathName,
const char* cpExt,
char* cpBuffer,
aint uiBufferLength) {
780 if (cpPathName && cpExt && cpBuffer && uiBufferLength) {
784 if(cpPathName[0] == 0){
788 if((cpPathName[0] == cDot) && (cpPathName[1] == cDot) && (cpPathName[2] == cDot)){
793 uiDot = uiLastChar(cDot, cpPathName);
794 if ((uiDot ==
APG_UNDEFINED) || (uiDot == 0) || (uiDot == 1)) {
795 uiDot = (
aint) strlen(cpPathName);
797 if((uiDot + strlen(cpExt) + 2) > uiBufferLength){
802 for (; ui < uiDot; ui++) {
803 cpBuffer[ui] = cpPathName[ui];
806 cpBuffer[ui++] = cDot;
808 strcat(cpBuffer, cpExt);
816 static abool bGetFileName(
const char* cpPathName,
char* cpBuffer,
aint uiBufferLength) {
818 if (cpPathName && cpBuffer && uiBufferLength) {
821 char cBackSlash =
'\\';
824 if(cpPathName[0] == 0){
828 if((cpPathName[0] == cDot) && (cpPathName[1] == cDot) && (cpPathName[2] == cDot)){
835 uiDivider = uiLastChar(cSlash, cpPathName);
838 uiDivider = uiLastChar(cBackSlash, cpPathName);
845 uiDot = uiLastChar(cDot, cpPathName);
846 if ((uiDot ==
APG_UNDEFINED) || (uiDot == 0) || (uiDot == 1)) {
847 uiDot = (
aint) strlen(cpPathName) + 1;
849 aint uiLen = uiDot - uiDivider;
850 if (uiLen >= uiBufferLength) {
856 for (; ui < uiDot; ui++, uii++) {
857 cpBuffer[uii] = cpPathName[ui];
867 static char cToUpper(
char cChar){
868 if(cChar >= 97 && cChar <= 122){
873 static char cToLower(
char cChar){
874 if(cChar >= 65 && cChar <= 90){
879 static abool bIsLetter(
char cLetter){
880 if(cLetter >= 65 && cLetter <= 90){
883 if(cLetter >= 97 && cLetter <= 122){
886 if(cLetter >= 48 && cLetter <= 57){
891 static abool bNameToCaps(
const char* cpPrefix,
const char* cpName,
char* cpBuffer,
aint uiBufferLength){
893 aint uiPreLen = (
aint)strlen(cpPrefix);
894 aint uiNameLen = (
aint)strlen(cpName);
896 if((uiPreLen + uiNameLen + 1) >= uiBufferLength){
901 for(ui = 0; ui < uiPreLen; ui++){
902 if(bIsLetter(cpPrefix[ui])){
903 cpBuffer[ui] = cToUpper(cpPrefix[ui]);
905 cpBuffer[ui] = cUnder;
908 cpBuffer[ui] = cUnder;
912 for(ui = 0; ui < uiNameLen; ui++, uii++){
913 if(bIsLetter(cpName[ui])){
914 cpBuffer[uii] = cToUpper(cpName[ui]);
916 cpBuffer[uii] = cUnder;
924 static abool bNameToCamelCase(
const char* cpPrefix,
const char* cpName,
char* cpBuffer,
aint uiBufferLength){
925 aint uiPreLen = (
aint)strlen(cpPrefix);
926 aint uiNameLen = (
aint)strlen(cpName);
929 if((uiPreLen + uiNameLen) >= uiBufferLength){
934 for(ui = 0; ui < uiPreLen; ui++){
935 if(!bIsLetter(cpPrefix[ui])){
939 cpBuffer[uiCount] = cToUpper(cpPrefix[ui]);
942 cpBuffer[uiCount] = cToLower(cpPrefix[ui]);
949 for(ui = 0; ui < uiNameLen; ui++){
950 if(!bIsLetter(cpName[ui])){
954 cpBuffer[uiCount] = cToUpper(cpName[ui]);
957 cpBuffer[uiCount] = cToLower(cpName[ui]);
962 cpBuffer[uiCount] = 0;
966 static int iCompRule(
const void* vpL,
const void* vpR) {
974 aint uiLesser = uiLenL < uiLenR ? uiLenL : uiLenR;
977 if (l >= 65 && l <= 90) {
981 if (r >= 65 && r <= 90) {
993 if (uiLenL < uiLenR) {
996 if (uiLenL > uiLenR) {
1002 static int iCompUdt(
const void* vpL,
const void* vpR) {
1010 aint uiLesser = uiLenL < uiLenR ? uiLenL : uiLenR;
1011 while (uiLesser--) {
1013 if (l >= 65 && l <= 90) {
1017 if (r >= 65 && r <= 90) {
1029 if (uiLenL < uiLenR) {
1032 if (uiLenL > uiLenR) {
1037 static void vPrintChars(FILE* spOut,
const uint8_t* ucpChars,
aint uiLength){
1041 for(; ui < uiLength; ui++){
1043 fprintf(spOut,
" %d", ucpChars[ui]);
1045 fprintf(spOut,
",%d", ucpChars[ui]);
1048 if(uiNewLine == uiEnd){
1049 fprintf(spOut,
"\n");
1053 static void vPrintLongs(FILE* spOut,
const luint* luiVals,
aint uiLength){
1056 for(; ui < uiLength; ui++){
1058 if(luiVals[ui] == (
luint)-1){
1059 fprintf(spOut,
" -1");
1061 fprintf(spOut,
" %"PRIuMAX
"", luiVals[ui]);
1064 if(luiVals[ui] == (
luint)-1){
1065 fprintf(spOut,
",-1");
1067 fprintf(spOut,
",%"PRIuMAX
"", luiVals[ui]);
1071 fprintf(spOut,
"\n");
1078 if(luiValue <= 0xFF){
1081 if(luiValue <= 0xFFFF){
1084 if(luiValue <= 0xFFFFFFFF){
1090 static const char* cpGetType(
luint luiValue){
1091 if(luiValue <= 0xFF){
1094 if(luiValue <= 0xFFFF){
1097 if(luiValue <= 0xFFFFFFFF){
1103 static void* vpMakeParserInit(
api* spApi,
luint luiUintMax,
luint* luipData,
aint uiLen){
1104 aint uiSize = uiGetSize(luiUintMax);
1109 for(; ui < uiLen; ui++){
1110 pChars[ui] = (uint8_t)luipData[ui];
1112 }
else if(uiSize == 2){
1115 for(; ui < uiLen; ui++){
1117 pChars[ui] = (uint16_t)luipData[ui];
1119 pChars[ui] = (uint16_t)luipData[ui];
1121 }
else if(uiSize == 4){
1124 for(; ui < uiLen; ui++){
1125 pChars[ui] = (uint32_t)luipData[ui];
1127 }
else if(uiSize == 8){
1130 for(; ui < uiLen; ui++){
1131 pChars[ui] = (uint64_t)luipData[ui];
1136 static void* vpMakeAcharTable(
api* spApi,
luint luiAcharMax,
luint* luipTable,
aint uiLen){
1137 aint uiSize = uiGetSize(luiAcharMax);
1142 for(; ui < uiLen; ui++){
1143 pChars[ui] = (uint8_t)luipTable[ui];
1145 }
else if(uiSize == 2){
1148 for(; ui < uiLen; ui++){
1149 pChars[ui] = (uint16_t)luipTable[ui];
1151 }
else if(uiSize == 4){
1154 for(; ui < uiLen; ui++){
1155 pChars[ui] = (uint32_t)luipTable[ui];
1157 }
else if(uiSize == 8){
1160 for(; ui < uiLen; ui++){
1161 pChars[ui] = (uint64_t)luipTable[ui];
1168 static void vTestNames(){
1170 char* cpaNames[] = {
1171 "header.h",
"../header",
"linuxfolder/linuxname.zip",
"D:\\windowsfolder\\windows.c",
1172 "noext",
"./folder/foldernoext",
".hidden",
".hidden/folder/wayup.java",
"",
".../error"
1175 aint uiBufferSize = 128;
1176 aint uiCount =
sizeof(cpaNames)/
sizeof(
char*);
1178 printf(
"TEST bGetFileName():\n");
1179 printf(
"path name: file name\n");
1180 for(ui = 0; ui < uiCount; ui++){
1181 if(bGetFileName(cpaNames[ui], caBuffer, uiBufferSize)){
1182 printf(
"'%s': '%s'\n", cpaNames[ui], caBuffer);
1184 printf(
"'%s': failed\n", cpaNames[ui]);
1189 char* cpaExt[] = {
"h",
"c",
"",
"longextension",
"zip",
"java",
"cpp",
"hpp",
"empty",
"exterror"};
1191 printf(
"TEST bbSetFileExtension():\n");
1192 printf(
"file name: extension: added\n");
1193 for(ui = 0; ui < uiCount; ui++){
1194 if(bSetFileExtension(cpaNames[ui], cpaExt[ui], caBuffer, uiBufferSize)){
1195 printf(
"'%s': '%s': '%s'\n", cpaNames[ui], cpaExt[ui], caBuffer);
1197 printf(
"'%s': '%s': failed\n", cpaNames[ui], cpaExt[ui]);
1202 char* cpaUppers[] = {
1203 "file-name",
"text-type",
"_type-to-",
"_file_name_",
1204 "UPPER_CASE",
"lower_case",
".hidden.h",
".hidden/folder/wayup.java"
1206 uiCount =
sizeof(cpaUppers)/
sizeof(
char*);
1208 printf(
"TEST bNameToCaps():\n");
1209 printf(
"prefix: name: UPPER\n");
1210 char* cpPrefix =
"my-Pre_Fix";
1211 for(ui = 0; ui < uiCount; ui++){
1212 if(bNameToCaps(cpPrefix, cpaUppers[ui], caBuffer, uiBufferSize)){
1213 printf(
"'%s': '%s': '%s'\n", cpPrefix, cpaUppers[ui], caBuffer);
1215 printf(
"'%s': '%s': failed\n", cpPrefix, cpaUppers[ui]);
1220 char* cpaCamel[] = {
1221 "file-name",
"text-type",
"_type-to-",
"_file_name_",
1222 "UPPER_CASE",
"lower_case",
".hidden.h",
".hidden/folder/wayup.java"
1224 uiCount =
sizeof(cpaCamel)/
sizeof(
char*);
1226 printf(
"TEST bNameToCamelCase():\n");
1227 printf(
"prefix: name: CamelCase\n");
1229 for(ui = 0; ui < uiCount; ui++){
1230 if(bNameToCamelCase(cpPrefix, cpaCamel[ui], caBuffer, uiBufferSize)){
1231 printf(
"'%s': '%s': '%s'\n", cpPrefix, cpaCamel[ui], caBuffer);
1233 printf(
"'%s': '%s': failed\n", cpPrefix, cpaCamel[ui]);