]> mj.ucw.cz Git - libucw.git/blob - lib/lib.h
Yet another bug in the pattern matcher fixed.
[libucw.git] / lib / lib.h
1 /*
2  *      Sherlock Library -- Miscellaneous Functions
3  *
4  *      (c) 1997 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
5  */
6
7 #include <lib/config.h>
8
9 /* Temporary Files */
10
11 #define TMP_DIR "tmp"
12 #define TMP_DIR_LEN 3
13
14 struct tempfile {
15   int fh;
16   byte name[32];
17 };
18
19 void open_temp(struct tempfile *, byte *);
20 void delete_temp(struct tempfile *);
21 ulg temprand(uns);
22
23 #define TF_GENERIC "t"
24 #define TF_QUEUE_CONTROL "c"
25 #define TF_QUEUE_DATA "d"
26 #define TF_DECODE "x"
27 #define TF_TRANSFORM "s"
28 #define TF_OBJECT "o"
29
30 /* Config Files */
31
32 struct cfitem {
33   byte *name;
34   int type;
35   void *var;
36 };
37
38 #define CI_STOP 0
39 #define CI_INT 1
40 #define CI_STRING 2
41 #define CI_FUNCTION 3
42
43 typedef byte *(*ci_func)(struct cfitem *, byte *);
44
45 void cf_read(byte *, struct cfitem *);
46
47 /* Logging */
48
49 #define L_DEBUG "<0>"
50 #define L_INFO "<2>"
51 #define L_WARN "<4>"
52 #define L_ERROR "<6>"
53 #define L_FATAL "<9>"
54
55 void log(byte *, ...);
56 void die(byte *, ...) NONRET;
57 void initlog(byte *);
58 void open_log_file(byte *);
59
60 /* Allocation */
61
62 void *xmalloc(uns);
63 byte *stralloc(byte *);
64
65 /* Content-Type pattern matching and filters */
66
67 struct ct_filter;
68
69 int match_ct_patt(byte *, byte *);
70
71 struct ct_filter *new_ct_filter(void);
72 byte *add_ct_filter(struct ct_filter *, byte *);
73 int match_ct_filter(struct ct_filter *, byte *);
74
75 /* Binary log */
76
77 int log2(ulg);
78
79 /* obj.c */
80
81 struct odes {                           /* Object description */
82   struct oattr *attrs;
83   struct mempool *pool;
84 };
85
86 struct oattr {                          /* Object attribute */
87   struct oattr *next, *same;
88   byte attr;
89   byte val[1];
90 };
91
92 void obj_dump(struct odes *);
93 struct odes *obj_fload(FILE *);
94 struct odes *obj_new(void);
95 struct odes *obj_load(byte *);
96 void obj_fwrite(FILE *, struct odes *);
97 void obj_write(byte *, struct odes *);
98 void obj_free(struct odes *);
99 struct oattr *find_attr(struct odes *, uns);
100 struct oattr *find_attr_last(struct odes *, uns);
101 uns del_attr(struct odes *, struct oattr *);
102 byte *find_aval(struct odes *, uns);
103 struct oattr *set_attr(struct odes *, uns, byte *);
104 struct oattr *set_attr_num(struct odes *, uns, uns);
105 struct oattr *add_attr(struct odes *, struct oattr *, uns, byte *);
106 struct oattr *prepend_attr(struct odes *, uns, byte *);
107
108 /* oname.c */
109
110 void mk_obj_name(byte *, ulg, byte *);
111 int dump_obj_to_file(byte *, ulg, struct odes *, int);
112
113 /* wordsplit.c */
114
115 int wordsplit(byte *, byte **, uns);
116
117 /* pat(i)match.c */
118
119 int match_pattern(byte *, byte *);
120 int match_pattern_nocase(byte *, byte *);
121
122 /* md5hex.c */
123
124 void md5_to_hex(byte *, byte *);
125 void hex_to_md5(byte *, byte *);
126
127 #define MD5_SIZE 16
128 #define MD5_HEX_SIZE 33
129
130 /* prime.c */
131
132 int isprime(uns);
133 uns nextprime(uns);
134
135 /* timer.c */
136
137 void init_timer(void);
138 uns get_timer(void);
139
140 /* regex.c */
141
142 typedef struct regex regex;
143
144 regex *rx_compile(byte *r);
145 void rx_free(regex *r);
146 int rx_match(regex *r, byte *s);
147 int rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen);