Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

UWM FA2023 CS537 – Assignment XXXXXXXXXX XXXXXXXXXX FA2023 CS537 Assignment 3 1 prompt> ./wis-grep foo bar.txt this line has foo in it so does this foolish line; do you see where? even this line,...

1 answer below »

UWM FA2023 CS537 – Assignment XXXXXXXXXX
XXXXXXXXXX FA2023 CS537 Assignment 3 1
prompt> ./wis-grep foo bar.txt this line has foo in it
so does this foolish line; do you see where?
even this line, having barfood in it, will be printed.
Unix Utilities
In Assignment 3 you will build a set of Unix utilities to execute on your qemu-gdb hosted xv6 VM. These versions will be simpler
versions of common commands like ls, cat, grep, etc. They’re simpler because the Unix originals are considerably more functional
and complicated. We will use different names to avoid confusion: namely wis-grep, wis-tar, wis-untar.
Learning Objectives:
To re-familiarize yourself with the C programming language, with a Unix shell / terminal / command-line, and to learn
how UNIX utilities are implemented.
Summary of what gets turned in via Canvas:
• Each should compile successfully when compiled with the -Wall and -We
or flags.
• Each should (hopefully) pass tests we’ll supply.
• Include a single README.md for all the files describing the implementation.
wis-grep
The first utility you will build is called wis-grep, a variant of the UNIX grep tool. This tool looks through a file, line by line, trying to
find a user-specified search term in the line. If a line has the word within it, the line is printed out, otherwise it is not.
Here is how a user would look for the term foo in the file bar.txt:
Details
Your program wis-grep is always passed a search term and zero or more files to grep through (thus, more than one is possible). It
should go through each line and see if the search term is in it; if so, the line should be printed, and if not, the line should be
skipped.
The matching is case sensitive. Thus, if searching for foo, lines with Foo will not match.
Lines can be a
itrarily long (that is, you may see many characters before you encounter a newline character (\n). wis-grep should
work as expected even with very long strings. For this, you might want to look into the getline() li
ary call.
If wis-grep is passed no command-line arguments, it should print “wis-grep: searchterm [file …] (followed by a
newline) and exit with status 1.
If wis-grep encounters a file that it cannot open, it should print “wis-grep: cannot open file” (followed by a newline) and
exit with status 1.
If a search term, but no file, is specified, wis-grep should work, but instead of reading from a file, it should read from standard
input. Doing so is easy, because the file stream stdin is already open; you can use fgets() (or similar routines) to read from it.
For simplicity, if passed the empty string as a search string, wis-grep can either match NO lines or match ALL lines, both are
acceptable.
wis-tar & wis-untar
The next two utilities to build will also be simpler versions of Unix tar and untar, commonly used utilities to combine (o
expand) a collection of files into one file (one file into a collection of files). This functionality is useful in several scenarios
UWM FA2023 CS537 – Assignment XXXXXXXXXX
XXXXXXXXXX FA2023 CS537 Assignment 3 2
prompt> echo abcd > a.txt #
creates the file a.txt prompt>
echo efgh > b.txt # creates the
file b.txt prompt> ./wis-tar
e.g., offering a single file to download for software. If you’ve heard the phrase ta
all, that comes from using tar!
The input to your wis-tar program will be the name of the tar file followed by a list of files that need to be archived (Fun
Fact: The name tar comes from tape archives!). Example:
wis-tar format
For this assignment, we will use a simple file format for the tar file:
Here are a few points to consider:
1. You can assume that the files provided as an input exist in the directory where the program is run from (no need to
handle ways to store pesky path names).
2. You can also assume the files provided as inputs only contain ASCII characters.
Details
If fewer than two arguments are supplied to your program, you should print “wis-tar: tar-file file […]”
(followed by a newline) and exit with status 1.
If any of the input files that should be a part of the tar file are not found, you should print “wis-tar: cannot open
file” (followed by a newline) and with exit status 1.
If a tar-file of the same name already exists, you can overwrite it with the new contents specified.
If any of the input file names are longer than 100 characters, you can only use the first 100 characters as the filename to
store in the tar format.
If any of the input file names are shorter than 100 characters, you can pad the filename such that it uses 100 bytes. For
example, if the file name was “a.txt”, that only has 5 characters. In this case you can append 95 NULL i.e., \0 characters
to make the name use 100 bytes in the tar file. (Remember '\0' is not the same as '0'. The first one represents NULL
while the second one represents the character 0!)
Here’s a complete example to make sure we understand the format and how to understand the contents of a valid tar file. In
the following example we first create a text file which contains the string hey. Its size is therefore 3.
We run wis-tar to create a.tar as shown below. Finally, we print the contents of a.tar using hexdump, a utility to print the
contents of a binary file. The comments to the right explain its output. The bytes are represented in hexadecimal format, so that
a table like this (https:
www.ascii-code.com/) helps you look up the ASCII values for strings. Try to decode the contents based
on the comments on the right!
As you can see below, the fields in the tar file are packed together with no new lines or other separators between them.
file1 name [100 bytes in ASCII]
file1 size [8 bytes as binary]
file1 contents [in ASCII]
file2 name [100 bytes]
file2 size [8 bytes]
file2 contents [in ASCII]
...
https:
www.ascii-code.com
UWM FA2023 CS537 – Assignment XXXXXXXXXX
XXXXXXXXXX FA2023 CS537 Assignment 3 3
➜ p1a cat a.txt
hey%
➜ p1a ./wis-tar a.tar a.txt
➜ p1a hexdump -v a.ta
Note that this is not in ASCII!
----------------------------------------------------> The last three bytes contain the string hey, the cont
ents of the file
prompt> ./wis-untar test.tar
prompt> ls # should contain a.txt and b.txt
XXXXXXXXXX2e XXXXXXXXXX XXXXXXXXXX --> The first five bytes here contain the file name a.txt
XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX ---> We have padded using \0 till we hit 100 bytes
XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX ---> The byte containing 03 indicates the file size is 3.
wis-untar
As the name suggests, the wis-untar program will do the reverse of the wis-tar program. Here you will take in the name of
an archive created using wis-tar and the program will create files co
esponding to those in the archive in the same directory
where the program is run from. For example
Details
If no arguments are provided, then you should print “wis-untar: tar-file” (followed by a newline) and exit with
status 1.
If the tar filename provided on the command line does not exist, you should print “wis-untar: cannot open file”
(followed by a newline) and exit with status 1.
To simplify this assignment, you can assume that if a tar file is provided and if the file exists, it matches the wis-tar format
described above.
While extracting files, if there already exist files with the same name as those in the archive, you can overwrite them.
Note
For this and all subsequent C programming exercises you are to document your source code using standard comment blocks
delineated by
or /* … */. The beginning of each program should contain a “header” containing, at minimum
program name
program author
program origination date
program last revision date
In line accompanying the c source code should be sufficient comments for another programmer to understand the programs flow,
any expected “side effects” and key assumptions.
    Unix Utilities
    wis-grep
    wis-tar & wis-unta
    wis-tar format
    wis-unta
Answered 1 days After Oct 02, 2022

Solution

Nidhi answered on Oct 03 2022
70 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here