From f4e38fd061a158ecb94881273c6db6e6a332f61d Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 17 Aug 2025 20:35:09 -0400 Subject: =?UTF-8?q?Switch=20from=20using=20dollar=20signs=20as=20namespace?= =?UTF-8?q?=20delimiters=20to=20using=20=E3=80=85,=20=E3=83=BD,=20and=20?= =?UTF-8?q?=E3=80=87.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stdlib/paths.c | 390 ++++++++++++++++++++++++++--------------------------- 1 file changed, 195 insertions(+), 195 deletions(-) (limited to 'src/stdlib/paths.c') diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c index 58702ec7..8aa57f17 100644 --- a/src/stdlib/paths.c +++ b/src/stdlib/paths.c @@ -33,20 +33,20 @@ #include "siphash.h" #include "siphash-internals.h" -static const Path_t HOME_PATH = {.type.$tag=PATH_HOME}, - ROOT_PATH = {.type.$tag=PATH_ABSOLUTE}, - CURDIR_PATH = {.type.$tag=PATH_RELATIVE}; +static const Path_t HOME_PATH = {.type.ヽtag=PATH_HOME}, + ROOT_PATH = {.type.ヽtag=PATH_ABSOLUTE}, + CURDIR_PATH = {.type.ヽtag=PATH_RELATIVE}; static void clean_components(List_t *components) { for (int64_t i = 0; i < components->length; ) { Text_t *component = (Text_t*)(components->data + i*components->stride); - if (component->length == 0 || Text$equal_values(*component, Text("."))) { - List$remove_at(components, I(i+1), I(1), sizeof(Text_t)); - } else if (i > 0 && Text$equal_values(*component, Text(".."))) { + if (component->length == 0 || Textヽequal_values(*component, Text("."))) { + Listヽremove_at(components, I(i+1), I(1), sizeof(Text_t)); + } else if (i > 0 && Textヽequal_values(*component, Text(".."))) { Text_t *prev = (Text_t*)(components->data + (i-1)*components->stride); - if (!Text$equal_values(*prev, Text(".."))) { - List$remove_at(components, I(i), I(2), sizeof(Text_t)); + if (!Textヽequal_values(*prev, Text(".."))) { + Listヽremove_at(components, I(i), I(2), sizeof(Text_t)); i -= 1; } else { i += 1; @@ -57,7 +57,7 @@ static void clean_components(List_t *components) } } -public Path_t Path$from_str(const char *str) +public Path_t Pathヽfrom_str(const char *str) { if (!str || str[0] == '\0' || streq(str, "/")) return ROOT_PATH; else if (streq(str, "~")) return HOME_PATH; @@ -68,16 +68,16 @@ public Path_t Path$from_str(const char *str) Path_t result = {.components={}}; if (str[0] == '/') { - result.type.$tag = PATH_ABSOLUTE; + result.type.ヽtag = PATH_ABSOLUTE; str += 1; } else if (str[0] == '~' && str[1] == '/') { - result.type.$tag = PATH_HOME; + result.type.ヽtag = PATH_HOME; str += 2; } else if (str[0] == '.' && str[1] == '/') { - result.type.$tag = PATH_RELATIVE; + result.type.ヽtag = PATH_RELATIVE; str += 2; } else { - result.type.$tag = PATH_RELATIVE; + result.type.ヽtag = PATH_RELATIVE; } while (str && *str) { @@ -87,12 +87,12 @@ public Path_t Path$from_str(const char *str) // ignore /./ } else if (component_len == 2 && strncmp(str, "..", 2) == 0 && result.components.length > 1 - && !Text$equal_values(Text(".."), *(Text_t*)(result.components.data + result.components.stride*(result.components.length-1)))) { + && !Textヽequal_values(Text(".."), *(Text_t*)(result.components.data + result.components.stride*(result.components.length-1)))) { // Pop off /foo/baz/.. -> /foo - List$remove_at(&result.components, I(result.components.length), I(1), sizeof(Text_t)); + Listヽremove_at(&result.components, I(result.components.length), I(1), sizeof(Text_t)); } else { - Text_t component = Text$from_strn(str, component_len); - List$insert_value(&result.components, component, I(0), sizeof(Text_t)); + Text_t component = Textヽfrom_strn(str, component_len); + Listヽinsert_value(&result.components, component, I(0), sizeof(Text_t)); } str += component_len; } @@ -101,90 +101,90 @@ public Path_t Path$from_str(const char *str) return result; } -public Path_t Path$from_text(Text_t text) +public Path_t Pathヽfrom_text(Text_t text) { - return Path$from_str(Text$as_c_string(text)); + return Pathヽfrom_str(Textヽas_c_string(text)); } -public Path_t Path$expand_home(Path_t path) +public Path_t Pathヽexpand_home(Path_t path) { - if (path.type.$tag == PATH_HOME) { - Path_t pwd = Path$from_str(getenv("HOME")); - List_t components = List$concat(pwd.components, path.components, sizeof(Text_t)); + if (path.type.ヽtag == PATH_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.$tag=PATH_ABSOLUTE, .components=components}; + path = (Path_t){.type.ヽtag=PATH_ABSOLUTE, .components=components}; } return path; } -public Path_t Path$_concat(int n, Path_t items[n]) +public Path_t Pathヽ_concat(int n, Path_t items[n]) { assert(n > 0); Path_t result = items[0]; LIST_INCREF(result.components); for (int i = 1; i < n; i++) { - if (items[i].type.$tag != PATH_RELATIVE) + if (items[i].type.ヽtag != PATH_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)); + Listヽinsert_all(&result.components, items[i].components, I(0), sizeof(Text_t)); } clean_components(&result.components); return result; } -public Path_t Path$resolved(Path_t path, Path_t relative_to) +public Path_t Pathヽresolved(Path_t path, Path_t relative_to) { - if (path.type.$tag == PATH_RELATIVE && !(relative_to.type.$tag == PATH_RELATIVE && relative_to.components.length == 0)) { - Path_t result = {.type.$tag=relative_to.type.$tag}; + if (path.type.ヽtag == PATH_RELATIVE && !(relative_to.type.ヽtag == PATH_RELATIVE && relative_to.components.length == 0)) { + Path_t result = {.type.ヽtag=relative_to.type.ヽtag}; result.components = relative_to.components; LIST_INCREF(result.components); - List$insert_all(&result.components, path.components, I(0), sizeof(Text_t)); + Listヽinsert_all(&result.components, path.components, I(0), sizeof(Text_t)); clean_components(&result.components); return result; } return path; } -public Path_t Path$relative_to(Path_t path, Path_t relative_to) +public Path_t Pathヽrelative_to(Path_t path, Path_t relative_to) { - if (path.type.$tag != relative_to.type.$tag) + if (path.type.ヽtag != relative_to.type.ヽtag) fail("Cannot create a path relative to a different path with a mismatching type: (", path, ") relative to (", relative_to, ")"); - Path_t result = {.type.$tag=PATH_RELATIVE}; + Path_t result = {.type.ヽtag=PATH_RELATIVE}; int64_t shared = 0; for (; shared < path.components.length && shared < relative_to.components.length; shared++) { Text_t *p = (Text_t*)(path.components.data + shared*path.components.stride); Text_t *r = (Text_t*)(relative_to.components.data + shared*relative_to.components.stride); - if (!Text$equal_values(*p, *r)) + if (!Textヽequal_values(*p, *r)) break; } for (int64_t i = shared; i < relative_to.components.length; i++) - List$insert_value(&result.components, Text(".."), I(1), sizeof(Text_t)); + Listヽinsert_value(&result.components, Text(".."), I(1), sizeof(Text_t)); for (int64_t i = shared; i < path.components.length; i++) { Text_t *p = (Text_t*)(path.components.data + i*path.components.stride); - List$insert(&result.components, p, I(0), sizeof(Text_t)); + Listヽinsert(&result.components, p, I(0), sizeof(Text_t)); } //clean_components(&result.components); return result; } -public bool Path$exists(Path_t path) +public bool Pathヽexists(Path_t path) { - path = Path$expand_home(path); + path = Pathヽexpand_home(path); struct stat sb; - return (stat(Path$as_c_string(path), &sb) == 0); + return (stat(Pathヽas_c_string(path), &sb) == 0); } static INLINE int path_stat(Path_t path, bool follow_symlinks, struct stat *sb) { - path = Path$expand_home(path); - const char *path_str = Path$as_c_string(path); + path = Pathヽexpand_home(path); + const char *path_str = Pathヽas_c_string(path); return follow_symlinks ? stat(path_str, sb) : lstat(path_str, sb); } -public bool Path$is_file(Path_t path, bool follow_symlinks) +public bool Pathヽis_file(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); @@ -192,7 +192,7 @@ public bool Path$is_file(Path_t path, bool follow_symlinks) return (sb.st_mode & S_IFMT) == S_IFREG; } -public bool Path$is_directory(Path_t path, bool follow_symlinks) +public bool Pathヽis_directory(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); @@ -200,7 +200,7 @@ public bool Path$is_directory(Path_t path, bool follow_symlinks) return (sb.st_mode & S_IFMT) == S_IFDIR; } -public bool Path$is_pipe(Path_t path, bool follow_symlinks) +public bool Pathヽis_pipe(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); @@ -208,7 +208,7 @@ public bool Path$is_pipe(Path_t path, bool follow_symlinks) return (sb.st_mode & S_IFMT) == S_IFIFO; } -public bool Path$is_socket(Path_t path, bool follow_symlinks) +public bool Pathヽis_socket(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); @@ -216,7 +216,7 @@ public bool Path$is_socket(Path_t path, bool follow_symlinks) return (sb.st_mode & S_IFMT) == S_IFSOCK; } -public bool Path$is_symlink(Path_t path) +public bool Pathヽis_symlink(Path_t path) { struct stat sb; int status = path_stat(path, false, &sb); @@ -224,10 +224,10 @@ public bool Path$is_symlink(Path_t path) return (sb.st_mode & S_IFMT) == S_IFLNK; } -public bool Path$can_read(Path_t path) +public bool Pathヽcan_read(Path_t path) { - path = Path$expand_home(path); - const char *path_str = Path$as_c_string(path); + path = Pathヽexpand_home(path); + const char *path_str = Pathヽas_c_string(path); #ifdef _GNU_SOURCE return (euidaccess(path_str, R_OK) == 0); #else @@ -235,10 +235,10 @@ public bool Path$can_read(Path_t path) #endif } -public bool Path$can_write(Path_t path) +public bool Pathヽcan_write(Path_t path) { - path = Path$expand_home(path); - const char *path_str = Path$as_c_string(path); + path = Pathヽexpand_home(path); + const char *path_str = Pathヽas_c_string(path); #ifdef _GNU_SOURCE return (euidaccess(path_str, W_OK) == 0); #else @@ -246,10 +246,10 @@ public bool Path$can_write(Path_t path) #endif } -public bool Path$can_execute(Path_t path) +public bool Pathヽcan_execute(Path_t path) { - path = Path$expand_home(path); - const char *path_str = Path$as_c_string(path); + path = Pathヽexpand_home(path); + const char *path_str = Pathヽas_c_string(path); #ifdef _GNU_SOURCE return (euidaccess(path_str, X_OK) == 0); #else @@ -257,7 +257,7 @@ public bool Path$can_execute(Path_t path) #endif } -public OptionalInt64_t Path$modified(Path_t path, bool follow_symlinks) +public OptionalInt64_t Pathヽmodified(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); @@ -265,7 +265,7 @@ public OptionalInt64_t Path$modified(Path_t path, bool follow_symlinks) return (OptionalInt64_t){.value=(int64_t)sb.st_mtime}; } -public OptionalInt64_t Path$accessed(Path_t path, bool follow_symlinks) +public OptionalInt64_t Pathヽaccessed(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); @@ -273,7 +273,7 @@ public OptionalInt64_t Path$accessed(Path_t path, bool follow_symlinks) return (OptionalInt64_t){.value=(int64_t)sb.st_atime}; } -public OptionalInt64_t Path$changed(Path_t path, bool follow_symlinks) +public OptionalInt64_t Pathヽchanged(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); @@ -283,46 +283,46 @@ public OptionalInt64_t Path$changed(Path_t path, bool follow_symlinks) static void _write(Path_t path, List_t bytes, int mode, int permissions) { - path = Path$expand_home(path); - const char *path_str = Path$as_c_string(path); + path = Pathヽexpand_home(path); + const char *path_str = Pathヽas_c_string(path); int fd = open(path_str, mode, permissions); if (fd == -1) fail("Could not write to file: ", path_str, "\n", strerror(errno)); if (bytes.stride != 1) - List$compact(&bytes, 1); + Listヽcompact(&bytes, 1); ssize_t written = write(fd, bytes.data, (size_t)bytes.length); if (written != (ssize_t)bytes.length) fail("Could not write to file: ", path_str, "\n", strerror(errno)); close(fd); } -public void Path$write(Path_t path, Text_t text, int permissions) +public void Pathヽwrite(Path_t path, Text_t text, int permissions) { - List_t bytes = Text$utf8_bytes(text); + List_t bytes = Textヽutf8_bytes(text); _write(path, bytes, O_WRONLY | O_CREAT | O_TRUNC, permissions); } -public void Path$write_bytes(Path_t path, List_t bytes, int permissions) +public void Pathヽwrite_bytes(Path_t path, List_t bytes, int permissions) { _write(path, bytes, O_WRONLY | O_CREAT | O_TRUNC, permissions); } -public void Path$append(Path_t path, Text_t text, int permissions) +public void Pathヽappend(Path_t path, Text_t text, int permissions) { - List_t bytes = Text$utf8_bytes(text); + List_t bytes = Textヽutf8_bytes(text); _write(path, bytes, O_WRONLY | O_APPEND | O_CREAT, permissions); } -public void Path$append_bytes(Path_t path, List_t bytes, int permissions) +public void Pathヽappend_bytes(Path_t path, List_t bytes, int permissions) { _write(path, bytes, O_WRONLY | O_APPEND | O_CREAT, permissions); } -public OptionalList_t Path$read_bytes(Path_t path, OptionalInt_t count) +public OptionalList_t Pathヽread_bytes(Path_t path, OptionalInt_t count) { - path = Path$expand_home(path); - int fd = open(Path$as_c_string(path), O_RDONLY); + path = Pathヽexpand_home(path); + int fd = open(Pathヽas_c_string(path), O_RDONLY); if (fd == -1) return NONE_LIST; @@ -330,7 +330,7 @@ public OptionalList_t Path$read_bytes(Path_t path, OptionalInt_t count) if (fstat(fd, &sb) != 0) return NONE_LIST; - int64_t const target_count = count.small ? Int64$from_int(count, false) : INT64_MAX; + int64_t const target_count = count.small ? Int64ヽfrom_int(count, false) : INT64_MAX; if (target_count < 0) fail("Cannot read a negative number of bytes!"); @@ -376,47 +376,47 @@ public OptionalList_t Path$read_bytes(Path_t path, OptionalInt_t count) } } -public OptionalText_t Path$read(Path_t path) +public OptionalText_t Pathヽread(Path_t path) { - List_t bytes = Path$read_bytes(path, NONE_INT); + List_t bytes = Pathヽread_bytes(path, NONE_INT); if (bytes.length < 0) return NONE_TEXT; - return Text$from_bytes(bytes); + return Textヽfrom_bytes(bytes); } -public OptionalText_t Path$owner(Path_t path, bool follow_symlinks) +public OptionalText_t Pathヽowner(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); if (status != 0) return NONE_TEXT; struct passwd *pw = getpwuid(sb.st_uid); - return pw ? Text$from_str(pw->pw_name) : NONE_TEXT; + return pw ? Textヽfrom_str(pw->pw_name) : NONE_TEXT; } -public OptionalText_t Path$group(Path_t path, bool follow_symlinks) +public OptionalText_t Pathヽgroup(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); if (status != 0) return NONE_TEXT; struct group *gr = getgrgid(sb.st_uid); - return gr ? Text$from_str(gr->gr_name) : NONE_TEXT; + return gr ? Textヽfrom_str(gr->gr_name) : NONE_TEXT; } -public void Path$set_owner(Path_t path, OptionalText_t owner, OptionalText_t group, bool follow_symlinks) +public void Pathヽset_owner(Path_t path, OptionalText_t owner, OptionalText_t group, bool follow_symlinks) { uid_t owner_id = (uid_t)-1; if (owner.length >= 0) { - struct passwd *pwd = getpwnam(Text$as_c_string(owner)); + struct passwd *pwd = getpwnam(Textヽas_c_string(owner)); if (pwd == NULL) fail("Not a valid user: ", owner); owner_id = pwd->pw_uid; } gid_t group_id = (gid_t)-1; if (group.length >= 0) { - struct group *grp = getgrnam(Text$as_c_string(group)); + struct group *grp = getgrnam(Textヽas_c_string(group)); if (grp == NULL) fail("Not a valid group: ", group); group_id = grp->gr_gid; } - const char *path_str = Path$as_c_string(path); + const char *path_str = Pathヽas_c_string(path); int result = follow_symlinks ? chown(path_str, owner_id, group_id) : lchown(path_str, owner_id, group_id); if (result < 0) fail("Could not set owner!"); @@ -442,10 +442,10 @@ static int _remove_files(const char *path, const struct stat *sbuf, int type, st } } -public void Path$remove(Path_t path, bool ignore_missing) +public void Pathヽremove(Path_t path, bool ignore_missing) { - path = Path$expand_home(path); - const char *path_str = Path$as_c_string(path); + path = Pathヽexpand_home(path); + const char *path_str = Pathヽas_c_string(path); struct stat sb; if (lstat(path_str, &sb) != 0) { if (!ignore_missing) @@ -465,10 +465,10 @@ public void Path$remove(Path_t path, bool ignore_missing) } } -public void Path$create_directory(Path_t path, int permissions) +public void Pathヽcreate_directory(Path_t path, int permissions) { - path = Path$expand_home(path); - const char *c_path = Path$as_c_string(path); + path = Pathヽexpand_home(path); + const char *c_path = Pathヽas_c_string(path); int status = mkdir(c_path, (mode_t)permissions); if (status != 0 && errno != EEXIST) fail("Could not create directory: ", c_path, " (", strerror(errno), ")"); @@ -476,10 +476,10 @@ public void Path$create_directory(Path_t path, int permissions) static List_t _filtered_children(Path_t path, bool include_hidden, mode_t filter) { - path = Path$expand_home(path); + path = Pathヽexpand_home(path); struct dirent *dir; List_t children = {}; - const char *path_str = Path$as_c_string(path); + const char *path_str = Pathヽas_c_string(path); size_t path_len = strlen(path_str); DIR *d = opendir(path_str); if (!d) @@ -501,32 +501,32 @@ static List_t _filtered_children(Path_t path, bool include_hidden, mode_t filter if (!((sb.st_mode & S_IFMT) & filter)) continue; - Path_t child = Path$from_str(child_str); - List$insert(&children, &child, I(0), sizeof(Path_t)); + Path_t child = Pathヽfrom_str(child_str); + Listヽinsert(&children, &child, I(0), sizeof(Path_t)); } closedir(d); return children; } -public List_t Path$children(Path_t path, bool include_hidden) +public List_t Pathヽchildren(Path_t path, bool include_hidden) { return _filtered_children(path, include_hidden, (mode_t)-1); } -public List_t Path$files(Path_t path, bool include_hidden) +public List_t Pathヽfiles(Path_t path, bool include_hidden) { return _filtered_children(path, include_hidden, S_IFREG); } -public List_t Path$subdirectories(Path_t path, bool include_hidden) +public List_t Pathヽsubdirectories(Path_t path, bool include_hidden) { return _filtered_children(path, include_hidden, S_IFDIR); } -public Path_t Path$unique_directory(Path_t path) +public Path_t Pathヽunique_directory(Path_t path) { - path = Path$expand_home(path); - const char *path_str = Path$as_c_string(path); + path = Pathヽexpand_home(path); + const char *path_str = Pathヽas_c_string(path); size_t len = strlen(path_str); if (len >= PATH_MAX) fail("Path is too long: ", path_str); char buf[PATH_MAX] = {}; @@ -536,13 +536,13 @@ public Path_t Path$unique_directory(Path_t path) buf[--len] = '\0'; char *created = mkdtemp(buf); if (!created) fail("Failed to create temporary directory: ", path_str, " (", strerror(errno), ")"); - return Path$from_str(created); + return Pathヽfrom_str(created); } -public Path_t Path$write_unique_bytes(Path_t path, List_t bytes) +public Path_t Pathヽwrite_unique_bytes(Path_t path, List_t bytes) { - path = Path$expand_home(path); - const char *path_str = Path$as_c_string(path); + path = Pathヽexpand_home(path); + const char *path_str = Pathヽas_c_string(path); size_t len = strlen(path_str); if (len >= PATH_MAX) fail("Path is too long: ", path_str); char buf[PATH_MAX] = {}; @@ -560,56 +560,56 @@ public Path_t Path$write_unique_bytes(Path_t path, List_t bytes) fail("Could not write to unique file: ", buf, "\n", strerror(errno)); if (bytes.stride != 1) - List$compact(&bytes, 1); + Listヽcompact(&bytes, 1); ssize_t written = write(fd, bytes.data, (size_t)bytes.length); if (written != (ssize_t)bytes.length) fail("Could not write to file: ", buf, "\n", strerror(errno)); close(fd); - return Path$from_str(buf); + return Pathヽfrom_str(buf); } -public Path_t Path$write_unique(Path_t path, Text_t text) +public Path_t Pathヽwrite_unique(Path_t path, Text_t text) { - return Path$write_unique_bytes(path, Text$utf8_bytes(text)); + return Pathヽwrite_unique_bytes(path, Textヽutf8_bytes(text)); } -public Path_t Path$parent(Path_t path) +public Path_t Pathヽparent(Path_t path) { - if (path.type.$tag == PATH_ABSOLUTE && path.components.length == 0) { + if (path.type.ヽtag == PATH_ABSOLUTE && path.components.length == 0) { return path; - } else if (path.components.length > 0 && !Text$equal_values(*(Text_t*)(path.components.data + path.components.stride*(path.components.length-1)), + } else if (path.components.length > 0 && !Textヽequal_values(*(Text_t*)(path.components.data + path.components.stride*(path.components.length-1)), Text(".."))) { - return (Path_t){.type.$tag=path.type.$tag, .components=List$slice(path.components, I(1), I(-2))}; + return (Path_t){.type.ヽtag=path.type.ヽtag, .components=Listヽslice(path.components, I(1), I(-2))}; } else { - Path_t result = {.type.$tag=path.type.$tag, .components=path.components}; + Path_t result = {.type.ヽtag=path.type.ヽtag, .components=path.components}; LIST_INCREF(result.components); - List$insert_value(&result.components, Text(".."), I(0), sizeof(Text_t)); + Listヽinsert_value(&result.components, Text(".."), I(0), sizeof(Text_t)); return result; } } -public PUREFUNC Text_t Path$base_name(Path_t path) +public PUREFUNC Text_t Pathヽbase_name(Path_t path) { if (path.components.length >= 1) return *(Text_t*)(path.components.data + path.components.stride*(path.components.length-1)); - else if (path.type.$tag == PATH_HOME) + else if (path.type.ヽtag == PATH_HOME) return Text("~"); - else if (path.type.$tag == PATH_RELATIVE) + else if (path.type.ヽtag == PATH_RELATIVE) return Text("."); else return EMPTY_TEXT; } -public Text_t Path$extension(Path_t path, bool full) +public Text_t Pathヽextension(Path_t path, bool full) { - const char *base = Text$as_c_string(Path$base_name(path)); + const char *base = Textヽas_c_string(Pathヽbase_name(path)); const char *dot = full ? strchr(base + 1, '.') : strrchr(base + 1, '.'); const char *extension = dot ? dot + 1 : ""; - return Text$from_str(extension); + return Textヽfrom_str(extension); } -public bool Path$has_extension(Path_t path, Text_t extension) +public bool Pathヽhas_extension(Path_t path, Text_t extension) { if (path.components.length < 2) return extension.length == 0; @@ -617,57 +617,57 @@ public bool Path$has_extension(Path_t path, Text_t extension) Text_t last = *(Text_t*)(path.components.data + path.components.stride*(path.components.length-1)); if (extension.length == 0) - return !Text$has(Text$from(last, I(2)), Text(".")) || Text$equal_values(last, Text("..")); + return !Textヽhas(Textヽfrom(last, I(2)), Text(".")) || Textヽequal_values(last, Text("..")); - if (!Text$starts_with(extension, Text("."), NULL)) + if (!Textヽstarts_with(extension, Text("."), NULL)) extension = Texts(Text("."), extension); - return Text$ends_with(Text$from(last, I(2)), extension, NULL); + return Textヽends_with(Textヽfrom(last, I(2)), extension, NULL); } -public Path_t Path$child(Path_t path, Text_t name) +public Path_t Pathヽchild(Path_t path, Text_t name) { - if (Text$has(name, Text("/")) || Text$has(name, Text(";"))) + if (Textヽhas(name, Text("/")) || Textヽhas(name, Text(";"))) fail("Path name has invalid characters: ", name); Path_t result = { - .type.$tag=path.type.$tag, + .type.ヽtag=path.type.ヽtag, .components=path.components, }; LIST_INCREF(result.components); - List$insert(&result.components, &name, I(0), sizeof(Text_t)); + Listヽinsert(&result.components, &name, I(0), sizeof(Text_t)); clean_components(&result.components); return result; } -public Path_t Path$sibling(Path_t path, Text_t name) +public Path_t Pathヽsibling(Path_t path, Text_t name) { - return Path$child(Path$parent(path), name); + return Pathヽchild(Pathヽparent(path), name); } -public Path_t Path$with_extension(Path_t path, Text_t extension, bool replace) +public Path_t Pathヽwith_extension(Path_t path, Text_t extension, bool replace) { if (path.components.length == 0) fail("A path with no components can't have an extension!"); - if (Text$has(extension, Text("/")) || Text$has(extension, Text(";"))) + if (Textヽhas(extension, Text("/")) || Textヽhas(extension, Text(";"))) fail("Path extension has invalid characters: ", extension); Path_t result = { - .type.$tag=path.type.$tag, + .type.ヽtag=path.type.ヽtag, .components=path.components, }; LIST_INCREF(result.components); Text_t last = *(Text_t*)(path.components.data + path.components.stride*(path.components.length-1)); - List$remove_at(&result.components, I(-1), I(1), sizeof(Text_t)); + Listヽremove_at(&result.components, I(-1), I(1), sizeof(Text_t)); if (replace) { - const char *base = Text$as_c_string(last); + const char *base = Textヽas_c_string(last); const char *dot = strchr(base + 1, '.'); if (dot) - last = Text$from_strn(base, (size_t)(dot - base)); + last = Textヽfrom_strn(base, (size_t)(dot - base)); } - last = Text$concat(last, extension); - List$insert(&result.components, &last, I(0), sizeof(Text_t)); + last = Textヽconcat(last, extension); + Listヽinsert(&result.components, &last, I(0), sizeof(Text_t)); return result; } @@ -697,16 +697,16 @@ static Text_t _next_line(FILE **f) if (u8_check((uint8_t*)line, (size_t)len) != NULL) fail("Invalid UTF8!"); - Text_t line_text = Text$from_strn(line, (size_t)len); + Text_t line_text = Textヽfrom_strn(line, (size_t)len); free(line); return line_text; } -public OptionalClosure_t Path$by_line(Path_t path) +public OptionalClosure_t Pathヽby_line(Path_t path) { - path = Path$expand_home(path); + path = Pathヽexpand_home(path); - FILE *f = fopen(Path$as_c_string(path), "r"); + FILE *f = fopen(Pathヽas_c_string(path), "r"); if (f == NULL) return NONE_CLOSURE; @@ -716,10 +716,10 @@ public OptionalClosure_t Path$by_line(Path_t path) return (Closure_t){.fn=(void*)_next_line, .userdata=wrapper}; } -public List_t Path$glob(Path_t path) +public List_t Pathヽglob(Path_t path) { glob_t glob_result; - int status = glob(Path$as_c_string(path), GLOB_BRACE | GLOB_TILDE, NULL, &glob_result); + int status = glob(Pathヽas_c_string(path), GLOB_BRACE | GLOB_TILDE, NULL, &glob_result); if (status != 0 && status != GLOB_NOMATCH) fail("Failed to perform globbing"); @@ -729,100 +729,100 @@ public List_t Path$glob(Path_t path) if ((len >= 2 && glob_result.gl_pathv[i][len-1] == '.' && glob_result.gl_pathv[i][len-2] == '/') || (len >= 2 && glob_result.gl_pathv[i][len-1] == '.' && glob_result.gl_pathv[i][len-2] == '.' && glob_result.gl_pathv[i][len-3] == '/')) continue; - Path_t p = Path$from_str(glob_result.gl_pathv[i]); - List$insert(&glob_files, &p, I(0), sizeof(Path_t)); + Path_t p = Pathヽfrom_str(glob_result.gl_pathv[i]); + Listヽinsert(&glob_files, &p, I(0), sizeof(Path_t)); } return glob_files; } -public Path_t Path$current_dir(void) +public Path_t Pathヽcurrent_dir(void) { char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd)) == NULL) fail("Could not get current working directory"); - return Path$from_str(cwd); + return Pathヽfrom_str(cwd); } -public PUREFUNC uint64_t Path$hash(const void *obj, const TypeInfo_t *type) +public PUREFUNC uint64_t Pathヽhash(const void *obj, const TypeInfo_t *type) { (void)type; Path_t *path = (Path_t*)obj; siphash sh; - siphashinit(&sh, (uint64_t)path->type.$tag); + siphashinit(&sh, (uint64_t)path->type.ヽtag); for (int64_t i = 0; i < path->components.length; i++) { - uint64_t item_hash = Text$hash(path->components.data + i*path->components.stride, &Text$info); + uint64_t item_hash = Textヽhash(path->components.data + i*path->components.stride, &Textヽinfo); siphashadd64bits(&sh, item_hash); } return siphashfinish_last_part(&sh, (uint64_t)path->components.length); } -public PUREFUNC int32_t Path$compare(const void *va, const void *vb, const TypeInfo_t *type) +public PUREFUNC int32_t Pathヽcompare(const void *va, const void *vb, const TypeInfo_t *type) { (void)type; Path_t *a = (Path_t*)va, *b = (Path_t*)vb; - int diff = ((int)a->type.$tag - (int)b->type.$tag); + int diff = ((int)a->type.ヽtag - (int)b->type.ヽtag); if (diff != 0) return diff; - return List$compare(&a->components, &b->components, List$info(&Text$info)); + return Listヽcompare(&a->components, &b->components, Listヽinfo(&Textヽinfo)); } -public PUREFUNC bool Path$equal(const void *va, const void *vb, const TypeInfo_t *type) +public PUREFUNC bool Pathヽequal(const void *va, const void *vb, const TypeInfo_t *type) { (void)type; Path_t *a = (Path_t*)va, *b = (Path_t*)vb; - if (a->type.$tag != b->type.$tag) return false; - return List$equal(&a->components, &b->components, List$info(&Text$info)); + if (a->type.ヽtag != b->type.ヽtag) return false; + return Listヽequal(&a->components, &b->components, Listヽinfo(&Textヽinfo)); } -public PUREFUNC bool Path$equal_values(Path_t a, Path_t b) +public PUREFUNC bool Pathヽequal_values(Path_t a, Path_t b) { - if (a.type.$tag != b.type.$tag) return false; - return List$equal(&a.components, &b.components, List$info(&Text$info)); + if (a.type.ヽtag != b.type.ヽtag) return false; + return Listヽequal(&a.components, &b.components, Listヽinfo(&Textヽinfo)); } -public int Path$print(FILE *f, Path_t path) +public int Pathヽprint(FILE *f, Path_t path) { if (path.components.length == 0) { - if (path.type.$tag == PATH_ABSOLUTE) return fputs("/", f); - else if (path.type.$tag == PATH_RELATIVE) return fputs(".", f); - else if (path.type.$tag == PATH_HOME) return fputs("~", f); + if (path.type.ヽtag == PATH_ABSOLUTE) return fputs("/", f); + else if (path.type.ヽtag == PATH_RELATIVE) return fputs(".", f); + else if (path.type.ヽtag == PATH_HOME) return fputs("~", f); } int n = 0; - if (path.type.$tag == PATH_ABSOLUTE) { + if (path.type.ヽtag == PATH_ABSOLUTE) { n += fputc('/', f); - } else if (path.type.$tag == PATH_HOME) { + } else if (path.type.ヽtag == PATH_HOME) { n += fputs("~/", f); - } else if (path.type.$tag == PATH_RELATIVE) { - if (!Text$equal_values(*(Text_t*)path.components.data, Text(".."))) + } else if (path.type.ヽtag == PATH_RELATIVE) { + if (!Textヽequal_values(*(Text_t*)path.components.data, Text(".."))) n += fputs("./", f); } for (int64_t i = 0; i < path.components.length; i++) { Text_t *comp = (Text_t*)(path.components.data + i*path.components.stride); - n += Text$print(f, *comp); + n += Textヽprint(f, *comp); if (i + 1 < path.components.length) n += fputc('/', f); } return n; } -public const char *Path$as_c_string(Path_t path) +public const char *Pathヽas_c_string(Path_t path) { return String(path); } -public Text_t Path$as_text(const void *obj, bool color, const TypeInfo_t *type) +public Text_t Pathヽas_text(const void *obj, bool color, const TypeInfo_t *type) { (void)type; if (!obj) return Text("Path"); Path_t *path = (Path_t*)obj; - Text_t text = Text$join(Text("/"), path->components); - if (path->type.$tag == PATH_HOME) - text = Text$concat(path->components.length > 0 ? Text("~/") : Text("~"), text); - else if (path->type.$tag == PATH_ABSOLUTE) - text = Text$concat(Text("/"), text); - else if (path->type.$tag == PATH_RELATIVE && (path->components.length == 0 || !Text$equal_values(*(Text_t*)(path->components.data), Text("..")))) - text = Text$concat(path->components.length > 0 ? Text("./") : Text("."), text); + Text_t text = Textヽjoin(Text("/"), path->components); + if (path->type.ヽtag == PATH_HOME) + text = Textヽconcat(path->components.length > 0 ? Text("~/") : Text("~"), text); + else if (path->type.ヽtag == PATH_ABSOLUTE) + text = Textヽconcat(Text("/"), text); + else if (path->type.ヽtag == PATH_RELATIVE && (path->components.length == 0 || !Textヽequal_values(*(Text_t*)(path->components.data), Text("..")))) + text = Textヽconcat(path->components.length > 0 ? Text("./") : Text("."), text); if (color) text = Texts(Text("\033[32;1m"), text, Text("\033[m")); @@ -830,48 +830,48 @@ public Text_t Path$as_text(const void *obj, bool color, const TypeInfo_t *type) return text; } -public CONSTFUNC bool Path$is_none(const void *obj, const TypeInfo_t *type) +public CONSTFUNC bool Pathヽis_none(const void *obj, const TypeInfo_t *type) { (void)type; - return ((Path_t*)obj)->type.$tag == PATH_NONE; + return ((Path_t*)obj)->type.ヽtag == PATH_NONE; } -public void Path$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type) +public void Pathヽserialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type) { (void)type; Path_t *path = (Path_t*)obj; - fputc((int)path->type.$tag, out); - List$serialize(&path->components, out, pointers, List$info(&Text$info)); + fputc((int)path->type.ヽtag, out); + Listヽserialize(&path->components, out, pointers, Listヽinfo(&Textヽinfo)); } -public void Path$deserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *type) +public void Pathヽdeserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *type) { (void)type; Path_t path = {}; - path.type.$tag = fgetc(in); - List$deserialize(in, &path.components, pointers, List$info(&Text$info)); + path.type.ヽtag = fgetc(in); + Listヽdeserialize(in, &path.components, pointers, Listヽinfo(&Textヽinfo)); *(Path_t*)obj = path; } -public const TypeInfo_t Path$info = { +public const TypeInfo_t Pathヽinfo = { .size=sizeof(Path_t), .align=__alignof__(Path_t), .tag=OpaqueInfo, .metamethods={ - .as_text=Path$as_text, - .hash=Path$hash, - .compare=Path$compare, - .equal=Path$equal, - .is_none=Path$is_none, - .serialize=Path$serialize, - .deserialize=Path$deserialize, + .as_text=Pathヽas_text, + .hash=Pathヽhash, + .compare=Pathヽcompare, + .equal=Pathヽequal, + .is_none=Pathヽis_none, + .serialize=Pathヽserialize, + .deserialize=Pathヽdeserialize, } }; -public const TypeInfo_t PathType$info = { +public const TypeInfo_t PathTypeヽinfo = { .size=sizeof(PathType_t), .align=__alignof__(PathType_t), - .metamethods=PackedDataEnum$metamethods, + .metamethods=PackedDataEnumヽmetamethods, .tag=EnumInfo, .EnumInfo={ .name="PathType", -- cgit v1.2.3