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