diff options
| author | dacctal <donotcontactmevia@email.invalid> | 2026-07-01 05:47:28 +0000 |
|---|---|---|
| committer | dacctal <donotcontactmevia@email.invalid> | 2026-07-01 05:47:28 +0000 |
| commit | fcfb6ac21651e286092bcc92309e89c8fa2e87fd (patch) | |
| tree | 0f68c74e6dbc777769beb332f79323b4ecce3bd9 /include | |
| parent | e328068fa24d61b3a171bac1ef915db90142bdcb (diff) | |
checkpoint!
Diffstat (limited to 'include')
| -rw-r--r-- | include/files.h | 30 | ||||
| -rw-r--r-- | include/globs.h | 137 | ||||
| -rw-r--r-- | include/help.h | 26 | ||||
| -rw-r--r-- | include/lua_globs.h | 42 | ||||
| -rw-r--r-- | include/lua_vars.h | 27 | ||||
| -rw-r--r-- | include/pkg_create.h | 25 | ||||
| -rw-r--r-- | include/str.h | 518 |
7 files changed, 745 insertions, 60 deletions
diff --git a/include/files.h b/include/files.h new file mode 100644 index 0000000..9fd1a71 --- /dev/null +++ b/include/files.h @@ -0,0 +1,30 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + +#ifndef PKGIT_FILES_H +#define PKGIT_FILES_H + +#include <sys/stat.h> +#include <stdbool.h> + +bool file_exists(const char *path); +bool is_directory(const char *path); + +#endif diff --git a/include/globs.h b/include/globs.h index 69fee60..f44ab85 100644 --- a/include/globs.h +++ b/include/globs.h @@ -21,53 +21,94 @@ #ifndef PKGIT_GLOBALS_H #define PKGIT_GLOBALS_H -#define VERSION "1.4.0_INDEV" -#define RED "\x1b[0;31m" -#define GREEN "\x1b[0;32m" -#define YELLOW "\x1b[0;33m" -#define BLUE "\x1b[0;34m" -#define MAGENTA "\x1b[0;35m" -#define CYAN "\x1b[0;36m" -#define GRAY "\x1b[0;37m" -#define BRIGHT_RED "\x1b[0;91m" -#define BRIGHT_GREEN "\x1b[0;92m" -#define BRIGHT_YELLOW "\x1b[0;93m" -#define BRIGHT_BLUE "\x1b[0;94m" -#define BRIGHT_MAGENTA "\x1b[0;95m" -#define BRIGHT_CYAN "\x1b[0;96m" -#define BRIGHT_GRAY "\x1b[0;97m" -#define BOLD_RED "\x1b[1;31m" -#define BOLD_GREEN "\x1b[1;32m" -#define BOLD_YELLOW "\x1b[1;33m" -#define BOLD_BLUE "\x1b[1;34m" -#define BOLD_MAGENTA "\x1b[1;35m" -#define BOLD_CYAN "\x1b[1;36m" -#define BOLD_GRAY "\x1b[1;37m" -#define BOLD_WHITE "\x1b[1;38m" -#define BOLD_BRIGHT_RED "\x1b[1;91m" -#define BOLD_BRIGHT_GREEN "\x1b[1;92m" -#define BOLD_BRIGHT_YELLOW "\x1b[1;93m" -#define BOLD_BRIGHT_BLUE "\x1b[1;94m" -#define BOLD_BRIGHT_MAGENTA "\x1b[1;95m" -#define BOLD_BRIGHT_CYAN "\x1b[1;96m" -#define BOLD_BRIGHT_GRAY "\x1b[1;97m" -#define ITALIC "\x1b[3m" -#define COLOR_RESET "\x1b[0m" - -#define PRINT_PKGIT BOLD_YELLOW "[" BOLD_MAGENTA "pkgit" BOLD_YELLOW "]" COLOR_RESET +#define VERSION "1.4.0_INDEV" +#define RED "\x1b[0;31m" +#define GREEN "\x1b[0;32m" +#define YELLOW "\x1b[0;33m" +#define BLUE "\x1b[0;34m" +#define MAGENTA "\x1b[0;35m" +#define CYAN "\x1b[0;36m" +#define GRAY "\x1b[0;37m" +#define BRIGHT_RED "\x1b[0;91m" +#define BRIGHT_GREEN "\x1b[0;92m" +#define BRIGHT_YELLOW "\x1b[0;93m" +#define BRIGHT_BLUE "\x1b[0;94m" +#define BRIGHT_MAGENTA "\x1b[0;95m" +#define BRIGHT_CYAN "\x1b[0;96m" +#define BRIGHT_GRAY "\x1b[0;97m" +#define BOLD "\x1b[1m" +#define BOLD_RED "\x1b[1;31m" +#define BOLD_GREEN "\x1b[1;32m" +#define BOLD_YELLOW "\x1b[1;33m" +#define BOLD_BLUE "\x1b[1;34m" +#define BOLD_MAGENTA "\x1b[1;35m" +#define BOLD_CYAN "\x1b[1;36m" +#define BOLD_GRAY "\x1b[1;37m" +#define BOLD_WHITE "\x1b[1;38m" +#define BOLD_BRIGHT_RED "\x1b[1;91m" +#define BOLD_BRIGHT_GREEN "\x1b[1;92m" +#define BOLD_BRIGHT_YELLOW "\x1b[1;93m" +#define BOLD_BRIGHT_BLUE "\x1b[1;94m" +#define BOLD_BRIGHT_MAGENTA "\x1b[1;95m" +#define BOLD_BRIGHT_CYAN "\x1b[1;96m" +#define BOLD_BRIGHT_GRAY "\x1b[1;97m" +#define ITALIC "\x1b[3m" +#define COLOR_RESET "\x1b[0m" + +#define eprintf(...) fprintf(stderr, __VA_ARGS__); + +#define check_alloc(ptr) \ + do { \ + if (ptr == NULL) \ + panic("allocation of `%s` failed", #ptr); \ + } while (0) + +#include <stdlib.h> +#define panic(...) \ + do { \ + eprintf(BOLD RED "panic:" COLOR_RESET " line %d, func \"%s\" in file " \ + "\"%s\": ", \ + __LINE__, __func__, __FILE_NAME__); \ + eprintf(__VA_ARGS__); \ + eprintf("\n"); \ + fflush(stderr); \ + abort(); \ + } while (0) + +#ifdef PKGIT_DEBUG +#define assert(expr) \ + do { \ + if (!(expr)) \ + panic("Assertion `%s` failed", #expr); \ + } while (0) +#else +#define assert(expr) (void)(expr) +#endif + +#ifdef unreachable +#undef unreachable +#endif +#define unreachable panic("reached unreachable code") + +#define PRINT_PKGIT \ + BOLD_YELLOW "[" BOLD_MAGENTA "pkgit" BOLD_YELLOW "]" COLOR_RESET #define PRINT_SUCCESS PRINT_PKGIT GREEN " [SUCCESS]" COLOR_RESET #define PRINT_SKIPPED PRINT_PKGIT BLUE " [SKIPPED]" COLOR_RESET #define PRINT_WARNING PRINT_PKGIT YELLOW " [WARNING]" COLOR_RESET #define PRINT_ERROR PRINT_PKGIT RED " [ERROR]" COLOR_RESET +#define MAX_REPOS 1000 +#define MAX_DIRS 100 +#define MAX_PATH_LEN 1024 + #include "str.h" typedef struct { - str_slc name; - str_slc url; - str_slc version; - str_slc target; - str_slc src; + str name; + str url; + str version; + str target; + str src; int is_local; } package; @@ -75,8 +116,24 @@ extern int is_verbose; extern int is_forced; extern int config_exists; -extern char root_config_file[20]; +extern str home_config_dir; +extern str home_config_file; +extern str home_repos_file; +extern str root_config_dir; +extern str root_config_file; +extern str root_repos_file; +extern int is_root_config; + +extern str config_dir; +extern str config_file; +extern str repos_file; + +extern str bin; +extern str lib; +extern str include; +extern str src; void init_vars(void); +void free_vars(void); #endif diff --git a/include/help.h b/include/help.h new file mode 100644 index 0000000..c194be4 --- /dev/null +++ b/include/help.h @@ -0,0 +1,26 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + +#ifndef HELP_H +#define HELP_H + +void help(void); + +#endif
\ No newline at end of file diff --git a/include/lua_globs.h b/include/lua_globs.h new file mode 100644 index 0000000..0a5426f --- /dev/null +++ b/include/lua_globs.h @@ -0,0 +1,42 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + +#ifndef PKGIT_LUA_GLOBALS_H +#define PKGIT_LUA_GLOBALS_H + +#include <lua.h> +#include <lauxlib.h> +#include <lualib.h> +#include <stdbool.h> + +extern lua_State *L; +extern lua_State *B; +extern bool config_loaded; + +void push_lua_path(lua_State *L, const char *new_path); +void init_lua_state(void); +void init_bldit(void); +void free_lua_state(void); + +lua_State *get_lua_state(void); + +void lua_isnt_type(char* variable, char* type); + +#endif diff --git a/include/lua_vars.h b/include/lua_vars.h new file mode 100644 index 0000000..dfc62d0 --- /dev/null +++ b/include/lua_vars.h @@ -0,0 +1,27 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + +#ifndef PKGIT_LUA_VARS_H +#define PKGIT_LUA_VARS_H +#include <lua.h> +#include <lauxlib.h> +#include <lualib.h> +void init_install_directories(void); +#endif diff --git a/include/pkg_create.h b/include/pkg_create.h new file mode 100644 index 0000000..908b6fd --- /dev/null +++ b/include/pkg_create.h @@ -0,0 +1,25 @@ +/* + + pkgit - package it! + + Copyright (C) 2026 dacctal + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +*/ + +#ifndef PKGIT_PKG_CREATE_H +#define PKGIT_PKG_CREATE_H +#include "globs.h" +package pkg_create(str_slc *arg); +#endif diff --git a/include/str.h b/include/str.h index c81bcbd..f5c79dd 100644 --- a/include/str.h +++ b/include/str.h @@ -18,33 +18,511 @@ */ -#ifndef PKGIT_STRING_H -#define PKGIT_STRING_H +#ifndef PKGIT_STR_H +#define PKGIT_STR_H + +#include <stdarg.h> +#include <stdbool.h> #include <stddef.h> +#include <stdint.h> +#include <stdio.h> +/** + * Heap-allocated, owned character string. + * + * All library functions assert that pointers passed in are valid and point to + * valid data. All references to "C strings" infer null-terminated pointers to + * characters. + * + * When data is NULL, it is deemed invalid. + */ typedef struct { - char* data; + char *data; + size_t cap; size_t len; -} str_slc; +} str; +/** + * A view into any character buffer that may not be + * resized, but may be heap-allocated. + * + * When data is NULL, it is deemed invalid. + */ typedef struct { - char* data; - size_t cap; + const char *data; size_t len; -} str; +} str_slc; + +#define str_is_valid(str) ((str)->data != NULL) + +// for printf formatting +#define str_fmt(s) (int)((s)->len), (s)->data + +/** + * Creates and initializes an empty, valid str. + */ +str str_new(void); + +/** + * Creates and initializes an empty str with a specified capacity. + */ +str str_new_with_capacity(size_t cap); + +/** + * Make a str from a C string. + */ +str str_from_cstr(const char *s); + +/** + * Equivalent to str_from_cstr + */ +str mstr(const char *s); + +/** + * Make a str from a string slice. + */ +str str_from_str_slc(const str_slc s); + +/** + * Return a str from the result of an sprintf-style call. + */ +str str_format(const char *format, ...); + +/** + * Saves the result of an sprintf-style call into s. + */ +void str_format_into(str *s, const char *format, ...); + +/** + * Reserves 1.5*new_cap bytes of space in the string. + */ +void str_reserve(str *s, size_t new_cap); + +/** + * Reserves EXACTLY new_cap of bytes of space in the string. + */ +void str_reserve_exact(str *s, size_t new_cap); + +/** + * Clears the entire string buffer to zeroes and resets the length. + */ +void str_clear(str *s); + +/** + * Frees the internal heap-allocated buffer. + */ +void str_free(str *s); + +/** + * Copies the entirety of src into dest, resizing it if necessary, while + * overwriting all existing data. + */ +void str_copy_into(str *dest, const str *src); + +/** + * Copies a source C string at src into an already initialized + * str, resizing the buffer if necessary, overwriting all existing data. + */ +void str_copy_cstr_into(str *dest, const char *src); + +/** + * Copies a source string slice at src into an already initialized + * str, resizing the buffer if necessary, overwriting all existing data. + */ +void str_copy_str_slc_into(str *dest, const str_slc src); + +/** + * Copies n bytes of src into an already initialized str dest, + * resizing it if necessary, while overwriting all existing data. + */ +void str_ncopy_into(str *dest, const str *src, size_t count); + +/** + * Copies n bytes of a C string src into an already initialized str dest, + * resizing it if necessary, while overwriting all existing data. + */ +void str_ncopy_cstr_into(str *dest, const char *src, size_t count); + +/** + * Copies n bytes of a string slice src into an already initialized str dest, + * resizing it if necessary, while overwriting all existing data. + */ +void str_ncopy_str_slc_into(str *dest, const str_slc src, size_t count); + +/** + * Duplicates a str exactly, retaining its original capacity. + */ +str str_dupe(const str *src); + +/** + * Appends a str into an existing str, resizing the buffer if necessary. + */ +void str_append(str *src, const str *new); + +/** + * Appends a single character new into src, resizing the buffer if necessary. + */ +void str_append_char(str *src, char new); + +/** + * Appends a C string into an existing str, resizing the buffer if necessary. + */ +void str_append_cstr(str *src, const char *new); + +/** + * Appends a string slice into an existing str, resizing the buffer if + * necessary. + */ +void str_append_str_slc(str *src, const str_slc new); + +/** + * Removes the last character from src, returning it. + */ +char str_pop_last(str *src); + +/** + * Concatenates lhs and rhs together into a new string. + */ +str str_concat(const str *lhs, const str *rhs); + +/** + * Concatenates lhs and a C string rhs together into a new string. + */ +str str_concat_cstr(const str *lhs, const char *rhs); + +/** + * Concatenates lhs and a str_slc rhs together into a new string. + */ +str str_concat_str_slc(const str *lhs, const str_slc rhs); + +/** + * Trims all whitespace characters in s away only on the left, and returns the + * result. + */ +str str_trim_left(const str *s); + +/** + * Trims all whitespace characters in s away only on the left, and returns the + * result. + */ +str str_trim_right(const str *s); + +/** + * Trims all whitespace characters in s away on the left and right, and returns + * the result. + */ +str str_trim(const str *s); + +/** + * Converts all characters in s to uppercase and returns the result. + */ +str str_to_upper(const str *s); + +/** + * Converts all characters in s to lowercase and returns the result + */ +str str_to_lower(const str *s); + +/** + * Trims all whitespace characters in s away only on the left, modifying the + * string s. + */ +void str_trim_left_in_place(str *s); + +/** + * Trims all whitespace characters in s away only on the right, modifying the + * string s. + */ +void str_trim_right_in_place(str *s); + +/** + * Trims all whitespace characters in s away on the left and right, modifying + * the string s. + */ +void str_trim_in_place(str *s); + +/** + * Converts all characters in s to uppercase, modifying the string s. + */ +void str_to_upper_in_place(str *s); + +/** + * Converts all characters in s to lowercase, modifying the string s. + */ +void str_to_lower_in_place(str *s); + +/** + * Returns if lhs and rhs are equal. + */ +bool str_equal(const str *lhs, const str *rhs); + +/** + * Returns if lhs and rhs (a C string) are equal. + */ +bool str_equal_cstr(const str *lhs, const char *rhs); + +/** + * Returns if lhs and rhs (a string slice) are equal. + */ +bool str_equal_str_slc(const str *lhs, const str_slc rhs); + +/** + * Compares the strings lhs and rhs lexicographically, similar to strcmp. + */ +int str_compare(const str *lhs, const str *rhs); + +/** + * Compares the strings lhs and rhs (a C string) lexicographically, similar to + * strcmp. + */ +int str_compare_cstr(const str *lhs, const char *rhs); + +/** + * Compares the strings lhs and rhs (a string slice) lexicographically, similar + * to strcmp. + */ +int str_compare_str_slc(const str *lhs, const str_slc rhs); + +/** + * Returns if lhs and rhs are equal, ignoring case. + */ +bool str_equal_case_insensitive(const str *lhs, const str *rhs); + +/** + * Returns if lhs and rhs (a C string) are equal, ignoring case. + */ +bool str_equal_cstr_case_insensitive(const str *lhs, const char *rhs); + +/** + * Returns if lhs and rhs (a string slice) are equal, ignoring case. + */ +bool str_equal_str_slc_case_insensitive(const str *lhs, const str_slc rhs); + +/** + * Compares the strings lhs and rhs lexicographically, ignoring case, similar to + * strcasecmp. + */ +int str_compare_case_insensitive(const str *lhs, const str *rhs); + +/** + * Compares the strings lhs and rhs (a C string) lexicographically, ignoring + * case, similar to strcasecmp. + */ +int str_compare_cstr_case_insensitive(const str *lhs, const char *rhs); + +/** + * Compares the strings lhs and rhs (a String slice) lexicographically, ignoring + * case, similar to strcasecmp. + */ +int str_compare_str_slc_case_insensitive(const str *lhs, const str_slc rhs); + +/** + * Slices a string from `begin` to `end`, clamping values to [0, src->len] if + * needed, and returning the result. + * ptrdiff_t's are used, as slicing functions may return negative values. + */ +str str_slice_to_str(const str *src, ptrdiff_t begin, ptrdiff_t end); + +/** + * Slices a C string from `begin` to `end`, clamping values to [0, src->len] if + * needed, returning the result as a str. + * ptrdiff_t's are used, as slicing functions may return negative values. + */ +str str_slice_from_cstr(const char *src, ptrdiff_t begin, ptrdiff_t end); + +/** + * Slices a string from `begin` to `end`, clamping values to [0, src->len] if + * needed, returning the result as a str_slc. + * ptrdiff_t's are used, as slicing functions may return negative values. + */ +str_slc str_slice(const str *src, ptrdiff_t begin, ptrdiff_t end); + +/** + * Slices a string slice from beginning to end, clamping values to [0, src->len] + * if needed Python, returning the result as a str. + * ptrdiff_t's are used, as slicing functions may return negative values. + */ +str str_slice_from_str_slc(const str_slc src, ptrdiff_t begin, ptrdiff_t end); + +/** + * Converts a str to a double with strtod(3), returning how many bytes of src + * were converted to a double. + */ +size_t str_to_double_pro(const str *src, double *res); + +/** + * Converts a str to a int64_t with strtoll(3), returning how many bytes of src + * were converted to a double. + */ +size_t str_to_int64_pro(const str *src, int64_t *res, int base); + +/** + * Converts a str to a double with strtod(3), returning a success or failure. + */ +bool str_to_double(const str *src, double *res); + +/** + * Converts a str to a int64_t with strtoll(3), returning a success or failure. + */ +bool str_to_int64(const str *src, int64_t *res); + +/** + * Reads a single line from f into a str, and returns it. + * Panics on failure. + */ +str str_read_line_from_file(FILE *f); + +/** + * Reads count characters from f into a str, and returns it. + * Panics on failure. + */ +str str_read_chars_from_file(FILE *f, size_t count); + +/** + * Reads the entirety of f into a str, and returns it. + * Panics on failure. + */ +str str_read_entire_file(FILE *f); + +/** + * Writes the entirety of a str to a file, returning a success or failure. + * Panics on failure. + */ +bool str_write_to_file(const str *s, FILE *f); + +/** + * Gets the nth character of a str, with bounds checking. + */ +char str_at(const str *s, size_t i); + +/** + * Gets the first character of a str, with bounds checking. + */ +char str_first(const str *s); + +/** + * Gets the last character of a str, with bounds checking. + */ +char str_last(const str *s); + +/** + * Finds a character c in s, from the left to the right. + * Returns -1 on failure + */ +size_t str_find_char(const str *s, char c); + +/** + * Finds a character c in s from the right to the left. + * Returns s->len on failure. + */ +size_t str_find_char_right(const str *s, char c); + +void str_print(const str *s); + +void str_println(const str *s); + +void str_fprint(const str *s, FILE *f); + +void str_fprintln(const str *s, FILE *f); + +/** + * Converts a str to a str_slc. + */ +str_slc str_slc_from_str(const str *s); + +/** + * Converts a C string to a str_slc. + */ +str_slc str_slc_from_cstr(const char *s); + +/** + * Equivalent to str_slc_from_cstr. + */ +str_slc mstrslc(const char *s); + +str str_slc_concat(const str_slc lhs, const str_slc rhs); + +str str_slc_concat_cstr(const str_slc lhs, const char *rhs); + +bool str_slc_equal(const str_slc lhs, const str_slc rhs); + +bool str_slc_equal_cstr(const str_slc lhs, const char *rhs); + +bool str_slc_equal_case_insensitive(const str_slc lhs, const str_slc rhs); + +bool str_slc_equal_cstr_case_insensitive(const str_slc lhs, const char *rhs); + +int str_slc_compare(const str_slc lhs, const str_slc rhs); + +int str_slc_compare_cstr(const str_slc lhs, const char *rhs); + +int str_slc_compare_case_insensitive(const str_slc lhs, const str_slc rhs); + +int str_slc_compare_cstr_case_insensitive(const str_slc lhs, const char *rhs); + +/** + * Slices a string slice from `begin` to `end`, clamping values to [0, src->len] + * if needed, and returning the result. + * ptrdiff_t's are used, as slicing functions may return negative values. + */ +str_slc str_slc_slice(const str_slc s, ptrdiff_t begin, ptrdiff_t end); + +/** + * Slices a string slice from `begin` to `end`, clamping values to [0, src->len] + * if needed, and returning the result. + * ptrdiff_t's are used, as slicing functions may return negative values. + */ +str str_slc_slice_to_str(const str_slc s, ptrdiff_t begin, ptrdiff_t end); + +str str_slc_to_lower(const str_slc s); + +str str_slc_to_upper(const str_slc s); + +str_slc str_slc_trim_left(const str_slc s); + +str_slc str_slc_trim_right(const str_slc s); + +str_slc str_slc_trim(const str_slc s); + +size_t str_slc_to_double_pro(const str_slc src, double *res); + +size_t str_slc_to_int64_pro(const str_slc src, int64_t *res, int base); + +bool str_slc_to_double(const str_slc src, double *res); + +bool str_slc_to_int64(const str_slc src, int64_t *res); + +bool str_slc_write_to_file(const str_slc src, FILE *f); + +char str_slc_first(const str_slc s); + +char str_slc_last(const str_slc s); + +char str_slc_at(const str_slc s, size_t i); + +void str_slc_print(const str_slc s); + +void str_slc_println(const str_slc s); + +void str_slc_fprint(const str_slc s, FILE *f); + +void str_slc_fprintln(const str_slc s, FILE *f); + +/** + * Finds a character c in s, from the left to the right. + * Returns -1 on failure + */ +ptrdiff_t str_slc_find_char(const str_slc s, char c); + +/** + * Finds a character c in s from the right to the left. + * Returns s->len on failure. + */ +ptrdiff_t str_slc_find_char_right(const str_slc s, char c); -#define str_fmt(slice) (int)((slice).len), (slice).data -// Usage: printf("%.*s", format_string(slice)); - -void print_slice(str_slc s); -str_slc slc_from_cstr(char* cstr); -#define slc_from_cstr(cstr) slc_from_cstr(cstr) -int slc_eq(str_slc a, str_slc b); -int slc_starts_with(str_slc slice, str_slc prefix); -str_slc slc_take(str_slc slice, size_t n); -str_slc slc_drop(str_slc slice, size_t n); -str_slc slc_trim(str_slc slice); -void slc_cat(str_slc first, str_slc second, str_slc *new_slc); -//#define slc_cat(first, second, new_slc) slc_cat(first, second, *new_slc) +str str_from_after_delim(str *arg, char delimiter); +str str_from_before_delim(str *arg, char delimiter); +str_slc str_slc_from_after_delim(str_slc arg, char delimiter); +str_slc str_slc_from_before_delim(str_slc arg, char delimiter); #endif |
