Revert "Resolve some issues in mhl Rollang Illig pointed us to:"

This reverts commit 60f2d8d3c0.
This commit is contained in:
Patrick Winnertz 2009-02-10 13:21:17 +01:00
parent 161dc235a6
commit 428e233f37
6 changed files with 23 additions and 29 deletions

View File

@ -1,5 +1,5 @@
#ifndef MHL_ENV_H #ifndef __MHL_ENV_H
#define MHL_ENV_H #define __MHL_ENV_H
#include <mhl/string.h> #include <mhl/string.h>

View File

@ -1,5 +1,5 @@
#ifndef MHL_ESCAPE_H #ifndef __MHL_SHELL_ESCAPE_H
#define MHL_ESCAPE_H #define __MHL_SHELL_ESCAPE_H
/* Micro helper library: shell escaping functions */ /* Micro helper library: shell escaping functions */
@ -63,7 +63,7 @@ static inline SHELL_ESCAPED_STR mhl_shell_escape_dup(const char* src)
/** Unescape paths or other strings for e.g the internal cd /** Unescape paths or other strings for e.g the internal cd
shell-unescape within a given buffer (writing to it!) shell-unescape within a given buffer (writing to it!)
/params const char * src /params const char * in
string for unescaping string for unescaping
/returns /returns
return unescaped string return unescaped string
@ -112,7 +112,7 @@ static inline char* mhl_shell_unescape_buf(char* text)
case '`': case '`':
case '"': case '"':
case ';': case ';':
case '\0': /* end of string! malformed escape string */ case '\0': /* end of line! malformed escape string */
goto out; goto out;
default: default:
(*writeptr) = c; writeptr++; break; (*writeptr) = c; writeptr++; break;

View File

@ -1,5 +1,5 @@
#ifndef MHL_MEMORY_H #ifndef __MHL_MEM
#define MHL_MEMORY_H #define __MHL_MEM
#include <memory.h> #include <memory.h>
#include <stdlib.h> #include <stdlib.h>
@ -17,7 +17,7 @@ static inline void mhl_mem_free(void* ptr)
} }
/* free an ptr and NULL it */ /* free an ptr and NULL it */
#define MHL_PTR_FREE(ptr) do { mhl_mem_free(ptr); (ptr) = NULL; } while (0) #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 */ /* allocate a chunk on stack - automatically free'd on function exit */
#define mhl_stack_alloc(sz) (alloca(sz)) #define mhl_stack_alloc(sz) (alloca(sz))

View File

@ -1,5 +1,5 @@
#ifndef MHL_STRHASH_H #ifndef __MHL_STRHASH_H
#define MHL_STRHASH_H #define __MHL_STRHASH_H
#include <hash.h> #include <hash.h>
#include <mhl/memory.h> #include <mhl/memory.h>

View File

@ -1,5 +1,5 @@
#ifndef MHL_STRING_H #ifndef __MHL_STRING_H
#define MHL_STRING_H #define __MHL_STRING_H
#include <ctype.h> #include <ctype.h>
#include <stdarg.h> #include <stdarg.h>
@ -10,9 +10,6 @@
#define mhl_str_ndup(str,len) ((str ? strndup(str,len) : strdup(""))) #define mhl_str_ndup(str,len) ((str ? strndup(str,len) : strdup("")))
#define mhl_str_len(str) ((str ? strlen(str) : 0)) #define mhl_str_len(str) ((str ? strlen(str) : 0))
#define ISSPACE(c) isspace((unsigned char)(c))
#define TOUPPER(c) toupper((unsigned char)(c))
static inline char * mhl_str_dup_range(const char * s_start, const char * s_bound) 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); return mhl_str_ndup(s_start, s_bound - s_start);
@ -23,26 +20,26 @@ static inline char* mhl_str_trim(char* str)
if (!str) return NULL; /* NULL string ?! bail out. */ if (!str) return NULL; /* NULL string ?! bail out. */
/* find the first non-space */ /* find the first non-space */
char* start; for (start=str; ((*str) && (!ISSPACE(*str))); str++); char* start; for (start=str; ((*str) && (!isspace(*str))); str++);
/* only spaces ? */ /* only spaces ? */
if (!(*str)) { *str = 0; return str; } if (!(*str)) { *str = 0; return str; }
/* get the size (cannot be empty - caught above) */ /* get the size (cannot be empty - catched above) */
size_t _sz = strlen(str); size_t _sz = strlen(str);
/* find the proper end */ /* find the proper end */
char* end; char* end;
for (end=(str+_sz-1); ((end>str) && (ISSPACE(*end))); end--); for (end=(str+_sz-1); ((end>str) && (isspace(*end))); end--);
end[1] = 0; /* terminate, just to be sure */ end[1] = 0; /* terminate, just to be sure */
/* if we have no leading spaces, just trucate */ /* if we have no leading spaces, just trucate */
if (start==str) { end++; *end = 0; return str; } if (start==str) { end++; *end = 0; return str; }
/* if it's only one char, dont need memmove for that */ /* if it' only one char, dont need memmove for that */
if (start==end) { str[0]=*start; str[1]=0; return str; } if (start==end) { str[0]=*start; str[1]=0; return str; }
/* by here we have a (non-empty) region between start and end */ /* by here we have a (non-empty) region between start end end */
memmove(str,start,(end-start+1)); memmove(str,start,(end-start+1));
return str; return str;
} }
@ -51,7 +48,7 @@ static inline void mhl_str_toupper(char* str)
{ {
if (str) if (str)
for (;*str;str++) for (;*str;str++)
*str = TOUPPER(*str); *str = toupper(*str);
} }
/* note: we use ((char*)(1)) as terminator - NULL is a valid argument ! */ /* note: we use ((char*)(1)) as terminator - NULL is a valid argument ! */
@ -130,7 +127,6 @@ static inline char * mhl_strmove(char * dest, const char * src)
{ {
size_t n = strlen (src) + 1; /* + '\0' */ size_t n = strlen (src) + 1; /* + '\0' */
/* strictly speaking, this invokes undefined behavior as soon as dest and src are pointers into different objects. */
assert (dest<=src); assert (dest<=src);
return memmove(dest, src, n); return memmove(dest, src, n);
@ -169,4 +165,4 @@ static inline char* mhl_str_dir_plus_file(const char* dirname, const char* filen
return buffer; return buffer;
} }
#endif /* MHL_STRING_H */ #endif /* __MHL_STRING_H */

View File

@ -4,15 +4,13 @@
*/ */
#ifndef MHL_TYPES_H #ifndef __MHL_TYPES_H
#define MHL_TYPES_H #define __MHL_TYPES_H
#if !defined(__bool_true_false_are_defined) && !defined(false) && !defined(true) && !defined(bool) typedef enum
typedef enum
{ {
false = 0, false = 0,
true = 1 true = 1
} bool; } bool;
#endif
#endif #endif