From 1e3fb8a2c0cca385d65c52679411b118b5fb4641 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 24 Nov 2024 16:18:21 -0500 Subject: Rename "NULL" to "NONE" --- stdlib/arrays.c | 4 ++-- stdlib/bools.c | 2 +- stdlib/bytes.h | 2 +- stdlib/integers.c | 4 ++-- stdlib/integers.h | 8 ++++---- stdlib/moments.c | 4 ++-- stdlib/optionals.c | 4 ++-- stdlib/optionals.h | 14 +++++++------- stdlib/paths.c | 22 +++++++++++----------- stdlib/patterns.c | 6 +++--- stdlib/patterns.h | 2 +- stdlib/shell.c | 12 ++++++------ stdlib/stdlib.c | 4 ++-- stdlib/text.c | 4 ++-- 14 files changed, 46 insertions(+), 46 deletions(-) (limited to 'stdlib') diff --git a/stdlib/arrays.c b/stdlib/arrays.c index 8814f31a..4db3d2d1 100644 --- a/stdlib/arrays.c +++ b/stdlib/arrays.c @@ -222,7 +222,7 @@ public Int_t Array$find(Array_t arr, void *item, const TypeInfo_t *type) if (generic_equal(item, arr.data + i*arr.stride, item_type)) return I(i+1); } - return NULL_INT; + return NONE_INT; } public Int_t Array$first(Array_t arr, Closure_t predicate) @@ -232,7 +232,7 @@ public Int_t Array$first(Array_t arr, Closure_t predicate) if (is_good(arr.data + i*arr.stride, predicate.userdata)) return I(i+1); } - return NULL_INT; + return NONE_INT; } public void Array$sort(Array_t *arr, Closure_t comparison, int64_t padded_item_size) diff --git a/stdlib/bools.c b/stdlib/bools.c index 9a2c8cd6..50cd3f4c 100644 --- a/stdlib/bools.c +++ b/stdlib/bools.c @@ -35,7 +35,7 @@ PUREFUNC public OptionalBool_t Bool$parse(Text_t text) || Text$equal_ignoring_case(text, Text("0"))) { return no; } else { - return NULL_BOOL; + return NONE_BOOL; } } diff --git a/stdlib/bytes.h b/stdlib/bytes.h index ef5c0729..8c14ef1e 100644 --- a/stdlib/bytes.h +++ b/stdlib/bytes.h @@ -35,6 +35,6 @@ typedef struct { bool is_null:1; } OptionalByte_t; -#define NULL_BYTE ((OptionalByte_t){.is_null=true}) +#define NONE_BYTE ((OptionalByte_t){.is_null=true}) // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/stdlib/integers.c b/stdlib/integers.c index 3b95c994..baf1b0c8 100644 --- a/stdlib/integers.c +++ b/stdlib/integers.c @@ -303,7 +303,7 @@ public Int_t Int$power(Int_t base, Int_t exponent) public OptionalInt_t Int$sqrt(Int_t i) { if (Int$compare_value(i, I(0)) < 0) - return NULL_INT; + return NONE_INT; mpz_t result; mpz_init_set_int(result, i); mpz_sqrt(result, result); @@ -327,7 +327,7 @@ public Int_t Int$from_str(const char *str) { result = mpz_init_set_str(i, str, 10); } if (result != 0) - return NULL_INT; + return NONE_INT; return Int$from_mpz(i); } diff --git a/stdlib/integers.h b/stdlib/integers.h index 7bda6398..0c4b87fc 100644 --- a/stdlib/integers.h +++ b/stdlib/integers.h @@ -79,10 +79,10 @@ DEFINE_INT_TYPE(int16_t, Int16, CONSTFUNC) DEFINE_INT_TYPE(int8_t, Int8, CONSTFUNC) #undef DEFINE_INT_TYPE -#define NULL_INT64 ((OptionalInt64_t){.is_null=true}) -#define NULL_INT32 ((OptionalInt32_t){.is_null=true}) -#define NULL_INT16 ((OptionalInt16_t){.is_null=true}) -#define NULL_INT8 ((OptionalInt8_t){.is_null=true}) +#define NONE_INT64 ((OptionalInt64_t){.is_null=true}) +#define NONE_INT32 ((OptionalInt32_t){.is_null=true}) +#define NONE_INT16 ((OptionalInt16_t){.is_null=true}) +#define NONE_INT8 ((OptionalInt8_t){.is_null=true}) #define Int64$abs(...) I64(labs(__VA_ARGS__)) #define Int32$abs(...) I32(abs(__VA_ARGS__)) diff --git a/stdlib/moments.c b/stdlib/moments.c index 955d5e93..848626cb 100644 --- a/stdlib/moments.c +++ b/stdlib/moments.c @@ -14,7 +14,7 @@ #include "text.h" #include "util.h" -static OptionalText_t _local_timezone = NULL_TEXT; +static OptionalText_t _local_timezone = NONE_TEXT; #define WITH_TIMEZONE(tz, body) ({ if (tz.length >= 0) { \ OptionalText_t old_timezone = _local_timezone; \ @@ -220,7 +220,7 @@ public OptionalMoment_t Moment$parse(Text_t text, Text_t format) char *invalid = strptime(str, fmt, &info); if (!invalid || invalid[0] != '\0') - return NULL_MOMENT; + return NONE_MOMENT; long offset = info.tm_gmtoff; // Need to cache this because mktime() mutates it to local timezone >:( time_t t = mktime(&info); diff --git a/stdlib/optionals.c b/stdlib/optionals.c index 8c295228..2fb734f0 100644 --- a/stdlib/optionals.c +++ b/stdlib/optionals.c @@ -18,7 +18,7 @@ public PUREFUNC bool is_null(const void *obj, const TypeInfo_t *non_optional_typ if (non_optional_type == &Int$info) return ((Int_t*)obj)->small == 0; else if (non_optional_type == &Bool$info) - return *((OptionalBool_t*)obj) == NULL_BOOL; + return *((OptionalBool_t*)obj) == NONE_BOOL; else if (non_optional_type == &Num$info) return isnan(*((Num_t*)obj)); else if (non_optional_type == &Num32$info) @@ -72,7 +72,7 @@ public Text_t Optional$as_text(const void *obj, bool colorize, const TypeInfo_t return Text$concat(generic_as_text(obj, colorize, type->OptionalInfo.type), Text("?")); if (is_null(obj, type->OptionalInfo.type)) - return colorize ? Text("\x1b[31mNULL\x1b[m") : Text("NULL"); + return colorize ? Text("\x1b[31mNONE\x1b[m") : Text("NONE"); return generic_as_text(obj, colorize, type->OptionalInfo.type); } diff --git a/stdlib/optionals.h b/stdlib/optionals.h index b5326479..7d52375b 100644 --- a/stdlib/optionals.h +++ b/stdlib/optionals.h @@ -16,13 +16,13 @@ #define OptionalText_t Text_t #define OptionalClosure_t Closure_t -#define NULL_ARRAY ((Array_t){.length=-1}) -#define NULL_BOOL ((OptionalBool_t)2) -#define NULL_INT ((OptionalInt_t){.small=0}) -#define NULL_TABLE ((OptionalTable_t){.entries.length=-1}) -#define NULL_CLOSURE ((OptionalClosure_t){.fn=NULL}) -#define NULL_TEXT ((OptionalText_t){.length=-1}) -#define NULL_MOMENT ((OptionalMoment_t){.tv_usec=-1}) +#define NONE_ARRAY ((Array_t){.length=-1}) +#define NONE_BOOL ((OptionalBool_t)2) +#define NONE_INT ((OptionalInt_t){.small=0}) +#define NONE_TABLE ((OptionalTable_t){.entries.length=-1}) +#define NONE_CLOSURE ((OptionalClosure_t){.fn=NULL}) +#define NONE_TEXT ((OptionalText_t){.length=-1}) +#define NONE_MOMENT ((OptionalMoment_t){.tv_usec=-1}) PUREFUNC bool is_null(const void *obj, const TypeInfo_t *non_optional_type); Text_t Optional$as_text(const void *obj, bool colorize, const TypeInfo_t *type); diff --git a/stdlib/paths.c b/stdlib/paths.c index 56492718..ee73647d 100644 --- a/stdlib/paths.c +++ b/stdlib/paths.c @@ -209,7 +209,7 @@ public OptionalMoment_t Path$modified(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); - if (status != 0) return NULL_MOMENT; + if (status != 0) return NONE_MOMENT; return (Moment_t){.tv_sec=sb.st_mtime}; } @@ -217,7 +217,7 @@ public OptionalMoment_t Path$accessed(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); - if (status != 0) return NULL_MOMENT; + if (status != 0) return NONE_MOMENT; return (Moment_t){.tv_sec=sb.st_atime}; } @@ -225,7 +225,7 @@ public OptionalMoment_t Path$changed(Path_t path, bool follow_symlinks) { struct stat sb; int status = path_stat(path, follow_symlinks, &sb); - if (status != 0) return NULL_MOMENT; + if (status != 0) return NONE_MOMENT; return (Moment_t){.tv_sec=sb.st_ctime}; } @@ -271,11 +271,11 @@ public OptionalArray_t Path$read_bytes(Path_t path, OptionalInt_t count) path = Path$_expand_home(path); int fd = open(Text$as_c_string(path), O_RDONLY); if (fd == -1) - return NULL_ARRAY; + return NONE_ARRAY; struct stat sb; if (fstat(fd, &sb) != 0) - return NULL_ARRAY; + return NONE_ARRAY; int64_t const target_count = count.small ? Int_to_Int64(count, false) : INT64_MAX; if (target_count < 0) @@ -301,7 +301,7 @@ public OptionalArray_t Path$read_bytes(Path_t path, OptionalInt_t count) ssize_t just_read = read(fd, chunk, to_read); if (just_read < 0) { close(fd); - return NULL_ARRAY; + return NONE_ARRAY; } else if (just_read == 0) { if (errno == EAGAIN || errno == EINTR) continue; @@ -325,8 +325,8 @@ public OptionalArray_t Path$read_bytes(Path_t path, OptionalInt_t count) public OptionalText_t Path$read(Path_t path) { - Array_t bytes = Path$read_bytes(path, NULL_INT); - if (bytes.length < 0) return NULL_TEXT; + Array_t bytes = Path$read_bytes(path, NONE_INT); + if (bytes.length < 0) return NONE_TEXT; return Text$from_bytes(bytes); } @@ -511,14 +511,14 @@ static void _line_reader_cleanup(FILE **f) static Text_t _next_line(FILE **f) { - if (!f || !*f) return NULL_TEXT; + if (!f || !*f) return NONE_TEXT; char *line = NULL; size_t size = 0; ssize_t len = getline(&line, &size, *f); if (len <= 0) { _line_reader_cleanup(f); - return NULL_TEXT; + return NONE_TEXT; } while (len > 0 && (line[len-1] == '\r' || line[len-1] == '\n')) @@ -538,7 +538,7 @@ public OptionalClosure_t Path$by_line(Path_t path) FILE *f = fopen(Text$as_c_string(path), "r"); if (f == NULL) - return NULL_CLOSURE; + return NONE_CLOSURE; FILE **wrapper = GC_MALLOC(sizeof(FILE*)); *wrapper = f; diff --git a/stdlib/patterns.c b/stdlib/patterns.c index 97cade4a..3bf2ebfd 100644 --- a/stdlib/patterns.c +++ b/stdlib/patterns.c @@ -802,13 +802,13 @@ public OptionalMatch_t Text$find(Text_t text, Pattern_t pattern, Int_t from_inde if (first == 0) fail("Invalid index: 0"); if (first < 0) first = text.length + first + 1; if (first > text.length || first < 1) - return NULL_MATCH; + return NONE_MATCH; capture_t captures[MAX_BACKREFS] = {}; int64_t len = 0; int64_t found = _find(text, pattern, first-1, text.length-1, &len, captures); if (found == -1) - return NULL_MATCH; + return NONE_MATCH; Array_t capture_array = {}; for (int i = 0; captures[i].occupied; i++) { @@ -845,7 +845,7 @@ public OptionalArray_t Text$matches(Text_t text, Pattern_t pattern) capture_t captures[MAX_BACKREFS] = {}; int64_t match_len = match(text, 0, pattern, 0, captures, 0); if (match_len != text.length) - return NULL_ARRAY; + return NONE_ARRAY; Array_t capture_array = {}; for (int i = 0; captures[i].occupied; i++) { diff --git a/stdlib/patterns.h b/stdlib/patterns.h index 2b30a3ae..641009a7 100644 --- a/stdlib/patterns.h +++ b/stdlib/patterns.h @@ -21,7 +21,7 @@ typedef struct { } Match_t; typedef Match_t OptionalMatch_t; -#define NULL_MATCH ((OptionalMatch_t){.index=NULL_INT}) +#define NONE_MATCH ((OptionalMatch_t){.index=NONE_INT}) Text_t Text$replace(Text_t str, Pattern_t pat, Text_t replacement, Pattern_t backref_pat, bool recursive); Pattern_t Pattern$escape_text(Text_t text); diff --git a/stdlib/shell.c b/stdlib/shell.c index 68c61115..ec78f5e7 100644 --- a/stdlib/shell.c +++ b/stdlib/shell.c @@ -50,7 +50,7 @@ public OptionalArray_t Shell$run_bytes(Shell_t command) const char *cmd_str = Text$as_c_string(command); FILE *prog = popen(cmd_str, "r"); if (!prog) - return NULL_ARRAY; + return NONE_ARRAY; size_t capacity = 256, len = 0; char *content = GC_MALLOC_ATOMIC(capacity); @@ -73,7 +73,7 @@ public OptionalArray_t Shell$run_bytes(Shell_t command) int status = pclose(prog); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) - return NULL_ARRAY; + return NONE_ARRAY; return (Array_t){.data=content, .atomic=1, .stride=1, .length=len}; } @@ -82,7 +82,7 @@ public OptionalText_t Shell$run(Shell_t command) { Array_t bytes = Shell$run_bytes(command); if (bytes.length < 0) - return NULL_TEXT; + return NONE_TEXT; if (bytes.length > 0 && *(char*)(bytes.data + (bytes.length-1)*bytes.stride) == '\n') { --bytes.length; @@ -102,14 +102,14 @@ static void _line_reader_cleanup(FILE **f) static Text_t _next_line(FILE **f) { - if (!f || !*f) return NULL_TEXT; + if (!f || !*f) return NONE_TEXT; char *line = NULL; size_t size = 0; ssize_t len = getline(&line, &size, *f); if (len <= 0) { _line_reader_cleanup(f); - return NULL_TEXT; + return NONE_TEXT; } while (len > 0 && (line[len-1] == '\r' || line[len-1] == '\n')) @@ -128,7 +128,7 @@ public OptionalClosure_t Shell$by_line(Shell_t command) const char *cmd_str = Text$as_c_string(command); FILE *prog = popen(cmd_str, "r"); if (!prog) - return NULL_CLOSURE; + return NONE_CLOSURE; FILE **wrapper = GC_MALLOC(sizeof(FILE*)); *wrapper = prog; diff --git a/stdlib/stdlib.c b/stdlib/stdlib.c index 0e72dfc4..5d51f651 100644 --- a/stdlib/stdlib.c +++ b/stdlib/stdlib.c @@ -96,9 +96,9 @@ static bool parse_single_arg(const TypeInfo_t *info, char *arg, void *dest) return !parsed.is_null; } else if (info == &Bool$info) { OptionalBool_t parsed = Bool$parse(Text$from_str(arg)); - if (parsed != NULL_BOOL) + if (parsed != NONE_BOOL) *(OptionalBool_t*)dest = parsed; - return parsed != NULL_BOOL; + return parsed != NONE_BOOL; } else if (info == &Num$info) { OptionalNum_t parsed = Num$parse(Text$from_str(arg)); if (!isnan(parsed)) diff --git a/stdlib/text.c b/stdlib/text.c index 69e54ff6..8a05f968 100644 --- a/stdlib/text.c +++ b/stdlib/text.c @@ -678,7 +678,7 @@ public OptionalText_t Text$from_strn(const char *str, size_t len) return ret; } else { if (u8_check((uint8_t*)str, len) != NULL) - return NULL_TEXT; + return NONE_TEXT; ucs4_t buf[128]; size_t length = sizeof(buf)/sizeof(buf[0]); @@ -1330,7 +1330,7 @@ public OptionalText_t Text$from_codepoint_names(Array_t codepoint_names) const char *name_str = Text$as_c_string(*name); ucs4_t codepoint = unicode_name_character(name_str); if (codepoint == UNINAME_INVALID) - return NULL_TEXT; + return NONE_TEXT; Array$insert(&codepoints, &codepoint, I_small(0), sizeof(ucs4_t)); } return Text$from_codepoints(codepoints); -- cgit v1.2.3