чување 0ea5903b70d2990a3d8786ab92d2388cda101165
родитељ 38c29279d8c8fc4dda306d37c5f6ba4478f01733
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Sun, 27 Feb 2022 21:38:41 +0100
Output empty lines as empty rows; BOOL -> int
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | defs.h | | | 6 | ------ |
| M | table.c | | | 79 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------- |
измењених датотека: 2, додавања: 58(+), брисања: 27(-)
diff --git a/defs.h b/defs.h
@@ -11,12 +11,6 @@
#define ANSI_SGR_BOLD_ON "\e[1m"
#define ANSI_SGR_BOLD_OFF "\e[0m"
-typedef enum
-{
- FALSE = 0,
- TRUE = 1
-} BOOL;
-
typedef unsigned char UBYTE;
typedef unsigned int UINT;
typedef unsigned long ULONG;
diff --git a/table.c b/table.c
@@ -76,10 +76,10 @@ u32 delimiter = L',';
ULONG* format = NULL;
size_t format_size = 0;
ULONG format_value = 0;
-BOOL border_mode = FALSE;
-BOOL handle_ansi = TRUE;
-BOOL msdos = FALSE;
-BOOL expand_tabs = FALSE;
+int border_mode = 0;
+int handle_ansi = 1;
+int msdos = 0;
+int expand_tabs = 0;
int
version()
@@ -131,14 +131,14 @@ substr(const char* src, int start, int finish)
return result;
}
-BOOL
+int
startswith(const char* s, const char* what)
{
if (!s || !what)
return 0;
- char* subs = substr(s, 0, strlen(what));
- BOOL result = !strcmp(subs, what);
+ char* subs = substr(s, 0, strlen(what));
+ int result = !strcmp(subs, what);
free(subs);
@@ -350,7 +350,7 @@ round_div(UINT a, UINT b)
return (a + (b / 2)) / b;
}
-BOOL
+int
within_column(size_t column_start)
{
return format ? (current_rune_column
@@ -381,7 +381,7 @@ do_arg:
else if (startswith(arg, "border-mode"))
{
arg += strlen("border-mode");
- border_mode = TRUE;
+ border_mode = 1;
}
else if (startswith(arg, "columns="))
{
@@ -404,7 +404,7 @@ do_arg:
else if (startswith(arg, "expand-tabs"))
{
arg += strlen("expand-tabs");
- expand_tabs = TRUE;
+ expand_tabs = 1;
}
else if (startswith(arg, "format="))
{
@@ -414,12 +414,12 @@ do_arg:
else if (startswith(arg, "msdos"))
{
arg += strlen("msdos");
- msdos = TRUE;
+ msdos = 1;
}
else if (startswith(arg, "no-ansi"))
{
arg += strlen("no-ansi");
- handle_ansi = FALSE;
+ handle_ansi = 0;
}
else if (startswith(arg, "symbols="))
{
@@ -444,7 +444,7 @@ do_arg:
switch (c)
{
case 'b':
- border_mode = TRUE;
+ border_mode = 1;
break;
case 'c':
cmd = CMD_COLUMNS;
@@ -459,16 +459,16 @@ do_arg:
return usage();
break;
case 'm':
- msdos = TRUE;
+ msdos = 1;
break;
case 'n':
- handle_ansi = FALSE;
+ handle_ansi = 0;
break;
case 's':
cmd = CMD_SYMBOLS;
break;
case 't':
- expand_tabs = TRUE;
+ expand_tabs = 1;
break;
case 'v':
cmd = CMD_VERSION;
@@ -526,9 +526,9 @@ done_arg:
else
input = stdin;
- u8* line = NULL;
- u8* pline = NULL;
- BOOL quote = FALSE;
+ u8* line = NULL;
+ u8* pline = NULL;
+ int quote = 0;
u32 uch;
u8 u8ch[7];
size_t u8len = 0;
@@ -555,9 +555,9 @@ do_input:
}
if (!*line)
- goto do_input;
+ goto empty_line;
- quote = FALSE;
+ quote = 0;
pline = line;
colno = 0;
current_rune_column = 0;
@@ -648,6 +648,43 @@ do_column:
done_columns:
printf("\n");
output_lines++;
+ goto not_first;
+
+empty_line:
+ current_table_column = 0;
+ current_rune_column = 0;
+ column_start = 0;
+ u8len = u32_char_to_u8(u8ch, *table_symbols[current_symbol_set][3]);
+ u8ch[u8len] = 0;
+ printf("%s", u8ch);
+ while (current_table_column < table_columns - 1)
+ {
+ while (within_column(column_start))
+ {
+ printf(" ");
+ current_rune_column++;
+ }
+ u8len = u32_char_to_u8(u8ch,
+ *table_inner_symbols[current_inner_symbol_set][1]);
+ u8ch[u8len] = 0;
+ printf("%s", u8ch);
+ column_start++;
+ if (format)
+ column_start += *(format + current_table_column);
+ else
+ column_start += format_value;
+ current_table_column++;
+ current_rune_column++;
+ }
+ while (within_column(column_start))
+ {
+ printf(" ");
+ current_rune_column++;
+ }
+ u8len = u32_char_to_u8(u8ch, *table_symbols[current_symbol_set][5]);
+ u8ch[u8len] = 0;
+ printf("%s\n", u8ch);
+ goto do_input;
not_first:
/* Inner rows */