Revert some stuff

This commit is contained in:
Piotr Marendowski 2024-03-17 11:09:22 +01:00
parent e80f9ccd7f
commit 86e8733e08
2 changed files with 12 additions and 11 deletions

21
ccc.c
View file

@ -202,7 +202,7 @@ int main(int argc, char** argv)
} }
break; break;
/* go to $HOME */ /* '~' go to $HOME */
case TILDE:; case TILDE:;
char *home = getenv("HOME"); char *home = getenv("HOME");
if (home == NULL) { if (home == NULL) {
@ -385,7 +385,7 @@ int get_directory_size(const char *fpath, const struct stat *sb, int typeflag, s
/* /*
* Get file's last modified time, size, type * Get file's last modified time, size, type
* Add that file into list * Add that file into list
* ftype: 0 = normal file, 1 = marked * ftype: normal file = 0, marked = 1
*/ */
long add_file_stat(char *filepath, int ftype) long add_file_stat(char *filepath, int ftype)
{ {
@ -427,6 +427,8 @@ long add_file_stat(char *filepath, int ftype)
/* if file is to be marked */ /* if file is to be marked */
if (ftype == 1) { if (ftype == 1) {
long index = add_marked(filepath, type); long index = add_marked(filepath, type);
/* free type and return without allocating more stuff */
free(type);
if (index != -1) { if (index != -1) {
return index; /* just marked */ return index; /* just marked */
} else { } else {
@ -454,23 +456,22 @@ long add_file_stat(char *filepath, int ftype)
/* max 25 chars due to long, space, suffix and null */ /* max 25 chars due to long, space, suffix and null */
char *size = memalloc(25 * sizeof(char)); char *size = memalloc(25 * sizeof(char));
int unit = 0; int unit = 0;
const char* units[] = {" B", "KiB", "MiB", "GiB", "TiB", "PiB"}; const char* units[] = {"B", "KB", "MB", "GB", "TB", "PB"};
while (bytes > 1024) { while (bytes > 1024) {
bytes /= 1024; bytes /= 1024;
unit++; unit++;
} }
/* 4 sig fig, limiting characters to have better format */ /* display sizes */
sprintf(size, "%-6.4g %-3s", bytes, units[unit]); sprintf(size, "%.3g%s", bytes, units[unit]);
char *total_stat = memalloc(45 * sizeof(char)); char *total_stat = memalloc(45 * sizeof(char));
snprintf(total_stat, 45, "%-18s %-10s", time, size); snprintf(total_stat, 45, "%-18s %-8s", time, size);
total_stat[strlen(total_stat)] = '\0'; total_stat[strlen(total_stat)] = '\0';
free(time);
free(size);
long index = add_file(filepath, total_stat, type, color); long index = add_file(filepath, total_stat, type, color);
free(time);
free(size);
free(total_stat); free(total_stat);
free(type); free(type);
return index; return index;
@ -636,7 +637,7 @@ void edit_file()
} }
/* /*
* Print line to panel * Print line to the panel
*/ */
void wpprintw(const char *line) void wpprintw(const char *line)
{ {

View file

@ -2,7 +2,7 @@
#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 */
/* Calculate directories' sizes upon entering? */ /* Calculate directories' sizes RECURSIVELY upon entering? */
#define DIRS_SIZE false #define DIRS_SIZE false
/* Default text editor */ /* Default text editor */