COS 217 Spring 1996. Generating WWW Listings

COS 217. Introduction to Programming Systems. Spring 1996.

Generating WWW Listings

Write c2html, a program that generates Hypertext to render a listing of its file arguments suitable for browsing with a Wide World Web client, such as netscape. For example, the commands

cd /u/cs217/src
../2/c2html -tUnique unique/main.c strset/strset.h strset/strset*.c > /u/your-login/unique.html

write to unique.html a WWW listing of the code for the unique strings program found in /u/cs217/src/{unique,strset}. This output is available in /u/cs217/2/unique.html.

WWW documents are written in `HTML' - the HyperText Markup Language. You do not need to know much about HTML; simply mimic the output of the program /u/cs217/2/c2html. The source code for program is 106 lines long.

A HTML document contains text and embedded formatting commands. Most formatting commands have the form <X>text</X> where X is the formatting command that applies to text. Commands that do not apply to specific pieces of text have only the leading <X>.

The command like the one shown above generates an HTML file that has the following general structure.

<header>
<title>title</title>
</header>
<body>
<h1>title</h1>

<h2><a name="contents">Contents</a></h2>

<ul>
<li><a href="#2">file1</a>
...
<li><a href="#N">fileN</a>
</ul>

<h2><a name="2">file1</a></h2>
<pre>...listing for file1...
</pre>
<a href="#contents">Goto the Contents</a>
...
<h2><a name="N">fileN</a></h2>
<pre>...listing for fileN...
</pre>
<a href="#contents">Goto the Contents</a>
<p>
<hr>

<address>
date
</address>
</body>
title is the title string, which is specified by the -t option, e.g., -tUnique. If this option is omitted, the lines <title>title</title> and <h1>title</h1> do not appear in the output. file1 through fileN are the file names in the order they appear on the command line. date is the date and time the command is executed as printed by the date command, e.g.,

Fri Sep 9 16:21:35 EDT 1994

Each file is listed verbatim, except for some include directives. If an include directive refers to one of the ANSI Standard include files in brackets, a hypertext link to the include file itself is planted in the output. For example, unique/main.c includes the line

#include <stdlib.h>

and c2html prints this line as

#include &lt;<a href="http://www.princeton.edu/~cs217/include/stdlib.h">stdlib.h</a>&gt;

Note the use of `&lt;' and `&gt;' for the literal occurrences of < and >; c2html must replace all left and right brackets with &lt; and &gt; to avoid confusing WWW clients that interpret HTML formatting codes. It must also replace occurrences of `&' with &amp;.

Similarly, if an include directive refers to one of the file arguments, a self-referential hypertext link to that file is emitted. For example, unique/main.c includes the line

#include "strset/strset.h"

and c2html prints this line as

#include "<a href="#3">strset/strset.h</a>"

The "#3" is the same string that appears just after the <h2> code at the beginning of the listing for strset/strset.h.

If an include directive refers to file that is elsewhere, it is printed without a hypertext link. For example, strset/strset1.c includes the line

#include "strset.h"

This line names strset.h, but the file name used in the command above is strset/strset.h, so c2html prints this line verbatim.

Submission

Submit your program, a makefile, and a readme. The readme file is a brief description of your program; it should include the program's input, output, author, and modification history. Submit your program electronically with the command
/u/cs217/bin/submit 2 readme makefile ...
You may use other computing facilities to develop your program, but the submitted version must compile with lcc and execute correctly on the SparcServers.

Due: submitted by 11:59pm, Monday, 19 Feb.

Copyright (c) 1994,1996 by David R. Hanson
Sun Feb 11 11:29:45 EST 1996