(file) Can File/stat with only 4 bytes of length
This commit is contained in:
parent
29823e5bd1
commit
1f622ff541
25
build.sh
25
build.sh
|
@ -38,7 +38,7 @@ while [ $# -gt 0 ]; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
rm -f ./bin/*
|
rm -f bin/*
|
||||||
|
|
||||||
# When clang-format is present
|
# When clang-format is present
|
||||||
|
|
||||||
|
@ -89,23 +89,26 @@ then
|
||||||
cp bin/uxnemu bin/uxnasm bin/uxncli $HOME/bin/
|
cp bin/uxnemu bin/uxnasm bin/uxncli $HOME/bin/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
./bin/uxnasm projects/software/launcher.tal bin/launcher.rom
|
bin/uxnasm projects/software/launcher.tal bin/launcher.rom
|
||||||
./bin/uxnasm projects/software/asma.tal bin/asma.rom
|
bin/uxnasm projects/software/asma.tal bin/asma.rom
|
||||||
|
|
||||||
if [ $norun = 1 ]; then exit; fi
|
if [ $norun = 1 ]; then exit; fi
|
||||||
|
|
||||||
# Test usage
|
# Test usage
|
||||||
|
|
||||||
./bin/uxnasm
|
bin/uxnasm
|
||||||
./bin/uxncli
|
bin/uxncli
|
||||||
./bin/uxnemu
|
bin/uxnemu
|
||||||
|
|
||||||
# Test version
|
# Test version
|
||||||
|
|
||||||
./bin/uxnasm -v
|
bin/uxnasm -v
|
||||||
./bin/uxncli -v
|
bin/uxncli -v
|
||||||
./bin/uxnemu -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 UxnFile uxn_file[POLYFILEY];
|
||||||
|
|
||||||
|
static char
|
||||||
|
inthex(int n)
|
||||||
|
{
|
||||||
|
n &= 0xf;
|
||||||
|
return n < 10 ? '0' + n : 'a' + (n - 10);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
reset(UxnFile *c)
|
reset(UxnFile *c)
|
||||||
{
|
{
|
||||||
|
@ -71,7 +78,29 @@ reset(UxnFile *c)
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint16
|
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;
|
struct stat st;
|
||||||
if(len < strlen(basename) + 8)
|
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);
|
snprintf(pathname, sizeof(pathname), "%s/%s", c->current_filename, c->de->d_name);
|
||||||
else
|
else
|
||||||
pathname[0] = '\0';
|
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;
|
if(!n) break;
|
||||||
p += n;
|
p += n;
|
||||||
len -= n;
|
len -= n;
|
||||||
|
@ -233,7 +262,7 @@ file_stat(UxnFile *c, void *dest, Uint16 len)
|
||||||
basename++;
|
basename++;
|
||||||
else
|
else
|
||||||
basename = c->current_filename;
|
basename = c->current_filename;
|
||||||
return get_entry(dest, len, c->current_filename, basename, 0);
|
return put_info(dest, len, c->current_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint16
|
static Uint16
|
||||||
|
|
Loading…
Reference in New Issue