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