cex

C/Curses file EXplorer
git clone git://git.wimdupont.com/cex.git
Log | Files | Refs | README | LICENSE

commit 77d4880f24ae7d2a919c8a54a3ad4fac9f91751b
parent 810f07051268a0575959610cdf65e8f9aa7c09d1
Author: Wim Dupont <wim@wimdupont.com>
Date:   Sat, 14 Jun 2025 23:33:39 +0200

updated flags

Diffstat:
MMakefile | 8+-------
Mcex.c | 41+++++++++++++++++++++++------------------
Aconfig.mk | 11+++++++++++
3 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,10 +1,4 @@ -CC = gcc - -NAME = cex -VERSION = 0.1 - -PREFIX = /usr/local -MANPREFIX = ${PREFIX}/share/man +include config.mk BIN = cex SRC = cex.c diff --git a/cex.c b/cex.c @@ -16,6 +16,7 @@ #include "config.h" #define ctrl(x) ((x) & 0x1f) +#define arrlen(arr) (sizeof(arr)/sizeof(0[arr])) typedef enum {OTHER, LEFT, RIGHT, UP, DOWN} Direction; typedef enum {CURRENT, PARENT, CHILD} WinType; @@ -91,8 +92,8 @@ static int compare_file(const void *a, const void *b); static int get_mime(char *buf, size_t bufsize, const char *path); static int get_mime_default(char *buf, size_t bufsize, const char *mime); static int read_command(char *buf, size_t bufsize, const char *cmd); -static int make_file(const char *path); -static int make_dir(const char *path); +static int make_file(void); +static int make_dir(void); static int make_mod(void); static void make_access(void); static void make_open_default(void); @@ -539,7 +540,7 @@ print_win(DirWin *dirwin) } } else if (dirwin->winfiles != NULL) { while (!dirwin->usehighlight) { - for (size_t i = 0; i < dirwin->filecount; ++i) { + for (int i = 0; i < dirwin->filecount; ++i) { memcpy(name, dirwin->winfiles[i].d_name, size); name[size] = '\0'; if (strcmp(basename(curwin.path), dirwin->winfiles[i].d_name) == 0) { @@ -551,7 +552,7 @@ print_win(DirWin *dirwin) } break; } - for (size_t i = dirwin->startpr; i < dirwin->filecount; ++i) { + for (int i = dirwin->startpr; i < dirwin->filecount; ++i) { mvwaddch(dirwin->window, y, x-1, ' '); if (dirwin->winfiles[i].selected) { wattron(dirwin->window, COLOR_PAIR(MARK_SELECTED_COLOR)); @@ -873,12 +874,12 @@ combo_make(int key) { switch (key) { case KEY_COMBO_MAKE_FILE: - make_file(curwin.path); + make_file(); set_win_files(&curwin); update_child_win(); break; case KEY_COMBO_MAKE_DIR: - make_dir(curwin.path); + make_dir(); set_win_files(&curwin); update_child_win(); break; @@ -1101,7 +1102,7 @@ next_search(void) if (searchc == 0) return; - for (size_t i = curwin.highlight; i < MAX(curwin.filecount-1, 0); i++) { + for (int i = curwin.highlight; i < MAX(curwin.filecount-1, 0); i++) { if ((strstr(curwin.winfiles[i+1].d_name, searchq) != NULL)) { curwin.highlight = i+1; return; @@ -1115,7 +1116,7 @@ prev_search(void) if (searchc == 0) return; - for (size_t i = curwin.highlight; i > 0; i--) { + for (int i = curwin.highlight; i > 0; i--) { if ((strstr(curwin.winfiles[i-1].d_name, searchq) != NULL)) { curwin.highlight = i-1; return; @@ -1198,11 +1199,11 @@ human_readable_bytes(char *buf, intmax_t bytes) double dblBytes = bytes; int power = SIZE_DECIMAL_FORMAT ? 1000 : 1024; char *suffix[] = {"B", "KB", "MB", "GB", "TB"}; - char length = sizeof(suffix) / sizeof(suffix[0]); - int i = 0; + size_t length = arrlen(suffix); + size_t i = 0; if (bytes > power) - for (i = 0; (bytes / power) > 0 && i<length-1; i++, bytes /= power) + for (i = 0; (bytes / power) > 0 && i < length-1; i++, bytes /= power) dblBytes = bytes / (double) power; sprintf(buf, "%.02lf%s", dblBytes, suffix[i]); @@ -1318,7 +1319,7 @@ run_command(size_t size, const char *fmt, ...) } int -make_dir(const char *path) +make_dir(void) { char name[PATH_MAX]; @@ -1327,7 +1328,7 @@ make_dir(const char *path) } int -make_file(const char *path) +make_file(void) { FILE *fptr; char name[PATH_MAX]; @@ -1339,6 +1340,7 @@ make_file(const char *path) fatal("Error opening file \"%s\"\n", name); fclose(fptr); } + return 0; } int @@ -1353,7 +1355,7 @@ rm_file(const char *fname) run_command(cmdsize, rmdirfmt, fname); else res = remove(fname); - curwin.highlight = MAX(curwin.highlight-1, 0); + curwin.highlight = curwin.highlight > 0 ? curwin.highlight -1 : 0; } if (res != 0) { @@ -1401,7 +1403,7 @@ make_mod(void) if (strlen(name) == 3) { isvalid = TRUE; - for (size_t i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { if (!isdigit(name[i])) isvalid = FALSE; } @@ -1516,7 +1518,7 @@ clear_selected(void) void clear_search(void) { - for (size_t i = 0; i < SEARCHLEN; i++) + for (int i = 0; i < SEARCHLEN; i++) searchq[i] = '\0'; searchc = 0; } @@ -1535,11 +1537,14 @@ get_fullpath(char *buf, DirWin *dirwin, size_t index) { index = MIN(index, dirwin->filecount-1); index = MAX(index, 0); + size_t len; if (strcmp(dirwin->path, "/") == 0) snprintf(buf, PATH_MAX, "/%s", dirwin->winfiles[index].d_name); - else - snprintf(buf, PATH_MAX, "%s/%s", dirwin->path, dirwin->winfiles[index].d_name); + else { + len = PATH_MAX + arrlen(dirwin->winfiles[index].d_name); + snprintf(buf, len, "%s/%s", dirwin->path, dirwin->winfiles[index].d_name); + } return buf; } diff --git a/config.mk b/config.mk @@ -0,0 +1,11 @@ +NAME = cex + +VERSION = 0.1 + +CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" +CFLAGS = -std=c99 -pedantic -Wall -Wextra -I/usr/local/include ${CPPFLAGS} + +PREFIX = /usr/local +MANPREFIX = ${PREFIX}/share/man + +CC = gcc -g