apply clang-format to tool sources

This commit is contained in:
Henny022p
2021-11-23 09:31:09 +01:00
parent 5f41468ba8
commit dee773da4a
54 changed files with 5581 additions and 6826 deletions
Executable → Regular
+37 -65
View File
@@ -25,27 +25,24 @@
#ifdef _MSC_VER
#define FATAL_ERROR(format, ...) \
do \
{ \
fprintf(stderr, format, __VA_ARGS__); \
exit(1); \
} while (0)
#define FATAL_ERROR(format, ...) \
do { \
fprintf(stderr, format, __VA_ARGS__); \
exit(1); \
} while (0)
#else
#define FATAL_ERROR(format, ...) \
do \
{ \
fprintf(stderr, format, ##__VA_ARGS__); \
exit(1); \
} while (0)
#define FATAL_ERROR(format, ...) \
do { \
fprintf(stderr, format, ##__VA_ARGS__); \
exit(1); \
} while (0)
#endif // _MSC_VER
unsigned char *ReadWholeFile(char *path, int *size)
{
FILE *fp = fopen(path, "rb");
unsigned char* ReadWholeFile(char* path, int* size) {
FILE* fp = fopen(path, "rb");
if (fp == NULL)
FATAL_ERROR("Failed to open \"%s\" for reading.\n", path);
@@ -54,7 +51,7 @@ unsigned char *ReadWholeFile(char *path, int *size)
*size = ftell(fp);
unsigned char *buffer = malloc(*size);
unsigned char* buffer = malloc(*size);
if (buffer == NULL)
FATAL_ERROR("Failed to allocate memory for reading \"%s\".\n", path);
@@ -69,33 +66,26 @@ unsigned char *ReadWholeFile(char *path, int *size)
return buffer;
}
int ExtractData(unsigned char *buffer, int offset, int size)
{
switch (size)
{
case 1:
return buffer[offset];
case 2:
return (buffer[offset + 1] << 8)
| buffer[offset];
case 4:
return (buffer[offset + 3] << 24)
| (buffer[offset + 2] << 16)
| (buffer[offset + 1] << 8)
| buffer[offset];
default:
FATAL_ERROR("Invalid size passed to ExtractData.\n");
int ExtractData(unsigned char* buffer, int offset, int size) {
switch (size) {
case 1:
return buffer[offset];
case 2:
return (buffer[offset + 1] << 8) | buffer[offset];
case 4:
return (buffer[offset + 3] << 24) | (buffer[offset + 2] << 16) | (buffer[offset + 1] << 8) | buffer[offset];
default:
FATAL_ERROR("Invalid size passed to ExtractData.\n");
}
}
int main(int argc, char **argv)
{
int main(int argc, char** argv) {
if (argc < 3)
FATAL_ERROR("Usage: bin2c INPUT_FILE VAR_NAME [OPTIONS...]\n");
int fileSize;
unsigned char *buffer = ReadWholeFile(argv[1], &fileSize);
char *var_name = argv[2];
unsigned char* buffer = ReadWholeFile(argv[1], &fileSize);
char* var_name = argv[2];
int col = 1;
int pad = 0;
int size = 1;
@@ -103,28 +93,22 @@ int main(int argc, char **argv)
bool isStatic = false;
bool isDecimal = false;
for (int i = 3; i < argc; i++)
{
if (!strcmp(argv[i], "-col"))
{
for (int i = 3; i < argc; i++) {
if (!strcmp(argv[i], "-col")) {
i++;
if (i >= argc)
FATAL_ERROR("Missing argument after '-col'.\n");
col = atoi(argv[i]);
}
else if (!strcmp(argv[i], "-pad"))
{
} else if (!strcmp(argv[i], "-pad")) {
i++;
if (i >= argc)
FATAL_ERROR("Missing argument after '-pad'.\n");
pad = atoi(argv[i]);
}
else if (!strcmp(argv[i], "-size"))
{
} else if (!strcmp(argv[i], "-size")) {
i++;
if (i >= argc)
@@ -134,22 +118,14 @@ int main(int argc, char **argv)
if (size != 1 && size != 2 && size != 4)
FATAL_ERROR("Size must be 1, 2, or 4.\n");
}
else if (!strcmp(argv[i], "-signed"))
{
} else if (!strcmp(argv[i], "-signed")) {
isSigned = true;
isDecimal = true;
}
else if (!strcmp(argv[i], "-static"))
{
} else if (!strcmp(argv[i], "-static")) {
isStatic = true;
}
else if (!strcmp(argv[i], "-decimal"))
{
} else if (!strcmp(argv[i], "-decimal")) {
isDecimal = true;
}
else
{
} else {
FATAL_ERROR("Unrecognized option '%s'.\n", argv[i]);
}
}
@@ -174,23 +150,19 @@ int main(int argc, char **argv)
int count = fileSize / size;
int offset = 0;
for (int i = 0; i < count; i++)
{
for (int i = 0; i < count; i++) {
if (i % col == 0)
printf("\n ");
int data = ExtractData(buffer, offset, size);
offset += size;
if (isDecimal)
{
if (isDecimal) {
if (isSigned)
printf("%*d, ", pad, data);
else
printf("%*uu, ", pad, data);
}
else
{
} else {
printf("%#*xu, ", pad, data);
}
}