diff --git a/auto.h b/auto.h index b9dd6fd..d971b68 100644 --- a/auto.h +++ b/auto.h @@ -17,6 +17,13 @@ public: operator T*() const { return _t; } T& operator[](int index) { return _t[index]; } + void reset(T *t) + { + if (t == _t) return; + if (_t) delete[] _t; + _t = t; + } + private: T *_t; }; diff --git a/pascal/File.cpp b/pascal/File.cpp index ae8ff86..43c5e07 100644 --- a/pascal/File.cpp +++ b/pascal/File.cpp @@ -48,7 +48,7 @@ VolumeEntry::VolumeEntry() _fileNameLength = 0; std::memset(_fileName, 0, 8); _lastVolumeBlock = 0; - _numberOfFiles = 0; + _fileCount = 0; _accessTime = 0; setInode(1); @@ -65,7 +65,7 @@ VolumeEntry::VolumeEntry(ProFUSE::BlockDevice *device) device->read(2, buffer.get()); - init(tmp); + init(buffer.get()); // todo -- verify reasonable values. blockCount = blocks(); @@ -84,7 +84,7 @@ VolumeEntry::VolumeEntry(ProFUSE::BlockDevice *device) try { - for (unsigned i = 1; i < _numberFiles; ++i) + for (unsigned i = 1; i < _fileCount; ++i) { std::auto_ptr child; @@ -96,7 +96,7 @@ VolumeEntry::VolumeEntry(ProFUSE::BlockDevice *device) } catch (...) { - std::vectoriterator iter; + std::vector::iterator iter; for(iter = _files.begin(); iter != _files.end(); ++iter) { if (*iter) delete *iter; @@ -109,7 +109,7 @@ VolumeEntry::VolumeEntry(ProFUSE::BlockDevice *device) VolumeEntry::~VolumeEntry() { - std::vectoriterator iter; + std::vector::iterator iter; for(iter = _files.begin(); iter != _files.end(); ++iter) { if (*iter) delete *iter; @@ -128,9 +128,9 @@ void VolumeEntry::init(void *vp) std::memcpy(_fileName, 7 + (uint8_t *)vp, _fileNameLength); _lastVolumeBlock = Read16(vp, 0x0e); - _numberFile = Read16(vp, 0x10); + _fileCount = Read16(vp, 0x10); _accessTime = Read16(vp, 0x12); - _bootDate = DateRec(Read16(vp, 0x14); + _lastBoot = DateRec(Read16(vp, 0x14)); setInode(1); _inodeGenerator = 1; @@ -139,10 +139,10 @@ void VolumeEntry::init(void *vp) FileEntry *VolumeEntry::fileAtIndex(unsigned i) const { - return i < _files.length() ? _files[i] : NULL; + return i < _files.size() ? _files[i] : NULL; } - +#if 0 #pragma mark - #pragma mark FileEntry @@ -356,4 +356,6 @@ void TextFile::init() _fileSize += size; _pageSize.push_back(size); } -} \ No newline at end of file +} + +#endif diff --git a/pascal/File.h b/pascal/File.h index ab2edfc..c1d7f3c 100644 --- a/pascal/File.h +++ b/pascal/File.h @@ -7,7 +7,7 @@ namespace ProFUSE { class BlockDevice; -}; +} namespace Pascal { @@ -19,9 +19,10 @@ public: virtual ~Entry(); + unsigned blocks() const { return _firstBlock - _lastBlock; } + unsigned firstBlock() const { return _firstBlock; } unsigned lastBlock() const { return _lastBlock; } - unsigned blocks() const { return _firstBlock - lastBlock; } unsigned fileKind() const { return _fileKind; } @@ -39,7 +40,7 @@ protected: unsigned _fileKind; unsigned _inode; -} +}; class VolumeEntry : public Entry { @@ -50,18 +51,21 @@ public: virtual ~VolumeEntry(); const char *name() const { return _fileName; } - unsigned fileCount() const { return _numberFiles; } + unsigned fileCount() const { return _fileCount; } Pascal::DateRec lastBoot() const { return _lastBoot; } FileEntry *fileAtIndex(unsigned i) const; private: - + VolumeEntry(); + + void init(void *); + unsigned _fileNameLength; char _fileName[8]; unsigned _lastVolumeBlock; - unsigned _numberFiles; + unsigned _fileCount; unsigned _accessTime; Pascal::DateRec _lastBoot;