| 1464 | } |
| 1465 | |
| 1466 | void bFile::writeChunks(FILE *fp, bool fixupPointers) |
| 1467 | { |
| 1468 | bParse::bDNA *fileDna = mFileDNA ? mFileDNA : mMemoryDNA; |
| 1469 | |
| 1470 | for (int i = 0; i < m_chunks.size(); i++) |
| 1471 | { |
| 1472 | bChunkInd &dataChunk = m_chunks.at(i); |
| 1473 | |
| 1474 | // Ouch! need to rebuild the struct |
| 1475 | short *oldStruct, *curStruct; |
| 1476 | char *oldType, *newType; |
| 1477 | int oldLen, curLen, reverseOld; |
| 1478 | |
| 1479 | oldStruct = fileDna->getStruct(dataChunk.dna_nr); |
| 1480 | oldType = fileDna->getType(oldStruct[0]); |
| 1481 | oldLen = fileDna->getLength(oldStruct[0]); |
| 1482 | ///don't try to convert Link block data, just memcpy it. Other data can be converted. |
| 1483 | reverseOld = mMemoryDNA->getReverseType(oldType); |
| 1484 | |
| 1485 | if ((reverseOld != -1)) |
| 1486 | { |
| 1487 | // make sure it's here |
| 1488 | //assert(reverseOld!= -1 && "getReverseType() returned -1, struct required!"); |
| 1489 | // |
| 1490 | curStruct = mMemoryDNA->getStruct(reverseOld); |
| 1491 | newType = mMemoryDNA->getType(curStruct[0]); |
| 1492 | // make sure it's the same |
| 1493 | assert((strcmp(oldType, newType) == 0) && "internal error, struct mismatch!"); |
| 1494 | |
| 1495 | curLen = mMemoryDNA->getLength(curStruct[0]); |
| 1496 | dataChunk.dna_nr = reverseOld; |
| 1497 | if (strcmp("Link", oldType) != 0) |
| 1498 | { |
| 1499 | dataChunk.len = curLen * dataChunk.nr; |
| 1500 | } |
| 1501 | else |
| 1502 | { |
| 1503 | // printf("keep length of link = %d\n",dataChunk.len); |
| 1504 | } |
| 1505 | |
| 1506 | //write the structure header |
| 1507 | fwrite(&dataChunk, sizeof(bChunkInd), 1, fp); |
| 1508 | |
| 1509 | short int *curStruct1; |
| 1510 | curStruct1 = mMemoryDNA->getStruct(dataChunk.dna_nr); |
| 1511 | assert(curStruct1 == curStruct); |
| 1512 | |
| 1513 | char *cur = fixupPointers ? (char *)findLibPointer(dataChunk.oldPtr) : (char *)dataChunk.oldPtr; |
| 1514 | |
| 1515 | //write the actual contents of the structure(s) |
| 1516 | fwrite(cur, dataChunk.len, 1, fp); |
| 1517 | } |
| 1518 | else |
| 1519 | { |
| 1520 | printf("serious error, struct mismatch: don't write\n"); |
| 1521 | } |
| 1522 | } |
| 1523 | } |