The goal of this program is to introduce you to UNIX system calls. The program is simple (only about 150 lines of code), but you will need to learn about several system calls, and the syntax of system calls can be tricky.
Implement a rudimentary version of the UNIX find utility. find searches a directory tree looking for a given filename. The command line arguments should be a pathname followed by a target:
% find <pathname> <target>For example,
% find /home/tyson p1.html
will recursively search /home/tyson and all its subdirectories. When it finds a file with the name "p1.html" it will print to standard output (cout) the path for that file (relative to the path specified on the command line):
/home/tyson/classes/15b.f05/public/p1.htmlAnother example,
/home/tyson/classes/340.f05/public/p1.html
% find foo a.cpp
would print paths of the form:
foo/a.cppPart 1 (85%): get find working w/o regular expressions, that is, the target is just a string.
foo/my_directory/a.cpp
Part 2 (10%): get find working w/regular expressions, that is, the target is a regular expression.
Part 3 (5 %): modify your find so that it does not follow symbolic links.
// from main(), these errors all have to do with bad input
// all of these errors cause the program to give up (that is, call exit(1))
cerr << "find: must specify path and target" << endl; // use this if there are not the right number of arguments
cerr << "find: empty path specified" << endl; // use this if some pinhead passes empty quotes as the path
cerr << "find: empty target specified" << endl; // use this is some pinhead passes empty quotes as the target
cerr << "find: permission denied <" << pathname << ">" << endl;
cerr << "find: directory does not exist <" << pathname << ">" <<endl;
cerr << "find: path is not a directory <" << pathname << ">" <<endl;
cerr << "find: error opening <" << pathname << ">" << endl;
// from my recursive search function, these errors do not stop the program
// if opendir() fails because of EACCES error
cerr << "find: permission denied <" << pathname << ">" << endl;
// if opendir() fails for any other reason, you can write your own message, I won't test this
// if stat() fails for any reason
cerr << "find: cannot stat <" << full_path << ">" << endl;
% cd to student's directory
% ~tyson/340/tests/p1/t01.cmd > t01.out 2> t01.err
% diff t01.out ~tyson/340/tests/p1/t01.out
% diff t01.err ~tyson/340/tests/p1/t01.err
search(directory, target)
{
for all files in this directory
if current file is a directory
search(new_directory, target)
}
I will deduct 10 percent if your program does not compile using the command "g++ -o find find.cpp" on a Linux machine.
I will grade your program using another program, so if your program does not work exactly as specified you will lose points. For example, if you put an extra space at the end of the line, or a blank line at the end of the output, you will lose points. Test your program using the sample tests in the test directory (see above).
Please put your name at the top of all your files. If you are working with someone, put both your names at the top of all files.
You must turn in the following file:
find.cppcopy the above file into the directory:
where USERNAME is your ecst username./user/projects/csci340/p1/USERNAME
If you are working with someone, only turn in one copy of the assignment. It is very helpful is people working together always turn their assignments in under the same name.
Notes: You will not be able to access your turn in directory once the deadline has passed.
You will lose 10% for each 24 hours your assignment is late.
e-mail late assignments to me.
It may take me much, much longer to grade late assignments (if I have already graded the other assignments, grading late assignments gets a low priority).
I use the time I receive your e-mail, not the time you send your e-mail as the turn in time (sometimes e-mail from an ISP takes a day or two). If you want to be absolutely sure your assignment gets to me immediately, e-mail it from your ecst account (use your browser (webmail.ecst.csuchico.edu) to e-mail the file to me).