(file) put_line use put_info

This commit is contained in:
Devine Lu Linvega 2024-01-04 11:28:21 -08:00
parent 1f622ff541
commit 9ca712237b
2 changed files with 12 additions and 18 deletions

View File

@ -64,14 +64,10 @@ inthex(int n)
static void static void
reset(UxnFile *c) reset(UxnFile *c)
{ {
if(c->f != NULL) { if(c->f != NULL)
fclose(c->f); fclose(c->f), c->f = NULL;
c->f = NULL; if(c->dir != NULL)
} closedir(c->dir), c->dir = NULL;
if(c->dir != NULL) {
closedir(c->dir);
c->dir = NULL;
}
c->de = NULL; c->de = NULL;
c->state = IDLE; c->state = IDLE;
c->outside_sandbox = 0; c->outside_sandbox = 0;
@ -100,19 +96,17 @@ put_info(char *p, Uint16 len, const char *pathname)
} }
static Uint16 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; struct stat st;
if(len < strlen(basename) + 8) if(len < strlen(basename) + 8)
return 0; return 0;
if(stat(pathname, &st)) stat(pathname, &st);
return fail_nonzero ? snprintf(p, len, "!!!! %s\n", basename) : 0; put_info(p, len, pathname);
else if(S_ISDIR(st.st_mode)) if(S_ISDIR(st.st_mode))
return snprintf(p, len, "---- %s/\n", basename); return snprintf(p + 4, len, " %s/\n", basename) + 4;
else if(st.st_size < 0x10000)
return snprintf(p, len, "%04x %s\n", (unsigned int)st.st_size, basename);
else else
return snprintf(p, len, "???? %s\n", basename); return snprintf(p + 4, len, " %s\n", basename) + 4;
} }
static Uint16 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); snprintf(pathname, sizeof(pathname), "%s/%s", c->current_filename, c->de->d_name);
else else
pathname[0] = '\0'; 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; if(!n) break;
p += n; p += n;
len -= n; len -= n;

View File

@ -486,6 +486,7 @@ emu_end(Uxn *u)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int i = 1;
Uint8 *ram; Uint8 *ram;
char *rom; char *rom;
Uxn u = {0}; Uxn u = {0};
@ -493,7 +494,6 @@ main(int argc, char **argv)
Uxn u_audio = {0}; Uxn u_audio = {0};
u.dev = (Uint8 *)&dev; u.dev = (Uint8 *)&dev;
u_audio.dev = (Uint8 *)&dev; u_audio.dev = (Uint8 *)&dev;
int i = 1;
/* flags */ /* flags */
if(argc > 1 && argv[i][0] == '-') { if(argc > 1 && argv[i][0] == '-') {
if(!strcmp(argv[i], "-v")) if(!strcmp(argv[i], "-v"))