CSCI 415/515: Fall 2022
Systems Programming
Extra Credit: htmlper.sh

Due: Tue, Dec 13, 7:00am


In this project, you will implement a shell script called htmlper.sh that helps with writing HTML files. HTML is the markup language of webpages. When your browser fetches a webpage, the browser is really downloading HTML files (as well as other assets like JaveScript and style sheets), and then rendering these files to your screen. Like many shell scripts, htmlper.sh wraps and composes a few existing programs to provide a convenient interface.

Name

htmlper.sh - tool to help write HTML files

Synopsis

htmlper.sh [-h] [-p] [-s] [-t TITLE] [-v] HTML_FILE

Description

Without any options, the command:

        ./htmlper.sh index.html
        

creates a file called index.html with the following content:



        

If the file index.html already exists, then htmlper.sh prompts the user whether to overwrite the file or quit.

If the -t TITLE option is also given, then htmlpers.h sets the title tag's inner text to TITLE as part of creating the new file. For instance, the command:


        ./htmlper.sh -t Trees index.html
        

creates a file called index.html with the contents:



        

Otherwise, exactly one of the -p (prettify), -s (spell-check), or -v (validate) options is provided, with htmlper.sh performing that operation on an existing HTML_FILE.

Options

-h

Print a usage statement to stdout and exit with status 0.

-p

Remove trailing white space (spaces and tabs) from all lines in HTML_FILE.

-s

Spell check HTML_FILE using the aspell utility. The output is an alphabetically ordered list of misspellings prefaced with the number of times that the misspelling occurred.

-t TITLE

Set the title tag's inner text to TITLE. This option is used only in conjunction with the default operation of generating a new HTML file.

-v

Validate that HTML_FILE is a properly formatted HTML file using the tidy utility. If HTML_FILE is properly formatted, htmlper.sh prints the line $HTML_FILE passed validation to stdout; otherwise, htmlper.sh prints the line $HTML_FILE failed validation to stdout, and then prints a list of the file's syntactical errors/warnings.

Submitting

Submit your project as a zip file via gradescope. The zip file should contain a single executable file called htmlper.sh. Please refer to the instructions for submitting an assignment for details on how to login to gradescope and properly zip your project.

Rubric (50 pts)

Help (-h option)


1.1 Print a usage statement (2 pts)


        ./htmlper.sh -h
        

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.

1.2 Zero exit status (2 pts)


        ./htmlper.sh -h
        echo $?
        0
        

The exit status is zero.

Bad Usage


2.1 Error Message on Multiple Operations (2 pts)


        ./htmlper.sh -v -s index.html
        

Prints a one line message to stderr.

2.2 Nonzero Exit Status on Multiple Operations (2 pts)


        ./htmlper.sh -v -s index.html
        

Specifying multiple operations causes htmlper.sh to terminate with a nonzero exit status.

Generate File


3.1 New File (3 pts)


        ./htmlper.sh index.html
        

Creates a new file index.html.

3.2 New File with Title(3 pts)


        ./htmlper.sh -t Trees trees.html
        

Creates a new file trees.html.

Overwrite File


4.1 Overwrite File (3 pts)


        ./htmlper.sh overwrite.html.
        overwrite.html already exists.  OK to overwrite? [y/n]: y
        

Assuming overwrite.html already exists, htmlper.sh queries the user whether to overwrite the file. The user enters y, and the script overwrites the file. The byte-for-byte content of htmlper.sh should now be the same as index.html.

You can change the message that htmlper.sh presents to the user, but your script must handle the responses of y or n.

4.1 Do Not Overwrite File (3 pts)


        ./htmlper.sh overwrite.html.
        overwrite.html already exists.  OK to overwrite? [y/n]: n
        

Assuming overwrite.html already exists, htmlper.sh queries the user whether to overwrite the file. The user enters n, and the script terminates and does not overwrite the file. In particular, overwrite.html should still have the same content.

You can change the message that htmlper.sh presents to the user, but your script must handle the responses of y or n.

Remove Trailing Whitespace (-p option)


5.1 Remove Spaces (5 pts)


        ./htmlper.sh -p index-trailing-spaces.html
        

After execution, index-trailing-spaces.html should have the same byte-for-byte content as index.html.

5.2 Remove Spaces and Tabs (5 pts)


        ./htmlper.sh -p index-trailing-spaces-tabs.html
        

After execution, index-trailing-spaces-and-tabs.html should have the same byte-for-byte content as index.html.

Spell Check (-s option)


6.1 Spell Check (10 pts)


        ./htmlper.sh -s mispellings.html
             1 blu
             1 lullabie
             2 rainbox
             2 teh
        

Prints the above output to stduot. The amount of whitespace that you use when formatting each line of output is irrelevant.

Validate (-v option)


7.1 Validate Success (5 pts)


        ./htmlper.sh -v index.html
        index.html passed validation
        

Prints the above output to stdout.

7.2 Validate Failure (5 pts)


        ./htmlper.sh -v invalid.html
        invalid.html failed validation
        line 9 column 5 - Warning: missing </h1> before </h2>
        line 9 column 22 - Warning: discarding unexpected </h2>
        

Prints the above output to stdout. To tolerate potential differences in output between different versions of tidy, the test only checks that the script wrote two or more lines to stdout, with the first line exactly matching invalid.html failed validation.