diff --git a/Makefile b/Makefile index 4eeec43..ce65e35 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ CFLAGS = -O3 -march=native -mtune=native -pipe -s -std=c99 -pedantic -Wall -D_DE SRC = ccc.c util.c file.c icons.c -$(TARGET): $(SRC) +$(TARGET): $(SRC) $(CONF) $(CC) $(SRC) -o $@ $(CFLAGS) $(LDFLAGS) dist: diff --git a/ccc.c b/ccc.c index 5cfa39d..e506152 100644 --- a/ccc.c +++ b/ccc.c @@ -621,28 +621,27 @@ void add_file_stat(char *filepath, int ftype) bytes = total_dir_size; } } - /* max 25 chars due to long, space, suffix and null */ - char *size = memalloc(8 * sizeof(char)); + /* 3 before decimal + 1 decimal + SIZE_OFFSET (after decimal) + 1 space + 1 null */ + int size_size = 3 + 1 + DECIMAL_PLACES + 1 + 1; + char *size = memalloc(size_size * sizeof(char)); int unit = 0; - const char* units[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB"}; while (bytes > 1024) { bytes /= 1024; unit++; } - /* display sizes */ - /* Check if there are decimal places */ + /* display sizes and check if there are decimal places */ if (bytes == (unsigned int) bytes) { sprintf(size, "%d%s", (unsigned int) bytes, units[unit]); } else { - sprintf(size, "%.2f%s", bytes, units[unit]); + sprintf(size, "%.*f%s", DECIMAL_PLACES, bytes, units[unit]); } - /* get file mode string */ char *mode_str = get_file_mode(file_stat.st_mode); - /* 11 + 17 + 8 + 1 for null */ - char *total_stat = memalloc(37 * sizeof(char)); - snprintf(total_stat, 37, "%s %s %-8s", mode_str, time, size); + /* 11 + 17 + size_size + 1 space + 1 null */ + int stat_size = 11 + 17 + size_size + 1 + 1; + char *total_stat = memalloc(stat_size * sizeof(char)); + snprintf(total_stat, stat_size, "%s %s %-*s ", mode_str, time, size_size, size); arraylist_add(files, filepath, total_stat, type, icon_str, color, false, false); diff --git a/config.h b/config.h index 52032bc..7c2202c 100644 --- a/config.h +++ b/config.h @@ -1,21 +1,15 @@ #include "icons.h" /* Settings */ -#define PH 1 /* panel height */ -#define JUMP_NUM 14 /* how long ctrl + u/d jump are */ -#define PATH_MAX 4096 +#define PH 1 /* panel height */ +#define JUMP_NUM 14 /* how long ctrl + u/d jump are */ +#define PATH_MAX 4096 /* max length of the path */ +#define DECIMAL_PLACES 1 /* how many decimal places show size with */ -/* Calculate directories' sizes RECURSIVELY upon entering? */ -#define DIRS_SIZE false +/* Size units */ +const char* units[] = {"B", "K", "M", "G", "T", "P"}; -#define DRAW_BORDERS true /* Draw borders around windows? */ -#define DRAW_PREVIEW true /* Draw file preview? */ - -#define SHOW_HIDDEN true /* show hidden files/dotfiles in preview */ -#define SHOW_DETAILS true /* show file details */ -#define SHOW_ICONS true /* show file icons */ - -/* set width offset for windows: +/* Set width offset for windows: +-------------%-------------+ | % | | files % preview | @@ -29,13 +23,25 @@ In COLS: -15 will make preview bigger */ #define WINDOW_OFFSET 0 +/* Options */ +#define DRAW_BORDERS true /* draw borders around windows */ +#define DRAW_PREVIEW true /* draw file preview */ + +#define SHOW_HIDDEN true /* show hidden files/dotfiles at startup */ +#define SHOW_DETAILS true /* show file details at startup */ +#define SHOW_ICONS true /* show file icons at startup */ + +/* Calculate directories' sizes RECURSIVELY upon entering + `A` keybind at the startup */ +#define DIRS_SIZE false + /* Default text editor */ #define EDITOR "nvim" /* File location to write last directory */ #define LAST_D "~/.cache/ccc/.ccc_d" -/* will create this directory if doesn't exist! */ +/* Will create this directory if doesn't exist! */ #define TRASH_DIR "~/.cache/ccc/trash/" /* Keybindings */ diff --git a/icons.c b/icons.c index 135955b..1c20868 100644 --- a/icons.c +++ b/icons.c @@ -44,6 +44,7 @@ void hashtable_init() strcpy(hpp->name, "hpp"); hpp->icon = L"󰰀"; + icon *md = memalloc(sizeof(icon)); strcpy(md->name, "md"); md->icon = L"";