aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib')
-rw-r--r--src/stdlib/datatypes.h2
-rw-r--r--src/stdlib/optionals.h2
-rw-r--r--src/stdlib/paths.c48
3 files changed, 26 insertions, 26 deletions
diff --git a/src/stdlib/datatypes.h b/src/stdlib/datatypes.h
index dbb321b0..40d9be3e 100644
--- a/src/stdlib/datatypes.h
+++ b/src/stdlib/datatypes.h
@@ -101,7 +101,7 @@ typedef struct Text_s {
};
} Text_t;
-typedef enum PathEnum { PATH_NONE, PATH_RELATIVE, PATH_ABSOLUTE, PATH_HOME } PathType_t;
+typedef enum PathEnum { PATHTYPE_NONE, PATHTYPE_RELATIVE, PATHTYPE_ABSOLUTE, PATHTYPE_HOME } PathType_t;
#define OptionalPathType_t PathType_t
typedef struct {
diff --git a/src/stdlib/optionals.h b/src/stdlib/optionals.h
index 9c875bd1..d067ec94 100644
--- a/src/stdlib/optionals.h
+++ b/src/stdlib/optionals.h
@@ -15,7 +15,7 @@
#define NONE_TABLE ((OptionalTable_t){.entries.data = NULL})
#define NONE_CLOSURE ((OptionalClosure_t){.fn = NULL})
#define NONE_TEXT ((OptionalText_t){.tag = TEXT_NONE})
-#define NONE_PATH ((Path_t){.type = PATH_NONE})
+#define NONE_PATH ((Path_t){.type = PATHTYPE_NONE})
PUREFUNC bool is_none(const void *obj, const TypeInfo_t *non_optional_type);
PUREFUNC uint64_t Optional$hash(const void *obj, const TypeInfo_t *type);
diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c
index 47ddba54..b6152ed4 100644
--- a/src/stdlib/paths.c
+++ b/src/stdlib/paths.c
@@ -32,8 +32,8 @@
// Use inline version of the siphash code for performance:
#include "siphash-internals.h"
-static const Path_t HOME_PATH = {.type = PATH_HOME}, ROOT_PATH = {.type = PATH_ABSOLUTE},
- CURDIR_PATH = {.type = PATH_RELATIVE};
+static const Path_t HOME_PATH = {.type = PATHTYPE_HOME}, ROOT_PATH = {.type = PATHTYPE_ABSOLUTE},
+ CURDIR_PATH = {.type = PATHTYPE_RELATIVE};
static void clean_components(List_t *components) {
for (int64_t i = 0; i < (int64_t)components->length;) {
@@ -64,16 +64,16 @@ Path_t Path$from_str(const char *str) {
Path_t result = {.components = {}};
if (str[0] == '/') {
- result.type = PATH_ABSOLUTE;
+ result.type = PATHTYPE_ABSOLUTE;
str += 1;
} else if (str[0] == '~' && str[1] == '/') {
- result.type = PATH_HOME;
+ result.type = PATHTYPE_HOME;
str += 2;
} else if (str[0] == '.' && str[1] == '/') {
- result.type = PATH_RELATIVE;
+ result.type = PATHTYPE_RELATIVE;
str += 2;
} else {
- result.type = PATH_RELATIVE;
+ result.type = PATHTYPE_RELATIVE;
}
while (str && *str) {
@@ -104,12 +104,12 @@ Path_t Path$from_text(Text_t text) { return Path$from_str(Text$as_c_string(text)
public
Path_t Path$expand_home(Path_t path) {
- if (path.type == PATH_HOME) {
+ if (path.type == PATHTYPE_HOME) {
Path_t pwd = Path$from_str(getenv("HOME"));
List_t components = List$concat(pwd.components, path.components, sizeof(Text_t));
assert(components.length == path.components.length + pwd.components.length);
clean_components(&components);
- path = (Path_t){.type = PATH_ABSOLUTE, .components = components};
+ path = (Path_t){.type = PATHTYPE_ABSOLUTE, .components = components};
}
return path;
}
@@ -120,7 +120,7 @@ Path_t Path$_concat(int n, Path_t items[n]) {
Path_t result = items[0];
LIST_INCREF(result.components);
for (int i = 1; i < n; i++) {
- if (items[i].type != PATH_RELATIVE)
+ if (items[i].type != PATHTYPE_RELATIVE)
fail("Cannot concatenate an absolute or home-based path onto another path: (", items[i], ")");
List$insert_all(&result.components, items[i].components, I(0), sizeof(Text_t));
}
@@ -130,7 +130,7 @@ Path_t Path$_concat(int n, Path_t items[n]) {
public
Path_t Path$resolved(Path_t path, Path_t relative_to) {
- if (path.type == PATH_RELATIVE && !(relative_to.type == PATH_RELATIVE && relative_to.components.length == 0)) {
+ if (path.type == PATHTYPE_RELATIVE && !(relative_to.type == PATHTYPE_RELATIVE && relative_to.components.length == 0)) {
Path_t result = {.type = relative_to.type};
result.components = relative_to.components;
LIST_INCREF(result.components);
@@ -147,7 +147,7 @@ Path_t Path$relative_to(Path_t path, Path_t relative_to) {
fail("Cannot create a path relative to a different path with a mismatching type: (", path, ") relative to (",
relative_to, ")");
- Path_t result = {.type = PATH_RELATIVE};
+ Path_t result = {.type = PATHTYPE_RELATIVE};
int64_t shared = 0;
for (; shared < (int64_t)path.components.length && shared < (int64_t)relative_to.components.length; shared++) {
Text_t *p = (Text_t *)(path.components.data + shared * path.components.stride);
@@ -558,7 +558,7 @@ Path_t Path$write_unique(Path_t path, Text_t text) { return Path$write_unique_by
public
Path_t Path$parent(Path_t path) {
- if (path.type == PATH_ABSOLUTE && path.components.length == 0) {
+ if (path.type == PATHTYPE_ABSOLUTE && path.components.length == 0) {
return path;
} else if (path.components.length > 0
&& !Text$equal_values(
@@ -577,8 +577,8 @@ public
PUREFUNC Text_t Path$base_name(Path_t path) {
if (path.components.length >= 1)
return *(Text_t *)(path.components.data + path.components.stride * ((int64_t)path.components.length - 1));
- else if (path.type == PATH_HOME) return Text("~");
- else if (path.type == PATH_RELATIVE) return Text(".");
+ else if (path.type == PATHTYPE_HOME) return Text("~");
+ else if (path.type == PATHTYPE_RELATIVE) return Text(".");
else return EMPTY_TEXT;
}
@@ -765,17 +765,17 @@ PUREFUNC bool Path$equal_values(Path_t a, Path_t b) {
public
int Path$print(FILE *f, Path_t path) {
if (path.components.length == 0) {
- if (path.type == PATH_ABSOLUTE) return fputs("/", f);
- else if (path.type == PATH_RELATIVE) return fputs(".", f);
- else if (path.type == PATH_HOME) return fputs("~", f);
+ if (path.type == PATHTYPE_ABSOLUTE) return fputs("/", f);
+ else if (path.type == PATHTYPE_RELATIVE) return fputs(".", f);
+ else if (path.type == PATHTYPE_HOME) return fputs("~", f);
}
int n = 0;
- if (path.type == PATH_ABSOLUTE) {
+ if (path.type == PATHTYPE_ABSOLUTE) {
n += fputc('/', f);
- } else if (path.type == PATH_HOME) {
+ } else if (path.type == PATHTYPE_HOME) {
n += fputs("~/", f);
- } else if (path.type == PATH_RELATIVE) {
+ } else if (path.type == PATHTYPE_RELATIVE) {
if (!Text$equal_values(*(Text_t *)path.components.data, Text(".."))) n += fputs("./", f);
}
@@ -796,9 +796,9 @@ Text_t Path$as_text(const void *obj, bool color, const TypeInfo_t *type) {
if (!obj) return Text("Path");
Path_t *path = (Path_t *)obj;
Text_t text = Text$join(Text("/"), path->components);
- if (path->type == PATH_HOME) text = Text$concat(path->components.length > 0 ? Text("~/") : Text("~"), text);
- else if (path->type == PATH_ABSOLUTE) text = Text$concat(Text("/"), text);
- else if (path->type == PATH_RELATIVE
+ if (path->type == PATHTYPE_HOME) text = Text$concat(path->components.length > 0 ? Text("~/") : Text("~"), text);
+ else if (path->type == PATHTYPE_ABSOLUTE) text = Text$concat(Text("/"), text);
+ else if (path->type == PATHTYPE_RELATIVE
&& (path->components.length == 0 || !Text$equal_values(*(Text_t *)(path->components.data), Text(".."))))
text = Text$concat(path->components.length > 0 ? Text("./") : Text("."), text);
@@ -810,7 +810,7 @@ Text_t Path$as_text(const void *obj, bool color, const TypeInfo_t *type) {
public
CONSTFUNC bool Path$is_none(const void *obj, const TypeInfo_t *type) {
(void)type;
- return ((Path_t *)obj)->type == PATH_NONE;
+ return ((Path_t *)obj)->type == PATHTYPE_NONE;
}
public