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