blob: 8fb4c23feff832875154bb0d38cc34ac3d5d4c3a [file] [log] [blame]
Adam Tkacfded0782008-03-22 11:20:54 +00001/* $XConsortium: def.h,v 1.25 94/04/17 20:10:33 gildea Exp $ */
2/*
3
4Copyright (c) 1993, 1994 X Consortium
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23Except as contained in this notice, the name of the X Consortium shall not be
24used in advertising or otherwise to promote the sale, use or other dealings
25in this Software without prior written authorization from the X Consortium.
26
27*/
28
29#include <stdio.h>
30#include <ctype.h>
31#ifndef X_NOT_POSIX
32#ifndef _POSIX_SOURCE
33#define _POSIX_SOURCE
34#endif
35#endif
36#include <sys/types.h>
37#include <fcntl.h>
38#include <sys/stat.h>
39
40#define MAXDEFINES 512
41#define MAXFILES 512
42#define MAXDIRS 64
43#define SYMTABINC 10 /* must be > 1 for define() to work right */
44#define TRUE 1
45#define FALSE 0
46
47/* the following must match the directives table in main.c */
48#define IF 0
49#define IFDEF 1
50#define IFNDEF 2
51#define ELSE 3
52#define ENDIF 4
53#define DEFINE 5
54#define UNDEF 6
55#define INCLUDE 7
56#define LINE 8
57#define PRAGMA 9
58#define ERROR 10
59#define IDENT 11
60#define SCCS 12
61#define ELIF 13
62#define EJECT 14
63#define IFFALSE 15 /* pseudo value --- never matched */
64#define ELIFFALSE 16 /* pseudo value --- never matched */
65#define INCLUDEDOT 17 /* pseudo value --- never matched */
66#define IFGUESSFALSE 18 /* pseudo value --- never matched */
67#define ELIFGUESSFALSE 19 /* pseudo value --- never matched */
68
69#ifdef DEBUG
70extern int _debugmask;
71/*
72 * debug levels are:
73 *
74 * 0 show ifn*(def)*,endif
75 * 1 trace defined/!defined
76 * 2 show #include
77 * 3 show #include SYMBOL
78 * 4-6 unused
79 */
80#define debug(level,arg) { if (_debugmask & (1 << level)) warning arg; }
81#else
82#define debug(level,arg) /**/
83#endif /* DEBUG */
84
85typedef unsigned char boolean;
86
87struct symtab {
88 char *s_name;
89 char *s_value;
90};
91
92struct inclist {
93 char *i_incstring; /* string from #include line */
94 char *i_file; /* path name of the include file */
95 struct inclist **i_list; /* list of files it itself includes */
96 int i_listlen; /* length of i_list */
97 struct symtab *i_defs; /* symbol table for this file */
98 int i_ndefs; /* current # defines */
99 int i_deflen; /* amount of space in table */
100 boolean i_defchecked; /* whether defines have been checked */
101 boolean i_notified; /* whether we have revealed includes */
102 boolean i_marked; /* whether it's in the makefile */
103 boolean i_searched; /* whether we have read this */
104 boolean i_included_sym; /* whether #include SYMBOL was found */
105 /* Can't use i_list if TRUE */
106};
107
108struct filepointer {
109 char *f_p;
110 char *f_base;
111 char *f_end;
112 long f_len;
113 long f_line;
114};
115
116#ifndef X_NOT_STDC_ENV
117#include <stdlib.h>
118#if defined(macII) && !defined(__STDC__) /* stdlib.h fails to define these */
119char *malloc(), *realloc();
120#endif /* macII */
121#else
122char *malloc();
123char *realloc();
124#endif
125
126char *copy();
127char *base_name();
128char *getline();
129struct symtab *slookup();
130struct symtab *isdefined();
131struct symtab *fdefined();
132struct filepointer *getfile();
133struct inclist *newinclude();
134struct inclist *inc_path();
135
136#if NeedVarargsPrototypes
137extern fatalerr(char *, ...);
138extern warning(char *, ...);
139extern warning1(char *, ...);
140#endif