1*cdf0e10cSrcweir /* $XConsortium: def.h,v 1.25 94/04/17 20:10:33 gildea Exp $ */ 2*cdf0e10cSrcweir /* 3*cdf0e10cSrcweir 4*cdf0e10cSrcweir Copyright (c) 1993, 1994 X Consortium 5*cdf0e10cSrcweir 6*cdf0e10cSrcweir Permission is hereby granted, free of charge, to any person obtaining a copy 7*cdf0e10cSrcweir of this software and associated documentation files (the "Software"), to deal 8*cdf0e10cSrcweir in the Software without restriction, including without limitation the rights 9*cdf0e10cSrcweir to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10*cdf0e10cSrcweir copies of the Software, and to permit persons to whom the Software is 11*cdf0e10cSrcweir furnished to do so, subject to the following conditions: 12*cdf0e10cSrcweir 13*cdf0e10cSrcweir The above copyright notice and this permission notice shall be included in 14*cdf0e10cSrcweir all copies or substantial portions of the Software. 15*cdf0e10cSrcweir 16*cdf0e10cSrcweir THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17*cdf0e10cSrcweir IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18*cdf0e10cSrcweir FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19*cdf0e10cSrcweir X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20*cdf0e10cSrcweir AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21*cdf0e10cSrcweir CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22*cdf0e10cSrcweir 23*cdf0e10cSrcweir Except as contained in this notice, the name of the X Consortium shall not be 24*cdf0e10cSrcweir used in advertising or otherwise to promote the sale, use or other dealings 25*cdf0e10cSrcweir in this Software without prior written authorization from the X Consortium. 26*cdf0e10cSrcweir 27*cdf0e10cSrcweir */ 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir #ifndef NO_X11 30*cdf0e10cSrcweir #include <X11/Xosdefs.h> 31*cdf0e10cSrcweir #ifdef WIN32 32*cdf0e10cSrcweir #include <X11/Xw32defs.h> 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir #ifndef SUNOS4 35*cdf0e10cSrcweir #include <X11/Xfuncproto.h> 36*cdf0e10cSrcweir #endif /* SUNOS4 */ 37*cdf0e10cSrcweir #endif /* NO_X11 */ 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <stdio.h> 40*cdf0e10cSrcweir #include <stdlib.h> 41*cdf0e10cSrcweir #include <string.h> 42*cdf0e10cSrcweir #include <unistd.h> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <ctype.h> 45*cdf0e10cSrcweir #ifndef X_NOT_POSIX 46*cdf0e10cSrcweir #ifndef _POSIX_SOURCE 47*cdf0e10cSrcweir #define _POSIX_SOURCE 48*cdf0e10cSrcweir #endif 49*cdf0e10cSrcweir #endif 50*cdf0e10cSrcweir #include <sys/types.h> 51*cdf0e10cSrcweir #include <fcntl.h> 52*cdf0e10cSrcweir #include <sys/stat.h> 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir #ifndef S_IFDIR 55*cdf0e10cSrcweir #define S_IFDIR 0040000 56*cdf0e10cSrcweir #endif 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #ifndef S_IFREG 59*cdf0e10cSrcweir #define S_IFREG 0100000 60*cdf0e10cSrcweir #endif 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir #define MAXDEFINES 512 63*cdf0e10cSrcweir #define MAXFILES ( 1<<16 ) /* Increased from 512. -mcafee */ 64*cdf0e10cSrcweir /* Increased from 1024. -mh */ 65*cdf0e10cSrcweir /* Increased from 2048. -b_michaelsen */ 66*cdf0e10cSrcweir #define MAXDIRS 64 67*cdf0e10cSrcweir #define SYMHASHSEED 131 /* 131 1313 13131 ... */ 68*cdf0e10cSrcweir #define SYMHASHMEMBERS 64 /* must be 2^x to work right */ 69*cdf0e10cSrcweir #define TRUE 1 70*cdf0e10cSrcweir #define FALSE 0 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir /* the following must match the directives table in main.c */ 73*cdf0e10cSrcweir #define IF 0 74*cdf0e10cSrcweir #define IFDEF 1 75*cdf0e10cSrcweir #define IFNDEF 2 76*cdf0e10cSrcweir #define ELSE 3 77*cdf0e10cSrcweir #define ENDIF 4 78*cdf0e10cSrcweir #define DEFINE 5 79*cdf0e10cSrcweir #define UNDEF 6 80*cdf0e10cSrcweir #define INCLUDE 7 81*cdf0e10cSrcweir #define LINE 8 82*cdf0e10cSrcweir #define PRAGMA 9 83*cdf0e10cSrcweir #define ERROR 10 84*cdf0e10cSrcweir #define IDENT 11 85*cdf0e10cSrcweir #define SCCS 12 86*cdf0e10cSrcweir #define ELIF 13 87*cdf0e10cSrcweir #define EJECT 14 88*cdf0e10cSrcweir #define IFFALSE 15 /* pseudo value --- never matched */ 89*cdf0e10cSrcweir #define ELIFFALSE 16 /* pseudo value --- never matched */ 90*cdf0e10cSrcweir #define INCLUDEDOT 17 /* pseudo value --- never matched */ 91*cdf0e10cSrcweir #define IFGUESSFALSE 18 /* pseudo value --- never matched */ 92*cdf0e10cSrcweir #define ELIFGUESSFALSE 19 /* pseudo value --- never matched */ 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir #ifdef DEBUG 95*cdf0e10cSrcweir extern int _debugmask; 96*cdf0e10cSrcweir /* 97*cdf0e10cSrcweir * debug levels are: 98*cdf0e10cSrcweir * 99*cdf0e10cSrcweir * 0 show ifn*(def)*,endif 100*cdf0e10cSrcweir * 1 trace defined/!defined 101*cdf0e10cSrcweir * 2 show #include 102*cdf0e10cSrcweir * 3 show #include SYMBOL 103*cdf0e10cSrcweir * 4-6 unused 104*cdf0e10cSrcweir */ 105*cdf0e10cSrcweir #define debug(level,arg) { if (_debugmask & (1 << level)) warning arg; } 106*cdf0e10cSrcweir #else 107*cdf0e10cSrcweir #define debug(level,arg) /**/ 108*cdf0e10cSrcweir #endif /* DEBUG */ 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir // VG: a C++ class for information about directories 111*cdf0e10cSrcweir #include "collectdircontent.hxx" 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir typedef unsigned char boolean; 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir struct pair { 116*cdf0e10cSrcweir char *p_name; 117*cdf0e10cSrcweir char *p_value; 118*cdf0e10cSrcweir struct pair *p_next; 119*cdf0e10cSrcweir }; 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir struct symhash { 122*cdf0e10cSrcweir struct pair *s_pairs[SYMHASHMEMBERS]; 123*cdf0e10cSrcweir }; 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir struct inclist { 126*cdf0e10cSrcweir char *i_incstring; /* string from #include line */ 127*cdf0e10cSrcweir char *i_file; /* path name of the include file */ 128*cdf0e10cSrcweir struct inclist **i_list; /* list of files it itself includes */ 129*cdf0e10cSrcweir int i_listlen; /* length of i_list */ 130*cdf0e10cSrcweir boolean i_defchecked; /* whether defines have been checked */ 131*cdf0e10cSrcweir boolean i_notified; /* whether we have revealed includes */ 132*cdf0e10cSrcweir boolean i_marked; /* whether it's in the makefile */ 133*cdf0e10cSrcweir boolean i_searched; /* whether we have read this */ 134*cdf0e10cSrcweir boolean i_included_sym; /* whether #include SYMBOL was found */ 135*cdf0e10cSrcweir /* Can't use i_list if TRUE */ 136*cdf0e10cSrcweir }; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir struct filepointer { 139*cdf0e10cSrcweir char *f_p; 140*cdf0e10cSrcweir char *f_base; 141*cdf0e10cSrcweir char *f_end; 142*cdf0e10cSrcweir long f_len; 143*cdf0e10cSrcweir long f_line; 144*cdf0e10cSrcweir }; 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir #ifndef X_NOT_STDC_ENV 147*cdf0e10cSrcweir #include <stdlib.h> 148*cdf0e10cSrcweir #if defined(macII) && !defined(__STDC__) /* stdlib.h fails to define these */ 149*cdf0e10cSrcweir char *malloc(), *realloc(); 150*cdf0e10cSrcweir #endif /* macII */ 151*cdf0e10cSrcweir #else 152*cdf0e10cSrcweir char *malloc(); 153*cdf0e10cSrcweir char *realloc(); 154*cdf0e10cSrcweir #endif 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir char *copy(); 157*cdf0e10cSrcweir char *base_name(); 158*cdf0e10cSrcweir char *get_line(); 159*cdf0e10cSrcweir char *isdefined(); 160*cdf0e10cSrcweir struct filepointer *getfile(); 161*cdf0e10cSrcweir struct inclist *newinclude(); 162*cdf0e10cSrcweir struct inclist *inc_path(); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir void define( char *def, struct symhash **symbols ); 165*cdf0e10cSrcweir void hash_define(char *name, char * val, struct symhash **symbols); 166*cdf0e10cSrcweir struct symhash *hash_copy( struct symhash *symbols ); 167*cdf0e10cSrcweir void hash_free( struct symhash *symbols ); 168*cdf0e10cSrcweir void freefile( struct filepointer * fp ); 169*cdf0e10cSrcweir int find_includes(struct filepointer *filep, struct inclist *file, 170*cdf0e10cSrcweir struct inclist *file_red, int recursion, boolean failOK, 171*cdf0e10cSrcweir struct IncludesCollection* incCollection, struct symhash *symbols); 172*cdf0e10cSrcweir void included_by(register struct inclist *ip, 173*cdf0e10cSrcweir register struct inclist * newfile); 174*cdf0e10cSrcweir int cppsetup(register char *line, 175*cdf0e10cSrcweir register struct filepointer *filep, register struct inclist *inc); 176*cdf0e10cSrcweir void add_include(struct filepointer *filep, struct inclist *file, 177*cdf0e10cSrcweir struct inclist *file_red, char *include, boolean dot, boolean failOK, 178*cdf0e10cSrcweir struct IncludesCollection* incCollection, struct symhash *symbols); 179*cdf0e10cSrcweir int match(register char *str, register char **list); 180*cdf0e10cSrcweir void recursive_pr_include(register struct inclist *head, register char *file, 181*cdf0e10cSrcweir register char *base); 182*cdf0e10cSrcweir void inc_clean(); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir void fatalerr(char *, ...); 185*cdf0e10cSrcweir void warning(char *, ...); 186*cdf0e10cSrcweir void warning1(char *, ...); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir void convert_slashes(char *); 189*cdf0e10cSrcweir char *append_slash(char *); 190