]> mj.ucw.cz Git - libucw.git/blob - lib/lib.h
2f27ffe43d0c7085479144e783498889c4fe2f53
[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
28 /* Config Files */
29
30 struct cfitem {
31   byte *name;
32   int type;
33   void *var;
34 };
35
36 #define CI_STOP 0
37 #define CI_INT 1
38 #define CI_STRING 2
39 #define CI_FUNCTION 3
40
41 typedef byte *(*ci_func)(struct cfitem *, byte *);
42
43 void cf_read(byte *, struct cfitem *);
44
45 /* Logging */
46
47 #define L_DEBUG "<0>"
48 #define L_INFO "<2>"
49 #define L_WARN "<4>"
50 #define L_ERROR "<6>"
51 #define L_FATAL "<9>"
52
53 void log(byte *, ...);
54 void die(byte *, ...) NONRET;
55 void initlog(byte *);
56
57 /* Allocation */
58
59 void *xmalloc(uns);
60 byte *stralloc(byte *);
61
62 /* Content-Type pattern matching and filters */
63
64 struct ct_filter;
65
66 int match_ct_patt(byte *, byte *);
67
68 struct ct_filter *new_ct_filter(void);
69 byte *add_ct_filter(struct ct_filter *, byte *);
70 int match_ct_filter(struct ct_filter *, byte *);
71
72 /* Binary log */
73
74 #ifdef HAVE_FFS
75 #define log2(x) (ffs(x) - 1)
76 #else
77 int log2(ulg);
78 #endif
79
80 /* obj.c */
81
82 struct odes {                           /* Object description */
83   struct oattr *attrs;
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 *); /* Closes the file afterwards... */
97 void obj_free(struct odes *);
98 struct oattr *find_attr(struct odes *, uns);
99 struct oattr *find_attr_last(struct odes *, uns);
100 byte *find_aval(struct odes *, uns);
101 struct oattr *set_attr(struct odes *, uns, byte *);
102 struct oattr *set_attr_num(struct odes *, uns, uns);
103 struct oattr *add_attr(struct odes *, struct oattr *, uns, byte *);
104 struct oattr *prepend_attr(struct odes *, uns, byte *);
105
106 /* oname.c */
107
108 void mk_obj_name(byte *, ulg, byte *);
109 FILE *create_obj_file(byte *, ulg);
110
111 /* wordsplit.c */
112
113 int wordsplit(byte *, byte **, uns);
114
115 /* patmatch.c */
116
117 int match_pattern(byte *, byte *);