Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cxbe: Add clang-format #648

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tools/cxbe/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
BasedOnStyle: Microsoft
ColumnLimit: '100'
Cpp11BracedListStyle: 'false'
IndentCaseLabels: 'true'
Language: Cpp
PenaltyBreakBeforeFirstCallParameter: '0'
SpaceBeforeParens: Never

...
23 changes: 11 additions & 12 deletions tools/cxbe/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
#include <string.h>

// parse command line
int ParseOptions(char *argv[], int argc,
const Option *options, char *szErrorMessage)
int ParseOptions(char *argv[], int argc, const Option *options, char *szErrorMessage)
{
for(int v=1;v<argc;v++)
for(int v = 1; v < argc; v++)
{
const Option *option = NULL;
char *szOption = 0;
char *szParam = 0;
char *szOption = 0;
char *szParam = 0;

// if this isn't an option, it must be the default option
if(argv[v][0] != '-')
Expand All @@ -31,7 +30,7 @@ int ParseOptions(char *argv[], int argc,
{
uint dwColon = (uint)-1;

for(uint c=1;argv[v][c] != 0;c++)
for(uint c = 1; argv[v][c] != 0; c++)
{
if(argv[v][c] == ':')
{
Expand All @@ -49,7 +48,7 @@ int ParseOptions(char *argv[], int argc,
argv[v][dwColon] = '\0';

szOption = &argv[v][1];
szParam = &argv[v][dwColon + 1];
szParam = &argv[v][dwColon + 1];
}

// interpret the current switch
Expand Down Expand Up @@ -98,25 +97,25 @@ void ShowUsage(const char *program, const char *desc, const Option *options)
}
}

int GenerateFilename(char *szNewPath, const char *szNewExtension,
const char *szOldPath, const char *szOldExtension)
int GenerateFilename(char *szNewPath, const char *szNewExtension, const char *szOldPath,
const char *szOldExtension)
{
strncpy(szNewPath, szOldPath, OPTION_LEN);

char *szFilename = &szNewPath[0];

// locate last \ or / (if there are any)
{
for(int c=0;szNewPath[c] != 0;c++)
for(int c = 0; szNewPath[c] != 0; c++)
if(szNewPath[c] == '\\' || szNewPath[c] == '/')
szFilename = &szNewPath[c+1];
szFilename = &szNewPath[c + 1];
}

// locate and remove last . (if there are any)
{
char *szWorking = szFilename;

for(int c=0;szFilename[c] != 0;c++)
for(int c = 0; szFilename[c] != 0; c++)
if(szFilename[c] == '.')
szWorking = &szFilename[c];

Expand Down
10 changes: 5 additions & 5 deletions tools/cxbe/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
#define OPTION_LEN 266
#define ERROR_LEN 256

struct Option {
struct Option
{
char *value;
const char *key;
const char *desc;
};

int ParseOptions(char *argv[], int argc,
const Option *options, char *szErrorMessage);
int ParseOptions(char *argv[], int argc, const Option *options, char *szErrorMessage);
void ShowUsage(const char *program, const char *desc, const Option *options);
int GenerateFilename(char *szNewPath, const char *szNewExtension,
const char *szOldPath, const char *szOldExtension);
int GenerateFilename(char *szNewPath, const char *szNewExtension, const char *szOldPath,
const char *szOldExtension);
bool CompareString(const char *szA, const char *szB);

#endif
26 changes: 13 additions & 13 deletions tools/cxbe/Cxbx.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
#include <stdint.h>

// Caustik's favorite typedefs
typedef signed int sint;
typedef unsigned int uint;
typedef int8_t int08;
typedef int16_t int16;
typedef int32_t int32;
typedef uint8_t uint08;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef int8_t sint08;
typedef int16_t sint16;
typedef int32_t sint32;
typedef intptr_t sintptr;
typedef signed int sint;
typedef unsigned int uint;
typedef int8_t int08;
typedef int16_t int16;
typedef int32_t int32;
typedef uint8_t uint08;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef int8_t sint08;
typedef int16_t sint16;
typedef int32_t sint32;
typedef intptr_t sintptr;

#define VERSION "unknown"

Expand All @@ -32,7 +32,7 @@ static uint32 RoundUp(uint32 dwValue, uint32 dwMult)
if(dwMult == 0)
return dwValue;

return dwValue - (dwValue-1)%dwMult + (dwMult - 1);
return dwValue - (dwValue - 1) % dwMult + (dwMult - 1);
}

#endif
6 changes: 3 additions & 3 deletions tools/cxbe/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
bool Error::ClearError()
{
if(m_bFatal)
return false;
return false;

delete[] m_szError;

m_szError = 0;

m_bFatal = false;
m_bFatal = false;

return true;
}
Expand All @@ -30,7 +30,7 @@ void Error::SetError(const char *x_szError, bool x_bFatal)
{
if(m_szError == 0)
{
m_szError = new char[ERROR_LEN+1];
m_szError = new char[ERROR_LEN + 1];
m_szError[ERROR_LEN] = '\0';
}

Expand Down
59 changes: 35 additions & 24 deletions tools/cxbe/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,41 @@
// inherit from this class for handy error reporting capability
class Error
{
public:
// return current error (zero if there is none)
const char *GetError() const { return m_szError; }

// is the current error fatal? (class is "dead" on fatal errors)
bool IsFatal() const { return m_bFatal; }

// clear the current error (returns false if error was fatal)
bool ClearError();

protected:
// protected constructor so this class must be inherited from
Error() : m_szError(0), m_bFatal(false) { }

// protected deconstructor
~Error() { delete[] m_szError; }

// protected so only derived class may set an error
void SetError(const char *x_szError, bool x_bFatal);

private:
// current error information
bool m_bFatal;
char *m_szError;
public:
// return current error (zero if there is none)
const char *GetError() const
{
return m_szError;
}

// is the current error fatal? (class is "dead" on fatal errors)
bool IsFatal() const
{
return m_bFatal;
}

// clear the current error (returns false if error was fatal)
bool ClearError();

protected:
// protected constructor so this class must be inherited from
Error() : m_szError(0), m_bFatal(false)
{
}

// protected deconstructor
~Error()
{
delete[] m_szError;
}

// protected so only derived class may set an error
void SetError(const char *x_szError, bool x_bFatal);

private:
// current error information
bool m_bFatal;
char *m_szError;
};

#endif
36 changes: 19 additions & 17 deletions tools/cxbe/Exe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#include "Exe.h"

#include <stdio.h>
#include <memory.h>
#include <stdio.h>

// construct via Exe file
Exe::Exe(const char *x_szFilename)
Expand Down Expand Up @@ -38,11 +38,11 @@ Exe::Exe(const char *x_szFilename)
goto cleanup;
}

if(m_DOSHeader.m_magic == *(uint16*)"MZ")
if(m_DOSHeader.m_magic == *(uint16 *)"MZ")
{
printf("Found, Ignoring...");

if(fread(&m_DOSHeader.m_cblp, sizeof(m_DOSHeader)-2, 1, ExeFile) != 1)
if(fread(&m_DOSHeader.m_cblp, sizeof(m_DOSHeader) - 2, 1, ExeFile) != 1)
{
SetError("Unexpected read error while reading DOS stub", true);
goto cleanup;
Expand All @@ -68,7 +68,7 @@ Exe::Exe(const char *x_szFilename)
goto cleanup;
}

if(m_Header.m_magic != *(uint32*)"PE\0\0")
if(m_Header.m_magic != *(uint32 *)"PE\0\0")
{
SetError("Invalid file (could not locate PE header)", true);
goto cleanup;
Expand All @@ -93,7 +93,7 @@ Exe::Exe(const char *x_szFilename)
goto cleanup;
}

printf("OK\n");
printf("OK\n");
}

// read section headers
Expand All @@ -102,7 +102,7 @@ Exe::Exe(const char *x_szFilename)

printf("Exe::Exe: Reading Section Headers...\n");

for(uint32 v=0;v<m_Header.m_sections;v++)
for(uint32 v = 0; v < m_Header.m_sections; v++)
{
printf("Exe::Exe: Reading Section Header 0x%.04X...", v);

Expand All @@ -122,9 +122,9 @@ Exe::Exe(const char *x_szFilename)
{
printf("Exe::Exe: Reading Sections...\n");

m_bzSection = new uint08*[m_Header.m_sections];
m_bzSection = new uint08 *[m_Header.m_sections];

for(uint32 v=0;v<m_Header.m_sections;v++)
for(uint32 v = 0; v < m_Header.m_sections; v++)
{
printf("Exe::Exe: Reading Section 0x%.04X...", v);

Expand Down Expand Up @@ -181,15 +181,15 @@ Exe::Exe(const char *x_szFilename)
void Exe::ConstructorInit()
{
m_SectionHeader = NULL;
m_bzSection = NULL;
m_bzSection = NULL;
}

// deconstructor
Exe::~Exe()
{
if(m_bzSection != 0)
{
for(uint32 v=0;v<m_Header.m_sections;v++)
for(uint32 v = 0; v < m_Header.m_sections; v++)
delete[] m_bzSection[v];

delete[] m_bzSection;
Expand Down Expand Up @@ -260,14 +260,15 @@ void Exe::Export(const char *x_szExeFilename)
{
printf("Exe::Export: Writing Section Headers...\n");

for(uint32 v=0;v<m_Header.m_sections;v++)
for(uint32 v = 0; v < m_Header.m_sections; v++)
{
printf("Exe::Export: Writing Section Header 0x%.04X...", v);

if(fwrite(&m_SectionHeader[v], sizeof(SectionHeader), 1, ExeFile) != 1)
{
char buffer[255];
snprintf(buffer, sizeof(buffer), "Could not write PE section header %d (%Xh)", v, v);
snprintf(
buffer, sizeof(buffer), "Could not write PE section header %d (%Xh)", v, v);
SetError(buffer, false);
goto cleanup;
}
Expand All @@ -280,7 +281,7 @@ void Exe::Export(const char *x_szExeFilename)
{
printf("Exe::Export: Writing Sections...\n");

for(uint32 v=0;v<m_Header.m_sections;v++)
for(uint32 v = 0; v < m_Header.m_sections; v++)
{
printf("Exe::Export: Writing Section 0x%.04X...", v);

Expand Down Expand Up @@ -326,19 +327,20 @@ void Exe::Export(const char *x_szExeFilename)
return;
}

const uint08 *Exe::ReadAddr(uint32 x_dwVirtualAddress) const {
return const_cast<Exe*>(this)->GetAddr(x_dwVirtualAddress);
const uint08 *Exe::ReadAddr(uint32 x_dwVirtualAddress) const
{
return const_cast<Exe *>(this)->GetAddr(x_dwVirtualAddress);
}

// return a modifiable pointer inside this structure that corresponds to a virtual address
uint08 *Exe::GetAddr(uint32 x_dwVirtualAddress)
{
for(uint32 v=0;v<m_Header.m_sections;v++)
for(uint32 v = 0; v < m_Header.m_sections; v++)
{
uint32 virt_addr = m_SectionHeader[v].m_virtual_addr;
uint32 virt_size = m_SectionHeader[v].m_virtual_size;

if( (x_dwVirtualAddress >= virt_addr) && (x_dwVirtualAddress < (virt_addr + virt_size)) )
if((x_dwVirtualAddress >= virt_addr) && (x_dwVirtualAddress < (virt_addr + virt_size)))
return &m_bzSection[v][x_dwVirtualAddress - virt_addr];
}

Expand Down
Loading