]> mj.ucw.cz Git - libucw.git/blob - lib/lib.h
c4698ec0b5137883f8160a30ee02c2eb9049e6de
[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 and filters */
62
63 struct ct_filter;
64
65 int match_ct_patt(byte *, byte *);
66
67 struct ct_filter *new_ct_filter(void);
68 byte *add_ct_filter(struct ct_filter *, byte *);
69 int match_ct_filter(struct ct_filter *, byte *);
70
71 /* Binary log */
72
73 #ifdef HAVE_FFS
74 #define log2(x) (ffs(x) - 1)
75 #else
76 int log2(ulg);
77 #endif
78
79 /* obj.c */
80
81 struct odes {                           /* Object description */
82   struct oattr *attrs;
83 };
84
85 struct oattr {                          /* Object attribute */
86   struct oattr *next, *same;
87   byte attr;
88   byte val[1];
89 };
90
91 void obj_dump(struct odes *);
92 struct odes *obj_fload(FILE *);
93 struct odes *obj_new(void);
94 struct odes *obj_load(byte *);
95 void obj_fwrite(FILE *, struct odes *); /* Closes the file afterwards... */
96 void obj_free(struct odes *);
97 struct oattr *find_attr(struct odes *, uns);
98 struct oattr *find_attr_last(struct odes *, uns);
99 byte *find_aval(struct odes *, uns);
100 struct oattr *set_attr(struct odes *, uns, byte *);
101 struct oattr *set_attr_num(struct odes *, uns, uns);
102 struct oattr *add_attr(struct odes *, struct oattr *, uns, byte *);
103
104 /* oname.c */
105
106 void mk_obj_name(byte *, ulg, byte *);
107 FILE *create_obj_file(byte *, ulg);
108
109 /* wordsplit.c */
110
111 int wordsplit(byte *, byte **, uns);
112
113 /* patmatch.c */
114
115 int match_pattern(byte *, byte *);