mirror of
https://github.com/nzeemin/ukncbtl-utils.git
synced 2025-04-18 06:04:02 +03:00
rt11dsk: -trimz option used to trim trailing zeroes in the last block of extracted file
This commit is contained in:
parent
ba70ca7892
commit
f1adc9b075
@ -28,5 +28,6 @@ Options:
|
||||
* `-oXXXXX` — Set start offset to XXXXX; 0 by default (offsets 128 and 256 are detected by word 000240)
|
||||
* `-ms0515` — Sector interleaving used for MS0515 disks
|
||||
* `-hd32` — Hard disk with 32 MB partitions
|
||||
* `-trimz` — (Extract file commands) Trim trailing zeroes in the last block
|
||||
|
||||
NOTE: '-' character used as an option sign under Linux/Mac, '/' character under Windows.
|
||||
|
@ -587,6 +587,7 @@ struct d_save_one
|
||||
{
|
||||
CHostFile* hf_p;
|
||||
CDiskImage* di_p;
|
||||
bool okTrimZeroes;
|
||||
};
|
||||
|
||||
EIterOp cb_save_one(CVolumeCatalogEntry* pEntry, void* opaque)
|
||||
@ -639,8 +640,22 @@ EIterOp cb_save_one(CVolumeCatalogEntry* pEntry, void* opaque)
|
||||
for (uint16_t blockpos = 0; blockpos < filelength; blockpos++)
|
||||
{
|
||||
uint8_t* pData = (uint8_t*) r->di_p->GetBlock(filestart + blockpos);
|
||||
size_t nBytesWritten = ::fwrite(pData, sizeof(uint8_t), RT11_BLOCK_SIZE, foutput);
|
||||
if (nBytesWritten < RT11_BLOCK_SIZE)
|
||||
|
||||
size_t sizeToSave = RT11_BLOCK_SIZE;
|
||||
if (r->okTrimZeroes && blockpos == filelength - 1) // Need to trim zeroes in the last block
|
||||
{
|
||||
while (sizeToSave > 0)
|
||||
{
|
||||
if (pData[sizeToSave - 1] != 0)
|
||||
break;
|
||||
sizeToSave--;
|
||||
}
|
||||
if (sizeToSave == 0)
|
||||
sizeToSave = RT11_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
size_t nBytesWritten = ::fwrite(pData, sizeof(uint8_t), sizeToSave, foutput);
|
||||
if (nBytesWritten < sizeToSave)
|
||||
{
|
||||
fprintf(stderr, "Failed to write output file\n"); //TODO: Show error number
|
||||
::fclose(foutput);
|
||||
@ -648,16 +663,18 @@ EIterOp cb_save_one(CVolumeCatalogEntry* pEntry, void* opaque)
|
||||
return IT_STOP;
|
||||
}
|
||||
}
|
||||
|
||||
::fclose(foutput);
|
||||
return IT_STOP;
|
||||
}
|
||||
|
||||
void CDiskImage::SaveEntryToExternalFile(const char * sFileName)
|
||||
void CDiskImage::SaveEntryToExternalFile(const char * sFileName, bool trimZeroes)
|
||||
{
|
||||
CHostFile hf(sFileName);
|
||||
struct d_save_one res;
|
||||
struct d_save_one res;
|
||||
res.hf_p = &hf;
|
||||
res.di_p = this;
|
||||
res.okTrimZeroes = trimZeroes;
|
||||
|
||||
if (!hf.ParseFileName63())
|
||||
return; // error
|
||||
|
@ -156,7 +156,7 @@ public:
|
||||
void FlushChanges();
|
||||
void DecodeImageCatalog();
|
||||
void UpdateCatalogSegment(int segno);
|
||||
void SaveEntryToExternalFile(const char * sFileName);
|
||||
void SaveEntryToExternalFile(const char * sFileName, bool trimZeroes);
|
||||
void SaveAllEntriesToExternalFiles();
|
||||
void AddFileToImage(const char * sFileName);
|
||||
void DeleteFileFromImage(const char * sFileName);
|
||||
|
@ -58,6 +58,7 @@ int g_nPartition = -1;
|
||||
long g_lStartOffset = 0;
|
||||
bool g_okInterleaving = false;
|
||||
bool g_okHard32M = false;
|
||||
bool g_okTrimZeroes = false;
|
||||
|
||||
enum CommandRequirements
|
||||
{
|
||||
@ -131,6 +132,7 @@ void PrintUsage()
|
||||
" " OPTIONSTR "oXXXXX Set start offset to XXXXX; 0 by default (offsets 128 and 256 are detected by word 000240)\n"
|
||||
" " OPTIONSTR "ms0515 Sector interleaving used for MS0515 disks\n"
|
||||
" " OPTIONSTR "hd32 Hard disk with 32 MB partitions\n"
|
||||
" " OPTIONSTR "trimz (Extract file commands) Trim trailing zeroes in the last block\n"
|
||||
);
|
||||
}
|
||||
|
||||
@ -157,6 +159,10 @@ bool ParseCommandLine(int argc, char * argv[])
|
||||
{
|
||||
g_okHard32M = true;
|
||||
}
|
||||
else if (strcmp(arg + 1, "trimz") == 0)
|
||||
{
|
||||
g_okTrimZeroes = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown option: %s\n", arg);
|
||||
@ -285,7 +291,7 @@ void DoDiskList()
|
||||
void DoDiskExtractFile()
|
||||
{
|
||||
g_diskimage.DecodeImageCatalog();
|
||||
g_diskimage.SaveEntryToExternalFile(g_sFileName);
|
||||
g_diskimage.SaveEntryToExternalFile(g_sFileName, g_okTrimZeroes);
|
||||
}
|
||||
|
||||
void DoDiskExtractAllFiles()
|
||||
@ -388,7 +394,7 @@ void DoHardPartitionExtractFile()
|
||||
}
|
||||
|
||||
g_diskimage.DecodeImageCatalog();
|
||||
g_diskimage.SaveEntryToExternalFile(g_sFileName);
|
||||
g_diskimage.SaveEntryToExternalFile(g_sFileName, g_okTrimZeroes);
|
||||
}
|
||||
|
||||
void DoHardPartitionAddFile()
|
||||
|
Loading…
x
Reference in New Issue
Block a user