git-svn-id: https://profuse.googlecode.com/svn/branches/v2@146 aa027e90-d47c-11dd-86d7-074df07e0730

This commit is contained in:
ksherlock 2009-12-11 15:03:04 +00:00
parent 8d93501d0d
commit 6bbeb86da3

View File

@ -7,10 +7,14 @@
#include <cstdio> #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <unistd.h> #include <unistd.h>
#include <strings.h>
#include "File.h" #include "File.h"
#include "DateRec.h" #include "DateRec.h"
@ -64,7 +68,7 @@ void printUnusedRecord(unsigned block, unsigned size)
std::printf("< UNUSED > %4u %4u\n", size, block); std::printf("< UNUSED > %4u %4u\n", size, block);
} }
void list(Pascal::VolumeEntry *volume, bool extended) int list(Pascal::VolumeEntry *volume, bool extended)
{ {
unsigned fileCount = volume->fileCount(); unsigned fileCount = volume->fileCount();
unsigned used = volume->blocks(); unsigned used = volume->blocks();
@ -125,7 +129,9 @@ void list(Pascal::VolumeEntry *volume, bool extended)
if (extended && (lastBlock != volumeSize)) if (extended && (lastBlock != volumeSize))
{ {
printUnusedRecord(lastBlock, volumeSize - lastBlock); unsigned size = volumeSize - lastBlock;
max = std::max(max, size);
printUnusedRecord(lastBlock, size);
} }
@ -140,6 +146,7 @@ void list(Pascal::VolumeEntry *volume, bool extended)
max max
); );
return 0;
} }
@ -148,7 +155,7 @@ void usage()
{ {
std::printf( std::printf(
"Pascal File Manager v 0.0\n\n" "Pascal File Manager v 0.0\n\n"
"Usage: fileman [-h] [-f format] action diskimage\n" "Usage: fileman [-h] [-f format] diskimage action\n"
"Options:\n" "Options:\n"
" -h Show usage information.\n" " -h Show usage information.\n"
" -f format Specify disk format. Valid values are:\n" " -f format Specify disk format. Valid values are:\n"
@ -166,11 +173,13 @@ int main(int argc, char **argv)
{ {
std::auto_ptr<Pascal::VolumeEntry> volume; std::auto_ptr<Pascal::VolumeEntry> volume;
std::auto_ptr<ProFUSE::BlockDevice> device; std::auto_ptr<ProFUSE::BlockDevice> device;
int c;
std::string format; std::string format;
while ((int c = ::getopt(argc, argv, "f:h")) != -1) while ((c = ::getopt(argc, argv, "f:h")) != -1)
{ {
std::printf("%c\n", c);
switch(c) switch(c)
{ {
case 'f': case 'f':
@ -180,23 +189,35 @@ int main(int argc, char **argv)
case 'h': case 'h':
case '?': case '?':
usage(); usage();
exit(); std::exit(0);
} }
} }
argc -= optind;
argv += optind;
const char *file = argv[1]; if (argc != 2)
{
usage();
std::exit(1);
}
const char *file = argv[0];
const char *action = argv[1];
try { try {
device.reset( new ProFUSE::DOSOrderDiskImage(file, true)); device.reset( new ProFUSE::DOSOrderDiskImage(file, true));
volume.reset( new Pascal::VolumeEntry(device.get())); volume.reset( new Pascal::VolumeEntry(device.get()));
device.release(); device.release();
list(volume.get(), true);
if (!::strcasecmp("E", action)) return list(volume.get(), true);
if (!::strcasecmp("L", action)) return list(volume.get(), false);
} }
catch (ProFUSE::Exception& e) catch (ProFUSE::Exception& e)
{ {