annotate dlib/dlib.h @ 1053:64e078b7a711

Refactor the preferences parser
author Tim Nieradzik, Jorge Arellano Cid
date Tue, 28 Apr 2009 08:32:47 -0400
parents 17d77a1950d8
children a450688d276e
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 #ifndef __DLIB_H__
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 #define __DLIB_H__
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
4 #include <stdio.h> /* for FILE* */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 #include <stddef.h> /* for size_t */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 #include <stdarg.h> /* for va_list */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 #include <string.h> /* for strerror */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8 #include <strings.h> /* for strcasecmp, strncasecmp (POSIX 2001) */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11 #ifdef __cplusplus
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12 extern "C" {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13 #endif /* __cplusplus */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
15 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
16 *-- Common macros -----------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 #ifndef FALSE
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19 #define FALSE (0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20 #endif
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 #ifndef TRUE
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23 #define TRUE (!FALSE)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24 #endif
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26 #undef MAX
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29 #undef MIN
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33 *-- Casts -------------------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
34 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
35 /* TODO: include a void* size test in configure.in */
4
9a9338f78888 +- Connected signals to <li> elements (fixes links within lists).
jcid
parents: 0
diff changeset
36 /* (long) works for both 32bit and 64bit */
9a9338f78888 +- Connected signals to <li> elements (fixes links within lists).
jcid
parents: 0
diff changeset
37 #define VOIDP2INT(p) ((long)(p))
306
7a76f872ce73 - Eliminated gcc 4.2.3 warnings on 64bit OS.
jcid
parents: 167
diff changeset
38 #define INT2VOIDP(i) ((void*)((long)(i)))
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
39
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
40 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
41 *-- Memory -------------------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
42 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
43 #define dNew(type, count) \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
44 ((type *) dMalloc ((unsigned) sizeof (type) * (count)))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
45 #define dNew0(type, count) \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
46 ((type *) dMalloc0 ((unsigned) sizeof (type) * (count)))
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48 void *dMalloc (size_t size);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49 void *dRealloc (void *mem, size_t size);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50 void *dMalloc0 (size_t size);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51 void dFree (void *mem);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
54 *- Debug macros --------------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
56 #define D_STMT_START do
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
57 #define D_STMT_END while (0)
786
17d77a1950d8 Added: dReturn_if() and dReturn_val_if() macros to Dlib.
Jorge Arellano Cid <jcid@dillo.org>
parents: 306
diff changeset
58 #define dReturn_if(expr) \
17d77a1950d8 Added: dReturn_if() and dReturn_val_if() macros to Dlib.
Jorge Arellano Cid <jcid@dillo.org>
parents: 306
diff changeset
59 D_STMT_START{ \
17d77a1950d8 Added: dReturn_if() and dReturn_val_if() macros to Dlib.
Jorge Arellano Cid <jcid@dillo.org>
parents: 306
diff changeset
60 if (expr) { return; }; \
17d77a1950d8 Added: dReturn_if() and dReturn_val_if() macros to Dlib.
Jorge Arellano Cid <jcid@dillo.org>
parents: 306
diff changeset
61 }D_STMT_END
17d77a1950d8 Added: dReturn_if() and dReturn_val_if() macros to Dlib.
Jorge Arellano Cid <jcid@dillo.org>
parents: 306
diff changeset
62 #define dReturn_val_if(expr) \
17d77a1950d8 Added: dReturn_if() and dReturn_val_if() macros to Dlib.
Jorge Arellano Cid <jcid@dillo.org>
parents: 306
diff changeset
63 D_STMT_START{ \
17d77a1950d8 Added: dReturn_if() and dReturn_val_if() macros to Dlib.
Jorge Arellano Cid <jcid@dillo.org>
parents: 306
diff changeset
64 if (expr) { return val; }; \
17d77a1950d8 Added: dReturn_if() and dReturn_val_if() macros to Dlib.
Jorge Arellano Cid <jcid@dillo.org>
parents: 306
diff changeset
65 }D_STMT_END
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
66 #define dReturn_if_fail(expr) \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
67 D_STMT_START{ \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
68 if (!(expr)) { return; }; \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
69 }D_STMT_END
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
70 #define dReturn_val_if_fail(expr,val) \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
71 D_STMT_START{ \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
72 if (!(expr)) { return val; }; \
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
73 }D_STMT_END
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
75 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
76 *- C strings -----------------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
77 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
78 char *dStrdup(const char *s);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
79 char *dStrndup(const char *s, size_t sz);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80 char *dStrconcat(const char *s1, ...);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
81 char *dStrstrip(char *s);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
82 char *dStrnfill(size_t len, char c);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
83 char *dStrsep(char **orig, const char *delim);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
84 char *dStristr(const char *haystack, const char *needle);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86 /* these are in POSIX 2001. Could be implemented if a port requires it */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87 #define dStrcasecmp strcasecmp
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
88 #define dStrncasecmp strncasecmp
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
89 #define dStrerror strerror
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
90
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
91 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
92 *-- dStr ---------------------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
93 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
94 #define Dstr_char_t char
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
95
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
96 typedef struct _dstr {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
97 int sz; /* allocated size (private) */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
98 int len;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
99 Dstr_char_t *str;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
100 } Dstr;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
101
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
102 Dstr *dStr_new (const char *s);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
103 Dstr *dStr_sized_new (int sz);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
104 void dStr_fit (Dstr *ds);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
105 void dStr_free (Dstr *ds, int all);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
106 void dStr_append_c (Dstr *ds, int c);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
107 void dStr_append (Dstr *ds, const char *s);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
108 void dStr_append_l (Dstr *ds, const char *s, int l);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
109 void dStr_insert (Dstr *ds, int pos_0, const char *s);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
110 void dStr_insert_l (Dstr *ds, int pos_0, const char *s, int l);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
111 void dStr_truncate (Dstr *ds, int len);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
112 void dStr_erase (Dstr *ds, int pos_0, int len);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
113 void dStr_vsprintfa (Dstr *ds, const char *format, va_list argp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
114 void dStr_vsprintf (Dstr *ds, const char *format, va_list argp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
115 void dStr_sprintf (Dstr *ds, const char *format, ...);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
116 void dStr_sprintfa (Dstr *ds, const char *format, ...);
157
49d4a18c4928 - Switched URL_DATA type from char* to a dStr.
jcid
parents: 67
diff changeset
117 int dStr_cmp(Dstr *ds1, Dstr *ds2);
163
9b036ecc40a4 - Added dStr_memmem() to dlib.
jcid
parents: 162
diff changeset
118 char *dStr_memmem(Dstr *haystack, Dstr *needle);
167
1540ba94d145 - Added dStr_printable() to dlib.
jcid
parents: 163
diff changeset
119 const char *dStr_printable(Dstr *in, int maxlen);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
120
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
121 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
122 *-- dList --------------------------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
123 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
124 struct Dlist_ {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
125 int sz; /* allocated size (private) */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
126 int len;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
127 void **list;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
128 };
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
129
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
130 typedef struct Dlist_ Dlist;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
131
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
132 /* dCompareFunc:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
133 * Return: 0 if parameters are equal (for dList_find_custom).
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
134 * Return: 0 if equal, < 0 if (a < b), > 0 if (b < a) --for insert sorted.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
135 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
136 * For finding a data node with an external key, the comparison function
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
137 * parameters are: first the data node, and then the key.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
138 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
139 typedef int (*dCompareFunc) (const void *a, const void *b);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
140
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
141
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
142 Dlist *dList_new(int size);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
143 void dList_free (Dlist *lp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
144 void dList_append (Dlist *lp, void *data);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
145 void dList_prepend (Dlist *lp, void *data);
162
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 157
diff changeset
146 void dList_insert_pos (Dlist *lp, void *data, int pos0);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
147 int dList_length (Dlist *lp);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
148 void dList_remove (Dlist *lp, const void *data);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
149 void dList_remove_fast (Dlist *lp, const void *data);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
150 void *dList_nth_data (Dlist *lp, int n0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
151 void *dList_find (Dlist *lp, const void *data);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
152 int dList_find_idx (Dlist *lp, const void *data);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
153 void *dList_find_custom (Dlist *lp, const void *data, dCompareFunc func);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
154 void dList_sort (Dlist *lp, dCompareFunc func);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
155 void dList_insert_sorted (Dlist *lp, void *data, dCompareFunc func);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
156 void *dList_find_sorted (Dlist *lp, const void *data, dCompareFunc func);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
157
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
158 /*
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 4
diff changeset
159 *- Parse function ------------------------------------------------------------
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 4
diff changeset
160 */
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents: 786
diff changeset
161 int dParser_parse_rc_line(char **line, char **name, char **value);
67
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 4
diff changeset
162
ec671a7ea6e2 - * Improved the dpi framework. Now dpi-programs can be specified in dpidrc,
jcid
parents: 4
diff changeset
163 /*
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
164 *- Misc utility functions ----------------------------------------------------
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
165 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
166 char *dGetcwd ();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
167 char *dGethomedir ();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
168 char *dGetline (FILE *stream);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
169
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
170
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
171 #ifdef __cplusplus
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
172 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
173 #endif /* __cplusplus */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
174
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
175 #endif /* __DLIB_H__ */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
176