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