libixp

git clone git://oldgit.suckless.org/libixp/
Log | Files | Refs | LICENSE

ixp_local.h (2203B)


      1 #define IXP_NO_P9_
      2 #include <ixp.h>
      3 #include <stdbool.h>
      4 
      5 #undef ulong
      6 #define ulong _ixpulong
      7 typedef unsigned long ulong;
      8 
      9 #ifdef CPROTO
     10 # undef bool
     11 typedef int bool;
     12 typedef char* va_list;
     13 #endif
     14 
     15 char *argv0;
     16 #define ARGBEGIN \
     17 		int _argtmp=0, _inargv=0; char *_argv=nil; \
     18 		if(!argv0) {argv0=*argv; argv++, argc--;} \
     19 		_inargv=1; USED(_inargv); \
     20 		while(argc && argv[0][0] == '-') { \
     21 			_argv=&argv[0][1]; argv++; argc--; \
     22 			if(_argv[0] == '-' && _argv[1] == '\0') \
     23 				break; \
     24 			while(*_argv) switch(*_argv++)
     25 #define ARGEND }_inargv=0;USED(_argtmp, _argv, _inargv)
     26 
     27 #define EARGF(f) ((_inargv && *_argv) ? \
     28 			(_argtmp=strlen(_argv), _argv+=_argtmp, _argv-_argtmp) \
     29 			: ((argc > 0) ? \
     30 				(--argc, ++argv, _used(argc), *(argv-1)) \
     31 				: ((f), (char*)0)))
     32 #define ARGF() EARGF(_used(0))
     33 
     34 #ifndef KENC
     35   static inline void _used(long a, ...) { if(a){} }
     36 # define USED(...) _used((long)__VA_ARGS__)
     37 # define SET(x) (x = 0)
     38 /* # define SET(x) USED(&x) GCC 4 is 'too smart' for this. */
     39 #endif
     40 
     41 #undef nil
     42 #define nil ((void*)0)
     43 #define nelem(ary) (sizeof(ary) / sizeof(*ary))
     44 
     45 #define thread ixp_thread
     46 
     47 #define eprint ixp_eprint
     48 #define emalloc ixp_emalloc
     49 #define emallocz ixp_emallocz
     50 #define estrdup ixp_estrdup
     51 #define erealloc ixp_erealloc
     52 #define strlcat ixp_strlcat
     53 #define tokenize ixp_tokenize
     54 
     55 #define muxinit ixp_muxinit
     56 #define muxfree ixp_muxfree
     57 #define muxrpc ixp_muxrpc
     58 
     59 #define errstr ixp_errstr
     60 #define rerrstr ixp_rerrstr
     61 #define werrstr ixp_werrstr
     62 
     63 typedef struct IxpMap Map;
     64 typedef struct MapEnt MapEnt;
     65 
     66 typedef IxpTimer Timer;
     67 
     68 typedef struct timeval timeval;
     69 
     70 struct IxpMap {
     71 	MapEnt**	bucket;
     72 	int		nhash;
     73 
     74 	IxpRWLock	lock;
     75 };
     76 
     77 struct IxpTimer {
     78 	Timer*		link;
     79 	uint32_t	msec;
     80 	long		id;
     81 	void		(*fn)(long, void*);
     82 	void*		aux;
     83 };
     84 
     85 /* map.c */
     86 void	ixp_mapfree(IxpMap*, void(*)(void*));
     87 void	ixp_mapexec(IxpMap*, void(*)(void*, void*), void*);
     88 void	ixp_mapinit(IxpMap*, MapEnt**, int);
     89 bool	ixp_mapinsert(IxpMap*, ulong, void*, bool);
     90 void*	ixp_mapget(IxpMap*, ulong);
     91 void*	ixp_maprm(IxpMap*, ulong);
     92 
     93 /* mux.c */
     94 void	muxfree(IxpClient*);
     95 void	muxinit(IxpClient*);
     96 IxpFcall*	muxrpc(IxpClient*, IxpFcall*);
     97 
     98 /* timer.c */
     99 long	ixp_nexttimer(IxpServer*);
    100