def.h revision b2f5b1db
1/* 2 3Copyright (c) 1993, 1994, 1998 The Open Group. 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 25*/ 26 27#ifdef HAVE_CONFIG_H 28# include "makedepend-config.h" 29#endif 30 31#include <X11/Xos.h> 32#include <X11/Xfuncproto.h> 33#include <stdlib.h> 34#include <stdio.h> 35#include <string.h> 36#include <ctype.h> 37#include <sys/types.h> 38#include <fcntl.h> 39#include <sys/stat.h> 40 41#define MAXDEFINES 512 42#define MAXFILES 2048 43#define MAXINCFILES 128 /* "-include" files */ 44#define MAXDIRS 512 /* -I flags */ 45#define SYMTABINC 10 /* must be > 1 for define() to work right */ 46#define TRUE 1 47#define FALSE 0 48 49/* the following must match the directives table in main.c */ 50#define IF 0 51#define IFDEF 1 52#define IFNDEF 2 53#define ELSE 3 54#define ENDIF 4 55#define DEFINE 5 56#define UNDEF 6 57#define INCLUDE 7 58#define LINE 8 59#define PRAGMA 9 60#define ERROR 10 61#define IDENT 11 62#define SCCS 12 63#define ELIF 13 64#define EJECT 14 65#define WARNING 15 66#define INCLUDENEXT 16 67#define IFFALSE 17 /* pseudo value --- never matched */ 68#define ELIFFALSE 18 /* pseudo value --- never matched */ 69#define INCLUDEDOT 19 /* pseudo value --- never matched */ 70#define IFGUESSFALSE 20 /* pseudo value --- never matched */ 71#define ELIFGUESSFALSE 21 /* pseudo value --- never matched */ 72#define INCLUDENEXTDOT 22 /* pseudo value --- never matched */ 73 74#ifdef DEBUG 75extern int _debugmask; 76/* 77 * debug levels are: 78 * 79 * 0 show ifn*(def)*,endif 80 * 1 trace defined/!defined 81 * 2 show #include 82 * 3 show #include SYMBOL 83 * 4-6 unused 84 */ 85#define debug(level,arg) do { if (_debugmask & (1 << level)) warning arg; } while(0) 86#else 87#define debug(level,arg) do { /**/ } while (0) 88#endif /* DEBUG */ 89 90typedef unsigned char boolean; 91 92struct symtab { 93 char *s_name; 94 char *s_value; 95}; 96 97/* possible i_flag */ 98#define DEFCHECKED (1<<0) /* whether defines have been checked */ 99#define NOTIFIED (1<<1) /* whether we have revealed includes */ 100#define MARKED (1<<2) /* whether it's in the makefile */ 101#define SEARCHED (1<<3) /* whether we have read this */ 102#define FINISHED (1<<4) /* whether we are done reading this */ 103#define INCLUDED_SYM (1<<5) /* whether #include SYMBOL was found 104 Can't use i_list if TRUE */ 105struct inclist { 106 char *i_incstring; /* string from #include line */ 107 char *i_file; /* path name of the include file */ 108 struct inclist **i_list; /* list of files it itself includes */ 109 struct symtab **i_defs; /* symbol table for this file and its 110 children when merged */ 111 int i_listlen; /* length of i_list */ 112 int i_ndefs; /* current # defines */ 113 boolean *i_merged; /* whether we have merged child 114 defines */ 115 unsigned char i_flags; 116}; 117 118struct filepointer { 119 const char *f_name; 120 char *f_p; 121 char *f_base; 122 char *f_end; 123 long f_len; 124 long f_line; 125 long cmdinc_count; 126 char **cmdinc_list; 127 long cmdinc_line; 128}; 129 130#include <stdlib.h> 131 132int match(const char *str, const char * const *list); 133char *base_name(const char *file); 134char *getnextline(struct filepointer *fp); 135struct symtab **slookup(const char *symbol, struct inclist *file); 136struct symtab **isdefined(const char *symbol, struct inclist *file, 137 struct inclist **srcfile); 138struct symtab **fdefined(const char *symbol, struct inclist *file, 139 struct inclist **srcfile); 140struct filepointer *getfile(const char *file); 141void included_by(struct inclist *ip, 142 struct inclist *newfile); 143struct inclist *newinclude(const char *newfile, 144 const char *incstring); 145void inc_clean (void); 146struct inclist *inc_path(const char *file, const char *include, 147 int type); 148 149void freefile(struct filepointer *fp); 150 151void define2(const char *name, const char *val, 152 struct inclist *file); 153void define(char *def, struct inclist *file); 154void undefine(const char *symbol, struct inclist *file); 155int find_includes(struct filepointer *filep, 156 struct inclist *file, 157 struct inclist *file_red, 158 int recursion, boolean failOK); 159 160void recursive_pr_include(struct inclist *head, 161 const char *file, 162 const char *base); 163void add_include(struct filepointer *filep, 164 struct inclist *file, 165 struct inclist *file_red, 166 const char *include, int type, 167 boolean failOK); 168 169int cppsetup(const char *filename, 170 const char *line, 171 struct filepointer *filep, 172 struct inclist *inc); 173 174 175extern void fatalerr(const char *, ...) _X_ATTRIBUTE_PRINTF(1, 2) _X_NORETURN; 176extern void warning(const char *, ...) _X_ATTRIBUTE_PRINTF(1, 2); 177extern void warning1(const char *, ...) _X_ATTRIBUTE_PRINTF(1, 2); 178 179extern struct inclist inclist[ MAXFILES ]; 180extern struct inclist *inclistp; 181extern struct inclist *inclistnext; 182extern struct inclist maininclist; 183extern const char *includedirs[ ]; 184extern const char **includedirsnext; 185extern const char * const directives[]; 186extern char *notdotdot[ ]; 187 188extern const char *objprefix; 189extern const char *objsuffix; 190extern int width; 191extern boolean printed; 192extern boolean verbose; 193extern boolean show_where_not; 194extern boolean warn_multiple; 195