Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
333 dpurdie 1
/* $XConsortium: def.h /main/27 1995/12/08 18:26:29 gildea $ */
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
 $Source: /cvsroot/device/DEVL/UTILS/MKDEPEND/def.h,v $
28
 $Revision: 1.5 $ $Date: 2004/11/04 07:11:37 $ $State: Exp $
29
 $Author: ayoung $ $Locker:  $
30
 
31
*/
32
 
33
#include "Xosdefs.h"
34
#ifdef MSDOS
35
#include "Xfuncpro.h"
36
#else
37
#include "Xfuncproto.h"
38
#endif
39
#include <stdio.h>
40
#include <stdlib.h>
41
#include <unistd.h>
42
#include <ctype.h>
43
#ifndef X_NOT_POSIX
44
#ifndef _POSIX_SOURCE
45
#define _POSIX_SOURCE
46
#endif
47
#endif
48
#include <sys/types.h>
49
#include <fcntl.h>
50
#include <sys/stat.h>
51
 
52
#define MAXDEFINES      512
53
#define MAXFILES        4096
54
#define MAXDIRS         1024
55
#define MAXPREFIXS      64 
56
#ifndef MAX_PATH
57
#define MAX_PATH        1024
58
#endif
59
#define SYMTABINC       10      /* must be > 1 for define() to work right */
60
#ifndef TRUE
61
#define TRUE            1
62
#define FALSE           0
63
#endif
64
 
65
/* embedded space handling */
66
#define BS_UNKNOWN      0
67
#define BS_IGNORE       1
68
#define BS_ESCAPE       2
69
#define BS_QUOTE        3
70
#define BS_JUNK         4
71
#define BS_URL          5
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 WARNING         15
90
#define IFFALSE         16      /* pseudo value --- never matched */
91
#define ELIFFALSE       17      /* pseudo value --- never matched */
92
#define INCLUDEDOT      18      /* pseudo value --- never matched */
93
#define IFGUESSFALSE    19      /* pseudo value --- never matched */
94
#define ELIFGUESSFALSE  20      /* pseudo value --- never matched */
95
 
96
#define MFLAG_NOSYSTEM  0x01
97
#define MFLAG_GENERATED 0x02
98
 
99
extern int      mflags;         /* -M flags */
100
 
101
#ifdef DEBUG
102
extern int      _debugmask;
103
/*
104
 * debug levels are:
105
 * 
106
 *     0        show ifn*(def)*,endif
107
 *     1        trace defined/!defined
108
 *     2        show #include
109
 *     3        show #include SYMBOL
110
 *     4-6      unused
111
 */
112
#define debug(level,arg) {      if (_debugmask & (1 << level)) info arg; }
113
#else
114
#define debug(level,arg) /**/
115
#endif /* DEBUG */
116
 
117
typedef unsigned char boolean;
118
 
119
struct symtab {
120
        char    *s_name;
121
        char    *s_value;
122
};
123
 
124
/* possible i_flag */
125
#define DEFCHECKED      (1<<0)  /* whether defines have been checked */
126
#define NOTIFIED        (1<<1)  /* whether we have revealed includes */
127
#define MARKED          (1<<2)  /* whether it's in the makefile */
128
#define SEARCHED        (1<<3)  /* whether we have read this */
129
#define FINISHED        (1<<4)  /* whether we are done reading this */
130
#define INCLUDED_SYM    (1<<5)  /* whether #include SYMBOL was found
131
                                   Can't use i_list if TRUE */
132
#define INCLUDED_SYMW   (1<<6)  /* Warning has been generated */
133
 
134
struct  inclist {
135
        char            *i_incstring;   /* string from #include line */
136
        char            *i_file;        /* path name of the include file */
137
        struct inclist  **i_list;       /* list of files it itself includes */
138
        int             i_listlen;      /* length of i_list */
139
        struct symtab   **i_defs;       /* symbol table for this file and its
140
                                           children when merged */
141
        int             i_ndefs;        /* current # defines */
142
        boolean         *i_merged;      /* whether we have merged child
143
                                           defines */
144
        unsigned char   i_flags;
145
};
146
 
147
struct filepointer {
148
        char   *f_p;
149
        char   *f_base;
150
        char   *f_end;
151
        long    f_len;
152
        long    f_line;
153
        char   *f_name;
154
};
155
 
156
#ifndef X_NOT_STDC_ENV
157
#include <stdlib.h>
158
#if defined(macII) && !defined(__STDC__)  /* stdlib.h fails to define these */
159
char            *malloc(), *realloc();
160
#endif /* macII */
161
#else
162
char            *malloc();
163
char            *realloc();
164
#endif
165
 
166
#ifndef __P
167
#if defined(__STDC__) || defined(__cplusplus)
168
# define __P(s) s
169
#else
170
# define __P(s) ()
171
#endif
172
#endif
173
 
174
/*cppsetup.c*/
175
extern int      cppsetup __P((char *line, struct filepointer *filep, struct inclist *inc));
176
extern struct   symtab **lookup __P((char *symbol));
177
extern int      pperror __P((int tag, int x0, int x1, int x2, int x3, int x4));
178
extern int      yyerror __P((char *s));
179
extern int      cppsetup __P((char *line, struct filepointer *filep, struct inclist *inc));
180
 
181
/*include.c*/
182
extern struct   inclist *inc_path __P((char *file, char *include, boolean dot));
183
extern int      remove_dotdot __P((char *path));
184
extern int      isdot __P((char *p));
185
extern int      isdotdot __P((char *p));
186
extern int      issymbolic __P((char *dir, char *component));
187
extern struct   inclist *newinclude __P((char *newfile, char *incstring));
188
extern void     included_by __P((struct inclist *ip, struct inclist *newfile));
189
extern void     inc_clean __P((void));
190
extern void     inc_dump __P((void));
191
 
192
/*main.c*/
193
extern struct filepointer *getfile __P((char *file));
194
extern int      freefile __P((struct filepointer *fp));
195
extern char     *copy __P((char *str));
196
extern int      match __P((char *str, const char **list));
197
extern char     *getline __P((struct filepointer *filep));
198
extern char     *base_name __P((char *file));
199
#if defined(USG) && !defined(CRAY) && !defined(SVR4)
200
extern int      rename __P((char *from, char *to));
201
#endif
202
extern void     redirect __P((char *line, char *makefile));
203
#ifdef NeedVarargsPrototypes
204
extern void     fatalerr __P((char *, ...));
205
extern void     warning __P((char *, ...));
206
extern void     warning1 __P((char *, ...));
207
extern void     info __P((char *, ...));
208
#endif
209
 
210
/*parse.c*/
211
extern int      find_includes __P((struct filepointer *filep, struct inclist *file, struct inclist *file_red, int recursion, boolean failOK));
212
extern int      gobble __P((struct filepointer *filep, struct inclist *file, struct inclist *file_red));
213
extern int      deftype __P((char *line, struct filepointer *filep, struct inclist *file_red, struct inclist *file, int parse_it));
214
extern struct symtab **isdefined __P((char *symbol, struct inclist *file, struct inclist **srcfile));
215
extern struct symtab **fdefined __P((char *symbol, struct inclist *file, struct inclist **srcfile));
216
extern int      zero_value __P((char *exp, struct filepointer *filep, struct inclist *file_red));
217
extern void     define __P((char *def, struct inclist *file));
218
extern void     define2 __P((char *name, char *val, struct inclist *file));
219
extern struct symtab **slookup __P((char *symbol, struct inclist *file));
220
extern int      merge2defines __P((struct inclist *file1, struct inclist *file2));
221
extern void     undefine __P((char *symbol, struct inclist *file));
222
 
223
/*pr.c*/
224
extern void     add_include __P((struct filepointer *filep, struct inclist *file, struct inclist *file_red, char *include, boolean dot, int failOK));
225
extern void     recursive_pr_include __P((struct inclist *head, char *file, char *base));
226
extern void     pr __P((struct inclist *ip, char *file, char *base));
227
#undef __P
228