The goal of this program is to introduce you to UNIX/Linux 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 Linux updatedb & locate utilities. updatedb creates a database of all the file and directory names on a filesystem. locate allows the user to search this database for a given filename.
updatedb and locate are separate utilities. In order to simplify this assignment, your version of locate will (1) build the database and (2) allow the user to enter regular expressions (3) print all files in the database that match the entered regular expressions.
Your program must work like this (I use the name rlocate so my utility is not confused with /usr/bin/locate):
$ rlocate myfiles
enter target> ted
myfiles/ted
enter target> t.d
myfiles/dir/longname_with_tud_in_middle
myfiles/dir/tid.cpp
myfiles/tad
myfiles/ted
myfiles/tod
enter target> ^D
^D means the user holds the <ctrl> key while pressing the <d> key. It is the UNIX/Linux end-of-file character.
The only command line argument (which is required) is the path (path is a Linux term for directory) that rlocate will recursively search (myfiles in the above example). After the path has been searched and the database of all filenames and directory names has been created, rlocate prompts the user for a regular expressions. In the above example the first regular expression is <ted>. Of all the files in myfiles and its subdirectories, there is only one file that matches <myfiles/ted>
The second regular expression is <t.d> (in regular expressions the "." is a wildcard that stands for any single character). Of all the files in myfiles and its subdirectories, there are 5 that have a <t.d> in their names.
When the user enters ^D the program terminates.
cerr << "illegal regular expression: <" << target << ">" << endl;
cerr << "must specify path on command line" << endl;
cerr << "permission denied <" << pathname << ">" << endl;
cerr << "directory does not exist <" << pathname << ">" << 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
bool build_database(char *pathname)
{
for all files F in the current directory
put pathanme/F in the list of files
if F is a directory, call build_database on pathname/F
}
I will deduct 10 percent if your program does not compile using the command "g++ -o rlocate rlocate.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:
rlocate.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% if your program is 1-24 hours late.
You will lose 20% if your program is 24-48 hours late.
Programs will not be accepted 48 hours past the deadline.
e-mail late assignments to me (avoid .zip files because they are usually removed by virus scanners)
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 to be delivered). If you want to be absolutely sure your assignment gets to me immediately, e-mail it from your csuchico or ecst account (you can use your browser (webmail.ecst.csuchico.edu) to e-mail the file to me).