Home | History | Annotate | Line # | Download | only in common
      1 /*	$NetBSD: util.h,v 1.2 2013/11/22 15:52:05 christos Exp $ */
      2 /*-
      3  * Copyright (c) 1994
      4  *	The Regents of the University of California.  All rights reserved.
      5  * Copyright (c) 1994, 1995, 1996
      6  *	Keith Bostic.  All rights reserved.
      7  *
      8  * See the LICENSE file for redistribution information.
      9  *
     10  *	Id: util.h,v 10.5 1996/03/16 14:42:47 bostic Exp  (Berkeley) Date: 1996/03/16 14:42:47
     11  */
     12 
     13 /* Macros to init/set/clear/test flags. */
     14 #define	FL_INIT(l, f)	(l) = (f)		/* Specific flags location. */
     15 #define	FL_SET(l, f)	((l) |= (f))
     16 #define	FL_CLR(l, f)	((l) &= ~(f))
     17 #define	FL_ISSET(l, f)	((l) & (f))
     18 
     19 #define	LF_INIT(f)	FL_INIT(flags, f)	/* Local variable flags. */
     20 #define	LF_SET(f)	FL_SET(flags, f)
     21 #define	LF_CLR(f)	FL_CLR(flags, f)
     22 #define	LF_ISSET(f)	FL_ISSET(flags, f)
     23 
     24 #define	F_INIT(p, f)	FL_INIT((p)->flags, f)	/* Structure element flags. */
     25 #define	F_SET(p, f)	FL_SET((p)->flags, f)
     26 #define	F_CLR(p, f)	FL_CLR((p)->flags, f)
     27 #define	F_ISSET(p, f)	FL_ISSET((p)->flags, f)
     28 
     29 /* Offset to next column of stop size, e.g. tab offsets. */
     30 #define	COL_OFF(c, stop)	((stop) - ((c) % (stop)))
     31 
     32 /* Busy message types. */
     33 typedef enum { B_NONE, B_OFF, B_READ, B_RECOVER, B_SEARCH, B_WRITE } bmsg_t;
     34 
     35 /*
     36  * Number handling defines and protoypes.
     37  *
     38  * NNFITS:	test for addition of two negative numbers under a limit
     39  * NPFITS:	test for addition of two positive numbers under a limit
     40  * NADD_SLONG:	test for addition of two signed longs
     41  * NADD_USLONG:	test for addition of two unsigned longs
     42  */
     43 enum nresult { NUM_ERR, NUM_OK, NUM_OVER, NUM_UNDER };
     44 #define	NNFITS(min, cur, add)						\
     45 	(((long)(min)) - (cur) <= (add))
     46 #define	NPFITS(max, cur, add)						\
     47 	(((unsigned long)(max)) - (cur) >= (add))
     48 #define	NADD_SLONG(sp, v1, v2)						\
     49 	((v1) < 0 ?							\
     50 	    ((v2) < 0 &&						\
     51 	    NNFITS(LONG_MIN, (v1), (v2))) ? NUM_UNDER : NUM_OK :	\
     52 	 (v1) > 0 ?							\
     53 	    (v2) > 0 &&							\
     54 	    NPFITS(LONG_MAX, (unsigned long)(v1), (unsigned long)(v2)) ? \
     55 	      NUM_OK : NUM_OVER :					\
     56 	 NUM_OK)
     57 #define	NADD_USLONG(sp, v1, v2)						\
     58 	(NPFITS(ULONG_MAX, (v1), (v2)) ? NUM_OK : NUM_OVER)
     59