Answered You can hire a professional tutor to get the answer.

QUESTION

Implement in C a Unix utility program gasp. The command gasp [options] STRING FILE. should read the listed files (FILE.

Implement in C a Unix utility program gasp. The commandgasp [options] STRING FILE...should read the listed files (FILE...) and copy each line from the input to stdout if it contains STRING. Each output line should be preceded by the name of the file that contains it. The argument STRING may be any sequence of characters (as expanded, of course, by the shell depending on how it is quoted). There are two available options, which may appear in any order if both are present:* -i Ignore case when searching for lines that contain STRING. If the -i option is used, the strings "this", "This", "THIS", and "thiS" all match; if -i is not used, they are all considered different.* -n Number lines in output. Each line copied to stdout should include the line number in the file where it was found in addition to the file name. The lines in each file are numbered from 1.Your program does not need to be able to handle combinations of option letters written as a single multi-character option like -in or -ni. But it does need to be able to handle any combination of either or both (or neither) option when they appear separately on the command line.Besides the general specification given above, your program should meet the following requirements.1. Be able to handle input lines containing up to 500 characters (including the terminating ). This number should not be hard-wired everywhere in the code, but should be specified with an appropriate #define preprocessor command so it can be changed easily. Your program is allowed to produce incorrect results or fail if presented with input data containing lines longer than this limit.2. You may assume that the string pattern on the command line is no longer than 100 characters (including the terminating ). This length should also be specified by an appropriate #define.3. Use standard C library functions where possible; do not reimplement operations available in the basic libraries. For instance, strncpy in <string.h> can be used to copy -terminated strings; you should not be writing loops to copy such strings one character at a time.Exception: there is a getopt function in the Linux library that provides simplified handling of command line options. For this assignment, only, you may not use this function. You should implement the processing of command line options yourself, of course using the string library functions when these are helpful.4. You should use "safe" versions of file and string handling routines such as fgets and strncpy instead of routines like gets and strcpy. The safe functions allow specification of maximum buffer or array lengths and will not overrun adjacent memory if used properly.5. For the -i option, two characters are considered to be equal ignoring case if they are the same when translated by the tolower(c) function (or, alternatively, toupper(c)) in <ctype.h>.6. If an error occurs when opening or reading a file, the program should write an appropriate error message to stderr and continue processing any remaining files on the command line.

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question