From 8b7e47d9cca63bff63d4920466b522f63946b0a2 Mon Sep 17 00:00:00 2001 From: Patrick Winnertz Date: Tue, 10 Feb 2009 14:11:30 +0100 Subject: [PATCH] Last bunch of reverts and removal of mhl/* Signed-off-by: Patrick Winnertz --- mhl/.gitignore | 3 - mhl/README | 103 ----------------------------- mhl/env.h | 8 --- mhl/escape.h | 150 ------------------------------------------- mhl/memory.h | 28 -------- mhl/strhash.h | 49 -------------- mhl/string.h | 171 ------------------------------------------------- mhl/types.h | 16 ----- src/charsets.c | 2 - src/file.c | 10 +-- src/utilunix.c | 12 ++-- vfs/fish.c | 5 +- 12 files changed, 9 insertions(+), 548 deletions(-) delete mode 100644 mhl/.gitignore delete mode 100644 mhl/README delete mode 100644 mhl/env.h delete mode 100644 mhl/escape.h delete mode 100644 mhl/memory.h delete mode 100644 mhl/strhash.h delete mode 100644 mhl/string.h delete mode 100644 mhl/types.h diff --git a/mhl/.gitignore b/mhl/.gitignore deleted file mode 100644 index e99558847..000000000 --- a/mhl/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.deps -Makefile -Makefile.in diff --git a/mhl/README b/mhl/README deleted file mode 100644 index dbf3490bf..000000000 --- a/mhl/README +++ /dev/null @@ -1,103 +0,0 @@ - -Micro helper library. --- - -This is a tiny library of helper functions/macros. - - * MACRO-FUNC: macro w/ function syntax. (might become inline func) - * INLINE-FUNC: inline function (might become macro func) - * MACRO: strictly a macro (may never become a inline func) - --- - -mhl/memory.h: Memory management functions - - * mhl_mem_alloc_u(sz) [MACRO-FUNC] - - Allocate sz bytes on stack, unitialized - - * mhl_mem_alloc_z(sz) [INLINE-FUNC] - - Allocate sz bytes on stack, zero'ed - - * mhl_mem_free(ptr) [INLINE-FUNC] - - Free chunk @ptr (MUST be allocated w/ mhl_mem_alloc_*()), - passing NULL is graciously allowed - - * mhl_mem_realloc(ptr,newsize) -> returns newptr - - Re-allocates a heap chunk, just like realloc() - - * MHL_PTR_FREE(ptr) [MACRO-ONLY] - - like mhl_mem_free(), but with ptr as a variable that gets cleared - (use this as shortcut to "mhl_mem_free(foo); foo = NULL") - -mhl/string.h: String helpers - - * mhl_str_dup(const char*s) -> char* - - [MACRO-FUNC] Safe version of strdup(), when NULL passed, returns strdup("") - - * mhl_str_ndup(const char* s) -> char* - - [MACRO-FUNC] Safe version of strndup(), when NULL passed, returns strdup("") - - * mhl_str_trim(char* s) -> char* - - [INLINE-FUNC] Trims the string (removing leading and trailing whitespacs), - WITHIN the passed buffer, returning the string s itself. - When NULL passed returns NULL. - - * mhl_str_toupper(char* s) -> char* - - [INLINE-FUNC] Converts the string in passed buffer to uppercase, returns that - buffer. When NULL passed returns NULL. - - * mhl_str_concat_1(const char* base, const char* one) -> char* - - [INLINE-FUNC] Concatenates the string one onto the string base and returns the - result in a newly allocated buffer (free it w/ mhl_mem_free()). - For NULL strings, "" is assumed. - - * mhl_str_concat_2(const char* base,const char* one,const char* two) -> char* - mhl_str_concat_3(const char* base,const char* one,const char* two,const char* three) -> char* - mhl_str_concat_4(const char* base,const char* one,const char* two,const char* three,const char* four) -> char* - mhl_str_concat_5(const char* base,const char* one,const char* two,const char* three,const char* four,const char* five) -> char* - mhl_str_concat_6(const char* base,const char* one,const char* two,const char* three,const char* four,const char* five,const char* six) -> char* - mhl_str_concat_7(const char* base,const char* one,const char* two,const char* three,const char* four,const char* five,const char* six,const char* seven) -> char* - - [INLINE-FUNC] Like str_concat_1() but adding more strings. - - * mhl_str_reverse(char* str) -> char* - - [INLINE-FUNC] Reverses the string in passed buffer and returns the buffer ptr itself. - If NULL is passed, returns NULL. - -mhl/escape.h: Shell-style string escaping - - * mhl_shell_escape_toesc(char c) -> bool - - [MACRO-FUNC] returns true when given char has to be escaped - - * mhl_shell_escape_nottoesc(char c) -> bool - - [MACRO-FUNC] opposite of mhl_shell_escape_toesc() - - * mhl_shell_escape_dup(const char* s) -> char* - - [INLINE-FUNC] escapes an string and returns the result in a malloc()'ed chunk - Passing NULL returns an empty malloc()ed string. - - * mhl_shell_unescape_buf(char* s) -> char* - - [INLINE-FUNC] unescapes the string into given buffer (changes buffer!) and - returns ptr to the buffer itself. When NULL passed returns NULL. - -mhl/env.h: Environment variable helpers - - * mhl_getenv_dup(const char* n) -> char* - - [MACRO-FUNC] like getenv() but returns an strdup()'ed copy. When NULL passed, - returns strdup("") diff --git a/mhl/env.h b/mhl/env.h deleted file mode 100644 index 8d5633797..000000000 --- a/mhl/env.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __MHL_ENV_H -#define __MHL_ENV_H - -#include - -#define mhl_getenv_dup(name) (mhl_str_dup(name ? getenv(name) : "")) - -#endif diff --git a/mhl/escape.h b/mhl/escape.h deleted file mode 100644 index efc0aac52..000000000 --- a/mhl/escape.h +++ /dev/null @@ -1,150 +0,0 @@ -#ifndef __MHL_SHELL_ESCAPE_H -#define __MHL_SHELL_ESCAPE_H - -/* Micro helper library: shell escaping functions */ - -#include -#include - -#include - -#define mhl_shell_escape_toesc(x) \ - (((x)==' ')||((x)=='!')||((x)=='#')||((x)=='$')||((x)=='%')|| \ - ((x)=='(')||((x)==')')||((x)=='\'')||((x)=='&')||((x)=='~')|| \ - ((x)=='{')||((x)=='}')||((x)=='[')||((x)==']')||((x)=='`')|| \ - ((x)=='?')||((x)=='|')||((x)=='<')||((x)=='>')||((x)==';')|| \ - ((x)=='*')||((x)=='\\')||((x)=='"')) - -#define mhl_shell_escape_nottoesc(x) \ - (((x)!=0) && (!mhl_shell_escape_toesc((x)))) - -/* type for escaped string - just for a bit more type safety ;-p */ -typedef struct { char* s; } SHELL_ESCAPED_STR; - -/** To be compatible with the general posix command lines we have to escape - strings for the command line - - /params const char * in - string for escaping - /returns - return escaped string (later need to free) - */ -static inline SHELL_ESCAPED_STR mhl_shell_escape_dup(const char* src) -{ - if ((src==NULL)||(!(*src))) - return (SHELL_ESCAPED_STR){ .s = strdup("") }; - - char* buffer = calloc(1, strlen(src)*2+2); - char* ptr = buffer; - - /* look for the first char to escape */ - while (1) - { - char c; - /* copy over all chars not to escape */ - while ((c=(*src)) && mhl_shell_escape_nottoesc(c)) - { - *ptr = c; - ptr++; - src++; - } - - /* at this point we either have an \0 or an char to escape */ - if (!c) - return (SHELL_ESCAPED_STR){ .s = buffer }; - - *ptr = '\\'; - ptr++; - *ptr = c; - ptr++; - src++; - } -} - -/** Unescape paths or other strings for e.g the internal cd - shell-unescape within a given buffer (writing to it!) - - /params const char * in - string for unescaping - /returns - return unescaped string -*/ -static inline char* mhl_shell_unescape_buf(char* text) -{ - if (!text) - return NULL; - - /* look for the first \ - that's quick skipover if there's nothing to escape */ - char* readptr = text; - while ((*readptr) && ((*readptr)!='\\')) readptr++; - if (!(*readptr)) return text; - - /* if we're here, we're standing on the first '\' */ - char* writeptr = readptr; - char c; - while ((c = *readptr)) - { - if (c=='\\') - { - readptr++; - switch ((c = *readptr)) - { - case 'n': (*writeptr) = '\n'; writeptr++; break; - case 'r': (*writeptr) = '\r'; writeptr++; break; - case 't': (*writeptr) = '\t'; writeptr++; break; - - case ' ': - case '\\': - case '#': - case '$': - case '%': - case '(': - case ')': - case '[': - case ']': - case '{': - case '}': - case '<': - case '>': - case '!': - case '*': - case '?': - case '~': - case '`': - case '"': - case ';': - default: - (*writeptr) = c; writeptr++; break; - } - } - else /* got a normal character */ - { - (*writeptr) = *readptr; - writeptr++; - } - readptr++; - } - *writeptr = 0; - - return text; -} - -/** Check if char in pointer contain escape'd chars - - /params const char * in - string for checking - /returns - return TRUE if string contain escaped chars - otherwise return FALSE - */ -static inline bool -mhl_shell_is_char_escaped ( const char *in ) -{ - if (in == NULL || !*in || in[0] != '\\') - return false; - if (mhl_shell_escape_toesc(in[1])) - return true; - return false; -} - -#endif diff --git a/mhl/memory.h b/mhl/memory.h deleted file mode 100644 index b00617700..000000000 --- a/mhl/memory.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __MHL_MEM -#define __MHL_MEM - -#include -#include - -/* allocate a chunk of stack memory, uninitialized */ -#define mhl_mem_alloc_u(sz) (malloc(sz)) - -/* allocate a chunk of stack memory, zeroed */ -#define mhl_mem_alloc_z(sz) (calloc(1,sz)) - -/* free a chunk of memory from stack, passing NULL does no harm */ -static inline void mhl_mem_free(void* ptr) -{ - if (ptr) free(ptr); -} - -/* free an ptr and NULL it */ -#define MHL_PTR_FREE(ptr) do { mhl_mem_free(ptr); (ptr) = NULL; } while (0); - -/* allocate a chunk on stack - automatically free'd on function exit */ -#define mhl_stack_alloc(sz) (alloca(sz)) - -/* re-alloc memory chunk */ -#define mhl_mem_realloc(ptr,sz) (realloc(ptr,sz)) - -#endif diff --git a/mhl/strhash.h b/mhl/strhash.h deleted file mode 100644 index 1f195053c..000000000 --- a/mhl/strhash.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef __MHL_STRHASH_H -#define __MHL_STRHASH_H - -#include -#include - -static void __mhl_strhash_free_key(void* ptr) -{ - mhl_mem_free(ptr); -} - -static void __mhl_strhash_free_dummy(void* ptr) -{ -} - -typedef hash MHL_STRHASH; - -#define MHL_STRHASH_DECLARE(n) MHL_STRHASH n; - -#define MHL_STRHASH_INIT(h) \ - hash_initialise(h, 997U, \ - hash_hash_string, \ - hash_compare_string, \ - hash_copy_string, \ - __mhl_strhash_free_key, \ - __mhl_strhash_free_dummy) - -#define MHL_STRHASH_DECLARE_INIT(n) \ - MHL_STRHASH_DECLARE(n); \ - MHL_STRHASH_INIT(&n); - -#define MHL_STRHASH_DEINIT(ht) \ - hash_deinitialise(ht) - -static inline void mhl_strhash_addkey(MHL_STRHASH* ht, const char* key, void* value) -{ - hash_insert(ht, (char*)key, value); -} - -static inline void* mhl_strhash_lookup(MHL_STRHASH* ht, const char* key) -{ - void* retptr; - if (hash_retrieve(ht, (char*)key, &retptr)) - return retptr; - else - return NULL; -} - -#endif diff --git a/mhl/string.h b/mhl/string.h deleted file mode 100644 index f4c56e5ec..000000000 --- a/mhl/string.h +++ /dev/null @@ -1,171 +0,0 @@ -#ifndef __MHL_STRING_H -#define __MHL_STRING_H - -#include -#include -#include -#include - -#define mhl_str_dup(str) ((str ? strdup(str) : strdup(""))) -#define mhl_str_ndup(str,len) ((str ? strndup(str,len) : strdup(""))) -#define mhl_str_len(str) ((str ? strlen(str) : 0)) - -static inline char * mhl_str_dup_range(const char * s_start, const char * s_bound) -{ - return mhl_str_ndup(s_start, s_bound - s_start); -} - -static inline char* mhl_str_trim(char* str) -{ - if (!str) return NULL; /* NULL string ?! bail out. */ - - /* find the first non-space */ - char* start; for (start=str; ((*str) && (!isspace(*str))); str++); - - /* only spaces ? */ - if (!(*str)) { *str = 0; return str; } - - /* get the size (cannot be empty - catched above) */ - size_t _sz = strlen(str); - - /* find the proper end */ - char* end; - for (end=(str+_sz-1); ((end>str) && (isspace(*end))); end--); - end[1] = 0; /* terminate, just to be sure */ - - /* if we have no leading spaces, just trucate */ - if (start==str) { end++; *end = 0; return str; } - - /* if it' only one char, dont need memmove for that */ - if (start==end) { str[0]=*start; str[1]=0; return str; } - - /* by here we have a (non-empty) region between start end end */ - memmove(str,start,(end-start+1)); - return str; -} - -static inline void mhl_str_toupper(char* str) -{ - if (str) - for (;*str;str++) - *str = toupper(*str); -} - -#define __STR_CONCAT_MAX 32 -/* _NEVER_ call this function directly ! */ -static inline char* __mhl_str_concat_hlp(const char* base, ...) -{ - static const char* arg_ptr[__STR_CONCAT_MAX]; - static size_t arg_sz[__STR_CONCAT_MAX]; - int count = 0; - size_t totalsize = 0; - - if (base) - { - arg_ptr[0] = base; - arg_sz[0] = totalsize = strlen(base); - count = 1; - } - - va_list args; - va_start(args,base); - char* a; - /* note: we use ((char*)(1)) as terminator - NULL is a valid argument ! */ - while ((a = va_arg(args, char*))!=(char*)1) - { - if (a) - { - arg_ptr[count] = a; - arg_sz[count] = strlen(a); - totalsize += arg_sz[count]; - count++; - } - } - - if (!count) - return mhl_str_dup(""); - - /* now as we know how much to copy, allocate the buffer */ - char* buffer = (char*)mhl_mem_alloc_u(totalsize+2); - char* current = buffer; - int x=0; - for (x=0; x -#include - #include "global.h" #include "charsets.h" diff --git a/src/file.c b/src/file.c index 1fa461e1a..efd19fd01 100644 --- a/src/file.c +++ b/src/file.c @@ -50,10 +50,6 @@ #include #include -#include -#include -#include - #include "global.h" #include "tty.h" #include "eregex.h" @@ -181,7 +177,7 @@ do_transform_source (FileOpContext *ctx, const char *source) for (next_reg = 1, j = 0, k = 0; j < strlen (ctx->dest_mask); j++) { switch (ctx->dest_mask[j]) { case '\\': - if (mhl_shell_is_char_escaped (&ctx->dest_mask[j])){ + if (shell_is_char_escaped (&ctx->dest_mask[j])){ fntarget[k++] = ctx->dest_mask[j++]; fntarget[k++] = ctx->dest_mask[j]; break; @@ -1805,13 +1801,13 @@ panel_operate (void *source_panel, FileOperation operation, */ if (force_single) /* just copy */ - dest_dir_ = mhl_str_dup (dest_dir); + dest_dir_ = g_strdup (dest_dir); else /* add trailing separator */ if (*dest_dir && strcmp(&dest_dir[strlen(dest_dir)-1], PATH_SEP_STR)) { dest_dir_ = g_concat (dest_dir, PATH_SEP_STR); } else { - dest_dir_ = mhl_str_dup (dest_dir); + dest_dir_ = g_strdup (dest_dir); } if (!dest_dir_) { file_op_context_destroy (ctx); diff --git a/src/utilunix.c b/src/utilunix.c index 1b72b2e40..c2afdee2b 100644 --- a/src/utilunix.c +++ b/src/utilunix.c @@ -41,8 +41,6 @@ #endif #include -#include - #include "global.h" #include "execute.h" #include "wtools.h" /* message() */ @@ -428,7 +426,7 @@ canonicalize_pathname (char *path) if (p[0] == PATH_SEP && p[1] == PATH_SEP) { s = p + 1; while (*(++s) == PATH_SEP); - mhl_strmove (p + 1, s); + str_move (p + 1, s); } p++; } @@ -437,7 +435,7 @@ canonicalize_pathname (char *path) p = lpath; while (*p) { if (p[0] == PATH_SEP && p[1] == '.' && p[2] == PATH_SEP) - mhl_strmove (p, p + 2); + str_move (p, p + 2); else p++; } @@ -453,7 +451,7 @@ canonicalize_pathname (char *path) lpath[1] = 0; return; } else { - mhl_strmove (lpath, lpath + 2); + str_move (lpath, lpath + 2); } } @@ -499,10 +497,10 @@ canonicalize_pathname (char *path) if (p[3] != 0) { if (s == lpath && *s == PATH_SEP) { /* "/../foo" -> "/foo" */ - mhl_strmove (s + 1, p + 4); + str_move (s + 1, p + 4); } else { /* "token/../foo" -> "foo" */ - mhl_strmove (s, p + 4); + str_move (s, p + 4); } p = (s > lpath) ? s - 1 : s; continue; diff --git a/vfs/fish.c b/vfs/fish.c index ea1d0c954..869500cd0 100644 --- a/vfs/fish.c +++ b/vfs/fish.c @@ -50,9 +50,6 @@ #include "tcputil.h" #include "../src/unixcompat.h" #include "fish.h" -#include "../mhl/memory.h" -#include "../mhl/string.h" -#include "../mhl/escape.h" int fish_directory_timeout = 900; @@ -880,7 +877,7 @@ fish_send_command(struct vfs_class *me, struct vfs_s_super *super, const char *c #define PREFIX \ char buf[BUF_LARGE]; \ const char *crpath; \ - char *mpath = mhl_str_dup (path); \ + char *mpath = g_strdup (path); \ SHELL_ESCAPED_STR rpath; \ struct vfs_s_super *super; \ if (!(crpath = vfs_s_get_path_mangle (me, mpath, &super, 0))) { \