mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Clean up indentation
This commit is contained in:
parent
e54a13827b
commit
ce3101a380
4 changed files with 118 additions and 112 deletions
|
|
@ -24,18 +24,18 @@
|
|||
|
||||
struct config_t
|
||||
{
|
||||
const char *user;
|
||||
const char *user;
|
||||
|
||||
char *path;
|
||||
char *section_name;
|
||||
char *match;
|
||||
char *path;
|
||||
char *section_name;
|
||||
char *match;
|
||||
|
||||
char *tty;
|
||||
char *flow;
|
||||
char *parity;
|
||||
char *log_filename;
|
||||
char *socket;
|
||||
char *map;
|
||||
char *tty;
|
||||
char *flow;
|
||||
char *parity;
|
||||
char *log_filename;
|
||||
char *socket;
|
||||
char *map;
|
||||
};
|
||||
|
||||
void config_file_print(void);
|
||||
|
|
|
|||
72
src/error.c
72
src/error.c
|
|
@ -38,64 +38,64 @@ static bool in_session = false;
|
|||
|
||||
void error_enter_session_mode(void)
|
||||
{
|
||||
in_session = true;
|
||||
in_session = true;
|
||||
}
|
||||
|
||||
void error_printf_(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
char *line;
|
||||
va_list args;
|
||||
char *line;
|
||||
|
||||
va_start(args, format);
|
||||
vasprintf(&line, format, args);
|
||||
va_start(args, format);
|
||||
vasprintf(&line, format, args);
|
||||
|
||||
if (in_session)
|
||||
{
|
||||
if (print_tainted)
|
||||
if (in_session)
|
||||
{
|
||||
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;
|
||||
free(line);
|
||||
print_tainted = false;
|
||||
free(line);
|
||||
}
|
||||
|
||||
void tio_error_printf(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
vsnprintf(error[0], 1000, format, args);
|
||||
va_end(args);
|
||||
va_start(args, format);
|
||||
vsnprintf(error[0], 1000, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void tio_error_printf_silent(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
vsnprintf(error[1], 1000, format, args);
|
||||
va_end(args);
|
||||
va_start(args, format);
|
||||
vsnprintf(error[1], 1000, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void error_exit(void)
|
||||
{
|
||||
if (error[0][0] != 0)
|
||||
{
|
||||
/* Print error */
|
||||
error_printf_("Error: %s", error[0]);
|
||||
}
|
||||
else if ((error[1][0] != 0) && (option.no_autoconnect))
|
||||
{
|
||||
/* Print silent error */
|
||||
error_printf_("Error: %s", error[1]);
|
||||
}
|
||||
if (error[0][0] != 0)
|
||||
{
|
||||
/* Print error */
|
||||
error_printf_("Error: %s", error[0]);
|
||||
}
|
||||
else if ((error[1][0] != 0) && (option.no_autoconnect))
|
||||
{
|
||||
/* Print silent error */
|
||||
error_printf_("Error: %s", error[1]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
50
src/print.c
50
src/print.c
|
|
@ -31,45 +31,45 @@ char ansi_format[30];
|
|||
|
||||
void print_hex(char c)
|
||||
{
|
||||
printf("%02x ", (unsigned char) c);
|
||||
printf("%02x ", (unsigned char) c);
|
||||
}
|
||||
|
||||
void print_normal(char c)
|
||||
{
|
||||
putchar(c);
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
void print_init_ansi_formatting()
|
||||
{
|
||||
if (option.color == 256)
|
||||
{
|
||||
// Set bold text with no color changes
|
||||
sprintf(ansi_format, "\e[1m");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set bold text with user defined ANSI color
|
||||
sprintf(ansi_format, "\e[1;38;5;%dm", option.color);
|
||||
}
|
||||
if (option.color == 256)
|
||||
{
|
||||
// Set bold text with no color changes
|
||||
sprintf(ansi_format, "\e[1m");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set bold text with user defined ANSI color
|
||||
sprintf(ansi_format, "\e[1;38;5;%dm", option.color);
|
||||
}
|
||||
}
|
||||
|
||||
void tio_printf_array(const char *array)
|
||||
{
|
||||
int i = 0, j = 0;
|
||||
int i = 0, j = 0;
|
||||
|
||||
tio_printf("");
|
||||
tio_printf("");
|
||||
|
||||
while (array[i])
|
||||
{
|
||||
if (array[i] == '\n')
|
||||
while (array[i])
|
||||
{
|
||||
const char *line = &array[j];
|
||||
char *line_copy = strndup(line, i-j);
|
||||
tio_printf_raw("%s\r", line_copy);
|
||||
free(line_copy);
|
||||
j = i;
|
||||
if (array[i] == '\n')
|
||||
{
|
||||
const char *line = &array[j];
|
||||
char *line_copy = strndup(line, i-j);
|
||||
tio_printf_raw("%s\r", line_copy);
|
||||
free(line_copy);
|
||||
j = i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
tio_printf("");
|
||||
tio_printf("");
|
||||
}
|
||||
|
|
|
|||
88
src/print.h
88
src/print.h
|
|
@ -35,72 +35,78 @@ extern char ansi_format[];
|
|||
|
||||
#define ansi_printf(format, args...) \
|
||||
{ \
|
||||
if (!option.mute) { \
|
||||
if (option.color < 0) \
|
||||
fprintf (stdout, "\r" format "\r\n", ## args); \
|
||||
else \
|
||||
fprintf (stdout, "\r%s" format ANSI_RESET "\r\n", ansi_format, ## args); \
|
||||
} \
|
||||
if (!option.mute) \
|
||||
{ \
|
||||
if (option.color < 0) \
|
||||
fprintf (stdout, "\r" format "\r\n", ## args); \
|
||||
else \
|
||||
fprintf (stdout, "\r%s" format ANSI_RESET "\r\n", ansi_format, ## args); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ansi_error_printf(format, args...) \
|
||||
{ \
|
||||
if (!option.mute) { \
|
||||
if (option.color < 0) \
|
||||
fprintf (stderr, "\r" format "\r\n", ## args); \
|
||||
else \
|
||||
fprintf (stderr, "\r%s" format ANSI_RESET "\r\n", ansi_format, ## args); \
|
||||
fflush(stderr); \
|
||||
} \
|
||||
if (!option.mute) \
|
||||
{ \
|
||||
if (option.color < 0) \
|
||||
fprintf (stderr, "\r" format "\r\n", ## args); \
|
||||
else \
|
||||
fprintf (stderr, "\r%s" format ANSI_RESET "\r\n", ansi_format, ## args); \
|
||||
fflush(stderr); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ansi_printf_raw(format, args...) \
|
||||
{ \
|
||||
if (!option.mute) { \
|
||||
if (option.color < 0) \
|
||||
fprintf (stdout, format, ## args); \
|
||||
else \
|
||||
fprintf (stdout, "%s" format ANSI_RESET, ansi_format, ## args); \
|
||||
} \
|
||||
if (!option.mute) \
|
||||
{ \
|
||||
if (option.color < 0) \
|
||||
fprintf (stdout, format, ## args); \
|
||||
else \
|
||||
fprintf (stdout, "%s" format ANSI_RESET, ansi_format, ## args); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define tio_warning_printf(format, args...) \
|
||||
{ \
|
||||
if (!option.mute) { \
|
||||
if (print_tainted) \
|
||||
putchar('\n'); \
|
||||
if (option.color < 0) \
|
||||
fprintf (stdout, "\r[%s] Warning: " format "\r\n", timestamp_current_time(), ## args); \
|
||||
else \
|
||||
ansi_printf("[%s] Warning: " format, timestamp_current_time(), ## args); \
|
||||
} \
|
||||
if (!option.mute) \
|
||||
{ \
|
||||
if (print_tainted) \
|
||||
putchar('\n'); \
|
||||
if (option.color < 0) \
|
||||
fprintf (stdout, "\r[%s] Warning: " format "\r\n", timestamp_current_time(), ## args); \
|
||||
else \
|
||||
ansi_printf("[%s] Warning: " format, timestamp_current_time(), ## args); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define tio_printf(format, args...) \
|
||||
{ \
|
||||
if (!option.mute) { \
|
||||
if (print_tainted) \
|
||||
putchar('\n'); \
|
||||
ansi_printf("[%s] " format, timestamp_current_time(), ## args); \
|
||||
print_tainted = false; \
|
||||
} \
|
||||
if (!option.mute) \
|
||||
{ \
|
||||
if (print_tainted) \
|
||||
putchar('\n'); \
|
||||
ansi_printf("[%s] " format, timestamp_current_time(), ## args); \
|
||||
print_tainted = false; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define tio_printf_raw(format, args...) \
|
||||
{ \
|
||||
if (!option.mute) { \
|
||||
if (print_tainted) \
|
||||
putchar('\n'); \
|
||||
ansi_printf_raw("[%s] " format, timestamp_current_time(), ## args); \
|
||||
print_tainted = false; \
|
||||
} \
|
||||
if (!option.mute) \
|
||||
{ \
|
||||
if (print_tainted) \
|
||||
putchar('\n'); \
|
||||
ansi_printf_raw("[%s] " format, timestamp_current_time(), ## args); \
|
||||
print_tainted = false; \
|
||||
} \
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#define tio_debug_printf(format, args...) \
|
||||
fprintf (stdout, "[debug] " format, ## args)
|
||||
fprintf(stdout, "[debug] " format, ## args)
|
||||
#define tio_debug_printf_raw(format, args...) \
|
||||
fprintf (stdout, "" format, ## args)
|
||||
fprintf(stdout, "" format, ## args)
|
||||
#else
|
||||
#define tio_debug_printf(format, args...)
|
||||
#define tio_debug_printf_raw(format, args...)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue