CSCI 344
Programming Contest
Lab 15
This lab is graded on participation. If you are here and actively
participate (that is, try) in solving the problems you get full
participation credit.
Working in teams of 2-3 students solve as many of the following
problems as you can using Perl, Bash script, and Unix commands
(however, if the task is to implement a Unix command you can't use it
or any of its close cousins).
You may use the Internet as a reference, but you may not search for
solutions to these problems--that would completely defeat the purpose
of doing them.
Here is a link to a good intro to Perl: perldoc.perl.org/perlintro.html
1)
(5 points) Write the UNIX utility wc (word count) that reads from
standard input, or takes one or more filenames and counts the
characters, words (as delimited by spaces), and lines.
2) (5 points) Write a program that converts all files in the current
directory form DOS format to UNIX format. Alternatively, if one
or more arguments are passed to the program, assume each is a directory
and covert all the files in those directories. Specifically, you
need to remove all the carriage returns (\r) from the input. You
can check if a file is dos/unix format by using the file command.
3) (5 points) Print all the prime factors of the input number. For example,
$ prime 10
1 2 5
$ prime 17
1 17
$ prime 2310
1 2 3 5 7 11
$ prime 4
1 2
4) (5 points) Given a series of space delimited numbers, calculate a set of ranges that include on those numbers:
$ range 1 2 3 5 6 7 8 11 15 16 19
1-3 5-8 11 15-16 19
$
5) (10 points) Write an editor launcher that uses the extension of a file to determine which editor to use:
$ e a.cpp ==> launches vim
$ e notes.odt ==> launches open office
$ e lab15.html ==> launches nvu
Use e's process to run the editor (e.g. use exec in Perl). Have
your program read a startup file (maybe ~/.erc) to determine the action
to take for a given extension.
6) (10 points) Since OSX and WindowsXP have case insensitive filenames,
C/C++ programs written in these environments often won't compile on
Linux machines which have case sensitive filenames. The problem
is that the file "Symbol.h" can be included using #include "symbol.h"
on a OSX/WindowsXP machine but not on a Linux machine. Write a
program that considers all the .cpp and .h files in the current
directory and fixes the #include statements so they match the actual
include (.h) filenames. That is, if the file is Symbol.h then
the program should #include "Symbol.h" but if the file is symbol.h then
the program should contain #include "symbol.h"
7) (20 points) Write a program that takes an html file and recursively
finds all broken relative links. A relative link is one in the
same directory structure (on the same host) and looks like this: <a
href="foo/foo.html">.
8) (25 points) Implement a simplified version of Makedepend that only
considers non-system include files. In other words, files
included like #include "symbol.h" and not files included like #include
<string>. Assume all included files are in the current
directory unless a full path is given: #include "/home/xyz/src/f/f.h".
Make sure you recursively consider all files being included.