util.h revision 146184
1141104Sharti/*- 2141104Sharti * Copyright (c) 1988, 1989, 1990, 1993 3141104Sharti * The Regents of the University of California. All rights reserved. 4141104Sharti * Copyright (c) 1989 by Berkeley Softworks 5141104Sharti * All rights reserved. 6141104Sharti * 7141104Sharti * This code is derived from software contributed to Berkeley by 8141104Sharti * Adam de Boor. 9141104Sharti * 10141104Sharti * Redistribution and use in source and binary forms, with or without 11141104Sharti * modification, are permitted provided that the following conditions 12141104Sharti * are met: 13141104Sharti * 1. Redistributions of source code must retain the above copyright 14141104Sharti * notice, this list of conditions and the following disclaimer. 15141104Sharti * 2. Redistributions in binary form must reproduce the above copyright 16141104Sharti * notice, this list of conditions and the following disclaimer in the 17141104Sharti * documentation and/or other materials provided with the distribution. 18141104Sharti * 3. All advertising materials mentioning features or use of this software 19141104Sharti * must display the following acknowledgement: 20141104Sharti * This product includes software developed by the University of 21141104Sharti * California, Berkeley and its contributors. 22141104Sharti * 4. Neither the name of the University nor the names of its contributors 23141104Sharti * may be used to endorse or promote products derived from this software 24141104Sharti * without specific prior written permission. 25141104Sharti * 26141104Sharti * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27141104Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28141104Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29141104Sharti * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30141104Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31141104Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32141104Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33141104Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34141104Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35141104Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36141104Sharti * SUCH DAMAGE. 37141104Sharti * 38141104Sharti * $FreeBSD: head/usr.bin/make/util.h 146184 2005-05-13 13:47:41Z harti $ 39141104Sharti */ 40141104Sharti 41141104Sharti#ifndef util_h_b7020fdb 42141104Sharti#define util_h_b7020fdb 43141104Sharti 44141104Sharti#include <sys/types.h> 45143414Sharti#include <stdio.h> 46141104Sharti 47146177Sharti/* 48146177Sharti * A boolean type is defined as an integer, not an enum. This allows a 49146177Sharti * boolean argument to be an expression that isn't strictly 0 or 1 valued. 50146177Sharti */ 51146177Sharti 52146177Shartitypedef int Boolean; 53146177Sharti#ifndef TRUE 54146177Sharti#define TRUE 1 55146177Sharti#define FALSE 0 56146177Sharti#endif /* TRUE */ 57146177Sharti 58146177Shartitypedef int ReturnStatus; 59146177Sharti 60146177Sharti#define SUCCESS 0 61146177Sharti#define FAILURE 1 62146177Sharti 63141104Sharti#define CONCAT(a,b) a##b 64141104Sharti 65143414Shartistruct flag2str { 66143414Sharti u_int flag; 67143414Sharti const char *str; 68143414Sharti}; 69143414Sharti 70141104Sharti/* 71141104Sharti * debug control: 72141104Sharti * There is one bit per module. It is up to the module what debug 73141104Sharti * information to print. 74141104Sharti */ 75141104Sharti#define DEBUG_ARCH 0x0001 76141104Sharti#define DEBUG_COND 0x0002 77141104Sharti#define DEBUG_DIR 0x0004 78141104Sharti#define DEBUG_GRAPH1 0x0008 79141104Sharti#define DEBUG_GRAPH2 0x0010 80141104Sharti#define DEBUG_JOB 0x0020 81141104Sharti#define DEBUG_MAKE 0x0040 82141104Sharti#define DEBUG_SUFF 0x0080 83141104Sharti#define DEBUG_TARG 0x0100 84141104Sharti#define DEBUG_VAR 0x0200 85141104Sharti#define DEBUG_FOR 0x0400 86141104Sharti#define DEBUG_LOUD 0x0800 87141104Sharti 88141104Sharti#define DEBUG(module) (debug & CONCAT(DEBUG_,module)) 89141104Sharti#define DEBUGF(module,args) \ 90141104Shartido { \ 91141104Sharti if (DEBUG(module)) { \ 92141104Sharti Debug args ; \ 93141104Sharti } \ 94141104Sharti} while (0) 95143278Sharti#define DEBUGM(module, args) do { \ 96143278Sharti if (DEBUG(module)) { \ 97143278Sharti DebugM args; \ 98143278Sharti } \ 99143278Sharti } while (0) 100141104Sharti 101141104Sharti#define ISDOT(c) ((c)[0] == '.' && (((c)[1] == '\0') || ((c)[1] == '/'))) 102141104Sharti#define ISDOTDOT(c) ((c)[0] == '.' && ISDOT(&((c)[1]))) 103141104Sharti 104144386Sharti#ifndef MAX 105144386Sharti#define MAX(a, b) ((a) > (b) ? (a) : (b)) 106144386Sharti#endif 107144386Sharti 108141104Shartivoid Debug(const char *, ...); 109143278Shartivoid DebugM(const char *, ...); 110141104Shartivoid Error(const char *, ...); 111143277Shartivoid Fatal(const char *, ...) __dead2; 112143277Shartivoid Punt(const char *, ...) __dead2; 113143277Shartivoid DieHorribly(void) __dead2; 114143277Shartivoid Finish(int) __dead2; 115141104Shartichar *estrdup(const char *); 116141104Shartivoid *emalloc(size_t); 117141104Shartivoid *erealloc(void *, size_t); 118141104Shartiint eunlink(const char *); 119146184Shartivoid print_flags(FILE *, const struct flag2str *, u_int, int); 120141104Sharti 121141104Sharti#endif /* util_h_b7020fdb */ 122