Due: Fri, Sept 27 @7:00am
In this project, you will implement a basic file editor, which we will call fedit. Later in the semester, we will learn about ed and sed, which are two powerful command-line file editors.
The user must specify exactly one of of these operations (that is, the user cannot specify multiple operations).
Mandatory options to long options are also mandatory for the corresponding short options. In this specification, the symbol FSIZE is the input file's size.
Print a usage statement to stdout and exit with status 0.
Rotate the file NROTL bytes left (with wrap around).
Expand the file by NEXPAND. The value of these bytes is given by the --value option.
Contract (shrink) the file by NCONTRACT bytes. If NCONTRACT > FSIZE, shrink the file to 0 bytes.
The character value that is used when expanding the file.
Default: A.
Keep this many bytes (starting from the offset provided by --skip) (and remove all others). In the case of EOF, fewer than NKEEP bytes may be kept.
Optionally used with --keep. Skip NKSIP bytes
before keeping.
Default: 0
It is an error to use this option if the user does not also specify
--keep.
Implement the following feature:
Rotate the file NROTR bytes right (with wrap around).
Remember to include a blank file called bonus1 in your project submission so that I know to grade this feature.
Implement the following feature:
Repeat skip/keep operations as many times until the end of the file is reached. It is an error to use this option if the user does not also specify --keep.
Remember to include a blank file called bonus2 in your project submission so that I know to grade this feature.
Submit your project as a zip file via gradescope. Your project must include a Makefile that builds an executable called fedit. Please refer to the instructions for submitting an assignment for details on how to login to gradescope and properly zip your project.
You can download a zip file with the starter code (fedit.c, mu.c, mu.h, Makefile).
Input Files: alphabet
./fedit --help
Prints a usage statement to stdout. The statement must start with either Usage or usage; you decide the rest of the message. Conventionally, this option either prints the synopsis or a more verbose statement that also includes a description of the options.
./fedit --help
echo $?
0
The exit status is zero.
./fedit -x20 -c10 alphabet
Print a one-line error message to stderr (you decide the contents of the message).
./fedit -x20 -c10 alphabet
The exit status is nonzero.
./fedit -k 10 -q alphabet
Print a one-line error message to stderr (you decide the message).
./fedit -k 10 -q alphabet
The exit status is nonzero.
./fedit -k -s 2 alphabet
Print a one-line error message to stderr (you decide the message).
./fedit -k -s 2 alphabet
The exit status is nonzero.
./fedit -k10 nonexistent
Prints a message to stderr that includes the text No such file (case-insensitive).
./fedit -k10 nonexistent
The exit status is nonzero.
./fedit --rotate-left 5 alphabet
cat alphabet
fghijklmnopqrstuvwxyzabcde$
The file is modified as shown above. Note that the output does not have a newline, hence the shell prompt immediately follows.
./fedit --rotate-left 27 alphabet
cat alphabet
bcdefghijklmnopqrstuvwxyza$
The file is modified as shown above. Note that the output does not have a newline, hence the shell prompt immediately follows.
./fedit --rotate-left -1 alphabet
Print a one-line error message to stderr (you decide the contents of the message).
./fedit -x4 alphabet
cat alphabet
abcdefghijklmnopqrstuvwxyzAAAA$
The file is modified as shown above. Note that the output does not have a newline, hence the shell prompt immediately follows.
./fedit --expand 5 --value B alphabet
cat alphabet
abcdefghijklmnopqrstuvwxyzBBBBB$
The file is modified as shown above. Note that the output does not have a newline, hence the shell prompt immediately follows.
./fedit -c8 alphabet
cat alphabet
abcdefghijklmnopqr$
The file is modified as shown above. Note that the output does not have a newline, hence the shell prompt immediately follows.
./fedit -c26 alphabet
cat alphabet
The file has zero bytes.
./fedit -c30 alphabet
cat alphabet
The file has zero bytes.
./fedit --keep=5 alphabet
cat alphabet
abcde$
The file is modified as shown above. Note that the output does not have a newline, hence the shell prompt immediately follows.
./fedit --skip=3 --keep=6 alphabet
cat alphabet
defghi$
The file is modified as shown above. Note that the output does not have a newline, hence the shell prompt immediately follows.
./fedit -s20 -k10 alphabet
cat alphabet
uvwxyz$
The file is modified as shown above. Note that the output does not have a newline, hence the shell prompt immediately follows.
./fedit -s30 -k10 alphabet
cat alphabet
The file has zero bytes.
./fedit -r5 alphabet
cat alphabet
vwxyzabcdefghijklmnopqrstu$
The file is modified as shown above. Note that the output does not have a newline, hence the shell prompt immediately follows.
./fedit --rotate-right=28 alphabet
cat alphabet
yzabcdefghijklmnopqrstuvwx$
The file is modified as shown above. Note that the output does not have a newline, hence the shell prompt immediately follows.
./fedit -s2 -k3 -m alphabet
cat alphabet
cdehijmnorstwxy$
The file is modified as shown above. Note that the output does not have a newline, hence the shell prompt immediately follows.
./fedit -s5 -k10 -m alphabet
cat alphabet
fghijklmnouvwxyz$
The file is modified as shown above. Note that the output does not have a newline, hence the shell prompt immediately follows.