Good day everyone, I have been trying to make a cross-platform grep using C++11 standards and the boost library.
Here is what I have so far:
http://ideone.com/taP2U3 .
Now for my issues. I am planning to accept up to five flags as command line arguments, -i for case insensitivity, -V to reverse match, and only match files not containing the regular expression. -X for exact line match, -L, to output file names for files with no match, and -l to print file names with matches. For some Grep documentation :
http://unixhelp.ed.ac.uk/CGI/man-cgi?grep
Since a regex object has to be initialized with all it's flags, I would have to know which flags to assign before hand, which is not a problem. The problem is once I know which flags to assign how do I assign them all, see below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
unsigned short iCount=0, VCount=0, XCount=0, LCount=0, lCount=0;
for(unsigned short count=1; count<argv[argc-2];count++)
{
if(argv[count]=="-i")
{
iCount++;
continue;
}
if(argv[count]=="-V")
{
VCount++;
continue;
}
if(argv[count]=="-X")
{
XCount++;
continue;
}
if(argv[count]=="-L")
{
LCount++;
continue;
}
if(argv[count]=="-l")
{
lCount++;
continue;
}
}
//Here is the problem, I don't know how to assign the flags, since the .assign() function overwrites
//the previous regular expression and flags, so I have no clue how to assign it.
|
Also does anyone know how to iterate over all the files in a directory? Since the regular expression "C:\Users\admin\Desktop\*.txt" means search all txt files in the desktop. I already separated the root from the rest of it. Now how do I iterate over the entire directory, so I can now match the provided extension with the rest of the files.
Thanks in advance