Adam Tkac | fded078 | 2008-03-22 11:20:54 +0000 | [diff] [blame] | 1 | /* $XConsortium: def.h,v 1.25 94/04/17 20:10:33 gildea Exp $ */ |
| 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 | */ |
| 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 |
| 70 | extern 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 | |
| 85 | typedef unsigned char boolean; |
| 86 | |
| 87 | struct symtab { |
| 88 | char *s_name; |
| 89 | char *s_value; |
| 90 | }; |
| 91 | |
| 92 | struct 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 | |
| 108 | struct 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 */ |
| 119 | char *malloc(), *realloc(); |
| 120 | #endif /* macII */ |
| 121 | #else |
| 122 | char *malloc(); |
| 123 | char *realloc(); |
| 124 | #endif |
| 125 | |
| 126 | char *copy(); |
| 127 | char *base_name(); |
| 128 | char *getline(); |
| 129 | struct symtab *slookup(); |
| 130 | struct symtab *isdefined(); |
| 131 | struct symtab *fdefined(); |
| 132 | struct filepointer *getfile(); |
| 133 | struct inclist *newinclude(); |
| 134 | struct inclist *inc_path(); |
| 135 | |
| 136 | #if NeedVarargsPrototypes |
| 137 | extern fatalerr(char *, ...); |
| 138 | extern warning(char *, ...); |
| 139 | extern warning1(char *, ...); |
| 140 | #endif |