X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Flib.h;h=72337d93ea93b5118cd0aa180ce06ab174b1540d;hb=05d39c073356d120fec08689dfe1c43c78ed5ed4;hp=137c2472aff838d9f87900f28e6bf61945e6061c;hpb=5f8f26dc98d23fdbc6fe67223e77b82256713782;p=libucw.git diff --git a/lib/lib.h b/lib/lib.h index 137c2472..72337d93 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -4,8 +4,17 @@ * (c) 1997 Martin Mares, */ +#ifndef _SHERLOCK_LIB_H +#define _SHERLOCK_LIB_H + #include +/* Ugly structure handling macros */ + +#define OFFSETOF(s, i) ((unsigned int)&((s *)0)->i) +#define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i))) +#define ALIGN(s, a) (((s)+a-1)&~(a-1)) + /* Temporary Files */ #define TMP_DIR "tmp" @@ -18,7 +27,7 @@ struct tempfile { void open_temp(struct tempfile *, byte *); void delete_temp(struct tempfile *); -ulg temprand(uns); +u32 temprand(uns); #define TF_GENERIC "t" #define TF_QUEUE_CONTROL "c" @@ -43,6 +52,7 @@ struct cfitem { typedef byte *(*ci_func)(struct cfitem *, byte *); void cf_read(byte *, struct cfitem *); +int cf_read_err(byte *, struct cfitem *); /* Read with possible error, 1 = succeeded */ /* Logging */ @@ -57,9 +67,16 @@ void die(byte *, ...) NONRET; void initlog(byte *); void open_log_file(byte *); +#ifdef DEBUG +#define ASSERT(x) do { if (!(x)) die("Assertion `%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0) +#else +#define ASSERT(x) do { } while(0) +#endif + /* Allocation */ void *xmalloc(uns); +void *xrealloc(void *, uns); byte *stralloc(byte *); /* Content-Type pattern matching and filters */ @@ -74,11 +91,7 @@ int match_ct_filter(struct ct_filter *, byte *); /* Binary log */ -#ifdef HAVE_FFS -#define log2(x) (ffs(x) - 1) -#else -int log2(ulg); -#endif +int log2(u32); /* obj.c */ @@ -94,7 +107,7 @@ struct oattr { /* Object attribute */ }; void obj_dump(struct odes *); -struct odes *obj_fload(FILE *); +struct odes *obj_fload(FILE *, byte *); struct odes *obj_new(void); struct odes *obj_load(byte *); void obj_fwrite(FILE *, struct odes *); @@ -111,8 +124,11 @@ struct oattr *prepend_attr(struct odes *, uns, byte *); /* oname.c */ -void mk_obj_name(byte *, ulg, byte *); -int dump_obj_to_file(byte *, ulg, struct odes *, int); +#define OID_MIN 0x10000 /* Values less than this have special meaning */ + +oid_t new_oid(uns); +void mk_obj_name(byte *, oid_t, byte *); +int dump_obj_to_file(byte *, oid_t, struct odes *, int); /* wordsplit.c */ @@ -140,3 +156,26 @@ uns nextprime(uns); void init_timer(void); uns get_timer(void); + +/* regex.c */ + +typedef struct regex regex; + +regex *rx_compile(byte *r); +void rx_free(regex *r); +int rx_match(regex *r, byte *s); +int rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen); + +/* objwalk.c */ + +void scan_obj_tree(byte *, void (*)(oid_t, byte *)); + +/* random.c */ + +uns random_max(uns); + +/* mmap.c */ + +void *mmap_file(byte *name, unsigned *len); + +#endif