uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 9ca712237bec157a90ee24a13a6ae1a1d74588c5
parent 1f622ff541e6d96ca27243a5cd4e1ff515a51239
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Thu,  4 Jan 2024 11:28:21 -0800

(file) put_line use put_info

Diffstat:
Msrc/devices/file.c | 28+++++++++++-----------------
Msrc/uxnemu.c | 2+-
2 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/src/devices/file.c b/src/devices/file.c @@ -64,14 +64,10 @@ inthex(int n) static void reset(UxnFile *c) { - if(c->f != NULL) { - fclose(c->f); - c->f = NULL; - } - if(c->dir != NULL) { - closedir(c->dir); - c->dir = NULL; - } + if(c->f != NULL) + fclose(c->f), c->f = NULL; + if(c->dir != NULL) + closedir(c->dir), c->dir = NULL; c->de = NULL; c->state = IDLE; c->outside_sandbox = 0; @@ -100,19 +96,17 @@ put_info(char *p, Uint16 len, const char *pathname) } static Uint16 -put_line(char *p, Uint16 len, const char *pathname, const char *basename, int fail_nonzero) +put_line(char *p, Uint16 len, const char *pathname, const char *basename) { struct stat st; if(len < strlen(basename) + 8) return 0; - if(stat(pathname, &st)) - return fail_nonzero ? snprintf(p, len, "!!!! %s\n", basename) : 0; - else if(S_ISDIR(st.st_mode)) - return snprintf(p, len, "---- %s/\n", basename); - else if(st.st_size < 0x10000) - return snprintf(p, len, "%04x %s\n", (unsigned int)st.st_size, basename); + stat(pathname, &st); + put_info(p, len, pathname); + if(S_ISDIR(st.st_mode)) + return snprintf(p + 4, len, " %s/\n", basename) + 4; else - return snprintf(p, len, "???? %s\n", basename); + return snprintf(p + 4, len, " %s\n", basename) + 4; } static Uint16 @@ -143,7 +137,7 @@ file_read_dir(UxnFile *c, char *dest, Uint16 len) snprintf(pathname, sizeof(pathname), "%s/%s", c->current_filename, c->de->d_name); else pathname[0] = '\0'; - n = put_line(p, len, pathname, c->de->d_name, 1); + n = put_line(p, len, pathname, c->de->d_name); if(!n) break; p += n; len -= n; diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -486,6 +486,7 @@ emu_end(Uxn *u) int main(int argc, char **argv) { + int i = 1; Uint8 *ram; char *rom; Uxn u = {0}; @@ -493,7 +494,6 @@ main(int argc, char **argv) Uxn u_audio = {0}; u.dev = (Uint8 *)&dev; u_audio.dev = (Uint8 *)&dev; - int i = 1; /* flags */ if(argc > 1 && argv[i][0] == '-') { if(!strcmp(argv[i], "-v"))