27#define MAX(a, b) (((a) > (b)) ? (a) : (b))
30#define MIN(a, b) (((a) < (b)) ? (a) : (b))
33#define dIsspace(c) isspace((uchar_t)(c))
34#define dIsalnum(c) isalnum((uchar_t)(c))
36#define D_ASCII_TOUPPER(c) (((c) >= 'a' && (c) <= 'z') ? (c) - 0x20 : (c))
37#define D_ASCII_TOLOWER(c) (((c) >= 'A' && (c) <= 'Z') ? (c) + 0x20 : (c))
43#define VOIDP2INT(p) ((long)(p))
44#define INT2VOIDP(i) ((void*)((long)(i)))
49#define dNew(type, count) \
50 ((type *) dMalloc ((unsigned) sizeof (type) * (count)))
51#define dNew0(type, count) \
52 ((type *) dMalloc0 ((unsigned) sizeof (type) * (count)))
55void *
dRealloc (
void *mem,
size_t size);
57void dFree (
void *mem);
62#define D_STMT_START do
63#define D_STMT_END while (0)
64#define dReturn_if(expr) \
66 if (expr) { return; }; \
68#define dReturn_val_if(expr,val) \
70 if (expr) { return val; }; \
72#define dReturn_if_fail(expr) \
74 if (!(expr)) { return; }; \
76#define dReturn_val_if_fail(expr,val) \
78 if (!(expr)) { return val; }; \
85char *
dStrndup(
const char *s,
size_t sz);
89char *
dStrsep(
char **orig,
const char *delim);
95#define dStrerror strerror
100#define Dstr_char_t char
char * dGetline(FILE *stream)
Get a line from a FILE stream.
char * dStrconcat(const char *s1,...)
Concatenate a NULL-terminated list of strings.
void dList_insert_sorted(Dlist *lp, void *data, dCompareFunc func)
Insert an element into a sorted list.
int dStr_cmp(Dstr *ds1, Dstr *ds2)
Compare two dStrs.
char * dStrsep(char **orig, const char *delim)
strsep() implementation
void * dMalloc0(size_t size)
char * dStr_memmem(Dstr *haystack, Dstr *needle)
Return a pointer to the first occurrence of needle in haystack.
int dStrAsciiCasecmp(const char *s1, const char *s2)
void dStr_sprintfa(Dstr *ds, const char *format,...)
Printf-like function that appends.
char * dStrstrip(char *s)
Remove leading and trailing whitespace.
void dLib_show_messages(bool_t show)
void dStr_append(Dstr *ds, const char *s)
Append a C string to a Dstr.
void dList_insert_pos(Dlist *lp, void *data, int pos0)
Insert an element at a given position [0 based].
char * dStrdup(const char *s)
Dlist * dList_new(int size)
Create a new empty list.
int(* dCompareFunc)(const void *a, const void *b)
Dstr * dStr_sized_new(int sz)
Create a new string with a given size.
int dStrnAsciiCasecmp(const char *s1, const char *s2, size_t n)
void dStr_erase(Dstr *ds, int pos_0, int len)
Erase a substring.
int dList_length(Dlist *lp)
For completing the ADT.
void * dList_nth_data(Dlist *lp, int n0)
Return the nth data item, NULL when not found or 'n0' is out of range.
void dList_remove_fast(Dlist *lp, const void *data)
Remove a data item without preserving order.
void * dMalloc(size_t size)
void dStr_free(Dstr *ds, int all)
Free a dillo string.
void dStrshred(char *s)
Clear the contents of the string.
int dClose(int fd)
Close a FD handling EINTR.
char * dStriAsciiStr(const char *haystack, const char *needle)
Case insensitive strstr.
int dList_find_idx(Dlist *lp, const void *data)
Search a data item.
void dStr_append_l(Dstr *ds, const char *s, int l)
Append a C string to a Dstr (providing length).
void dStr_append_c(Dstr *ds, int c)
Append one character.
char * dStrndup(const char *s, size_t sz)
void dStr_sprintf(Dstr *ds, const char *format,...)
Printf-like function.
void dList_sort(Dlist *lp, dCompareFunc func)
Sort the list using a custom function.
void dStr_vsprintfa(Dstr *ds, const char *format, va_list argp)
vsprintf-like function that appends.
Dstr * dStr_new(const char *s)
Create a new string.
void dStr_shred(Dstr *ds)
Clear a Dstr.
void dList_append(Dlist *lp, void *data)
Append a data item to the list.
void dStr_vsprintf(Dstr *ds, const char *format, va_list argp)
vsprintf-like function.
void * dList_find_sorted(Dlist *lp, const void *data, dCompareFunc func)
Search a sorted list.
void dList_free(Dlist *lp)
Free a list (not its elements)
void dStr_insert_l(Dstr *ds, int pos_0, const char *s, int l)
Insert a C string, at a given position, into a Dstr (providing length).
void * dList_find_custom(Dlist *lp, const void *data, dCompareFunc func)
Search a data item using a custom function.
int dParser_parse_rc_line(char **line, char **name, char **value)
Take a dillo rc line and return 'name' and 'value' pointers to it.
void dList_prepend(Dlist *lp, void *data)
Prepend a data item to the list.
int dUsleep(unsigned long us)
Portable usleep() function.
void dStr_fit(Dstr *ds)
Return memory if there's too much allocated.
const char * dStr_printable(Dstr *in, int maxlen)
Return a printable representation of the provided Dstr, limited to a length of roughly maxlen.
void * dRealloc(void *mem, size_t size)
void dStr_insert(Dstr *ds, int pos_0, const char *s)
Insert a C string, at a given position, into a Dstr.
void dStr_truncate(Dstr *ds, int len)
Truncate a Dstr to be 'len' bytes long.
void dList_remove(Dlist *lp, const void *data)
char * dStrnfill(size_t len, char c)
Return a new string of length 'len' filled with 'c' characters.
char * dGethomedir(void)
Return the home directory in a static string (don't free)
char * dGetcwd(void)
Return the current working directory in a new string.
void * dList_find(Dlist *lp, const void *data)
Return the found data item, or NULL if not present.