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

This commit is contained in:
ksherlock 2009-12-12 04:51:53 +00:00
parent 72a5a28745
commit 147a16085a
5 changed files with 38 additions and 20 deletions

View File

@ -1,11 +1,11 @@
#include "DateRec.h"
#include "Date.h"
#include <cstring>
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;
@ -27,3 +27,18 @@ DateRec::operator std::time_t() const {
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);
}

View File

@ -1,18 +1,21 @@
#ifndef __DATEREC_H__
#define __DATEREC_H__
#ifndef __PASCAL_DATE_H__
#define __PASCAL_DATE_H__
#include <ctime>
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;

View File

@ -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;

View File

@ -1,7 +1,7 @@
#ifndef __FILE_H__
#define __FILE_H__
#include "DateRec.h"
#include "Date.h"
#include <vector>
@ -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<FileEntry *> _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();

View File

@ -17,7 +17,7 @@
#include <strings.h>
#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)
{