Directory/RB_Is_Source_File [ Functions ]
NAME
RB_Is_Source_File -- Is a file a sourcefile?
SYNOPSIS
int RB_Is_Source_File( struct RB_Path *path, char *filename )
FUNCTION
This functions examines the content of a file to see whether or not it is a sourcefile.
Currently it checks if there are no nul characters in the first 8191 characters of the file.
SOURCE
{ int is_source = 1; if ( RB_Not_Accepted( filename ) ) { /* File needs to be skipped based on it's name */ is_source = 0; } else { unsigned int size = 0; /* Compute the length of the filename including the path. */ size += strlen( path->name ); size += 1; size += strlen( filename ); if ( size < RB_CBUFFERSIZE ) { FILE *file; /* We use the content_buffer buffer temporarily to store the filename. */ content_buffer[0] = '\0'; strcat( content_buffer, path->name ); strcat( content_buffer, filename ); if ( ( file = fopen( content_buffer, "rb" ) ) ) { int no_read; no_read = fread( content_buffer, sizeof( char ), RB_CBUFFERSIZE, file ); if ( no_read > 10 ) { char *c; for ( c = content_buffer; no_read; --no_read, c++ ) { if ( *c == 0 ) { is_source = 0; break; } } } else { /* A file with only 9 characters can not contain any source plus documentation. */ is_source = 0; } fclose( file ); } else { /* The file could not be opened. */ is_source = 0; } } else { /* The filename is longer than 8191 characters, that's way too long... so we skip it. */ is_source = 0; } } return is_source; }