mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-05 05:45:05 +00:00
(file) Can File/stat with only 4 bytes of length
This commit is contained in:
parent
29823e5bd1
commit
1f622ff541
2 changed files with 46 additions and 14 deletions
25
build.sh
25
build.sh
|
@ -38,7 +38,7 @@ while [ $# -gt 0 ]; do
|
|||
esac
|
||||
done
|
||||
|
||||
rm -f ./bin/*
|
||||
rm -f bin/*
|
||||
|
||||
# When clang-format is present
|
||||
|
||||
|
@ -89,23 +89,26 @@ then
|
|||
cp bin/uxnemu bin/uxnasm bin/uxncli $HOME/bin/
|
||||
fi
|
||||
|
||||
./bin/uxnasm projects/software/launcher.tal bin/launcher.rom
|
||||
./bin/uxnasm projects/software/asma.tal bin/asma.rom
|
||||
bin/uxnasm projects/software/launcher.tal bin/launcher.rom
|
||||
bin/uxnasm projects/software/asma.tal bin/asma.rom
|
||||
|
||||
if [ $norun = 1 ]; then exit; fi
|
||||
|
||||
# Test usage
|
||||
|
||||
./bin/uxnasm
|
||||
./bin/uxncli
|
||||
./bin/uxnemu
|
||||
bin/uxnasm
|
||||
bin/uxncli
|
||||
bin/uxnemu
|
||||
|
||||
# Test version
|
||||
|
||||
./bin/uxnasm -v
|
||||
./bin/uxncli -v
|
||||
./bin/uxnemu -v
|
||||
bin/uxnasm -v
|
||||
bin/uxncli -v
|
||||
bin/uxnemu -v
|
||||
|
||||
./bin/uxnasm projects/examples/devices/mouse.tal bin/mouse.rom
|
||||
bin/uxnasm projects/examples/devices/mouse.tal bin/mouse.rom
|
||||
bin/uxnemu -2x bin/mouse.rom
|
||||
|
||||
# bin/uxnasm test.tal bin/test.rom
|
||||
# bin/uxncli bin/test.rom
|
||||
|
||||
./bin/uxnemu -2x bin/mouse.rom
|
||||
|
|
|
@ -54,6 +54,13 @@ typedef struct {
|
|||
|
||||
static UxnFile uxn_file[POLYFILEY];
|
||||
|
||||
static char
|
||||
inthex(int n)
|
||||
{
|
||||
n &= 0xf;
|
||||
return n < 10 ? '0' + n : 'a' + (n - 10);
|
||||
}
|
||||
|
||||
static void
|
||||
reset(UxnFile *c)
|
||||
{
|
||||
|
@ -71,7 +78,29 @@ reset(UxnFile *c)
|
|||
}
|
||||
|
||||
static Uint16
|
||||
get_entry(char *p, Uint16 len, const char *pathname, const char *basename, int fail_nonzero)
|
||||
put_info(char *p, Uint16 len, const char *pathname)
|
||||
{
|
||||
struct stat st;
|
||||
if(len < 4)
|
||||
return 0;
|
||||
if(stat(pathname, &st))
|
||||
p[0] = p[1] = p[2] = p[3] = '!';
|
||||
else if(S_ISDIR(st.st_mode))
|
||||
p[0] = p[1] = p[2] = p[3] = '-';
|
||||
else if(st.st_size >= 0x10000)
|
||||
p[0] = p[1] = p[2] = p[3] = '?';
|
||||
else {
|
||||
unsigned int size = st.st_size;
|
||||
p[0] = inthex(size >> 0xc);
|
||||
p[1] = inthex(size >> 0x8);
|
||||
p[2] = inthex(size >> 0x4);
|
||||
p[3] = inthex(size);
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
|
||||
static Uint16
|
||||
put_line(char *p, Uint16 len, const char *pathname, const char *basename, int fail_nonzero)
|
||||
{
|
||||
struct stat st;
|
||||
if(len < strlen(basename) + 8)
|
||||
|
@ -114,7 +143,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 = get_entry(p, len, pathname, c->de->d_name, 1);
|
||||
n = put_line(p, len, pathname, c->de->d_name, 1);
|
||||
if(!n) break;
|
||||
p += n;
|
||||
len -= n;
|
||||
|
@ -233,7 +262,7 @@ file_stat(UxnFile *c, void *dest, Uint16 len)
|
|||
basename++;
|
||||
else
|
||||
basename = c->current_filename;
|
||||
return get_entry(dest, len, c->current_filename, basename, 0);
|
||||
return put_info(dest, len, c->current_filename);
|
||||
}
|
||||
|
||||
static Uint16
|
||||
|
|
Loading…
Reference in a new issue