]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/engine/headers.c
Add patch for failing prerm scripts
[ceph.git] / ceph / src / boost / tools / build / src / engine / headers.c
1 /*
2 * Copyright 1993, 2000 Christopher Seiwald.
3 *
4 * This file is part of Jam - see jam.c for Copyright information.
5 */
6 /* This file is ALSO:
7 * Copyright 2001-2004 David Abrahams.
8 * Distributed under the Boost Software License, Version 1.0.
9 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
10 */
11
12 /*
13 * headers.c - handle #includes in source files
14 *
15 * Using regular expressions provided as the variable $(HDRSCAN), headers()
16 * searches a file for #include files and phonies up a rule invocation:
17 * $(HDRRULE) <target> : <include files> ;
18 *
19 * External routines:
20 * headers() - scan a target for include files and call HDRRULE
21 *
22 * Internal routines:
23 * headers1() - using regexp, scan a file and build include LIST
24 */
25
26 #include "jam.h"
27 #include "headers.h"
28
29 #include "compile.h"
30 #include "hdrmacro.h"
31 #include "lists.h"
32 #include "modules.h"
33 #include "object.h"
34 #include "parse.h"
35 #include "rules.h"
36 #include "subst.h"
37 #include "variable.h"
38 #include "output.h"
39
40 #ifdef OPT_HEADER_CACHE_EXT
41 # include "hcache.h"
42 #endif
43
44 #ifndef OPT_HEADER_CACHE_EXT
45 static LIST * headers1( LIST *, OBJECT * file, int rec, regexp * re[] );
46 #endif
47
48
49 /*
50 * headers() - scan a target for include files and call HDRRULE
51 */
52
53 #define MAXINC 10
54
55 void headers( TARGET * t )
56 {
57 LIST * hdrscan;
58 LIST * hdrrule;
59 #ifndef OPT_HEADER_CACHE_EXT
60 LIST * headlist = L0;
61 #endif
62 regexp * re[ MAXINC ];
63 int rec = 0;
64 LISTITER iter;
65 LISTITER end;
66
67 hdrscan = var_get( root_module(), constant_HDRSCAN );
68 if ( list_empty( hdrscan ) )
69 return;
70
71 hdrrule = var_get( root_module(), constant_HDRRULE );
72 if ( list_empty( hdrrule ) )
73 return;
74
75 if ( DEBUG_HEADER )
76 out_printf( "header scan %s\n", object_str( t->name ) );
77
78 /* Compile all regular expressions in HDRSCAN */
79 iter = list_begin( hdrscan );
80 end = list_end( hdrscan );
81 for ( ; ( rec < MAXINC ) && iter != end; iter = list_next( iter ) )
82 {
83 re[ rec++ ] = regex_compile( list_item( iter ) );
84 }
85
86 /* Doctor up call to HDRRULE rule */
87 /* Call headers1() to get LIST of included files. */
88 {
89 FRAME frame[ 1 ];
90 frame_init( frame );
91 lol_add( frame->args, list_new( object_copy( t->name ) ) );
92 #ifdef OPT_HEADER_CACHE_EXT
93 lol_add( frame->args, hcache( t, rec, re, hdrscan ) );
94 #else
95 lol_add( frame->args, headers1( headlist, t->boundname, rec, re ) );
96 #endif
97
98 if ( lol_get( frame->args, 1 ) )
99 {
100 OBJECT * rulename = list_front( hdrrule );
101 /* The third argument to HDRRULE is the bound name of $(<). */
102 lol_add( frame->args, list_new( object_copy( t->boundname ) ) );
103 list_free( evaluate_rule( bindrule( rulename, frame->module ), rulename, frame ) );
104 }
105
106 /* Clean up. */
107 frame_free( frame );
108 }
109 }
110
111
112 /*
113 * headers1() - using regexp, scan a file and build include LIST.
114 */
115
116 #ifndef OPT_HEADER_CACHE_EXT
117 static
118 #endif
119 LIST * headers1( LIST * l, OBJECT * file, int rec, regexp * re[] )
120 {
121 FILE * f;
122 char buf[ 1024 ];
123 int i;
124 static regexp * re_macros = 0;
125
126 #ifdef OPT_IMPROVED_PATIENCE_EXT
127 static int count = 0;
128 ++count;
129 if ( ( ( count == 100 ) || !( count % 1000 ) ) && DEBUG_MAKE )
130 {
131 out_printf( "...patience...\n" );
132 out_flush();
133 }
134 #endif
135
136 /* The following regexp is used to detect cases where a file is included
137 * through a line like "#include MACRO".
138 */
139 if ( re_macros == 0 )
140 {
141 OBJECT * const re_str = object_new(
142 "#[ \t]*include[ \t]*([A-Za-z][A-Za-z0-9_]*).*$" );
143 re_macros = regex_compile( re_str );
144 object_free( re_str );
145 }
146
147 if ( !( f = fopen( object_str( file ), "r" ) ) )
148 return l;
149
150 while ( fgets( buf, sizeof( buf ), f ) )
151 {
152 for ( i = 0; i < rec; ++i )
153 if ( regexec( re[ i ], buf ) && re[ i ]->startp[ 1 ] )
154 {
155 ( (char *)re[ i ]->endp[ 1 ] )[ 0 ] = '\0';
156 if ( DEBUG_HEADER )
157 out_printf( "header found: %s\n", re[ i ]->startp[ 1 ] );
158 l = list_push_back( l, object_new( re[ i ]->startp[ 1 ] ) );
159 }
160
161 /* Special treatment for #include MACRO. */
162 if ( regexec( re_macros, buf ) && re_macros->startp[ 1 ] )
163 {
164 OBJECT * header_filename;
165 OBJECT * macro_name;
166
167 ( (char *)re_macros->endp[ 1 ] )[ 0 ] = '\0';
168
169 if ( DEBUG_HEADER )
170 out_printf( "macro header found: %s", re_macros->startp[ 1 ] );
171
172 macro_name = object_new( re_macros->startp[ 1 ] );
173 header_filename = macro_header_get( macro_name );
174 object_free( macro_name );
175 if ( header_filename )
176 {
177 if ( DEBUG_HEADER )
178 out_printf( " resolved to '%s'\n", object_str( header_filename )
179 );
180 l = list_push_back( l, object_copy( header_filename ) );
181 }
182 else
183 {
184 if ( DEBUG_HEADER )
185 out_printf( " ignored !!\n" );
186 }
187 }
188 }
189
190 fclose( f );
191 return l;
192 }
193
194
195 void regerror( char const * s )
196 {
197 out_printf( "re error %s\n", s );
198 }