CSCI1730 Project 03-Unix Utility Solved

30.00 $

Category:

Description

5/5 - (1 vote)

 

For this project, you are tasked with implementing a collection of basic Unix utilities using low-level system calls. Not all utilities are the same difficulty. Please manage your time wisely.

Here is the list of utilities that you must implement:

  1. ./head [ -c number | -n number] [files…]
         ./tail [ -c number | -n number] [files...]
    

    (40 points) The head and tail utilities should copy their input files to the standard output, ending or starting the output for each file at a designated point, respectively. Copying must end/begin at the point in each input file indicated by the -c number or -n number option. The option-argument number is counted in units of lines or bytes, according to the options -n and -c, respectively. Both line and byte counts start from 1. If no options are specified, act as if -n 10 had been specified. If no files operand is specified, or when one of the files is -, then standard input is assumed.

    • 􏰃  -n number: The first (head) or last (tail) number lines of each input file to be copied to standard output. The application must ensure that the number option-argument is a positive decimal integer. When a file contains less than number lines, it must be copied to standard output in its entirety. This should not be an error.
    • 􏰃  -c number: Output the first (head) or last (tail) number of bytes. A positive decimal integer as well.
  2. ./wc [-clw] [files…]
    (40 points) The wc utility should read one or more input files and, by default, write the number of newlines, words, and bytes, in that order, contained in each input file to the standard output (in other words, the default behavior matches having the options -clw). The utility should also write a total count for all named files, if more than one input file is specified. The wc utility should consider a word to be a non-zero-length string of characters delimited by whitespace characters. Your program should be able to handle any combinations of the -c, -l and -w, in any order (e.g, -wl, -c, etc.). If no files operand is specified, or when one of the files is -, then standard input is assumed.

    􏰃 -c: Write to the standard output the number of bytes in each input file.
    􏰃 -l: Write to the standard output the number of newlines in each input file. 􏰃 -w: Write to the standard output the number of words in each input file.

  3. ./true ./false

    (10 points) The true utility shall return with exit code EXIT SUCCESS. The false utility shall return with exit code EXIT FAILURE.

  4. ./env
    (10 points) The env utility prints all of the currently set environmental variables to standard output.

1

Nonfunctional Requirements

Your submission needs to satisfy the following nonfunctional requirements:

  • 􏰃  Directory Setup: Make sure that all of your files are in a directory called LastName-FirstName-p3, where LastName

    and FirstName are replaced with your actual last name and first name.

  • 􏰃  Libraries: You are allowed to use any of the C standard libraries, but with the following restrictions: When reading or writing to a file are concerned, you need to use low-level calls to read(2) and write(2) and related functions. Whenever possible, program output should be unbuffered. You are NOT allowed to use the following system calls in any of your implementations: fork(2), execve(2), exec(3), popen(3), and system(3) (and related functions). Failure to adhere to this non-functional requirement will cause you to earn no points for the utility programs(s) in which these forbidden system calls/functions are used.
  • 􏰃  Documentations: Your code must be documented using Javadoc style comments. Use inline documentation, as needed, to explain ambiguous or tricky parts of your code. A maximum of 5 points will be deducted for not including appropriate documentations.
  • 􏰃  makefile: You need to include a makefile. The resulting executable names should correspond to the ones presented in the previous section. The very first target in your makefile should produce executables for all the utility programs. Please also include a ‘clean’ target to remove any object code and executables. The expectation is that the grader should be able to type make clean and make to clean and compile/link your submission, respectively. A maximum of 5 points will be deducted for a bad/missing makefile.
  • 􏰃  Standards & Flags: Make sure that when you compile, you pass the following options to gcc: -Wall -pedantic-errors

    Other compiler/linker options may be needed in addition to the ones mentioned above.

  • 􏰃  README File: Make sure to include a README file that includes the following information presented in a reasonably formatted way:

    – Your Name and UGA ID (811#)
    – Instructions on how to compile and run your program.

    A maximum of 5 points will be deducted for an README file that does not adhere to these standards.

  • 􏰃  Compiler Warnings: Since you should be compiling with both the -Wall and -pedantic-errors options, your code is expected to compile without gcc issuing any warnings. Failure to adhere to this non-functional requirement will result in an automatic 5 point deduction.
  • 􏰃  Memory Leaks: Since this project may make use of dynamic memory allocation, you are expected to ensure that your project implementation does not result in any memory leaks. We will test for memory leaks using the valgrind utility. Failure to adhere to this non-functional requirement will result in an automatic 5 point deduction.

    Submission

  • p3-tqurtp.zip