Add decimal places macro and fuck around config.h

This commit is contained in:
Piotr Marendowski 2024-03-30 22:00:57 +01:00
parent 1f0f19174a
commit 721cbfff35
4 changed files with 31 additions and 25 deletions

View file

@ -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 SRC = ccc.c util.c file.c icons.c
$(TARGET): $(SRC) $(TARGET): $(SRC) $(CONF)
$(CC) $(SRC) -o $@ $(CFLAGS) $(LDFLAGS) $(CC) $(SRC) -o $@ $(CFLAGS) $(LDFLAGS)
dist: dist:

19
ccc.c
View file

@ -621,28 +621,27 @@ void add_file_stat(char *filepath, int ftype)
bytes = total_dir_size; bytes = total_dir_size;
} }
} }
/* max 25 chars due to long, space, suffix and null */ /* 3 before decimal + 1 decimal + SIZE_OFFSET (after decimal) + 1 space + 1 null */
char *size = memalloc(8 * sizeof(char)); int size_size = 3 + 1 + DECIMAL_PLACES + 1 + 1;
char *size = memalloc(size_size * sizeof(char));
int unit = 0; int unit = 0;
const char* units[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB"};
while (bytes > 1024) { while (bytes > 1024) {
bytes /= 1024; bytes /= 1024;
unit++; unit++;
} }
/* display sizes */ /* display sizes and check if there are decimal places */
/* Check if there are decimal places */
if (bytes == (unsigned int) bytes) { if (bytes == (unsigned int) bytes) {
sprintf(size, "%d%s", (unsigned int) bytes, units[unit]); sprintf(size, "%d%s", (unsigned int) bytes, units[unit]);
} else { } else {
sprintf(size, "%.2f%s", bytes, units[unit]); sprintf(size, "%.*f%s", DECIMAL_PLACES, bytes, units[unit]);
} }
/* get file mode string */ /* get file mode string */
char *mode_str = get_file_mode(file_stat.st_mode); char *mode_str = get_file_mode(file_stat.st_mode);
/* 11 + 17 + 8 + 1 for null */ /* 11 + 17 + size_size + 1 space + 1 null */
char *total_stat = memalloc(37 * sizeof(char)); int stat_size = 11 + 17 + size_size + 1 + 1;
snprintf(total_stat, 37, "%s %s %-8s", mode_str, time, size); 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); arraylist_add(files, filepath, total_stat, type, icon_str, color, false, false);

View file

@ -1,21 +1,15 @@
#include "icons.h" #include "icons.h"
/* Settings */ /* Settings */
#define PH 1 /* panel height */ #define PH 1 /* panel height */
#define JUMP_NUM 14 /* how long ctrl + u/d jump are */ #define JUMP_NUM 14 /* how long ctrl + u/d jump are */
#define PATH_MAX 4096 #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? */ /* Size units */
#define DIRS_SIZE false const char* units[] = {"B", "K", "M", "G", "T", "P"};
#define DRAW_BORDERS true /* Draw borders around windows? */ /* Set width offset for 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:
+-------------%-------------+ +-------------%-------------+
| % | | % |
| files % preview | | files % preview |
@ -29,13 +23,25 @@ In COLS:
-15 will make preview bigger */ -15 will make preview bigger */
#define WINDOW_OFFSET 0 #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 */ /* Default text editor */
#define EDITOR "nvim" #define EDITOR "nvim"
/* File location to write last directory */ /* File location to write last directory */
#define LAST_D "~/.cache/ccc/.ccc_d" #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/" #define TRASH_DIR "~/.cache/ccc/trash/"
/* Keybindings */ /* Keybindings */

View file

@ -44,6 +44,7 @@ void hashtable_init()
strcpy(hpp->name, "hpp"); strcpy(hpp->name, "hpp");
hpp->icon = L"󰰀"; hpp->icon = L"󰰀";
icon *md = memalloc(sizeof(icon)); icon *md = memalloc(sizeof(icon));
strcpy(md->name, "md"); strcpy(md->name, "md");
md->icon = L""; md->icon = L"";