29 typedef unsigned char uchar;
32 static apg_uint uiLongLines(
void* vpMemCtx, BSTR* spMsg,
void* vpTransCtx);
33 static apg_uint uiBinaryCharacters(
void* vpMemctx, BSTR* spMsg,
void* vpTransCtx);
34 static apg_uint uiRepeatingStrings(
void* vpMemCtx, BSTR* spMsg,
void* vpTransCtx);
36 static char* g_cpLineEnd =
"\n";
39 static uchar ucaHexToInt[256] =
41 255,255,255,255,255,255,255,255,255,255,
42 255,255,255,255,255,255,255,255,255,255,
43 255,255,255,255,255,255,255,255,255,255,
44 255,255,255,255,255,255,255,255,255,255,
45 255,255,255,255,255,255,255,255, 0, 1,
46 2, 3, 4, 5, 6, 7, 8, 9,255,255,
47 255,255,255,255,255, 10, 11, 12, 13, 14,
48 15,255,255,255,255,255,255,255,255,255,
49 255,255,255,255,255,255,255,255,255,255,
50 255,255,255,255,255,255,255, 10, 11, 12,
51 13, 14, 15,255,255,255,255,255,255,255,
52 255,255,255,255,255,255,255,255,255,255,
53 255,255,255,255,255,255,255,255,255,255,
54 255,255,255,255,255,255,255,255,255,255,
55 255,255,255,255,255,255,255,255,255,255,
56 255,255,255,255,255,255,255,255,255,255,
57 255,255,255,255,255,255,255,255,255,255,
58 255,255,255,255,255,255,255,255,255,255,
59 255,255,255,255,255,255,255,255,255,255,
60 255,255,255,255,255,255,255,255,255,255,
61 255,255,255,255,255,255,255,255,255,255,
62 255,255,255,255,255,255,255,255,255,255,
63 255,255,255,255,255,255,255,255,255,255,
64 255,255,255,255,255,255,255,255,255,255,
65 255,255,255,255,255,255,255,255,255,255,
66 255,255,255,255,255,255
96 void* vpMsgsInCtx = NULL;
97 void* vpMsgsOutCtx = NULL;
98 void* vpTransOneCtx = NULL;
99 void* vpTransTwoCtx = NULL;
115 sSrc.cpStr = (
char*)
vpMemAlloc(vpMemCtx, sSrc.uiLength + 10);
117 sSrc.uiLength =
uiGetFile(cpInput, (
void*)sSrc.cpStr);
119 sSrc.cpStr[sSrc.uiLength] = 0;
122 vpMsgsInCtx =
vpVecCtor(vpMemCtx,
sizeof(BSTR), 0);
124 vpMsgsOutCtx =
vpVecCtor(vpMemCtx,
sizeof(BSTR), 0);
126 vpTransOneCtx =
vpVecCtor(vpMemCtx,
sizeof(uchar), 0);
128 vpTransTwoCtx =
vpVecCtor(vpMemCtx,
sizeof(uchar), 0);
132 uiBytes = uiLongLines(vpMemCtx, &sSrc, vpTransOneCtx);
136 sTemp.cpStr = (
char*)
vpVecFront(vpTransOneCtx);
138 sTemp.uiLength =
uiVecSize(vpTransOneCtx);
139 uiBytes = uiRepeatingStrings(vpMemCtx, &sTemp, vpTransTwoCtx);
143 sTemp.cpStr = (
char*)
vpVecFront(vpTransTwoCtx);
145 sTemp.uiLength =
uiVecSize(vpTransTwoCtx);
147 uiBytes = uiBinaryCharacters(vpMemCtx, &sTemp, vpTransOneCtx);
152 sTemp.uiLength =
uiVecSize(vpTransOneCtx);
178 static apg_uint uiLongLines(
void* vpMemCtx, BSTR* spMsg,
void* vpTransCtx)
190 static char* cpStartTag =
"<allOneLine>\n";
191 static char* cpEndTag =
"</allOneLine>\n";
192 apg_uint uiStartTagLen = strlen(cpStartTag);
193 apg_uint uiEndTagLen = strlen(cpEndTag);
196 cpPhrasePrev = (
char*)spMsg->cpStr;
197 cpPrefixEnd = cpPhrasePrev + spMsg->uiLength;
201 cpPhraseNext = strstr(cpPhrasePrev, cpStartTag);
202 if(!cpPhraseNext){
break;}
203 cpPhraseEnd = strstr(cpPhraseNext, cpEndTag);
207 uiPrefixLen = (
apg_uint)(cpPhraseNext - cpPhrasePrev);
210 vpTest =
vpVecPushn(vpTransCtx, (
void*)cpPhrasePrev, uiPrefixLen);
215 cSave = *cpPhraseEnd;
217 cpPhraseNext += uiStartTagLen;
218 cpLineBeg = cpPhraseNext;
221 cpLineEnd = strstr(cpLineBeg, g_cpLineEnd);
222 if(!cpLineEnd){
break;}
223 uiPrefixLen = (
apg_uint)(cpLineEnd - cpLineBeg);
226 vpTest =
vpVecPushn(vpTransCtx, (
void*)cpLineBeg, uiPrefixLen);
230 cpLineBeg = cpLineEnd + strlen(g_cpLineEnd);
232 *cpPhraseEnd = cSave;
235 vpTest =
vpVecPushn(vpTransCtx, (
void*)g_cpLineEnd, strlen(g_cpLineEnd));
239 cpPhrasePrev = cpPhraseEnd + uiEndTagLen;
243 uiPrefixLen = (
apg_uint)(cpPrefixEnd - cpPhrasePrev);
246 vpTest =
vpVecPushn(vpTransCtx, (
void*)cpPhrasePrev, uiPrefixLen);
269 static apg_uint uiRepeatingStrings(
void* vpMemCtx, BSTR* spMsg,
void* vpTransCtx)
282 static char* cpStartTag =
"<repeat count=";
283 static char* cpEndTag =
"</repeat>";
284 apg_uint uiStartTagLen = strlen(cpStartTag);
285 apg_uint uiEndTagLen = strlen(cpEndTag);
288 cpPhrasePrev = (
char*)spMsg->cpStr;
289 cpPrefixEnd = cpPhrasePrev + spMsg->uiLength;
293 cpPhraseNext = strstr(cpPhrasePrev, cpStartTag);
294 if(!cpPhraseNext){
break;}
295 cpPhraseEnd = strstr(cpPhraseNext, cpEndTag);
299 uiPrefixLen = (
apg_uint)(cpPhraseNext - cpPhrasePrev);
302 vpTest =
vpVecPushn(vpTransCtx, (
void*)cpPhrasePrev, uiPrefixLen);
307 cpRepeat = strstr(cpPhraseNext,
">");
311 uiCount = (
apg_uint)atol(cpPhraseNext + uiStartTagLen);
318 cSave = *cpPhraseEnd;
320 uiPrefixLen = (
apg_uint)strlen(cpRepeat);
321 for(uiIndex = 0; uiIndex < uiCount; ++uiIndex)
323 vpTest =
vpVecPushn(vpTransCtx, (
void*)cpRepeat, uiPrefixLen);
326 *cpPhraseEnd = cSave;
329 cpPhrasePrev = cpPhraseEnd + uiEndTagLen;
333 uiPrefixLen = (
apg_uint)(cpPrefixEnd - cpPhrasePrev);
336 vpTest =
vpVecPushn(vpTransCtx, (
void*)cpPhrasePrev, uiPrefixLen);
359 static apg_uint uiBinaryCharacters(
void* vpMemCtx, BSTR* spMsg,
void* vpTransCtx)
368 static char* cpStartTag =
"<hex>";
369 static char* cpEndTag =
"</hex>";
370 apg_uint uiStartTagLen = strlen(cpStartTag);
371 apg_uint uiEndTagLen = strlen(cpEndTag);
374 cpPhrasePrev = (
char*)spMsg->cpStr;
375 cpPrefixEnd = cpPhrasePrev + spMsg->uiLength;
379 cpPhraseNext = strstr(cpPhrasePrev, cpStartTag);
380 if(!cpPhraseNext){
break;}
381 cpPhraseEnd = strstr(cpPhraseNext, cpEndTag);
385 uiPrefixLen = (
apg_uint)(cpPhraseNext - cpPhrasePrev);
388 vpTest =
vpVecPushn(vpTransCtx, (
void*)cpPhrasePrev, uiPrefixLen);
393 cpPhraseNext += uiStartTagLen;
400 if(cpPhraseNext == cpPhraseEnd){
break;}
401 if(*cpPhraseNext == CR || *cpPhraseNext == LF)
409 ucDigit1 = ucaHexToInt[(uchar)*cpPhraseNext];
414 MASSERT(cpPhraseNext < cpPhraseEnd);
415 ucDigit2 = ucaHexToInt[(uchar)*cpPhraseNext];
419 ucBinary = (ucDigit1 << 4) + ucDigit2;
420 vpTest =
vpVecPush(vpTransCtx, (
void*)&ucBinary);
427 cpPhrasePrev = cpPhraseEnd + uiEndTagLen;
431 uiPrefixLen = (
apg_uint)(cpPrefixEnd - cpPhrasePrev);
434 vpTest =
vpVecPushn(vpTransCtx, (
void*)cpPhrasePrev, uiPrefixLen);