| 1497 | } |
| 1498 | |
| 1499 | void bFile::writeChunks(FILE *fp, bool fixupPointers) |
| 1500 | { |
| 1501 | bParse::bDNA *fileDna = mFileDNA ? mFileDNA : mMemoryDNA; |
| 1502 | |
| 1503 | for (int i = 0; i < m_chunks.size(); i++) |
| 1504 | { |
| 1505 | bChunkInd &dataChunk = m_chunks.at(i); |
| 1506 | |
| 1507 | // Ouch! need to rebuild the struct |
| 1508 | short *oldStruct, *curStruct; |
| 1509 | char *oldType, *newType; |
| 1510 | int curLen, reverseOld; |
| 1511 | |
| 1512 | oldStruct = fileDna->getStruct(dataChunk.dna_nr); |
| 1513 | oldType = fileDna->getType(oldStruct[0]); |
| 1514 | //int oldLen = fileDna->getLength(oldStruct[0]); |
| 1515 | ///don't try to convert Link block data, just memcpy it. Other data can be converted. |
| 1516 | reverseOld = mMemoryDNA->getReverseType(oldType); |
| 1517 | |
| 1518 | if ((reverseOld != -1)) |
| 1519 | { |
| 1520 | // make sure it's here |
| 1521 | //assert(reverseOld!= -1 && "getReverseType() returned -1, struct required!"); |
| 1522 | // |
| 1523 | curStruct = mMemoryDNA->getStruct(reverseOld); |
| 1524 | newType = mMemoryDNA->getType(curStruct[0]); |
| 1525 | // make sure it's the same |
| 1526 | assert((strcmp(oldType, newType) == 0) && "internal error, struct mismatch!"); |
| 1527 | |
| 1528 | curLen = mMemoryDNA->getLength(curStruct[0]); |
| 1529 | dataChunk.dna_nr = reverseOld; |
| 1530 | if (strcmp("Link", oldType) != 0) |
| 1531 | { |
| 1532 | dataChunk.len = curLen * dataChunk.nr; |
| 1533 | } |
| 1534 | else |
| 1535 | { |
| 1536 | // printf("keep length of link = %d\n",dataChunk.len); |
| 1537 | } |
| 1538 | |
| 1539 | //write the structure header |
| 1540 | fwrite(&dataChunk, sizeof(bChunkInd), 1, fp); |
| 1541 | |
| 1542 | short int *curStruct1; |
| 1543 | curStruct1 = mMemoryDNA->getStruct(dataChunk.dna_nr); |
| 1544 | assert(curStruct1 == curStruct); |
| 1545 | |
| 1546 | char *cur = fixupPointers ? (char *)findLibPointer(dataChunk.oldPtr) : (char *)dataChunk.oldPtr; |
| 1547 | |
| 1548 | //write the actual contents of the structure(s) |
| 1549 | fwrite(cur, dataChunk.len, 1, fp); |
| 1550 | } |
| 1551 | else |
| 1552 | { |
| 1553 | printf("serious error, struct mismatch: don't write\n"); |
| 1554 | } |
| 1555 | } |
| 1556 | } |