src: more clang-format

This commit is contained in:
Markus F.X.J. Oberhumer
2022-11-27 22:03:20 +01:00
parent 02f6786b2a
commit 65a2da4b40
3 changed files with 120 additions and 174 deletions
+7 -6
View File
@@ -76,14 +76,15 @@ ifeq ($(shell uname),Linux)
CLANG_FORMAT_FILES += bele.h bele_policy.h CLANG_FORMAT_FILES += bele.h bele_policy.h
CLANG_FORMAT_FILES += c_file.cpp c_init.cpp c_none.cpp c_screen.cpp CLANG_FORMAT_FILES += c_file.cpp c_init.cpp c_none.cpp c_screen.cpp
CLANG_FORMAT_FILES += compress_lzma.cpp compress_ucl.cpp compress_zlib.cpp CLANG_FORMAT_FILES += compress_lzma.cpp compress_ucl.cpp compress_zlib.cpp
CLANG_FORMAT_FILES += except.cpp except.h CLANG_FORMAT_FILES += console.h except.cpp except.h
CLANG_FORMAT_FILES += file.cpp file.h lefile.cpp lefile.h CLANG_FORMAT_FILES += file.cpp file.h lefile.cpp lefile.h
CLANG_FORMAT_FILES += linker.cpp linker.h packhead.cpp packmast.cpp packmast.h CLANG_FORMAT_FILES += linker.cpp linker.h main.cpp msg.cpp options.cpp options.h
CLANG_FORMAT_FILES += main.cpp options.cpp options.h packer.cpp packer.h CLANG_FORMAT_FILES += p_armpe.cpp p_armpe.h p_com.cpp p_com.h p_djgpp2.cpp p_djgpp2.h
CLANG_FORMAT_FILES += p_armpe.cpp p_armpe.h CLANG_FORMAT_FILES += p_exe.cpp p_exe.h p_ps1.cpp p_ps1.h p_sys.cpp p_sys.h
CLANG_FORMAT_FILES += p_com.cpp p_com.h p_djgpp2.cpp p_djgpp2.h p_exe.cpp p_exe.h p_ps1.cpp p_ps1.h CLANG_FORMAT_FILES += p_tmt.cpp p_tmt.h p_tos.cpp p_tos.h
CLANG_FORMAT_FILES += p_sys.cpp p_sys.h p_tmt.cpp p_tmt.h p_tos.cpp p_tos.h p_wcle.cpp p_wcle.h
CLANG_FORMAT_FILES += p_w32pe.h p_w64pep.h CLANG_FORMAT_FILES += p_w32pe.h p_w64pep.h
CLANG_FORMAT_FILES += p_wcle.cpp p_wcle.h
CLANG_FORMAT_FILES += packer.cpp packer.h packhead.cpp packmast.cpp packmast.h
CLANG_FORMAT_FILES += s_djgpp2.cpp s_object.cpp s_vcsa.cpp s_win32.cpp screen.h CLANG_FORMAT_FILES += s_djgpp2.cpp s_object.cpp s_vcsa.cpp s_win32.cpp screen.h
CLANG_FORMAT_FILES += ui.cpp ui.h work.cpp CLANG_FORMAT_FILES += ui.cpp ui.h work.cpp
CLANG_FORMAT_FILES += $(wildcard util/[a-ln-z]*.[ch]* util/mem*.[ch]*) CLANG_FORMAT_FILES += $(wildcard util/[a-ln-z]*.[ch]* util/mem*.[ch]*)
+3 -23
View File
@@ -25,8 +25,6 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
@@ -66,7 +64,6 @@
#define USE_SCREEN_WIN32 1 #define USE_SCREEN_WIN32 1
#endif #endif
#if 0 || (NO_ANSI) #if 0 || (NO_ANSI)
#undef USE_ANSI #undef USE_ANSI
#endif #endif
@@ -80,7 +77,6 @@
#undef USE_FRAMES #undef USE_FRAMES
#endif #endif
#if 0 || (USE_ANSI) || (USE_SCREEN) #if 0 || (USE_ANSI) || (USE_SCREEN)
#define USE_CONSOLE 1 #define USE_CONSOLE 1
#endif #endif
@@ -94,37 +90,23 @@
#undef USE_FRAMES #undef USE_FRAMES
#endif #endif
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
enum { enum { CON_INIT, CON_NONE, CON_FILE, CON_ANSI_MONO, CON_ANSI_COLOR, CON_SCREEN, CON_UNUSED };
CON_INIT,
CON_NONE,
CON_FILE,
CON_ANSI_MONO,
CON_ANSI_COLOR,
CON_SCREEN,
CON_UNUSED
};
#if (USE_CONSOLE) #if (USE_CONSOLE)
typedef struct typedef struct {
{
int (*init)(FILE *f, int, int); int (*init)(FILE *f, int, int);
int (*set_fg)(FILE *f, int fg); int (*set_fg)(FILE *f, int fg);
void (*print0)(FILE *f, const char *s); void (*print0)(FILE *f, const char *s);
bool (*intro)(FILE *f); bool (*intro)(FILE *f);
} } console_t;
console_t;
void con_fprintf(FILE *f, const char *format, ...) attribute_format(2, 3); void con_fprintf(FILE *f, const char *format, ...) attribute_format(2, 3);
#define FG_BLACK 0x00 #define FG_BLACK 0x00
#define FG_BLUE 0x01 #define FG_BLUE 0x01
#define FG_GREEN 0x02 #define FG_GREEN 0x02
@@ -153,7 +135,6 @@ void con_fprintf(FILE *f, const char *format, ...) attribute_format(2, 3);
#endif /* USE_CONSOLE */ #endif /* USE_CONSOLE */
/************************************************************************* /*************************************************************************
// //
**************************************************************************/ **************************************************************************/
@@ -172,7 +153,6 @@ extern console_t console_ansi_mono;
extern console_t console_ansi_color; extern console_t console_ansi_color;
extern console_t console_screen; extern console_t console_screen;
#define con_fg(f, x) con->set_fg(f, x) #define con_fg(f, x) con->set_fg(f, x)
#else #else
+26 -61
View File
@@ -25,10 +25,8 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com> <markus@oberhumer.com> <ezerotven+github@gmail.com>
*/ */
#include "conf.h" #include "conf.h"
/************************************************************************* /*************************************************************************
// FIXME: if stdout is redirected to a file and stderr is not, should // FIXME: if stdout is redirected to a file and stderr is not, should
// we write all error messages to both stderr and stdout ? // we write all error messages to both stderr and stdout ?
@@ -36,17 +34,11 @@
static int pr_need_nl = 0; static int pr_need_nl = 0;
void printSetNl(int need_nl) { pr_need_nl = need_nl; }
void printSetNl(int need_nl) void printClearLine(FILE *f) {
{
pr_need_nl = need_nl;
}
void printClearLine(FILE *f)
{
static char clear_line_msg[1 + 79 + 1 + 1]; static char clear_line_msg[1 + 79 + 1 + 1];
if (!clear_line_msg[0]) if (!clear_line_msg[0]) {
{
char *msg = clear_line_msg; char *msg = clear_line_msg;
msg[0] = '\r'; msg[0] = '\r';
memset(msg + 1, ' ', 79); memset(msg + 1, ' ', 79);
@@ -54,7 +46,8 @@ void printClearLine(FILE *f)
msg[81] = 0; msg[81] = 0;
} }
fflush(stdout); fflush(stderr); fflush(stdout);
fflush(stderr);
if (f == nullptr) if (f == nullptr)
f = stdout; f = stdout;
con_fprintf(f, "%s", clear_line_msg); con_fprintf(f, "%s", clear_line_msg);
@@ -62,24 +55,21 @@ void printClearLine(FILE *f)
printSetNl(0); printSetNl(0);
} }
static void pr_print(bool c, const char *msg) {
static void pr_print(bool c, const char *msg)
{
if (c && !opt->to_stdout) if (c && !opt->to_stdout)
con_fprintf(stderr, "%s", msg); con_fprintf(stderr, "%s", msg);
else else
fprintf(stderr, "%s", msg); fprintf(stderr, "%s", msg);
} }
static void pr_error(const char *iname, const char *msg, bool is_warning) static void pr_error(const char *iname, const char *msg, bool is_warning) {
{ fflush(stdout);
fflush(stdout); fflush(stderr); fflush(stderr);
char buf[1024]; char buf[1024];
buf[0] = 0; buf[0] = 0;
if (pr_need_nl == 2) if (pr_need_nl == 2)
printClearLine(stdout); printClearLine(stdout);
else if (pr_need_nl) else if (pr_need_nl) {
{
buf[0] = '\n'; buf[0] = '\n';
buf[1] = 0; buf[1] = 0;
printSetNl(0); printSetNl(0);
@@ -99,16 +89,15 @@ static void pr_error(const char *iname, const char *msg, bool is_warning)
//(void)con_fg(stderr,FG_BRTRED); //(void)con_fg(stderr,FG_BRTRED);
pr_print(c, msg); pr_print(c, msg);
pr_print(c, "\n"); pr_print(c, "\n");
fflush(stdout); fflush(stderr); fflush(stdout);
fflush(stderr);
fg = con_fg(stderr, fg); fg = con_fg(stderr, fg);
UNUSED(is_warning); UNUSED(is_warning);
UNUSED(fg); UNUSED(fg);
} }
void printErr(const char *iname, const Throwable *e) {
void printErr(const char *iname, const Throwable *e)
{
char buf[1024]; char buf[1024];
size_t l; size_t l;
@@ -130,9 +119,7 @@ void printErr(const char *iname, const Throwable *e)
pr_error(iname, buf, e->isWarning()); pr_error(iname, buf, e->isWarning());
} }
void printErr(const char *iname, const char *format, ...) {
void printErr(const char *iname, const char *format, ...)
{
va_list args; va_list args;
char buf[1024]; char buf[1024];
@@ -143,9 +130,7 @@ void printErr(const char *iname, const char *format, ...)
pr_error(iname, buf, false); pr_error(iname, buf, false);
} }
void printWarn(const char *iname, const char *format, ...) {
void printWarn(const char *iname, const char *format, ...)
{
va_list args; va_list args;
char buf[1024]; char buf[1024];
@@ -156,38 +141,30 @@ void printWarn(const char *iname, const char *format, ...)
pr_error(iname, buf, true); pr_error(iname, buf, true);
} }
void printUnhandledException(const char *iname, const std::exception *e) {
void printUnhandledException(const char *iname, const std::exception *e)
{
if (e) if (e)
printErr(iname, "unhandled exception: %s\n", prettyName(e->what())); printErr(iname, "unhandled exception: %s\n", prettyName(e->what()));
else else
printErr(iname, "internal error: unhandled exception!\n"); printErr(iname, "internal error: unhandled exception!\n");
if (opt->cmd != CMD_COMPRESS) if (opt->cmd != CMD_COMPRESS) {
{
printErr(iname, " this file has possibly been modified/hacked; take care!\n"); printErr(iname, " this file has possibly been modified/hacked; take care!\n");
} }
} }
/************************************************************************* /*************************************************************************
// FIXME: should use colors and a consistent layout here // FIXME: should use colors and a consistent layout here
**************************************************************************/ **************************************************************************/
static int info_header = 0; static int info_header = 0;
static void info_print(const char *msg) {
static void info_print(const char *msg)
{
if (opt->info_mode <= 0) if (opt->info_mode <= 0)
return; return;
FILE *f = opt->to_stdout ? stderr : stdout; FILE *f = opt->to_stdout ? stderr : stdout;
if (pr_need_nl) if (pr_need_nl) {
{
printClearLine(f); printClearLine(f);
con_fprintf(f, "%s\n", msg); con_fprintf(f, "%s\n", msg);
} } else if (pr_need_nl)
else if (pr_need_nl)
con_fprintf(f, "\n%s\n", msg); con_fprintf(f, "\n%s\n", msg);
else else
con_fprintf(f, "%s\n", msg); con_fprintf(f, "%s\n", msg);
@@ -195,14 +172,9 @@ static void info_print(const char *msg)
printSetNl(0); printSetNl(0);
} }
void infoHeader() { info_header = 0; }
void infoHeader() void infoHeader(const char *format, ...) {
{
info_header = 0;
}
void infoHeader(const char *format, ...)
{
if (opt->info_mode <= 0) if (opt->info_mode <= 0)
return; return;
va_list args; va_list args;
@@ -214,9 +186,7 @@ void infoHeader(const char *format, ...)
info_header = 1; info_header = 1;
} }
void info(const char *format, ...) {
void info(const char *format, ...)
{
if (opt->info_mode <= 0) if (opt->info_mode <= 0)
return; return;
va_list args; va_list args;
@@ -229,11 +199,8 @@ void info(const char *format, ...)
info_print(buf); info_print(buf);
} }
void infoWarning(const char *format, ...) {
void infoWarning(const char *format, ...) if (opt->info_mode <= 0) {
{
if (opt->info_mode <= 0)
{
// FIXME - should still print something here // FIXME - should still print something here
return; return;
} }
@@ -245,9 +212,7 @@ void infoWarning(const char *format, ...)
info("[WARNING] %s\n", buf); info("[WARNING] %s\n", buf);
} }
void infoWriting(const char *what, long size) {
void infoWriting(const char *what, long size)
{
if (opt->info_mode <= 0) if (opt->info_mode <= 0)
return; return;
info("Writing %s: %ld bytes", what, size); info("Writing %s: %ld bytes", what, size);