Clean up indentation

This commit is contained in:
Martin Lund 2022-09-18 19:20:12 +02:00
parent e54a13827b
commit ce3101a380
4 changed files with 118 additions and 112 deletions

View file

@ -24,18 +24,18 @@
struct config_t struct config_t
{ {
const char *user; const char *user;
char *path; char *path;
char *section_name; char *section_name;
char *match; char *match;
char *tty; char *tty;
char *flow; char *flow;
char *parity; char *parity;
char *log_filename; char *log_filename;
char *socket; char *socket;
char *map; char *map;
}; };
void config_file_print(void); void config_file_print(void);

View file

@ -38,64 +38,64 @@ static bool in_session = false;
void error_enter_session_mode(void) void error_enter_session_mode(void)
{ {
in_session = true; in_session = true;
} }
void error_printf_(const char *format, ...) void error_printf_(const char *format, ...)
{ {
va_list args; va_list args;
char *line; char *line;
va_start(args, format); va_start(args, format);
vasprintf(&line, format, args); vasprintf(&line, format, args);
if (in_session) if (in_session)
{
if (print_tainted)
{ {
putchar('\n'); if (print_tainted)
{
putchar('\n');
}
ansi_error_printf("[%s] %s", timestamp_current_time(), line);
}
else
{
fprintf(stderr, "%s\n", line);
} }
ansi_error_printf("[%s] %s", timestamp_current_time(), line);
}
else
{
fprintf(stderr, "%s\n", line);
}
va_end(args); va_end(args);
print_tainted = false; print_tainted = false;
free(line); free(line);
} }
void tio_error_printf(const char *format, ...) void tio_error_printf(const char *format, ...)
{ {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
vsnprintf(error[0], 1000, format, args); vsnprintf(error[0], 1000, format, args);
va_end(args); va_end(args);
} }
void tio_error_printf_silent(const char *format, ...) void tio_error_printf_silent(const char *format, ...)
{ {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
vsnprintf(error[1], 1000, format, args); vsnprintf(error[1], 1000, format, args);
va_end(args); va_end(args);
} }
void error_exit(void) void error_exit(void)
{ {
if (error[0][0] != 0) if (error[0][0] != 0)
{ {
/* Print error */ /* Print error */
error_printf_("Error: %s", error[0]); error_printf_("Error: %s", error[0]);
} }
else if ((error[1][0] != 0) && (option.no_autoconnect)) else if ((error[1][0] != 0) && (option.no_autoconnect))
{ {
/* Print silent error */ /* Print silent error */
error_printf_("Error: %s", error[1]); error_printf_("Error: %s", error[1]);
} }
} }

View file

@ -31,45 +31,45 @@ char ansi_format[30];
void print_hex(char c) void print_hex(char c)
{ {
printf("%02x ", (unsigned char) c); printf("%02x ", (unsigned char) c);
} }
void print_normal(char c) void print_normal(char c)
{ {
putchar(c); putchar(c);
} }
void print_init_ansi_formatting() void print_init_ansi_formatting()
{ {
if (option.color == 256) if (option.color == 256)
{ {
// Set bold text with no color changes // Set bold text with no color changes
sprintf(ansi_format, "\e[1m"); sprintf(ansi_format, "\e[1m");
} }
else else
{ {
// Set bold text with user defined ANSI color // Set bold text with user defined ANSI color
sprintf(ansi_format, "\e[1;38;5;%dm", option.color); sprintf(ansi_format, "\e[1;38;5;%dm", option.color);
} }
} }
void tio_printf_array(const char *array) void tio_printf_array(const char *array)
{ {
int i = 0, j = 0; int i = 0, j = 0;
tio_printf(""); tio_printf("");
while (array[i]) while (array[i])
{
if (array[i] == '\n')
{ {
const char *line = &array[j]; if (array[i] == '\n')
char *line_copy = strndup(line, i-j); {
tio_printf_raw("%s\r", line_copy); const char *line = &array[j];
free(line_copy); char *line_copy = strndup(line, i-j);
j = i; tio_printf_raw("%s\r", line_copy);
free(line_copy);
j = i;
}
i++;
} }
i++; tio_printf("");
}
tio_printf("");
} }

View file

@ -35,72 +35,78 @@ extern char ansi_format[];
#define ansi_printf(format, args...) \ #define ansi_printf(format, args...) \
{ \ { \
if (!option.mute) { \ if (!option.mute) \
if (option.color < 0) \ { \
fprintf (stdout, "\r" format "\r\n", ## args); \ if (option.color < 0) \
else \ fprintf (stdout, "\r" format "\r\n", ## args); \
fprintf (stdout, "\r%s" format ANSI_RESET "\r\n", ansi_format, ## args); \ else \
} \ fprintf (stdout, "\r%s" format ANSI_RESET "\r\n", ansi_format, ## args); \
} \
} }
#define ansi_error_printf(format, args...) \ #define ansi_error_printf(format, args...) \
{ \ { \
if (!option.mute) { \ if (!option.mute) \
if (option.color < 0) \ { \
fprintf (stderr, "\r" format "\r\n", ## args); \ if (option.color < 0) \
else \ fprintf (stderr, "\r" format "\r\n", ## args); \
fprintf (stderr, "\r%s" format ANSI_RESET "\r\n", ansi_format, ## args); \ else \
fflush(stderr); \ fprintf (stderr, "\r%s" format ANSI_RESET "\r\n", ansi_format, ## args); \
} \ fflush(stderr); \
} \
} }
#define ansi_printf_raw(format, args...) \ #define ansi_printf_raw(format, args...) \
{ \ { \
if (!option.mute) { \ if (!option.mute) \
if (option.color < 0) \ { \
fprintf (stdout, format, ## args); \ if (option.color < 0) \
else \ fprintf (stdout, format, ## args); \
fprintf (stdout, "%s" format ANSI_RESET, ansi_format, ## args); \ else \
} \ fprintf (stdout, "%s" format ANSI_RESET, ansi_format, ## args); \
} \
} }
#define tio_warning_printf(format, args...) \ #define tio_warning_printf(format, args...) \
{ \ { \
if (!option.mute) { \ if (!option.mute) \
if (print_tainted) \ { \
putchar('\n'); \ if (print_tainted) \
if (option.color < 0) \ putchar('\n'); \
fprintf (stdout, "\r[%s] Warning: " format "\r\n", timestamp_current_time(), ## args); \ if (option.color < 0) \
else \ fprintf (stdout, "\r[%s] Warning: " format "\r\n", timestamp_current_time(), ## args); \
ansi_printf("[%s] Warning: " format, timestamp_current_time(), ## args); \ else \
} \ ansi_printf("[%s] Warning: " format, timestamp_current_time(), ## args); \
} \
} }
#define tio_printf(format, args...) \ #define tio_printf(format, args...) \
{ \ { \
if (!option.mute) { \ if (!option.mute) \
if (print_tainted) \ { \
putchar('\n'); \ if (print_tainted) \
ansi_printf("[%s] " format, timestamp_current_time(), ## args); \ putchar('\n'); \
print_tainted = false; \ ansi_printf("[%s] " format, timestamp_current_time(), ## args); \
} \ print_tainted = false; \
} \
} }
#define tio_printf_raw(format, args...) \ #define tio_printf_raw(format, args...) \
{ \ { \
if (!option.mute) { \ if (!option.mute) \
if (print_tainted) \ { \
putchar('\n'); \ if (print_tainted) \
ansi_printf_raw("[%s] " format, timestamp_current_time(), ## args); \ putchar('\n'); \
print_tainted = false; \ ansi_printf_raw("[%s] " format, timestamp_current_time(), ## args); \
} \ print_tainted = false; \
} \
} }
#ifdef DEBUG #ifdef DEBUG
#define tio_debug_printf(format, args...) \ #define tio_debug_printf(format, args...) \
fprintf (stdout, "[debug] " format, ## args) fprintf(stdout, "[debug] " format, ## args)
#define tio_debug_printf_raw(format, args...) \ #define tio_debug_printf_raw(format, args...) \
fprintf (stdout, "" format, ## args) fprintf(stdout, "" format, ## args)
#else #else
#define tio_debug_printf(format, args...) #define tio_debug_printf(format, args...)
#define tio_debug_printf_raw(format, args...) #define tio_debug_printf_raw(format, args...)