Ticket #245: mhl.patch

File mhl.patch, 5.5 KB (added by Patrick Winnertz, 16 years ago)

Added by email2trac

  • mhl/env.h

    diff --git a/mhl/env.h b/mhl/env.h
    index 8d56337..6598e0c 100644
    a b  
    1 #ifndef __MHL_ENV_H 
    2 #define __MHL_ENV_H 
     1#ifndef MHL_ENV_H 
     2#define MHL_ENV_H 
    33 
    44#include <mhl/string.h> 
    55 
  • mhl/escape.h

    diff --git a/mhl/escape.h b/mhl/escape.h
    index 2ec4e0d..118e082 100644
    a b  
    1 #ifndef __MHL_SHELL_ESCAPE_H 
    2 #define __MHL_SHELL_ESCAPE_H 
     1#ifndef MHL_ESCAPE_H 
     2#define MHL_ESCAPE_H 
    33 
    44/* Micro helper library: shell escaping functions */ 
    55 
    static inline SHELL_ESCAPED_STR mhl_shell_escape_dup(const char* src) 
    6464/** Unescape paths or other strings for e.g the internal cd 
    6565    shell-unescape within a given buffer (writing to it!) 
    6666 
    67  /params const char * in 
     67 /params const char * src 
    6868 string for unescaping 
    6969 /returns 
    7070 return unescaped string 
    static inline char* mhl_shell_unescape_buf(char* text) 
    113113                case '`': 
    114114                case '"': 
    115115                case ';': 
    116                 case '\0': /* end of line! malformed escape string */ 
     116                case '\0': /* end of string! malformed escape string */ 
    117117                    goto out; 
    118118                default: 
    119119                    (*writeptr) = c; writeptr++; break; 
  • mhl/memory.h

    diff --git a/mhl/memory.h b/mhl/memory.h
    index b006177..3268e93 100644
    a b  
    1 #ifndef __MHL_MEM 
    2 #define __MHL_MEM 
     1#ifndef MHL_MEMORY_H 
     2#define MHL_MEMORY_H 
    33 
    44#include <memory.h> 
    55#include <stdlib.h> 
    static inline void mhl_mem_free(void* ptr) 
    1717} 
    1818 
    1919/* free an ptr and NULL it */ 
    20 #define         MHL_PTR_FREE(ptr)       do { mhl_mem_free(ptr); (ptr) = NULL; } while (0);  
     20#define         MHL_PTR_FREE(ptr)       do { mhl_mem_free(ptr); (ptr) = NULL; } while (0) 
    2121 
    2222/* allocate a chunk on stack - automatically free'd on function exit */ 
    2323#define         mhl_stack_alloc(sz)     (alloca(sz)) 
  • mhl/strhash.h

    diff --git a/mhl/strhash.h b/mhl/strhash.h
    index 1f19505..8ff17cb 100644
    a b  
    1 #ifndef __MHL_STRHASH_H 
    2 #define __MHL_STRHASH_H 
     1#ifndef MHL_STRHASH_H 
     2#define MHL_STRHASH_H 
    33 
    44#include <hash.h> 
    55#include <mhl/memory.h> 
  • mhl/string.h

    diff --git a/mhl/string.h b/mhl/string.h
    index ee74e1d..6431fdc 100644
    a b  
    1 #ifndef __MHL_STRING_H 
    2 #define __MHL_STRING_H 
     1#ifndef MHL_STRING_H 
     2#define MHL_STRING_H 
    33 
    44#include <ctype.h> 
    55#include <stdarg.h> 
     
    1010#define mhl_str_ndup(str,len)   ((str ? strndup(str,len) : strdup(""))) 
    1111#define mhl_str_len(str)        ((str ? strlen(str) : 0)) 
    1212 
     13#define ISSPACE(c)              isspace((unsigned char)(c)) 
     14#define TOUPPER(c)              toupper((unsigned char)(c)) 
     15 
    1316static inline char * mhl_str_dup_range(const char * s_start, const char * s_bound) 
    1417{ 
    1518    return mhl_str_ndup(s_start, s_bound - s_start); 
    static inline char* mhl_str_trim(char* str) 
    2023    if (!str) return NULL;      /* NULL string ?! bail out. */ 
    2124 
    2225    /* find the first non-space */ 
    23     char* start; for (start=str; ((*str) && (!isspace(*str))); str++); 
     26    char* start; for (start=str; ((*str) && (!ISSPACE(*str))); str++); 
    2427 
    2528    /* only spaces ? */ 
    2629    if (!(*str)) { *str = 0; return str; } 
    2730 
    28     /* get the size (cannot be empty - catched above) */ 
     31    /* get the size (cannot be empty - caught above) */ 
    2932    size_t _sz = strlen(str); 
    3033 
    3134    /* find the proper end */ 
    3235    char* end; 
    33     for (end=(str+_sz-1); ((end>str) && (isspace(*end))); end--); 
     36    for (end=(str+_sz-1); ((end>str) && (ISSPACE(*end))); end--); 
    3437    end[1] = 0;         /* terminate, just to be sure */ 
    3538 
    3639    /* if we have no leading spaces, just trucate */ 
    3740    if (start==str) { end++; *end = 0; return str; } 
    3841 
    39     /* if it' only one char, dont need memmove for that */ 
     42    /* if it's only one char, dont need memmove for that */ 
    4043    if (start==end) { str[0]=*start; str[1]=0; return str; } 
    4144 
    42     /* by here we have a (non-empty) region between start end end */ 
     45    /* by here we have a (non-empty) region between start and end */ 
    4346    memmove(str,start,(end-start+1)); 
    4447    return str; 
    4548} 
    static inline void mhl_str_toupper(char* str) 
    4851{ 
    4952    if (str) 
    5053        for (;*str;str++) 
    51             *str = toupper(*str); 
     54            *str = TOUPPER(*str); 
    5255} 
    5356 
    5457#define __STR_CONCAT_MAX        32 
    static inline char* __mhl_str_concat_hlp(const char* base, ...) 
    7982            arg_sz[count]  = strlen(a); 
    8083            totalsize += arg_sz[count]; 
    8184            count++; 
     85            assert(count < __STR_CONCAT_MAX); 
    8286        } 
    8387    } 
    8488 
    8589    if (!count) 
    8690        return mhl_str_dup(""); 
    8791 
    88     /* now as we know how much to copy, allocate the buffer */ 
    89     char* buffer = (char*)mhl_mem_alloc_u(totalsize+2); 
     92    /* now that we know how much to copy, allocate the buffer */ 
     93    char* buffer = (char*)mhl_mem_alloc_u(totalsize+2); /* why +2? */ 
    9094    char* current = buffer; 
    9195    int x=0; 
    9296    for (x=0; x<count; x++) 
    static inline char * mhl_strmove(char * dest, const char * src) 
    130134{ 
    131135    size_t n = strlen (src) + 1; /* + '\0' */ 
    132136 
    133     assert (dest<=src); 
     137    assert (dest<=src); /* strictly speaking, this invokes undefined behavior as soon as dest and src are pointers into different objects. */ 
    134138 
    135139    return memmove(dest, src, n); 
    136140} 
    static inline char* mhl_str_dir_plus_file(const char* dirname, const char* filen 
    168172    return buffer; 
    169173} 
    170174 
    171 #endif /* __MHL_STRING_H */ 
     175#endif /* MHL_STRING_H */ 
  • mhl/types.h

    diff --git a/mhl/types.h b/mhl/types.h
    index 1f84002..977c27a 100644
    a b  
    44 
    55*/ 
    66 
    7 #ifndef __MHL_TYPES_H 
    8 #define __MHL_TYPES_H 
     7#ifndef MHL_TYPES_H 
     8#define MHL_TYPES_H 
    99 
    10 typedef enum  
     10#if !defined(__bool_true_false_are_defined) && !defined(false) && !defined(true) && !defined(bool) 
     11typedef enum 
    1112{ 
    1213    false       = 0, 
    1314    true        = 1 
    1415} bool; 
     16#endif 
    1517 
    1618#endif