40#define MAX(a, b) (((a) > (b)) ? (a) : (b))
43#define MIN(a, b) (((a) < (b)) ? (a) : (b))
47static inline int dIsalnum(
unsigned char c) {
return isalnum(c); }
48static inline int dIsalpha(
unsigned char c) {
return isalpha(c); }
49static inline int dIscntrl(
unsigned char c) {
return iscntrl(c); }
50static inline int dIsdigit(
unsigned char c) {
return isdigit(c); }
51static inline int dIsprint(
unsigned char c) {
return isprint(c); }
52static inline int dIspunct(
unsigned char c) {
return ispunct(c); }
53static inline int dIsspace(
unsigned char c) {
return isspace(c); }
54static inline int dIsxdigit(
unsigned char c) {
return isxdigit(c); }
55static inline int dTolower(
unsigned char c) {
return tolower(c); }
57static inline int dIsascii(
unsigned char c) {
return (c & ~0x7f) == 0; }
59#define D_ASCII_TOUPPER(c) (((c) >= 'a' && (c) <= 'z') ? (c) - 0x20 : (c))
60#define D_ASCII_TOLOWER(c) (((c) >= 'A' && (c) <= 'Z') ? (c) + 0x20 : (c))
72#define VOIDP2INT(p) ((long)(p))
73#define INT2VOIDP(i) ((void*)((long)(i)))
78#define dNew(type, count) \
79 ((type *) dMalloc ((unsigned) sizeof (type) * (count)))
80#define dNew0(type, count) \
81 ((type *) dMalloc0 ((unsigned) sizeof (type) * (count)))
84void *
dRealloc (
void *mem,
size_t size);
86void dFree (
void *mem);
91#define D_STMT_START do
92#define D_STMT_END while (0)
93#define dReturn_if(expr) \
95 if (expr) { return; }; \
97#define dReturn_val_if(expr,val) \
99 if (expr) { return val; }; \
101#define dReturn_if_fail(expr) \
103 if (!(expr)) { return; }; \
105#define dReturn_val_if_fail(expr,val) \
107 if (!(expr)) { return val; }; \
114char *
dStrndup(
const char *s,
size_t sz);
118char *
dStrsep(
char **orig,
const char *delim);
120char *
dStriAsciiStr(
const char *haystack,
const char *needle);
124#define dStrerror strerror
129#define Dstr_char_t char
char * dGetline(FILE *stream)
Get a line from a FILE stream.
static int dIsprint(unsigned char c)
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)
static int dIsdigit(unsigned char c)
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)
static int dIsalpha(unsigned char c)
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.
static int dIsspace(unsigned char c)
void dStr_shorten(Dstr *dst, const char *src, int n)
Shorten string so it fits in n characters.
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)
static int dIspunct(unsigned char c)
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.
static int dTolower(unsigned char c)
char * dStriAsciiStr(const char *haystack, const char *needle)
Case insensitive strstr.
int dList_find_idx(Dlist *lp, const void *data)
Search a data item.
static int dIsascii(unsigned char c)
void dStr_append_l(Dstr *ds, const char *s, int l)
Append a C string to a Dstr (providing length).
static int dIsalnum(unsigned char c)
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.
static int dIscntrl(unsigned char c)
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.
static int dIsxdigit(unsigned char c)
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.