def.h revision 63165362
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 /* Autotooled for Xorg 7.0? */
28# include "makedepend-config.h"
29# define USING_AUTOCONF
30#endif
31
32#include <X11/Xos.h>
33#include <X11/Xfuncproto.h>
34#include <stdlib.h>
35#include <stdio.h>
36#include <string.h>
37#include <ctype.h>
38#include <sys/types.h>
39#include <fcntl.h>
40#include <sys/stat.h>
41
42#define MAXDEFINES	512
43#define MAXFILES	1024
44#define MAXINCFILES	128	/* "-include" files */
45#define MAXDIRS		64
46#define SYMTABINC	10	/* must be > 1 for define() to work right */
47#define	TRUE		1
48#define	FALSE		0
49
50/* the following must match the directives table in main.c */
51#define	IF		0
52#define	IFDEF		1
53#define	IFNDEF		2
54#define	ELSE		3
55#define	ENDIF		4
56#define	DEFINE		5
57#define	UNDEF		6
58#define	INCLUDE		7
59#define	LINE		8
60#define	PRAGMA		9
61#define ERROR           10
62#define IDENT           11
63#define SCCS            12
64#define ELIF            13
65#define EJECT           14
66#define WARNING         15
67#define INCLUDENEXT     16
68#define IFFALSE         17     /* pseudo value --- never matched */
69#define ELIFFALSE       18     /* pseudo value --- never matched */
70#define INCLUDEDOT      19     /* pseudo value --- never matched */
71#define IFGUESSFALSE    20     /* pseudo value --- never matched */
72#define ELIFGUESSFALSE  21     /* pseudo value --- never matched */
73#define INCLUDENEXTDOT  22     /* pseudo value --- never matched */
74
75#ifdef DEBUG
76extern int	_debugmask;
77/*
78 * debug levels are:
79 *
80 *     0	show ifn*(def)*,endif
81 *     1	trace defined/!defined
82 *     2	show #include
83 *     3	show #include SYMBOL
84 *     4-6	unused
85 */
86#define debug(level,arg) { if (_debugmask & (1 << level)) warning arg; }
87#else
88#define	debug(level,arg) /**/
89#endif /* DEBUG */
90
91typedef	unsigned char boolean;
92
93struct symtab {
94	char	*s_name;
95	char	*s_value;
96};
97
98/* possible i_flag */
99#define DEFCHECKED	(1<<0)	/* whether defines have been checked */
100#define NOTIFIED	(1<<1)	/* whether we have revealed includes */
101#define MARKED		(1<<2)	/* whether it's in the makefile */
102#define SEARCHED	(1<<3)	/* whether we have read this */
103#define FINISHED	(1<<4)	/* whether we are done reading this */
104#define INCLUDED_SYM	(1<<5)	/* whether #include SYMBOL was found
105				   Can't use i_list if TRUE */
106struct	inclist {
107	char		*i_incstring;	/* string from #include line */
108	char		*i_file;	/* path name of the include file */
109	struct inclist	**i_list;	/* list of files it itself includes */
110	int		i_listlen;	/* length of i_list */
111	struct symtab	**i_defs;	/* symbol table for this file and its
112					   children when merged */
113	int		i_ndefs;	/* current # defines */
114	boolean		*i_merged;      /* whether we have merged child
115					   defines */
116	unsigned char   i_flags;
117};
118
119struct filepointer {
120	const char	*f_name;
121	char	*f_p;
122	char	*f_base;
123	char	*f_end;
124	long	f_len;
125	long	f_line;
126	long	cmdinc_count;
127	char	**cmdinc_list;
128	long	cmdinc_line;
129};
130
131#include <stdlib.h>
132
133#define copy(s)		strdup(s)
134int                     match(const char *str, const char * const *list);
135char			*base_name(const char *file);
136char			*getnextline(struct filepointer *fp);
137struct symtab		**slookup(char *symbol, struct inclist *file);
138struct symtab		**isdefined(char *symbol, struct inclist *file,
139				    struct inclist **srcfile);
140struct symtab		**fdefined(char *symbol, struct inclist *file,
141				   struct inclist **srcfile);
142struct filepointer	*getfile(const char *file);
143void                    included_by(struct inclist *ip,
144				    struct inclist *newfile);
145struct inclist		*newinclude(const char *newfile,
146				    const char *incstring);
147void                    inc_clean (void);
148struct inclist		*inc_path(const char *file, const char *include,
149				  int type);
150
151void                    freefile(struct filepointer *fp);
152
153void                    define2(char *name, char *val, struct inclist *file);
154void                    define(char *def, struct inclist *file);
155void                    undefine(char *symbol, struct inclist *file);
156int                     find_includes(struct filepointer *filep,
157				      struct inclist *file,
158				      struct inclist *file_red,
159				      int recursion, boolean failOK);
160
161void                    recursive_pr_include(struct inclist *head,
162					     const char *file,
163					     const char *base);
164void                    add_include(struct filepointer *filep,
165				    struct inclist *file,
166				    struct inclist *file_red,
167				    const char *include, int type,
168				    boolean failOK);
169
170int                     cppsetup(const char *filename,
171				 const char *line,
172				 struct filepointer *filep,
173				 struct inclist *inc);
174
175
176extern void fatalerr(const char *, ...) _X_ATTRIBUTE_PRINTF(1, 2);
177extern void warning(const char *, ...) _X_ATTRIBUTE_PRINTF(1, 2);
178extern void warning1(const char *, ...) _X_ATTRIBUTE_PRINTF(1, 2);
179