Formatting pass

This commit is contained in:
Phillip Stephens 2016-09-05 13:56:09 -07:00
parent d0791ebd21
commit b082a92fb2
13 changed files with 268 additions and 289 deletions

29
.clang-format Normal file
View File

@ -0,0 +1,29 @@
---
IndentWidth: 4
ColumnLimit: 120
UseTab: Never
---
Language: Cpp
DerivePointerAlignment: false
PointerAlignment: Left
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
BreakBeforeBraces: Allman
IndentCaseLabels: false
AllowShortBlocksOnASingleLine: true
AlignOperands: true
AlignTrailingComments: true
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BreakConstructorInitializersBeforeComma: true
AlwaysBreakAfterReturnType: None
AlwaysBreakAfterDefinitionReturnType: None
AllowShortFunctionsOnASingleLine: All
Cpp11BracedListStyle: true
NamespaceIndentation: None
BinPackArguments: true
BinPackParameters: true
SortIncludes: false
AccessModifierOffset: -4
ConstructorInitializerIndentWidth: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: true

View File

@ -9,8 +9,7 @@ class BlockAllocationTable
{ {
friend class Card; friend class Card;
#pragma pack(push, 4) #pragma pack(push, 4)
union union {
{
struct struct
{ {
uint16_t m_checksum; uint16_t m_checksum;

View File

@ -22,8 +22,7 @@ public:
class Card class Card
{ {
#pragma pack(push, 4) #pragma pack(push, 4)
union union {
{
struct struct
{ {
uint8_t m_serial[12]; uint8_t m_serial[12];
@ -63,6 +62,7 @@ class Card
void _updateDirAndBat(); void _updateDirAndBat();
void _updateChecksum(); void _updateChecksum();
File* _fileFromHandle(const std::unique_ptr<IFileHandle>& fh) const; File* _fileFromHandle(const std::unique_ptr<IFileHandle>& fh) const;
public: public:
Card(); Card();
/** /**
@ -355,7 +355,8 @@ public:
void format(EDeviceId deviceId, ECardSize size = ECardSize::Card2043Mb, EEncoding encoding = EEncoding::ASCII); void format(EDeviceId deviceId, ECardSize size = ECardSize::Card2043Mb, EEncoding encoding = EEncoding::ASCII);
/** /**
* @brief Returns the size of the file in Megabits from a file on disk, useful for determining filesize ahead of time. * @brief Returns the size of the file in Megabits from a file on disk, useful for determining filesize ahead of
* time.
* @return Size of file in Megabits * @return Size of file in Megabits
*/ */
static uint32_t getSizeMbitFromFile(const SystemString& filename); static uint32_t getSizeMbitFromFile(const SystemString& filename);
@ -371,4 +372,3 @@ public:
} }
#endif // __CARD_HPP__ #endif // __CARD_HPP__

View File

@ -25,7 +25,6 @@ enum class EPermissions : uint8_t
}; };
ENABLE_BITWISE_ENUM(EPermissions) ENABLE_BITWISE_ENUM(EPermissions)
enum class EImageFormat : uint8_t enum class EImageFormat : uint8_t
{ {
None, None,

View File

@ -9,8 +9,7 @@ class Directory
{ {
friend class Card; friend class Card;
#pragma pack(push, 4) #pragma pack(push, 4)
union union {
{
struct struct
{ {
File m_files[MaxFiles]; File m_files[MaxFiles];

View File

@ -11,8 +11,7 @@ class File
friend class Directory; friend class Directory;
friend class Card; friend class Card;
#pragma pack(push, 4) #pragma pack(push, 4)
union union {
{
struct struct
{ {
uint8_t m_game[4]; uint8_t m_game[4];
@ -43,7 +42,6 @@ public:
File(const char* filename); File(const char* filename);
~File() {} ~File() {}
}; };
} }
#endif // __KABU_FILE_HPP__ #endif // __KABU_FILE_HPP__

View File

@ -65,7 +65,6 @@ inline type operator~(const type& key)\
} }
#endif #endif
namespace kabufuda namespace kabufuda
{ {
@ -104,18 +103,13 @@ static inline T bswap64(T val)
#elif _WIN32 #elif _WIN32
return _byteswap_uint64(val); return _byteswap_uint64(val);
#else #else
return ((val & 0xFF00000000000000ULL) >> 56) | return ((val & 0xFF00000000000000ULL) >> 56) | ((val & 0x00FF000000000000ULL) >> 40) |
((val & 0x00FF000000000000ULL) >> 40) | ((val & 0x0000FF0000000000ULL) >> 24) | ((val & 0x000000FF00000000ULL) >> 8) |
((val & 0x0000FF0000000000ULL) >> 24) | ((val & 0x00000000FF000000ULL) << 8) | ((val & 0x0000000000FF0000ULL) << 24) |
((val & 0x000000FF00000000ULL) >> 8) | ((val & 0x000000000000FF00ULL) << 40) | ((val & 0x00000000000000FFULL) << 56);
((val & 0x00000000FF000000ULL) << 8) |
((val & 0x0000000000FF0000ULL) << 24) |
((val & 0x000000000000FF00ULL) << 40) |
((val & 0x00000000000000FFULL) << 56);
#endif #endif
} }
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
static inline int16_t SBig(int16_t val) { return bswap16(val); } static inline int16_t SBig(int16_t val) { return bswap16(val); }
static inline uint16_t SBig(uint16_t val) { return bswap16(val); } static inline uint16_t SBig(uint16_t val) { return bswap16(val); }
@ -133,8 +127,7 @@ static inline double SBig(double val)
int64_t ival = bswap64(*((int64_t*)(&val))); int64_t ival = bswap64(*((int64_t*)(&val)));
return *((double*)(&ival)); return *((double*)(&ival));
} }
#define SBIG(q) ( ( (q) & 0x000000FF ) << 24 | ( (q) & 0x0000FF00 ) << 8 \ #define SBIG(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24)
| ( (q) & 0x00FF0000 ) >> 8 | ( (q) & 0xFF000000 ) >> 24 )
static inline int16_t SLittle(int16_t val) { return val; } static inline int16_t SLittle(int16_t val) { return val; }
static inline uint16_t SLittle(uint16_t val) { return val; } static inline uint16_t SLittle(uint16_t val) { return val; }
@ -162,8 +155,7 @@ static inline double SLittle(double val)
int64_t ival = bswap64(*((int64_t*)(&val))); int64_t ival = bswap64(*((int64_t*)(&val)));
return *((double*)(&ival)); return *((double*)(&ival));
} }
#define SLITTLE(q) ( ( (q) & 0x000000FF ) << 24 | ( (q) & 0x0000FF00 ) << 8 \ #define SLITTLE(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24)
| ( (q) & 0x00FF0000 ) >> 8 | ( (q) & 0xFF000000 ) >> 24 )
static inline int16_t SBig(int16_t val) { return val; } static inline int16_t SBig(int16_t val) { return val; }
static inline uint16_t SBig(uint16_t val) { return val; } static inline uint16_t SBig(uint16_t val) { return val; }
@ -180,16 +172,14 @@ static inline double SBig(double val) {return val;}
typedef wchar_t SystemChar; typedef wchar_t SystemChar;
static inline size_t StrLen(const SystemChar* str) { return wcslen(str); } static inline size_t StrLen(const SystemChar* str) { return wcslen(str); }
typedef std::wstring SystemString; typedef std::wstring SystemString;
static inline void ToLower(SystemString& str) static inline void ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towlower); }
{std::transform(str.begin(), str.end(), str.begin(), towlower);} static inline void ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towupper); }
static inline void ToUpper(SystemString& str)
{std::transform(str.begin(), str.end(), str.begin(), towupper);}
class SystemUTF8View class SystemUTF8View
{ {
std::string m_utf8; std::string m_utf8;
public: public:
explicit SystemUTF8View(const SystemString& str) explicit SystemUTF8View(const SystemString& str) : m_utf8(WideToUTF8(str)) {}
: m_utf8(WideToUTF8(str)) {}
operator const std::string&() const { return m_utf8; } operator const std::string&() const { return m_utf8; }
const std::string& str() const { return m_utf8; } const std::string& str() const { return m_utf8; }
const char* c_str() const { return m_utf8.c_str(); } const char* c_str() const { return m_utf8.c_str(); }
@ -201,9 +191,9 @@ inline std::string operator+(const char* lhs, const SystemUTF8View& rhs) {return
class SystemStringView class SystemStringView
{ {
std::wstring m_sys; std::wstring m_sys;
public: public:
explicit SystemStringView(const std::string& str) explicit SystemStringView(const std::string& str) : m_sys(UTF8ToWide(str)) {}
: m_sys(UTF8ToWide(str)) {}
operator const std::wstring&() const { return m_sys; } operator const std::wstring&() const { return m_sys; }
const std::wstring& sys_str() const { return m_sys; } const std::wstring& sys_str() const { return m_sys; }
const SystemChar* c_str() const { return m_sys.c_str(); } const SystemChar* c_str() const { return m_sys.c_str(); }
@ -220,16 +210,14 @@ typedef struct _stat Sstat;
typedef char SystemChar; typedef char SystemChar;
static inline size_t StrLen(const SystemChar* str) { return strlen(str); } static inline size_t StrLen(const SystemChar* str) { return strlen(str); }
typedef std::string SystemString; typedef std::string SystemString;
static inline void ToLower(SystemString& str) static inline void ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), tolower); }
{std::transform(str.begin(), str.end(), str.begin(), tolower);} static inline void ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), toupper); }
static inline void ToUpper(SystemString& str)
{std::transform(str.begin(), str.end(), str.begin(), toupper);}
class SystemUTF8View class SystemUTF8View
{ {
const std::string& m_utf8; const std::string& m_utf8;
public: public:
explicit SystemUTF8View(const SystemString& str) explicit SystemUTF8View(const SystemString& str) : m_utf8(str) {}
: m_utf8(str) {}
operator const std::string&() const { return m_utf8; } operator const std::string&() const { return m_utf8; }
const std::string& str() const { return m_utf8; } const std::string& str() const { return m_utf8; }
const char* c_str() const { return m_utf8.c_str(); } const char* c_str() const { return m_utf8.c_str(); }
@ -241,9 +229,9 @@ inline std::string operator+(const char* lhs, const SystemUTF8View& rhs) {return
class SystemStringView class SystemStringView
{ {
const std::string& m_sys; const std::string& m_sys;
public: public:
explicit SystemStringView(const std::string& str) explicit SystemStringView(const std::string& str) : m_sys(str) {}
: m_sys(str) {}
operator const std::string&() const { return m_sys; } operator const std::string&() const { return m_sys; }
const std::string& sys_str() const { return m_sys; } const std::string& sys_str() const { return m_sys; }
const SystemChar* c_str() const { return m_sys.c_str(); } const SystemChar* c_str() const { return m_sys.c_str(); }
@ -282,7 +270,8 @@ static inline FILE* Fopen(const SystemChar* path, const SystemChar* mode, FileLo
{ {
#if _WIN32 #if _WIN32
OVERLAPPED ov = {}; OVERLAPPED ov = {};
LockFileEx((HANDLE)(uintptr_t)_fileno(fp), (lock == FileLockType::Write) ? LOCKFILE_EXCLUSIVE_LOCK : 0, 0, 0, 1, &ov); LockFileEx((HANDLE)(uintptr_t)_fileno(fp), (lock == FileLockType::Write) ? LOCKFILE_EXCLUSIVE_LOCK : 0, 0, 0, 1,
&ov);
#else #else
if (flock(fileno(fp), ((lock == FileLockType::Write) ? LOCK_EX : LOCK_SH) | LOCK_NB)) if (flock(fileno(fp), ((lock == FileLockType::Write) ? LOCK_EX : LOCK_SH) | LOCK_NB))
fprintf(stderr, "flock %s: %s", path, strerror(errno)); fprintf(stderr, "flock %s: %s", path, strerror(errno));
@ -327,7 +316,9 @@ static inline int Stat(const SystemChar* path, Sstat* statOut)
{ {
#if CARD_UCS2 #if CARD_UCS2
size_t pos; size_t pos;
for (pos=0 ; pos<3 && path[pos] != L'\0' ; ++pos) {} for (pos = 0; pos < 3 && path[pos] != L'\0'; ++pos)
{
}
if (pos == 2 && path[1] == L':') if (pos == 2 && path[1] == L':')
{ {
SystemChar fixPath[4] = {path[0], L':', L'/', L'\0'}; SystemChar fixPath[4] = {path[0], L':', L'/', L'\0'};

View File

@ -2,7 +2,6 @@
#include "kabufuda/Util.hpp" #include "kabufuda/Util.hpp"
#include <vector> #include <vector>
namespace kabufuda namespace kabufuda
{ {
void BlockAllocationTable::swapEndian() void BlockAllocationTable::swapEndian()
@ -12,9 +11,7 @@ void BlockAllocationTable::swapEndian()
m_updateCounter = SBig(m_updateCounter); m_updateCounter = SBig(m_updateCounter);
m_freeBlocks = SBig(m_freeBlocks); m_freeBlocks = SBig(m_freeBlocks);
m_lastAllocated = SBig(m_lastAllocated); m_lastAllocated = SBig(m_lastAllocated);
std::for_each(std::begin(m_map), std::end(m_map), [](uint16_t& val){ std::for_each(std::begin(m_map), std::end(m_map), [](uint16_t& val) { val = SBig(val); });
val = SBig(val);
});
} }
void BlockAllocationTable::updateChecksum() void BlockAllocationTable::updateChecksum()
@ -41,8 +38,7 @@ BlockAllocationTable::BlockAllocationTable(uint32_t blockCount)
updateChecksum(); updateChecksum();
} }
BlockAllocationTable::~BlockAllocationTable() BlockAllocationTable::~BlockAllocationTable() {}
{}
uint16_t BlockAllocationTable::getNextBlock(uint16_t block) const uint16_t BlockAllocationTable::getNextBlock(uint16_t block) const
{ {

View File

@ -8,26 +8,21 @@
namespace kabufuda namespace kabufuda
{ {
IFileHandle::~IFileHandle() IFileHandle::~IFileHandle() {}
{
}
class FileHandle : public IFileHandle class FileHandle : public IFileHandle
{ {
friend class Card; friend class Card;
uint32_t idx; uint32_t idx;
int32_t offset = 0; int32_t offset = 0;
public: public:
FileHandle() = default; FileHandle() = default;
FileHandle(uint32_t idx) FileHandle(uint32_t idx) : idx(idx) {}
: idx(idx)
{}
virtual ~FileHandle(); virtual ~FileHandle();
}; };
FileHandle::~FileHandle() FileHandle::~FileHandle() {}
{}
void Card::_swapEndian() void Card::_swapEndian()
{ {
@ -43,10 +38,7 @@ void Card::_swapEndian()
m_checksumInv = SBig(m_checksumInv); m_checksumInv = SBig(m_checksumInv);
} }
Card::Card() Card::Card() { memset(__raw, 0xFF, BlockSize); }
{
memset(__raw, 0xFF, BlockSize);
}
Card::Card(const Card& other) Card::Card(const Card& other)
{ {
@ -59,8 +51,7 @@ Card::Card(const Card& other)
memcpy(m_maker, other.m_maker, 2); memcpy(m_maker, other.m_maker, 2);
} }
Card::Card(const SystemString& filename, const char* game, const char* maker) Card::Card(const SystemString& filename, const char* game, const char* maker) : m_filename(filename)
: m_filename(filename)
{ {
memset(__raw, 0xFF, BlockSize); memset(__raw, 0xFF, BlockSize);
if (game && strlen(game) == 4) if (game && strlen(game) == 4)
@ -188,7 +179,6 @@ std::unique_ptr<IFileHandle> Card::createFile(const char* filename, size_t size)
f->m_firstBlock = block; f->m_firstBlock = block;
f->m_blockCount = uint16_t(size / BlockSize); f->m_blockCount = uint16_t(size / BlockSize);
return std::unique_ptr<IFileHandle>(new FileHandle(m_currentDir->indexForFile(f))); return std::unique_ptr<IFileHandle>(new FileHandle(m_currentDir->indexForFile(f)));
} }
return nullptr; return nullptr;
@ -239,7 +229,6 @@ void Card::deleteFile(const std::unique_ptr<IFileHandle>& fh)
block = nextBlock; block = nextBlock;
} }
*m_currentDir->getFile(f->idx) = File(); *m_currentDir->getFile(f->idx) = File();
} }
void Card::write(const std::unique_ptr<IFileHandle>& fh, const void* buf, size_t size) void Card::write(const std::unique_ptr<IFileHandle>& fh, const void* buf, size_t size)

View File

@ -2,14 +2,11 @@
#include "kabufuda/Util.hpp" #include "kabufuda/Util.hpp"
#include <cstring> #include <cstring>
namespace kabufuda namespace kabufuda
{ {
void Directory::swapEndian() void Directory::swapEndian()
{ {
std::for_each(std::begin(m_files), std::end(m_files), [](File& f){ std::for_each(std::begin(m_files), std::end(m_files), [](File& f) { f.swapEndian(); });
f.swapEndian();
});
m_updateCounter = SBig(m_updateCounter); m_updateCounter = SBig(m_updateCounter);
m_checksum = SBig(m_checksum); m_checksum = SBig(m_checksum);
@ -39,24 +36,13 @@ Directory::Directory()
updateChecksum(); updateChecksum();
} }
Directory::Directory(uint8_t data[]) Directory::Directory(uint8_t data[]) { memcpy(__raw, data, BlockSize); }
{
memcpy(__raw, data, BlockSize);
}
Directory::Directory(const Directory& other) Directory::Directory(const Directory& other) { memcpy(__raw, other.__raw, BlockSize); }
{
memcpy(__raw, other.__raw, BlockSize);
}
void Directory::operator=(const Directory& other) void Directory::operator=(const Directory& other) { memcpy(__raw, other.__raw, BlockSize); }
{
memcpy(__raw, other.__raw, BlockSize);
}
Directory::~Directory() Directory::~Directory() {}
{
}
File* Directory::getFirstFreeFile(const char* game, const char* maker, const char* filename) File* Directory::getFirstFreeFile(const char* game, const char* maker, const char* filename)
{ {
@ -84,9 +70,11 @@ File *Directory::getFirstNonFreeFile(uint32_t start, const char *game, const cha
if (m_files[i].m_game[0] != 0xFF) if (m_files[i].m_game[0] != 0xFF)
{ {
File* ret = &m_files[i]; File* ret = &m_files[i];
if (game && std::strlen(game) == 4 && std::strncmp(reinterpret_cast<const char*>(ret->m_game), game, 4) != 0) if (game && std::strlen(game) == 4 &&
std::strncmp(reinterpret_cast<const char*>(ret->m_game), game, 4) != 0)
continue; continue;
if (maker && std::strlen(maker) == 2 && std::strncmp(reinterpret_cast<const char*>(ret->m_maker), maker, 2) != 0) if (maker && std::strlen(maker) == 2 &&
std::strncmp(reinterpret_cast<const char*>(ret->m_maker), maker, 2) != 0)
continue; continue;
return ret; return ret;
} }
@ -123,9 +111,8 @@ int32_t Directory::indexForFile(File *f)
if (!f) if (!f)
return -1; return -1;
auto it = std::find_if(std::begin(m_files), std::end(m_files), [&f](const File& file)->bool{ auto it =
return f == &file; std::find_if(std::begin(m_files), std::end(m_files), [&f](const File& file) -> bool { return f == &file; });
});
if (it == std::end(m_files)) if (it == std::end(m_files))
return -1; return -1;
return it - std::begin(m_files); return it - std::begin(m_files);

View File

@ -3,15 +3,9 @@
namespace kabufuda namespace kabufuda
{ {
File::File() File::File() { memset(__raw, 0xFF, 0x40); }
{
memset(__raw, 0xFF, 0x40);
}
File::File(char data[]) File::File(char data[]) { memcpy(__raw, data, 0x40); }
{
memcpy(__raw, data, 0x40);
}
File::File(const char* filename) File::File(const char* filename)
{ {

View File

@ -1,7 +1,7 @@
#include "kabufuda/SRAM.hpp" #include "kabufuda/SRAM.hpp"
namespace kabufuda namespace kabufuda
{ {
// clang-format off
const SRAM g_SRAM = const SRAM g_SRAM =
{{ {{
0xFF, 0x6B, 0xFF, 0x6B,
@ -26,7 +26,5 @@ const SRAM g_SRAM =
0x00, 0x00, 0x00, 0x00,
0x00, 0x00 0x00, 0x00
}}; }};
// clang-format on
} }