Skip to content

Commit da6a0bd

Browse files
abairemborgerson
authored andcommitted
cxbe: Add clang-format
1 parent 716bf1c commit da6a0bd

File tree

12 files changed

+834
-766
lines changed

12 files changed

+834
-766
lines changed

tools/cxbe/.clang-format

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
BasedOnStyle: Microsoft
3+
ColumnLimit: '100'
4+
Cpp11BracedListStyle: 'false'
5+
IndentCaseLabels: 'true'
6+
Language: Cpp
7+
PenaltyBreakBeforeFirstCallParameter: '0'
8+
SpaceBeforeParens: Never
9+
10+
...

tools/cxbe/Common.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
#include <string.h>
1212

1313
// parse command line
14-
int ParseOptions(char *argv[], int argc,
15-
const Option *options, char *szErrorMessage)
14+
int ParseOptions(char *argv[], int argc, const Option *options, char *szErrorMessage)
1615
{
17-
for(int v=1;v<argc;v++)
16+
for(int v = 1; v < argc; v++)
1817
{
1918
const Option *option = NULL;
20-
char *szOption = 0;
21-
char *szParam = 0;
19+
char *szOption = 0;
20+
char *szParam = 0;
2221

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

34-
for(uint c=1;argv[v][c] != 0;c++)
33+
for(uint c = 1; argv[v][c] != 0; c++)
3534
{
3635
if(argv[v][c] == ':')
3736
{
@@ -49,7 +48,7 @@ int ParseOptions(char *argv[], int argc,
4948
argv[v][dwColon] = '\0';
5049

5150
szOption = &argv[v][1];
52-
szParam = &argv[v][dwColon + 1];
51+
szParam = &argv[v][dwColon + 1];
5352
}
5453

5554
// interpret the current switch
@@ -98,25 +97,25 @@ void ShowUsage(const char *program, const char *desc, const Option *options)
9897
}
9998
}
10099

101-
int GenerateFilename(char *szNewPath, const char *szNewExtension,
102-
const char *szOldPath, const char *szOldExtension)
100+
int GenerateFilename(char *szNewPath, const char *szNewExtension, const char *szOldPath,
101+
const char *szOldExtension)
103102
{
104103
strncpy(szNewPath, szOldPath, OPTION_LEN);
105104

106105
char *szFilename = &szNewPath[0];
107106

108107
// locate last \ or / (if there are any)
109108
{
110-
for(int c=0;szNewPath[c] != 0;c++)
109+
for(int c = 0; szNewPath[c] != 0; c++)
111110
if(szNewPath[c] == '\\' || szNewPath[c] == '/')
112-
szFilename = &szNewPath[c+1];
111+
szFilename = &szNewPath[c + 1];
113112
}
114113

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

119-
for(int c=0;szFilename[c] != 0;c++)
118+
for(int c = 0; szFilename[c] != 0; c++)
120119
if(szFilename[c] == '.')
121120
szWorking = &szFilename[c];
122121

tools/cxbe/Common.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
#define OPTION_LEN 266
1010
#define ERROR_LEN 256
1111

12-
struct Option {
12+
struct Option
13+
{
1314
char *value;
1415
const char *key;
1516
const char *desc;
1617
};
1718

18-
int ParseOptions(char *argv[], int argc,
19-
const Option *options, char *szErrorMessage);
19+
int ParseOptions(char *argv[], int argc, const Option *options, char *szErrorMessage);
2020
void ShowUsage(const char *program, const char *desc, const Option *options);
21-
int GenerateFilename(char *szNewPath, const char *szNewExtension,
22-
const char *szOldPath, const char *szOldExtension);
21+
int GenerateFilename(char *szNewPath, const char *szNewExtension, const char *szOldPath,
22+
const char *szOldExtension);
2323
bool CompareString(const char *szA, const char *szB);
2424

2525
#endif

tools/cxbe/Cxbx.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
#include <stdint.h>
1212

1313
// Caustik's favorite typedefs
14-
typedef signed int sint;
15-
typedef unsigned int uint;
16-
typedef int8_t int08;
17-
typedef int16_t int16;
18-
typedef int32_t int32;
19-
typedef uint8_t uint08;
20-
typedef uint16_t uint16;
21-
typedef uint32_t uint32;
22-
typedef int8_t sint08;
23-
typedef int16_t sint16;
24-
typedef int32_t sint32;
25-
typedef intptr_t sintptr;
14+
typedef signed int sint;
15+
typedef unsigned int uint;
16+
typedef int8_t int08;
17+
typedef int16_t int16;
18+
typedef int32_t int32;
19+
typedef uint8_t uint08;
20+
typedef uint16_t uint16;
21+
typedef uint32_t uint32;
22+
typedef int8_t sint08;
23+
typedef int16_t sint16;
24+
typedef int32_t sint32;
25+
typedef intptr_t sintptr;
2626

2727
#define VERSION "unknown"
2828

@@ -32,7 +32,7 @@ static uint32 RoundUp(uint32 dwValue, uint32 dwMult)
3232
if(dwMult == 0)
3333
return dwValue;
3434

35-
return dwValue - (dwValue-1)%dwMult + (dwMult - 1);
35+
return dwValue - (dwValue - 1) % dwMult + (dwMult - 1);
3636
}
3737

3838
#endif

tools/cxbe/Error.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
bool Error::ClearError()
1515
{
1616
if(m_bFatal)
17-
return false;
17+
return false;
1818

1919
delete[] m_szError;
2020

2121
m_szError = 0;
2222

23-
m_bFatal = false;
23+
m_bFatal = false;
2424

2525
return true;
2626
}
@@ -30,7 +30,7 @@ void Error::SetError(const char *x_szError, bool x_bFatal)
3030
{
3131
if(m_szError == 0)
3232
{
33-
m_szError = new char[ERROR_LEN+1];
33+
m_szError = new char[ERROR_LEN + 1];
3434
m_szError[ERROR_LEN] = '\0';
3535
}
3636

tools/cxbe/Error.h

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,41 @@
1212
// inherit from this class for handy error reporting capability
1313
class Error
1414
{
15-
public:
16-
// return current error (zero if there is none)
17-
const char *GetError() const { return m_szError; }
18-
19-
// is the current error fatal? (class is "dead" on fatal errors)
20-
bool IsFatal() const { return m_bFatal; }
21-
22-
// clear the current error (returns false if error was fatal)
23-
bool ClearError();
24-
25-
protected:
26-
// protected constructor so this class must be inherited from
27-
Error() : m_szError(0), m_bFatal(false) { }
28-
29-
// protected deconstructor
30-
~Error() { delete[] m_szError; }
31-
32-
// protected so only derived class may set an error
33-
void SetError(const char *x_szError, bool x_bFatal);
34-
35-
private:
36-
// current error information
37-
bool m_bFatal;
38-
char *m_szError;
15+
public:
16+
// return current error (zero if there is none)
17+
const char *GetError() const
18+
{
19+
return m_szError;
20+
}
21+
22+
// is the current error fatal? (class is "dead" on fatal errors)
23+
bool IsFatal() const
24+
{
25+
return m_bFatal;
26+
}
27+
28+
// clear the current error (returns false if error was fatal)
29+
bool ClearError();
30+
31+
protected:
32+
// protected constructor so this class must be inherited from
33+
Error() : m_szError(0), m_bFatal(false)
34+
{
35+
}
36+
37+
// protected deconstructor
38+
~Error()
39+
{
40+
delete[] m_szError;
41+
}
42+
43+
// protected so only derived class may set an error
44+
void SetError(const char *x_szError, bool x_bFatal);
45+
46+
private:
47+
// current error information
48+
bool m_bFatal;
49+
char *m_szError;
3950
};
4051

4152
#endif

tools/cxbe/Exe.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
#include "Exe.h"
99

10-
#include <stdio.h>
1110
#include <memory.h>
11+
#include <stdio.h>
1212

1313
// construct via Exe file
1414
Exe::Exe(const char *x_szFilename)
@@ -38,11 +38,11 @@ Exe::Exe(const char *x_szFilename)
3838
goto cleanup;
3939
}
4040

41-
if(m_DOSHeader.m_magic == *(uint16*)"MZ")
41+
if(m_DOSHeader.m_magic == *(uint16 *)"MZ")
4242
{
4343
printf("Found, Ignoring...");
4444

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

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

96-
printf("OK\n");
96+
printf("OK\n");
9797
}
9898

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

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

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

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

125-
m_bzSection = new uint08*[m_Header.m_sections];
125+
m_bzSection = new uint08 *[m_Header.m_sections];
126126

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

@@ -181,15 +181,15 @@ Exe::Exe(const char *x_szFilename)
181181
void Exe::ConstructorInit()
182182
{
183183
m_SectionHeader = NULL;
184-
m_bzSection = NULL;
184+
m_bzSection = NULL;
185185
}
186186

187187
// deconstructor
188188
Exe::~Exe()
189189
{
190190
if(m_bzSection != 0)
191191
{
192-
for(uint32 v=0;v<m_Header.m_sections;v++)
192+
for(uint32 v = 0; v < m_Header.m_sections; v++)
193193
delete[] m_bzSection[v];
194194

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

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

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

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

@@ -326,19 +327,20 @@ void Exe::Export(const char *x_szExeFilename)
326327
return;
327328
}
328329

329-
const uint08 *Exe::ReadAddr(uint32 x_dwVirtualAddress) const {
330-
return const_cast<Exe*>(this)->GetAddr(x_dwVirtualAddress);
330+
const uint08 *Exe::ReadAddr(uint32 x_dwVirtualAddress) const
331+
{
332+
return const_cast<Exe *>(this)->GetAddr(x_dwVirtualAddress);
331333
}
332334

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

341-
if( (x_dwVirtualAddress >= virt_addr) && (x_dwVirtualAddress < (virt_addr + virt_size)) )
343+
if((x_dwVirtualAddress >= virt_addr) && (x_dwVirtualAddress < (virt_addr + virt_size)))
342344
return &m_bzSection[v][x_dwVirtualAddress - virt_addr];
343345
}
344346

0 commit comments

Comments
 (0)