mirror of
https://github.com/NeoFlock/neonucleus.git
synced 2025-09-24 09:03:32 +02:00
Compare commits
No commits in common. "4a5562549cec6db00a5a3fa435c0da3ed5fcc197" and "38ebb77eda6add768739e8113df9d2c627507ab6" have entirely different histories.
4a5562549c
...
38ebb77eda
1
TODO.md
1
TODO.md
@ -33,7 +33,6 @@
|
|||||||
- `microphone` component, allows reading audio from nearby sources
|
- `microphone` component, allows reading audio from nearby sources
|
||||||
- `tape_drive` component, compatible with Computronics, except maybe with proper seek times and support for multiple tapes
|
- `tape_drive` component, compatible with Computronics, except maybe with proper seek times and support for multiple tapes
|
||||||
- `cd_reader` and `cd_writer` components, to work with CDs
|
- `cd_reader` and `cd_writer` components, to work with CDs
|
||||||
- `serial` component, for serial communications with other devices (USB?)
|
|
||||||
|
|
||||||
# Internal changes
|
# Internal changes
|
||||||
|
|
||||||
|
@ -17,8 +17,6 @@ fn addEngineSources(b: *std.Build, opts: LibBuildOpts) *std.Build.Module {
|
|||||||
.unwind_tables = if(opts.optimize == .Debug) null else .none,
|
.unwind_tables = if(opts.optimize == .Debug) null else .none,
|
||||||
});
|
});
|
||||||
|
|
||||||
const strict = opts.optimize != .Debug;
|
|
||||||
|
|
||||||
dataMod.addCSourceFiles(.{
|
dataMod.addCSourceFiles(.{
|
||||||
.files = &[_][]const u8{
|
.files = &[_][]const u8{
|
||||||
"src/lock.c",
|
"src/lock.c",
|
||||||
@ -42,8 +40,8 @@ fn addEngineSources(b: *std.Build, opts: LibBuildOpts) *std.Build.Module {
|
|||||||
.flags = &.{
|
.flags = &.{
|
||||||
if(opts.baremetal) "-DNN_BAREMETAL" else "",
|
if(opts.baremetal) "-DNN_BAREMETAL" else "",
|
||||||
if(opts.bit32) "-DNN_BIT32" else "",
|
if(opts.bit32) "-DNN_BIT32" else "",
|
||||||
if(strict) "-Wall" else "",
|
"-Wall",
|
||||||
if(strict) "-Werror" else "",
|
"-Werror",
|
||||||
"-std=gnu23",
|
"-std=gnu23",
|
||||||
"-Wno-keyword-macro", // cuz bools
|
"-Wno-keyword-macro", // cuz bools
|
||||||
},
|
},
|
||||||
|
@ -30,7 +30,7 @@ typedef enum nn_vfmode {
|
|||||||
|
|
||||||
typedef struct nn_vfhandle {
|
typedef struct nn_vfhandle {
|
||||||
nn_vfnode *node;
|
nn_vfnode *node;
|
||||||
nn_intptr_t position;
|
nn_size_t position;
|
||||||
nn_vfmode mode;
|
nn_vfmode mode;
|
||||||
} nn_vfhandle;
|
} nn_vfhandle;
|
||||||
|
|
||||||
|
@ -292,20 +292,6 @@ void *nn_memdup(nn_Alloc *alloc, const void *buf, nn_size_t len);
|
|||||||
void nn_deallocStr(nn_Alloc *alloc, char *s);
|
void nn_deallocStr(nn_Alloc *alloc, char *s);
|
||||||
nn_address nn_randomUUID(nn_Context *ctx);
|
nn_address nn_randomUUID(nn_Context *ctx);
|
||||||
|
|
||||||
nn_bool_t nn_path_hasSlash(const char *path);
|
|
||||||
nn_size_t nn_path_firstSlash(const char *path);
|
|
||||||
nn_size_t nn_path_lastSlash(const char *path);
|
|
||||||
// returns whether it is the last name
|
|
||||||
nn_bool_t nn_path_firstName(const char path[NN_MAX_PATH], char firstDirectory[NN_MAX_PATH], char subpath[NN_MAX_PATH]);
|
|
||||||
// returns whether it is the only name
|
|
||||||
nn_bool_t nn_path_lastName(const char path[NN_MAX_PATH], char name[NN_MAX_PATH], char parent[NN_MAX_PATH]);
|
|
||||||
|
|
||||||
// returns whether the path is valid
|
|
||||||
nn_bool_t nn_path_isValid(const char *path);
|
|
||||||
// writes to canonical the standard form of the path
|
|
||||||
// returns whether the path is so horribly bad it cannot be converted in canonical form.
|
|
||||||
nn_bool_t nn_path_canonical(const char path[NN_MAX_PATH], char canonical[NN_MAX_PATH]);
|
|
||||||
|
|
||||||
nn_guard *nn_newGuard(nn_Context *context);
|
nn_guard *nn_newGuard(nn_Context *context);
|
||||||
void nn_lock(nn_Context *context, nn_guard *guard);
|
void nn_lock(nn_Context *context, nn_guard *guard);
|
||||||
nn_bool_t nn_tryLock(nn_Context *context, nn_guard *guard);
|
nn_bool_t nn_tryLock(nn_Context *context, nn_guard *guard);
|
||||||
|
106
src/utils.c
106
src/utils.c
@ -238,15 +238,11 @@ int nn_mapColor(int color, int *palette, int paletteSize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void nn_memset(void *buf, unsigned char byte, nn_size_t len) {
|
void nn_memset(void *buf, unsigned char byte, nn_size_t len) {
|
||||||
if(buf == NULL) return;
|
|
||||||
unsigned char *bytes = buf;
|
unsigned char *bytes = buf;
|
||||||
for(nn_size_t i = 0; i < len; i++) bytes[i] = byte;
|
for(nn_size_t i = 0; i < len; i++) bytes[i] = byte;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nn_memcpy(void *dest, const void *src, nn_size_t len) {
|
void nn_memcpy(void *dest, const void *src, nn_size_t len) {
|
||||||
if(dest == NULL) return;
|
|
||||||
if(src == NULL) return;
|
|
||||||
|
|
||||||
char *destBytes = dest;
|
char *destBytes = dest;
|
||||||
const char *srcBytes = src;
|
const char *srcBytes = src;
|
||||||
for(nn_size_t i = 0; i < len; i++) {
|
for(nn_size_t i = 0; i < len; i++) {
|
||||||
@ -255,7 +251,6 @@ void nn_memcpy(void *dest, const void *src, nn_size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *nn_strcpy(char *dest, const char *src) {
|
char *nn_strcpy(char *dest, const char *src) {
|
||||||
if(dest == NULL) return dest;
|
|
||||||
nn_size_t i = 0;
|
nn_size_t i = 0;
|
||||||
while(src[i]) {
|
while(src[i]) {
|
||||||
dest[i] = src[i];
|
dest[i] = src[i];
|
||||||
@ -285,7 +280,6 @@ int nn_strcmp(const char *a, const char *b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *nn_strchr(const char *str, int ch) {
|
const char *nn_strchr(const char *str, int ch) {
|
||||||
if(str == NULL) return NULL;
|
|
||||||
nn_size_t i = 0;
|
nn_size_t i = 0;
|
||||||
while(NN_TRUE) {
|
while(NN_TRUE) {
|
||||||
if(str[i] == ch) return str + i;
|
if(str[i] == ch) return str + i;
|
||||||
@ -295,19 +289,16 @@ const char *nn_strchr(const char *str, int ch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nn_size_t nn_strlen(const char *a) {
|
nn_size_t nn_strlen(const char *a) {
|
||||||
if(a == NULL) return 0;
|
|
||||||
nn_size_t l = 0;
|
nn_size_t l = 0;
|
||||||
while(a[l]) l++;
|
while(a[l]) l++;
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
nn_bool_t nn_error_isEmpty(nn_errorbuf_t buf) {
|
nn_bool_t nn_error_isEmpty(nn_errorbuf_t buf) {
|
||||||
if(buf == NULL) return true;
|
|
||||||
return buf[0] == 0;
|
return buf[0] == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nn_error_write(nn_errorbuf_t buf, const char *s) {
|
void nn_error_write(nn_errorbuf_t buf, const char *s) {
|
||||||
if(buf == NULL) return;
|
|
||||||
for(nn_size_t i = 0; i < NN_MAX_ERROR_BUFFER; i++) {
|
for(nn_size_t i = 0; i < NN_MAX_ERROR_BUFFER; i++) {
|
||||||
buf[i] = s[i];
|
buf[i] = s[i];
|
||||||
if(s[i] == 0) break;
|
if(s[i] == 0) break;
|
||||||
@ -317,102 +308,5 @@ void nn_error_write(nn_errorbuf_t buf, const char *s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void nn_error_clear(nn_errorbuf_t buf) {
|
void nn_error_clear(nn_errorbuf_t buf) {
|
||||||
if(buf == NULL) return;
|
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nn_bool_t nn_path_hasSlash(const char *path) {
|
|
||||||
while(*path) {
|
|
||||||
if(*path == '/') return true;
|
|
||||||
path++;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
nn_size_t nn_path_firstSlash(const char *path) {
|
|
||||||
for(nn_size_t i = 0; path[i]; i++) {
|
|
||||||
if(path[i] == '/') return i;
|
|
||||||
}
|
|
||||||
return 0; // should never happen
|
|
||||||
}
|
|
||||||
|
|
||||||
nn_size_t nn_path_lastSlash(const char *path) {
|
|
||||||
nn_size_t slash = 0;
|
|
||||||
for(nn_size_t i = 0; path[i]; i++) {
|
|
||||||
if(path[i] == '/') slash = i;
|
|
||||||
}
|
|
||||||
return slash;
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns whether it is the last name
|
|
||||||
nn_bool_t nn_path_firstName(const char *path, char firstDirectory[NN_MAX_PATH], char subpath[NN_MAX_PATH]) {
|
|
||||||
if(!nn_path_hasSlash(path)) {
|
|
||||||
nn_strcpy(firstDirectory, path);
|
|
||||||
nn_strcpy(subpath, "");
|
|
||||||
return false; // end
|
|
||||||
}
|
|
||||||
nn_size_t slash = nn_path_firstSlash(path);
|
|
||||||
|
|
||||||
nn_memcpy(firstDirectory, path, slash);
|
|
||||||
firstDirectory[slash] = 0;
|
|
||||||
|
|
||||||
nn_strcpy(subpath, path + slash + 1);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns whether it is the only name
|
|
||||||
nn_bool_t nn_path_lastName(const char *path, char name[NN_MAX_PATH], char parent[NN_MAX_PATH]) {
|
|
||||||
if(!nn_path_hasSlash(path)) {
|
|
||||||
nn_strcpy(name, path);
|
|
||||||
nn_strcpy(parent, "");
|
|
||||||
return false; // end
|
|
||||||
}
|
|
||||||
|
|
||||||
nn_size_t slash = nn_path_lastSlash(path);
|
|
||||||
nn_strcpy(name, path + slash + 1);
|
|
||||||
|
|
||||||
nn_memcpy(parent, path, slash);
|
|
||||||
parent[slash] = 0;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *nn_path_illegal = "\"\\:*?<>|";
|
|
||||||
|
|
||||||
nn_bool_t nn_path_isValid(const char *path) {
|
|
||||||
// if we don't check for these, we will be FUCKED
|
|
||||||
|
|
||||||
for(nn_size_t i = 0; nn_path_illegal[i] != '\0'; i++) {
|
|
||||||
if(nn_strchr(path, nn_path_illegal[i]) != NULL) return false;
|
|
||||||
}
|
|
||||||
return nn_strlen(path) < NN_MAX_PATH; // less then because we depend on the terminator
|
|
||||||
}
|
|
||||||
|
|
||||||
nn_bool_t nn_path_canonical(const char path[NN_MAX_PATH], char canonical[NN_MAX_PATH]) {
|
|
||||||
// attempts to convert a random barely legal path
|
|
||||||
// if this shit is ever bugged and a sandbox escape is done
|
|
||||||
// by tricking it into sneaking some .. in there
|
|
||||||
// !!!! WE WILL BE FUCKED, THE SERVER WILL BE HACKED, AND WE WILL DIE !!!!
|
|
||||||
|
|
||||||
if(!nn_path_isValid(path)) {
|
|
||||||
// HELL NO
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// tmp shit because lazy, maybe the optimizer be with us
|
|
||||||
char junk[NN_MAX_PATH];
|
|
||||||
|
|
||||||
// 0'd out because it fills it up with terminators, simplifying the rest of the code
|
|
||||||
// in theory this is suboptimal, however, I'm lazy
|
|
||||||
nn_memset(canonical, 0, NN_MAX_PATH);
|
|
||||||
size_t ptr = 0;
|
|
||||||
|
|
||||||
// TODO: burn it with fire and get banned from programming
|
|
||||||
for(nn_size_t i = 0; path[i]; i++) {
|
|
||||||
// all of this is very slow
|
|
||||||
|
|
||||||
while(path[i] == '/') continue; // just do not ask
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user