def.h revision 7dd2a3ff
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	4096
43#define MAXINCFILES	128	/* "-include" files */
44#define MAXDIRS		512	/* -I flags */
45#define PATHMAX		4096    /* realpath */
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) do { if (_debugmask & (1 << level)) warning arg; } while(0)
87#else
88#define	debug(level,arg) do { /**/ } while (0)
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	struct symtab	**i_defs;	/* symbol table for this file and its
111					   children when merged */
112	int		i_listlen;	/* length of i_list */
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
133int                     match(const char *str, const char * const *list);
134char			*base_name(const char *file);
135char			*getnextline(struct filepointer *fp);
136struct symtab		**slookup(const char *symbol, struct inclist *file);
137struct symtab		**isdefined(const char *symbol, struct inclist *file,
138				    struct inclist **srcfile);
139struct symtab		**fdefined(const char *symbol, struct inclist *file,
140				   struct inclist **srcfile);
141struct filepointer	*getfile(const char *file);
142void                    included_by(struct inclist *ip,
143				    struct inclist *newfile);
144struct inclist		*newinclude(const char *newfile,
145				    const char *incstring);
146void                    inc_clean (void);
147struct inclist		*inc_path(const char *file, const char *include,
148				  int type);
149
150void                    freefile(struct filepointer *fp);
151
152void                    define2(const char *name, const char *val,
153				struct inclist *file);
154void                    define(char *def, struct inclist *file);
155void                    undefine(const 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) _X_NORETURN;
177extern void warning(const char *, ...) _X_ATTRIBUTE_PRINTF(1, 2);
178extern void warning1(const char *, ...) _X_ATTRIBUTE_PRINTF(1, 2);
179
180extern struct inclist	  inclist[ MAXFILES ];
181extern struct inclist    *inclistp;
182extern struct inclist    *inclistnext;
183extern struct inclist     maininclist;
184extern const char        *includedirs[ ];
185extern const char       **includedirsnext;
186extern const char * const directives[];
187extern char              *notdotdot[ ];
188
189extern const char        *objprefix;
190extern const char        *objsuffix;
191extern int          	  width;
192extern boolean            printed;
193extern boolean            verbose;
194extern boolean            show_where_not;
195extern boolean            warn_multiple;
196