Beispiel #1
0
int main()
{
    FILE *rFile = fopen("Parsefile.txt", "w");
    FILE *bFile = fopen("Samplefile.bin", "rb");
    field fd = parseFieldStructure();

    fseek (bFile, 0, SEEK_END);
    long fSize = ftell (bFile);
    fseek (bFile, 0, SEEK_SET);
	BYTE *buffer = new BYTE[fSize];
	fread(buffer, fSize, 1, bFile);

	int numRec = fSize / fd.totBytes;
    int fieldIdx = 0, fieldIncIdx = 0, intPosIdx = 0, strIdx = 0;
    int fInt = 0;
    char fStr[255];
    bool typeInt = false;

    XML* xml = new XML();
	xml->LoadText("<data></data>");
    XMLElement* root = xml->GetRootElement();
	XMLElement* record[numRec];
	XMLElement* fields[115 * numRec];

    for (int recIdx = 0; recIdx < numRec; recIdx++) {
        record[recIdx] = new XMLElement(root, "record");
        root->InsertElement(recIdx, record[recIdx]);
        bytesToIntger(fStr, recIdx + 1);
        record[recIdx]->AddVariable("id", fStr);

        for (int xmlIdx = 115 * recIdx; xmlIdx < (1 + recIdx) * 115; xmlIdx++) {
            fields[xmlIdx] = new XMLElement(record[recIdx], "field");
            record[recIdx]->InsertElement(xmlIdx, fields[xmlIdx]);
        }
    }

    int xmlIdx = 0;

    for (int idx = 0; idx <= fSize - 1; idx++)
    {
        if(idx >= fieldIncIdx) {

            if(typeInt) {
                bytesToIntger(fStr, fInt);
            } else {
                bytesToStr(fStr, strIdx);
            }

            if(fieldIdx > 0) {
                fields[xmlIdx - 1]->AddVariable(fd.name[fieldIdx - 1], fStr);
            }
            else if(idx != 0) {
                fields[xmlIdx - 1]->AddVariable(fd.name[114], fStr);
            }

            xmlIdx++;
            typeInt = fd.type[fieldIdx] == 'I';

            fprintf(rFile, "%s", fStr);
            fprintf(rFile, "\t");

            fieldIncIdx += fd.bytes[fieldIdx];
            fieldIdx = fieldIdx < 114 ? fieldIdx + 1 : 0;
            if (fieldIdx == 0)
                fprintf(rFile, "\n");
        }

        if(buffer[idx] == 0xe9) {
            fieldIncIdx++;
        } else if(typeInt) {
            fInt <<= 8;
            fInt = (fInt | buffer[idx]);
        } else if (buffer[idx] > 0x1f && buffer[idx] < 0x7f) {
            fStr[strIdx++] = buffer[idx];
        }
    }

    xml->Save("XMLfile.xml");
    fclose(rFile);
    fclose(bFile);

    /* And now we can search for a attrinute
       like subscriber_no in our xml-file. */

    OpenXML("XMLfile.xml", "subscriber_no");

    return 0;
}