| 120 | static |
| 121 | #endif |
| 122 | LIST * headers1( LIST * l, OBJECT * file, int rec, regexp * re[] ) |
| 123 | { |
| 124 | FILE * f; |
| 125 | char buf[ 1024 ]; |
| 126 | int i; |
| 127 | static regexp * re_macros = 0; |
| 128 | |
| 129 | #ifdef OPT_IMPROVED_PATIENCE_EXT |
| 130 | static int count = 0; |
| 131 | ++count; |
| 132 | if ( ( ( count == 100 ) || !( count % 1000 ) ) && DEBUG_MAKE ) |
| 133 | { |
| 134 | out_printf( "...patience...\n" ); |
| 135 | out_flush(); |
| 136 | } |
| 137 | #endif |
| 138 | |
| 139 | /* The following regexp is used to detect cases where a file is included |
| 140 | * through a line like "#include MACRO". |
| 141 | */ |
| 142 | if ( re_macros == 0 ) |
| 143 | { |
| 144 | OBJECT * const re_str = object_new( |
| 145 | "#[ \t]*include[ \t]*([A-Za-z][A-Za-z0-9_]*).*$" ); |
| 146 | re_macros = regex_compile( re_str ); |
| 147 | object_free( re_str ); |
| 148 | } |
| 149 | |
| 150 | if ( !( f = fopen( object_str( file ), "r" ) ) ) |
| 151 | { |
| 152 | /* No source files will be generated when -n flag is passed */ |
| 153 | if ( !globs.noexec || errno != ENOENT ) |
| 154 | err_printf( "[errno %d] failed to scan file '%s': %s", |
| 155 | errno, object_str( file ), strerror(errno) ); |
| 156 | return l; |
| 157 | } |
| 158 | |
| 159 | while ( fgets( buf, sizeof( buf ), f ) ) |
| 160 | { |
| 161 | for ( i = 0; i < rec; ++i ) |
| 162 | if ( regexec( re[ i ], buf ) && re[ i ]->startp[ 1 ] ) |
| 163 | { |
| 164 | ( (char *)re[ i ]->endp[ 1 ] )[ 0 ] = '\0'; |
| 165 | if ( DEBUG_HEADER ) |
| 166 | out_printf( "header found: %s\n", re[ i ]->startp[ 1 ] ); |
| 167 | l = list_push_back( l, object_new( re[ i ]->startp[ 1 ] ) ); |
| 168 | } |
| 169 | |
| 170 | /* Special treatment for #include MACRO. */ |
| 171 | if ( regexec( re_macros, buf ) && re_macros->startp[ 1 ] ) |
| 172 | { |
| 173 | OBJECT * header_filename; |
| 174 | OBJECT * macro_name; |
| 175 | |
| 176 | ( (char *)re_macros->endp[ 1 ] )[ 0 ] = '\0'; |
| 177 | |
| 178 | if ( DEBUG_HEADER ) |
| 179 | out_printf( "macro header found: %s", re_macros->startp[ 1 ] ); |
no test coverage detected