Assignment 4 : sfind -n something

preliminary listing still working on refinements

Assignment Day           Tuesday, September 30, 2014 (evening)
Due Date Friday, October 10, 2014

Key Concepts and Learning Objectives

  • Deepened C Programmer knowledge
  • Deepened UNIX knowledge
  • UNIX Directory Tree Structure practice
  • Recursion
  • Demonstrate UNIX/C programming

Program Description:

You will implement a simplified version of the UNIX command find,here called: sfind that recursively searches directories for files or directories that match a substring given on the command line.

The syntax of your command should look like this:

  sfind <directory-where to start looking> -n substring-criteria -t <filetype> 

As background what you (really) are implementing is the UNIX equivalent of:

find <directory-where to start looking> -name substring -print -type <filetype>

Here are some example uses:

  • $ sfind ~maria -n exam-solutions.txt
    The above command line should find all the files and directories containing the string "exam-solutions.txt" 
    starting from the directory ~maria OR in any of the subdirectories that descends from the ~maria. The files
    returned can be of any type since it is not defined by the -t flat.
  • $ sfind . -n .txt -t f
    The above command line should find all the files and directories containing the string ".txt" in 
    the current directory OR in any of the subdirectories that descends from the current directory. The files returned must be 'regular files' (the file types shold be at the same syntax as specified by the find command and to query the type you should use lstat().
  • $ sfind . -n maria
    The above command line is similar to the first example, except that it starts searching from
    the current directory, and searches for the substring 'maria'

For the project you will use, lstat() instead of stat(). You used lstat() during the exam so it should be familiar, but just incase here is the man page of lstat() / stat() is ( here ).

Hints and Programming Strategies:

  1. Read the manual page on the find command. Try it out in your own directory, e.g.,:                      
          $ find . -name Makefile -print

  2. You need to use lstat() to determine the type of a file. Review the online documentation, and man page, as it is an essential part of your program.
  3. Consider writing a function called searchdir( char *dirname, char *findme , char type ). That opens a directory called dirname, then read it entry by entry, and prints out names of items that match all search criteria. If `dirname´ is not null, then the function will only list files that match that pattern given in the parameter findme. If `type´ is not ’\0’, then the function should (only) include items that are of the type specified.
  4. In addition, if any entry in the directory is a directory, then searchdir() will need to create a new string that holds the new directory name and pass that string to itself. Use malloc(), or calloc() to create the string; a fixed size buffer is liable to run out when you least expect it.

Other Requirements:

  • Each time a match is found, print the absolute path name for the matching file or directory.
  • Test access permission before trying to change to a directory.
  • Do not follow symbolic links.
  • Your program must compile on nike, and be compiled with a single 'make' command.
  • The programs should be robust and include appropriate error checks.

Submission:

You must submit the following files (i.e., all the files necessary to compile your program):
README.txt
*.c (all your .c files), you should have at least 2 .c files, main() should be in sfind.c
*.h (all your .h files), and you should have at least 1 .h file.
Makefile - where the command 'make' with no parameter should generate your executable sfind

To submit the files, you will need to use the submit program. Your files need to be under a common subdirectory called "1730_program4". If the 1730_program4 subdirectory is directly under your home directory you execute the below command line while in your home directory:

submit 1730_program4 cs1730