diff options
Diffstat (limited to 'lib/qpath.h')
-rw-r--r-- | lib/qpath.h | 157 |
1 files changed, 124 insertions, 33 deletions
diff --git a/lib/qpath.h b/lib/qpath.h index 27c61dff..23b710a6 100644 --- a/lib/qpath.h +++ b/lib/qpath.h @@ -22,15 +22,10 @@ #ifndef _ZEBRA_QPATH_H #define _ZEBRA_QPATH_H -#include "zebra.h" #include "misc.h" +#include "qstring.h" #include "memory.h" - - - - - - +#include "sys/stat.h" /*============================================================================== * For these purposes a path is "parts" separated by one more '/' characters. @@ -55,56 +50,111 @@ enum qpath_sex qp_double_absolute /* something, starting with "//" */ } ; -typedef struct qpath qpath_t ; -typedef struct qpath* qpath ; - /* The qpath structure is largely a qstring, but one in which there is always * a body, even if it only contains "\0", and the len is kept up to date. */ struct qpath { - qstring_t path ; + qstring_t path ; /* Embedded */ } ; +typedef struct qpath qpath_t[1] ; +typedef struct qpath* qpath ; + /*============================================================================== * Functions */ -extern qpath -qpath_init_new(qpath qp, const char* path) ; +extern qpath qpath_init_new(qpath qp) ; +extern qpath qpath_reset(qpath qp, free_keep_b free_structure) ; +extern qpath qpath_clear(qpath qp) ; -extern qpath -qpath_reset(qpath qp, bool free_structure) ; +Inline qpath qpath_new(void) ; +Inline qpath qpath_free(qpath qp) ; -Inline qpath -qpath_reset_free(qpath qp) { qpath_reset(qp, true) ; } ; +Inline const char* qpath_string(qpath qp) ; +Inline char* qpath_char_string(qpath qp) ; +Inline ulen qpath_len(qpath qp) ; +Inline const qstring qpath_qs(qpath qp) ; -Inline qpath -qpath_reset_keep(qpath qp) { qpath_reset(qp, false) ; } ; +extern qpath qpath_set(qpath dst, const char* src) ; +extern qpath qpath_set_n(qpath dst, const char* src, ulen n) ; +extern qpath qpath_set_qs(qpath dst, const qstring src) ; +extern qpath qpath_copy(qpath dst, const qpath src) ; +Inline qpath qpath_dup(const qpath qp) ; +Inline qpath qpath_dup_str(const char* src) ; -Inline const char* -qpath_path(qpath qp) ; +extern qpath qpath_getcwd(qpath dst) ; +extern int qpath_setcwd(qpath dst) ; +extern int qpath_stat(qpath qp, struct stat* stat) ; +extern int qpath_stat_is_file(qpath qp) ; +extern int qpath_stat_is_directory(qpath qp) ; -extern qpath -qpath_trim(qpath qp) ; +extern qpath qpath_shave(qpath qp) ; -extern qpath -qpath_copy(qpath qp) ; +extern qpath qpath_append(qpath dst, const qpath src) ; +extern qpath qpath_append_qs(qpath dst, const qstring src) ; +extern qpath qpath_append_str(qpath dst, const char* src) ; +extern qpath qpath_append_str_n(qpath dst, const char* src, ulen n) ; -extern qpath -qpath_pop(qpath qp) ; +extern qpath qpath_extend(qpath dst, const qpath src) ; +extern qpath qpath_extend_qs(qpath dst, const qstring src) ; +extern qpath qpath_extend_str(qpath dst, const char* src) ; +extern qpath qpath_extend_str_n(qpath dst, const char* src, ulen n) ; -extern qpath -qpath_push(qpath qp, qpath qp_a) ; +extern qpath qpath_prepend(qpath dst, const qpath src) ; +extern qpath qpath_prepend_qs(qpath dst, const qstring src) ; +extern qpath qpath_prepend_str(qpath dst, const char* src) ; +extern qpath qpath_prepend_str_n(qpath dst, const char* src, ulen n) ; -extern qpath -qpath_join(qpath qp, qpath qp_a) ; +extern qpath qpath_make(const char* src, const qpath dir) ; + +extern qpath qpath_complete(qpath dst, const qpath src) ; +extern qpath qpath_complete_qs(qpath dst, const qstring src) ; +extern qpath qpath_complete_str(qpath dst, const char* src) ; +extern qpath qpath_complete_str_n(qpath dst, const char* src, ulen n) ; /*============================================================================== * Inline stuff */ /*------------------------------------------------------------------------------ + * Create new qpath. + */ +Inline qpath +qpath_new(void) +{ + return qpath_init_new(NULL) ; +} ; + +/*------------------------------------------------------------------------------ + * Free qpath. + */ +Inline qpath +qpath_free(qpath qp) +{ + return qpath_reset(qp, free_it) ; +} ; + +/*------------------------------------------------------------------------------ + * Duplicate qpath -- result will need to be freed. + */ +Inline qpath +qpath_dup(const qpath qp) +{ + return qpath_copy(NULL, qp) ; +} ; + +/*------------------------------------------------------------------------------ + * Duplicate string as a qpath -- result will need to be freed. + */ +Inline qpath +qpath_dup_str(const char* src) +{ + return qpath_set(NULL, src) ; +} ; + +/*------------------------------------------------------------------------------ * Get *temporary* pointer to actual path contained in the given qpath. * * This is *temporary* to the extent that when the qpath is changed or freed, @@ -116,9 +166,50 @@ qpath_join(qpath qp, qpath qp_a) ; * ('\0' terminated ""). */ Inline const char* -qpath_path(qpath qp) +qpath_string(qpath qp) +{ + return (qp != NULL) ? qs_make_string(qp->path) : "" ; +} ; + +/*------------------------------------------------------------------------------ + * Get *temporary* pointer to actual path contained in the given qpath. + * + * This is *temporary* to the extent that when the qpath is changed or freed, + * this pointer will be INVALID -- you have been warned. + * + * This is a *const* pointer. + * + * qpath may *not* be NULL qpath. + */ +Inline char* +qpath_char_string(qpath qp) +{ + return qs_make_string(qp->path) ; +} ; + +/*------------------------------------------------------------------------------ + * Get length of the given qpath -- zero if NULL + */ +Inline ulen +qpath_len(qpath qp) +{ + return (qp != NULL) ? qs_len_nn(qp->path) : 0 ; +} ; + +/*------------------------------------------------------------------------------ + * Get *temporary* pointer to qstring rendering of the given path. + * + * This is *temporary* to the extent that when the qpath is changed or freed, + * this pointer will be INVALID -- you have been warned. + * + * This is a *const* pointer. + * + * For a NULL qpath returns NULL qstring. + */ +Inline const qstring +qpath_qs(qpath qp) { - return qs_string(qp != NULL ? &qp->path : qp) ; + return (qp != NULL) ? qp->path : NULL ; } ; #endif /* _ZEBRA_QPATH_H */ |