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

View File

@ -76,14 +76,15 @@ ifeq ($(shell uname),Linux)
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 += 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 += linker.cpp linker.h packhead.cpp packmast.cpp packmast.h
CLANG_FORMAT_FILES += main.cpp options.cpp options.h packer.cpp packer.h
CLANG_FORMAT_FILES += p_armpe.cpp p_armpe.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_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 += linker.cpp linker.h main.cpp msg.cpp options.cpp options.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_exe.cpp p_exe.h p_ps1.cpp p_ps1.h p_sys.cpp p_sys.h
CLANG_FORMAT_FILES += p_tmt.cpp p_tmt.h p_tos.cpp p_tos.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 += ui.cpp ui.h work.cpp
CLANG_FORMAT_FILES += $(wildcard util/[a-ln-z]*.[ch]* util/mem*.[ch]*)

View File

@ -25,8 +25,6 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
/*************************************************************************
//
**************************************************************************/
@ -40,120 +38,103 @@
#undef USE_FRAMES
#if 1 && (WITH_GUI) && !defined(NO_CONSOLE)
# define NO_CONSOLE 1
#define NO_CONSOLE 1
#endif
#if 1 && defined(__linux__)
# define USE_SCREEN 1
# define USE_SCREEN_VCSA 1
# if !(HAVE_LINUX_KD_H)
# undef USE_SCREEN
# undef USE_SCREEN_VCSA
# endif
# if !(HAVE_LINUX_KDEV_T_H) || !(HAVE_LINUX_MAJOR_H)
# undef USE_SCREEN
# undef USE_SCREEN_VCSA
# endif
#define USE_SCREEN 1
#define USE_SCREEN_VCSA 1
#if !(HAVE_LINUX_KD_H)
#undef USE_SCREEN
#undef USE_SCREEN_VCSA
#endif
#if !(HAVE_LINUX_KDEV_T_H) || !(HAVE_LINUX_MAJOR_H)
#undef USE_SCREEN
#undef USE_SCREEN_VCSA
#endif
#endif
#if 1 && (ACC_OS_DOS32) && defined(__DJGPP__)
# define USE_SCREEN 1
#define USE_SCREEN 1
#elif 1 && (ACC_OS_CYGWIN || ACC_OS_WIN32 || ACC_OS_WIN64)
# define USE_SCREEN 1
# define USE_SCREEN_WIN32 1
#define USE_SCREEN 1
#define USE_SCREEN_WIN32 1
#elif 1 && (ACC_OS_EMX && defined(__RSXNT__))
# define USE_SCREEN 1
# define USE_SCREEN_WIN32 1
#define USE_SCREEN 1
#define USE_SCREEN_WIN32 1
#endif
#if 0 || (NO_ANSI)
# undef USE_ANSI
#undef USE_ANSI
#endif
#if 0 || (NO_SCREEN)
# undef USE_SCREEN
#undef USE_SCREEN
#endif
#if 0 || (NO_FRAMES) || !(USE_SCREEN)
# undef USE_FRAMES
#undef USE_FRAMES
#endif
#if 1
# undef USE_FRAMES
#undef USE_FRAMES
#endif
#if 0 || (USE_ANSI) || (USE_SCREEN)
# define USE_CONSOLE 1
#define USE_CONSOLE 1
#endif
#if 0 || (NO_CONSOLE) || !(USE_CONSOLE)
# undef USE_CONSOLE
# undef USE_ANSI
# undef USE_SCREEN
# undef USE_SCREEN_VCSA
# undef USE_SCREEN_CURSES
# undef USE_FRAMES
#undef USE_CONSOLE
#undef USE_ANSI
#undef USE_SCREEN
#undef USE_SCREEN_VCSA
#undef USE_SCREEN_CURSES
#undef USE_FRAMES
#endif
/*************************************************************************
//
**************************************************************************/
enum {
CON_INIT,
CON_NONE,
CON_FILE,
CON_ANSI_MONO,
CON_ANSI_COLOR,
CON_SCREEN,
CON_UNUSED
};
enum { CON_INIT, CON_NONE, CON_FILE, CON_ANSI_MONO, CON_ANSI_COLOR, CON_SCREEN, CON_UNUSED };
#if (USE_CONSOLE)
typedef struct
{
typedef struct {
int (*init)(FILE *f, int, int);
int (*set_fg)(FILE *f, int fg);
void (*print0)(FILE *f, const char *s);
bool (*intro)(FILE *f);
}
console_t;
} console_t;
void con_fprintf(FILE *f, const char *format, ...) attribute_format(2, 3);
#define FG_BLACK 0x00
#define FG_BLUE 0x01
#define FG_GREEN 0x02
#define FG_CYAN 0x03
#define FG_RED 0x04
#define FG_VIOLET 0x05
#define FG_ORANGE 0x06
#define FG_LTGRAY 0x07
#define FG_DKGRAY 0x08
#define FG_BRTBLUE 0x09
#define FG_BRTGREEN 0x0a
#define FG_BRTCYAN 0x0b
#define FG_BRTRED 0x0c
#define FG_BLACK 0x00
#define FG_BLUE 0x01
#define FG_GREEN 0x02
#define FG_CYAN 0x03
#define FG_RED 0x04
#define FG_VIOLET 0x05
#define FG_ORANGE 0x06
#define FG_LTGRAY 0x07
#define FG_DKGRAY 0x08
#define FG_BRTBLUE 0x09
#define FG_BRTGREEN 0x0a
#define FG_BRTCYAN 0x0b
#define FG_BRTRED 0x0c
#define FG_BRTVIOLET 0x0d
#define FG_YELLOW 0x0e
#define FG_WHITE 0x0f
#define FG_YELLOW 0x0e
#define FG_WHITE 0x0f
#define BG_BLACK 0x00
#define BG_BLUE 0x10
#define BG_GREEN 0x20
#define BG_CYAN 0x30
#define BG_RED 0x40
#define BG_VIOLET 0x50
#define BG_ORANGE 0x60
#define BG_WHITE 0x70
#define BG_BLACK 0x00
#define BG_BLUE 0x10
#define BG_GREEN 0x20
#define BG_CYAN 0x30
#define BG_RED 0x40
#define BG_VIOLET 0x50
#define BG_ORANGE 0x60
#define BG_WHITE 0x70
#endif /* USE_CONSOLE */
/*************************************************************************
//
**************************************************************************/
@ -172,13 +153,12 @@ extern console_t console_ansi_mono;
extern console_t console_ansi_color;
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
#define con_fg(f,x) 0
#define con_fprintf fprintf
#define con_fg(f, x) 0
#define con_fprintf fprintf
#endif /* USE_CONSOLE */

View File

@ -25,10 +25,8 @@
<markus@oberhumer.com> <ezerotven+github@gmail.com>
*/
#include "conf.h"
/*************************************************************************
// FIXME: if stdout is redirected to a file and stderr is not, should
// we write all error messages to both stderr and stdout ?
@ -36,25 +34,20 @@
static int pr_need_nl = 0;
void printSetNl(int need_nl) { pr_need_nl = need_nl; }
void printSetNl(int need_nl)
{
pr_need_nl = need_nl;
}
void printClearLine(FILE *f)
{
static char clear_line_msg[1+79+1+1];
if (!clear_line_msg[0])
{
void printClearLine(FILE *f) {
static char clear_line_msg[1 + 79 + 1 + 1];
if (!clear_line_msg[0]) {
char *msg = clear_line_msg;
msg[0] = '\r';
memset(msg+1,' ',79);
memset(msg + 1, ' ', 79);
msg[80] = '\r';
msg[81] = 0;
}
fflush(stdout); fflush(stderr);
fflush(stdout);
fflush(stderr);
if (f == nullptr)
f = stdout;
con_fprintf(f, "%s", clear_line_msg);
@ -62,24 +55,21 @@ void printClearLine(FILE *f)
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)
con_fprintf(stderr, "%s", msg);
else
fprintf(stderr, "%s", msg);
}
static void pr_error(const char *iname, const char *msg, bool is_warning)
{
fflush(stdout); fflush(stderr);
static void pr_error(const char *iname, const char *msg, bool is_warning) {
fflush(stdout);
fflush(stderr);
char buf[1024];
buf[0] = 0;
if (pr_need_nl == 2)
printClearLine(stdout);
else if (pr_need_nl)
{
else if (pr_need_nl) {
buf[0] = '\n';
buf[1] = 0;
printSetNl(0);
@ -90,35 +80,34 @@ static void pr_error(const char *iname, const char *msg, bool is_warning)
// At least I can use some colors then...
bool c = acc_isatty(STDERR_FILENO) ? 1 : 0;
int fg = con_fg(stderr,FG_BRTRED);
snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),"%s: ", progname);
pr_print(c,buf);
int fg = con_fg(stderr, FG_BRTRED);
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s: ", progname);
pr_print(c, buf);
//(void)con_fg(stderr,FG_RED);
snprintf(buf,sizeof(buf),"%s: ", iname);
pr_print(c,buf);
snprintf(buf, sizeof(buf), "%s: ", iname);
pr_print(c, buf);
//(void)con_fg(stderr,FG_BRTRED);
pr_print(c,msg);
pr_print(c,"\n");
fflush(stdout); fflush(stderr);
fg = con_fg(stderr,fg);
pr_print(c, msg);
pr_print(c, "\n");
fflush(stdout);
fflush(stderr);
fg = con_fg(stderr, fg);
UNUSED(is_warning);
UNUSED(fg);
}
void printErr(const char *iname, const Throwable *e)
{
void printErr(const char *iname, const Throwable *e) {
char buf[1024];
size_t l;
snprintf(buf, sizeof(buf), "%s", prettyName(typeid(*e).name()));
l = strlen(buf);
if (l < sizeof(buf) && e->getMsg())
snprintf(buf+l, sizeof(buf)-l, ": %s", e->getMsg());
snprintf(buf + l, sizeof(buf) - l, ": %s", e->getMsg());
l = strlen(buf);
if (l < sizeof(buf) && e->getErrno()) {
snprintf(buf+l, sizeof(buf)-l, ": %s", strerror(e->getErrno()));
snprintf(buf + l, sizeof(buf) - l, ": %s", strerror(e->getErrno()));
#if 1
// some compilers (e.g. Borland C++) put a trailing '\n'
// into strerror() result
@ -127,127 +116,103 @@ void printErr(const char *iname, const Throwable *e)
buf[l] = 0;
#endif
}
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;
char buf[1024];
va_start(args,format);
upx_safe_vsnprintf(buf,sizeof(buf),format,args);
va_start(args, format);
upx_safe_vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
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;
char buf[1024];
va_start(args,format);
upx_safe_vsnprintf(buf,sizeof(buf),format,args);
va_start(args, format);
upx_safe_vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
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)
printErr(iname,"unhandled exception: %s\n", prettyName(e->what()));
printErr(iname, "unhandled exception: %s\n", prettyName(e->what()));
else
printErr(iname,"internal error: unhandled exception!\n");
if (opt->cmd != CMD_COMPRESS)
{
printErr(iname," this file has possibly been modified/hacked; take care!\n");
printErr(iname, "internal error: unhandled exception!\n");
if (opt->cmd != CMD_COMPRESS) {
printErr(iname, " this file has possibly been modified/hacked; take care!\n");
}
}
/*************************************************************************
// FIXME: should use colors and a consistent layout here
**************************************************************************/
static int info_header = 0;
static void info_print(const char *msg)
{
static void info_print(const char *msg) {
if (opt->info_mode <= 0)
return;
FILE *f = opt->to_stdout ? stderr : stdout;
if (pr_need_nl)
{
if (pr_need_nl) {
printClearLine(f);
con_fprintf(f,"%s\n",msg);
}
else if (pr_need_nl)
con_fprintf(f,"\n%s\n",msg);
con_fprintf(f, "%s\n", msg);
} else if (pr_need_nl)
con_fprintf(f, "\n%s\n", msg);
else
con_fprintf(f,"%s\n",msg);
con_fprintf(f, "%s\n", msg);
fflush(f);
printSetNl(0);
}
void infoHeader() { info_header = 0; }
void infoHeader()
{
info_header = 0;
}
void infoHeader(const char *format, ...)
{
void infoHeader(const char *format, ...) {
if (opt->info_mode <= 0)
return;
va_list args;
char buf[1024];
va_start(args,format);
upx_safe_vsnprintf(buf,sizeof(buf),format,args);
va_start(args, format);
upx_safe_vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
info_print(buf);
info_header = 1;
}
void info(const char *format, ...)
{
void info(const char *format, ...) {
if (opt->info_mode <= 0)
return;
va_list args;
char buf[1024];
const int n = 4 * info_header;
memset(buf, ' ', n);
va_start(args,format);
upx_safe_vsnprintf(buf+n,sizeof(buf)-n,format,args);
va_start(args, format);
upx_safe_vsnprintf(buf + n, sizeof(buf) - n, format, args);
va_end(args);
info_print(buf);
}
void infoWarning(const char *format, ...)
{
if (opt->info_mode <= 0)
{
void infoWarning(const char *format, ...) {
if (opt->info_mode <= 0) {
// FIXME - should still print something here
return;
}
va_list args;
char buf[1024];
va_start(args,format);
upx_safe_vsnprintf(buf,sizeof(buf),format,args);
va_start(args, format);
upx_safe_vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
info("[WARNING] %s\n", buf);
}
void infoWriting(const char *what, long size)
{
void infoWriting(const char *what, long size) {
if (opt->info_mode <= 0)
return;
info("Writing %s: %ld bytes", what, size);