/* cdir.h */
/* class to do some operation on all files that match masks */
/* task: maintain '*' and '?' in file masks */
/* author: Michal Niklas mniklas@computer.org */
#ifndef CDIR_INCLUDED
#define CDIR_INCLUDED
#include <string>
#include <vector>
typedef int (*match_fun_ptr)(const char *re, const char *txt);
/* function used to match filenames with wildchars like '*' and '?' */
typedef int (*file_fun_ptr)(const char *file_name, void *data);
/* what to do with every matched file */
class CFileList
{
private:
bool m_recursive; /* must we check subdirs */
static bool DefaultIgnoreCase; /* does our OS ignore case */
bool m_ignore_case; /* does our class ignore case */
match_fun_ptr m_match_fun; /* function to check file wildchars matching */
std::vector <std::string> m_masks; /* masks for files */
/* set all private members to initial values */
void Init();
/* check the masks before processing files */
/* if masks are empty return false */
virtual bool CheckMasks();
public:
/* construcors/destructor */
CFileList();
CFileList(std::string mask);
CFileList(char *masks[], int count);
virtual ~CFileList() { };
void AddMask(std::string mask);
void SetMasks(char *masks[], int count);
/* does file_name match any of mask */
bool MatchAnyMask(char *file_name);
/* set/get functions for private members */
bool Recursive() const { return m_recursive; }
bool &Recursive() { return m_recursive; }
bool IgnoreCase() const { return m_ignore_case; }
bool SetIgnoreCase(bool new_value);
/* workhorse of class, does most of the work: */
/* for every file that matches any mask do file_fun with data */
/* if recursive, checks all subsequent dirs */
/* if file_fun is NULL or CheckMask failed do nothing */
unsigned int ProcessFiles(std::string dir_name, file_fun_ptr file_fun,
file_fun_ptr dir_fun = NULL, void *data = NULL);
/* set class private members if needed */
/* return false if something is wrong or user wants help only */
/* here: */
/* recognize */
/* -h and -? for help */
/* -r for recursive */
/* -i for ignore case */
virtual bool ParseArgs(int argc, char *argv[]);
}; /* CFileList */
/* simple tool to check if in arg[] is -opt */
bool IsOptionOn(char arg[], char opt);
#endif