Ejemplo n.º 1
0
        void get_all_sub_dirs (
            const directory& top_of_tree,
            unsigned long max_depth,
            std::vector<directory>& result,
            std::vector<directory>& temp
        )
        {
            if (max_depth > 0)
            {
                top_of_tree.get_dirs(temp);
                const unsigned long start = result.size();
                result.insert(result.end(), temp.begin(), temp.end());
                const unsigned long end = start + temp.size();

                for (unsigned long i = start; i < end; ++i)
                {
                    get_all_sub_dirs(result[i], max_depth-1, result, temp);
                }
            }
        }
Ejemplo n.º 2
0
 directory get_parent_directory (
     const directory& dir
 )
 {
     return dir.get_parent();
 }
Ejemplo n.º 3
0
void add_files (
    const directory& dir,
    const std::string& out_dir,
    map_string_to_string& file_map,
    bool flatten,
    bool cat,
    const set_of_string& filter,
    unsigned long search_depth,
    unsigned long cur_depth
)
{
    const char separator = directory::get_separator();

    queue_of_files files;
    queue_of_dirs dirs;

    dir.get_files(files);

    // look though all the files in the current directory and add the
    // ones that match the filter to file_map
    string name, ext, in_file, out_file;
    files.reset();
    while (files.move_next())
    {
        name = files.element().name();
        string::size_type pos = name.find_last_of('.');
        if (pos != string::npos && filter.is_member(name.substr(pos+1)))
        {
            in_file = files.element().full_name();

            if (flatten)
            {
                pos = in_file.find_last_of(separator);
            }
            else
            {
                // figure out how much of the file's path we need to keep
                // for the output file name
                pos = in_file.size();
                for (unsigned long i = 0; i <= cur_depth && pos != string::npos; ++i)
                {
                    pos = in_file.find_last_of(separator,pos-1);
                }
            }

            if (pos != string::npos)
            {
                out_file = out_dir + in_file.substr(pos+1) + ".html";
            }
            else
            {
                out_file = out_dir + in_file + ".html"; 
            }

            if (file_map.is_in_domain(out_file))
            {
                if (file_map[out_file] != in_file)
                {
                    // there is a file name colision in the output folder. definitly a bad thing
                    ostringstream sout;
                    sout << "Error: Two of the input files have the same name and would overwrite each\n";
                    sout << "other.  They are " << in_file << " and " << file_map[out_file] << ".";
                    throw error(sout.str());
                }
                else
                {
                    continue;
                }
            }

            file_map.add(out_file,in_file);

        }
    } // while (files.move_next())
    files.clear();

    if (search_depth > cur_depth)
    {
        // search all the sub directories
        dir.get_dirs(dirs);
        dirs.reset();
        while (dirs.move_next())
        {
            if (!flatten && !cat)
            {
                string d = dirs.element().full_name();
                
                // figure out how much of the directorie's path we need to keep.
                string::size_type pos = d.size();
                for (unsigned long i = 0; i <= cur_depth && pos != string::npos; ++i)
                {
                    pos = d.find_last_of(separator,pos-1);
                }
                
                // make sure this directory exists in the output directory tree
                d = d.substr(pos+1);
                create_directory(out_dir + separator + d);
            }

            add_files(dirs.element(), out_dir, file_map, flatten, cat, filter, search_depth, cur_depth+1);
        }
    }
    
}