示例#1
0
static LIST *
#endif
headers1( 
	LIST	*l,
	char	*file,
	int	rec,
	regexp	*re[] )
{
	FILE	*f;
	char	buf[ 1024 ];
	int		i;
        static regexp *re_macros = 0;

        
#ifdef OPT_IMPROVED_PATIENCE_EXT
	static int count = 0;
	++count;
	if ( ((count == 100) || !( count % 1000 )) && DEBUG_MAKE )
	    printf("...patience...\n");
#endif
        
        /* the following regexp is used to detect cases where a  */
        /* file is included through a line line "#include MACRO" */
        if ( re_macros == 0 )
        {
            re_macros = regex_compile(
                "^[ 	]*#[ 	]*include[ 	]*([A-Za-z][A-Za-z0-9_]*).*$" );
        }


	if( !( f = fopen( file, "r" ) ) )
	    return l;

	while( fgets( buf, sizeof( buf ), f ) )
	{
            int size = strlen (buf);
            /* Remove trailing \r and \n, if any. */
            while (size > 0 
                   && (buf[size-1] == '\n' && buf[size-1] == '\r'))
            {
                buf[size-1] = '\0';
                --size;
            }

	    for( i = 0; i < rec; i++ )
		if( regexec( re[i], buf ) && re[i]->startp[1] )
	    {
		re[i]->endp[1][0] = '\0';

		if( DEBUG_HEADER )
		    printf( "header found: %s\n", re[i]->startp[1] );

		l = list_new( l, newstr( re[i]->startp[1] ) );
	    }
            
            /* special treatment for #include MACRO */
            if ( regexec( re_macros, buf ) && re_macros->startp[1] )
            {
              char*  header_filename;
              
              re_macros->endp[1][0] = '\0';
              
              if ( DEBUG_HEADER )
                printf( "macro header found: %s", re_macros->startp[1] );
                
              header_filename = macro_header_get( re_macros->startp[1] );
              if (header_filename)
              {
	        if ( DEBUG_HEADER )
                  printf( " resolved to '%s'\n", header_filename );
                l = list_new( l, newstr( header_filename ) );
              }
              else
              {
	        if ( DEBUG_HEADER )
                  printf( " ignored !!\n" );
              }
            }
	}

	fclose( f );

	return l;
}
示例#2
0
static
#endif
LIST * headers1( LIST * l, OBJECT * file, int rec, regexp * re[] )
{
    FILE * f;
    char buf[ 1024 ];
    int i;
    static regexp * re_macros = 0;

#ifdef OPT_IMPROVED_PATIENCE_EXT
    static int count = 0;
    ++count;
    if ( ( ( count == 100 ) || !( count % 1000 ) ) && DEBUG_MAKE )
    {
        out_printf( "...patience...\n" );
        out_flush();
    }
#endif

    /* The following regexp is used to detect cases where a file is included
     * through a line like "#include MACRO".
     */
    if ( re_macros == 0 )
    {
        OBJECT * const re_str = object_new(
            "#[ \t]*include[ \t]*([A-Za-z][A-Za-z0-9_]*).*$" );
        re_macros = regex_compile( re_str );
        object_free( re_str );
    }

    if ( !( f = fopen( object_str( file ), "r" ) ) )
        return l;

    while ( fgets( buf, sizeof( buf ), f ) )
    {
        for ( i = 0; i < rec; ++i )
            if ( regexec( re[ i ], buf ) && re[ i ]->startp[ 1 ] )
            {
                ( (char *)re[ i ]->endp[ 1 ] )[ 0 ] = '\0';
                if ( DEBUG_HEADER )
                    out_printf( "header found: %s\n", re[ i ]->startp[ 1 ] );
                l = list_push_back( l, object_new( re[ i ]->startp[ 1 ] ) );
            }

        /* Special treatment for #include MACRO. */
        if ( regexec( re_macros, buf ) && re_macros->startp[ 1 ] )
        {
            OBJECT * header_filename;
            OBJECT * macro_name;

            ( (char *)re_macros->endp[ 1 ] )[ 0 ] = '\0';

            if ( DEBUG_HEADER )
                out_printf( "macro header found: %s", re_macros->startp[ 1 ] );

            macro_name = object_new( re_macros->startp[ 1 ] );
            header_filename = macro_header_get( macro_name );
            object_free( macro_name );
            if ( header_filename )
            {
                if ( DEBUG_HEADER )
                    out_printf( " resolved to '%s'\n", object_str( header_filename )
                        );
                l = list_push_back( l, object_copy( header_filename ) );
            }
            else
            {
                if ( DEBUG_HEADER )
                    out_printf( " ignored !!\n" );
            }
        }
    }

    fclose( f );
    return l;
}