From 147a16085a1303d291a9152fd01eb31cdf3c2826 Mon Sep 17 00:00:00 2001 From: ksherlock Date: Sat, 12 Dec 2009 04:51:53 +0000 Subject: [PATCH] git-svn-id: https://profuse.googlecode.com/svn/branches/v2@151 aa027e90-d47c-11dd-86d7-074df07e0730 --- pascal/Date.cpp | 21 ++++++++++++++++++--- pascal/Date.h | 19 +++++++++++-------- pascal/File.cpp | 4 ++-- pascal/File.h | 10 +++++----- pascal/FileMan.cpp | 4 ++-- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/pascal/Date.cpp b/pascal/Date.cpp index 7a8bd7d..6efcb0d 100644 --- a/pascal/Date.cpp +++ b/pascal/Date.cpp @@ -1,11 +1,11 @@ -#include "DateRec.h" +#include "Date.h" #include using namespace Pascal; -DateRec::DateRec(unsigned val) +Date::Date(unsigned val) { // yyyy yyym mmmm dddd _month = val & 0xf; @@ -13,7 +13,7 @@ DateRec::DateRec(unsigned val) _year = (val >> 9) & 0x7f; } -DateRec::operator std::time_t() const { +Date::operator std::time_t() const { struct tm tm; if (_day == 0 || _month == 0) return (std::time_t)-1; @@ -26,4 +26,19 @@ DateRec::operator std::time_t() const { tm.tm_isdst = -1; return std::mktime(&tm); +} + +Date::operator unsigned() const { + // year must be 0 .. 127 + return (_year << 9) | (_day << 4) | _month; +} + +Date Date::Today() +{ + struct tm tm; + std::time_t t = std::time(NULL); + + ::localtime_r(&t, &tm); + + return Date(tm.tm_year, tm.tm_month, tm.tm_mday); } \ No newline at end of file diff --git a/pascal/Date.h b/pascal/Date.h index 8f9e2e4..510aa73 100644 --- a/pascal/Date.h +++ b/pascal/Date.h @@ -1,18 +1,21 @@ -#ifndef __DATEREC_H__ -#define __DATEREC_H__ +#ifndef __PASCAL_DATE_H__ +#define __PASCAL_DATE_H__ #include namespace Pascal { -class DateRec { +class Date { public: - DateRec(); - DateRec(unsigned yy, unsigned mm, unsigned dd); - DateRec(unsigned); + static Date Today(); + + Date(); + Date(unsigned yy, unsigned mm, unsigned dd); + Date(unsigned); operator std::time_t() const; + operator unsigned() const; unsigned month() const { return _month; } unsigned day() const { return _day; } @@ -25,14 +28,14 @@ private: }; -inline DateRec::DateRec() +inline Date::Date() { _year = 0; _month = 0; _day = 0; } -inline DateRec::DateRec(unsigned yy, unsigned mm, unsigned dd) +inline Date::Date(unsigned yy, unsigned mm, unsigned dd) { _year = yy; _month = mm; diff --git a/pascal/File.cpp b/pascal/File.cpp index efc3b7c..7e73cda 100644 --- a/pascal/File.cpp +++ b/pascal/File.cpp @@ -152,7 +152,7 @@ void VolumeEntry::init(void *vp) _lastVolumeBlock = Read16(vp, 0x0e); _fileCount = Read16(vp, 0x10); _accessTime = Read16(vp, 0x12); - _lastBoot = DateRec(Read16(vp, 0x14)); + _lastBoot = Date(Read16(vp, 0x14)); setInode(1); _inodeGenerator = 1; @@ -196,7 +196,7 @@ FileEntry::FileEntry(void *vp) : std::memset(_fileName, 0, 16); std::memcpy(_fileName, 0x07 + (uint8_t *)vp, _fileNameLength); _lastByte = Read16(vp, 0x16); - _modification = DateRec(Read16(vp, 0x18)); + _modification = Date(Read16(vp, 0x18)); _fileSize = 0; _pageSize = NULL; diff --git a/pascal/File.h b/pascal/File.h index 297986b..66c2c8b 100644 --- a/pascal/File.h +++ b/pascal/File.h @@ -1,7 +1,7 @@ #ifndef __FILE_H__ #define __FILE_H__ -#include "DateRec.h" +#include "Date.h" #include @@ -77,7 +77,7 @@ public: unsigned fileCount() const { return _fileCount; } unsigned volumeBlocks() const { return _lastVolumeBlock; } - Pascal::DateRec lastBoot() const { return _lastBoot; } + Pascal::Date lastBoot() const { return _lastBoot; } FileEntry *fileAtIndex(unsigned i) const; @@ -98,7 +98,7 @@ private: unsigned _lastVolumeBlock; unsigned _fileCount; unsigned _accessTime; - Pascal::DateRec _lastBoot; + Pascal::Date _lastBoot; std::vector _files; unsigned _inodeGenerator; @@ -121,7 +121,7 @@ class FileEntry : public Entry { int read(uint8_t *buffer, unsigned size, unsigned offset); const char *name() const { return _fileName; } - DateRec modification() const { return _modification; } + Date modification() const { return _modification; } protected: @@ -131,7 +131,7 @@ class FileEntry : public Entry { char _fileName[16]; unsigned _lastByte; - DateRec _modification; + Date _modification; // non-text files unsigned dataFileSize(); diff --git a/pascal/FileMan.cpp b/pascal/FileMan.cpp index a6a66a2..f06ca52 100644 --- a/pascal/FileMan.cpp +++ b/pascal/FileMan.cpp @@ -17,7 +17,7 @@ #include #include "File.h" -#include "DateRec.h" +#include "Date.h" #include "../BlockDevice.h" #include "../DiskCopy42Image.h" @@ -110,7 +110,7 @@ void printUnusedEntry(unsigned block, unsigned size) void printFileEntry(Pascal::FileEntry *e, bool extended) { - Pascal::DateRec dt = e->modification(); + Pascal::Date dt = e->modification(); if (extended) {