Unix Systems Programming: Lab 2
Lab time: No assigned lab time due to lab space
construction.
Work at your own pace, but work.
Due: Wednesday, October 13, 2010 @ 5:00
pm
PURPOSE AND RATIONALE
The purpose of this lab is to allow students to become comfortable with
basic Awk programming, and building static and shared libraries.
PRIMARY RESOURCES:
FAQ
(submission instructions and other useful resources)
You should refer to the online Awk text under required texts.
If possible, you should ssh into the cluster to perform all lab
activities.
README
- If you are not in our course email list, please subscribe
to the
cspp51081 email list here:
http://mailman.cs.uchicago.edu/mailman/listinfo/cspp51081
- Please start this lab as earlier as possible
- Before starting, please review lecture 2 notes and read Effective
awk Programming, 3rd ed., by Arnold Robbins, available online
- Turn the lab assignment in by email to the grader by the
due date
above.
- Make sure you have read the Homework Style Guidelines for
submission.
LAB 2
- Consider the file
normal.precip.txt. It contains the average amount of rainfall
over
a
30 year period for about 275 cities in North America. The first line of
the file is a header, which tells you what each column contains.
Basically,
each line contains a city name, the state the city is in, and then
average
rainfall amounts from January through December, and then an annual
average
for all months. The file is TAB delimited. QUESTION: What is the total
average amount of rainfall, in inches, for the month of January, for
the
following states: California (CA), Texas (TX), Alaska (AK). I want
individual
totalized averages for each of the above states for the month of
January. As a check on your algorithm, note that the totalized average
rainfall for
California (CA) for the month of February over the same period was
2.65067. This was derived by adding the rainfall values together for
all cities in
California for the month of February, and simply taking their average.
Please use Awk programming to implement above procedure.
There
are several steps for this lab:
- Figure out the regular expression that will match all
the
valid chunks of the form described above. Mark has provided a very
useful program to help with this process called showmatch
that can be used in the following manner:
hangao@gawaine:CSPP51081% echo "FOO8AB10BAR" | /home/mark/pub/51081/showmatch '[0-9]AB[0-9]'
FOO8AB10BAR
^^^^
hangao@gawaine:CSPP51081%
The matched portion of the string is returned with carrot characters
underneath. This will help you understand how "gawk" works.
- If a question is about California, notice that a mere
grep of
/CA/ will include:
WINNEMUCCA, NV
POCATELLO, ID
Probably NOT what you wanted. The shell script "showmatch" maybe help
you debug in this regard.
- Use "gawk" to integrate the patterns and actions we
described
above.
2.
Build Static and Shared Libraries using a
Makefile
- Read "make and Makefile" session in Chaper 10 of BLP
textbook
if you're using that text. Certainly refer to the online GNU
documentation
for GNU
make
.
- Write 3 very simple c source files: hello.c,
here.c, bye.c, mylib.h
. In hello.c, a function should print out
"Hello!"; in here.c
, another function should print out "I am here!"; and yet another
function
should print out "Bye bye!" in bye.c. So,
actually, in each code
file, there is only one C printf statement. mylib.h should include
prototypes for the 3 functions you will be writing.
- Write a main.c to call above 3
functions so that the result should display like following
"Hello!"
"I am here!"
"Bye bye!"
Please note there is no C printf statement in main.c;
- Read and understand this
makefile first and write your own Makefile called Makefile1
to compile them and build a static lib called mylib.a,
comprised
of hello.c, here.c, and bye.c (but NOT main.c).
- Review "shared libraries naming structure" and
"building a shared library" in lecture 3.
- Read and understand this makefile
first and write your own makefile called Makefile2
to compile them and build a shared lib with the soname of
libmylib.so.5. Make the minor
version .1 and the release .10. This will mean your actual
shared library
file will be named "libmylib.so.5.1.10" with .so links set accordingly.
- Note that the two makefiles actually build separate
libraries based
on the same source code files, one static, the other shared.
DELIVERABLES: see the
submission faq
MARKS DISTRIBUTION
- Excercise 1:
- 7 points: gawk script
- 3 points: correct answer as generated by the gawk script
- 1 points: correct answer in the submitted file
- Excercise 2:
- 11 points: correct libraries
- Correct Submission:
- 3 points: Lab submitted as given in the
instructions with names on top of files and proper format.
Total Marks: 25
HINTS
Take it slowly and complete each portion of the homework
before
working on the next as each step depends upon the correct solution to
the last. If you think you have the right answer for a step but the
test is still failing, mail the list. If you are having any questions
at all, mail the list.
Brian Martin