Directory/RB_Fill_Directory [ Functions ]

NAME

RB_Fill_Directory -- fill a RB_Directory structure

SYNOPSIS

void RB_Fill_Directory(
    struct RB_Directory *arg_rb_directory,
    struct RB_Path *arg_path,
    struct RB_Path *arg_doc_path )

FUNCTION

Walks through all the files in the directory pointed to by arg_path and adds all the files to arg_rb_directory. This is a recursive function.

INPUTS

RESULT

a RB_Directory structure filled with all sourcefiles and subdirectories in arg_path.

NOTE

This a is a recursive function.

SOURCE

{
    struct dirent      *a_direntry;
    DIR                *a_dirstream;

    RB_Say( "Scanning %s\n", SAY_INFO, arg_path->name );
    a_dirstream = opendir( arg_path->name );

    if ( a_dirstream )
    {
        T_RB_FileType       file_type;

        for ( a_direntry = readdir( a_dirstream );
              a_direntry; a_direntry = readdir( a_dirstream ) )
        {
            file_type = RB_FileType( arg_path->name, a_direntry );
            if ( file_type == RB_FT_FILE )
            {
                /* It is a regular file. See if it is a sourcefile. */
                if ( RB_Is_Source_File( arg_path, a_direntry->d_name ) )
                {
                    /* It is, so we add it to the directory tree */
                    RB_Directory_Insert_RB_Filename( arg_rb_directory,
                                                     RB_Get_RB_Filename
                                                     ( a_direntry->d_name,
                                                       arg_path ) );
                }
                else
                {
                    /* It's not a sourcefile so we skip it. */
                }
            }
            else if ( file_type == RB_FT_DIRECTORY )
            {
                if ( ( strcmp( ".", a_direntry->d_name ) == 0 ) ||
                     ( strcmp( "..", a_direntry->d_name ) == 0 ) )
                {
                    /* Don't recurse into . or ..
                       because that will result in an infinite */
                }
                else
                {
                    if ( RB_To_Be_Skipped( a_direntry->d_name ) )
                    {
                        /* User asked this directory to be skipped */
                    }
                    else
                    {
                        if ( course_of_action.do_nodesc )
                        {
                            /* Don't descent into the subdirectories */
                        }
                        else
                        {
                            struct RB_Path     *rb_path =
                                RB_Get_RB_Path2( arg_path->name,
                                                 a_direntry->d_name );

                            rb_path->parent = arg_path;
                            if ( ( arg_doc_path
                                   && strcmp( rb_path->name,
                                              arg_doc_path->name ) )
                                 || !arg_doc_path )
                            {
                                RB_Directory_Insert_RB_Path( arg_rb_directory,
                                                             rb_path );
                                RB_Fill_Directory( arg_rb_directory, rb_path,
                                                   arg_doc_path );
                            }
                            else
                            {
                                RB_Say( "skipping %s\n", SAY_INFO,
                                        rb_path->name );
                            }
                        }
                    }
                }
            }
            else
            {
                /* Not a file and also not a directory */
            }
        }
    }
    closedir( a_dirstream );
}