The code — phase 2

Now that we understand the basic functionality of the web counter, it's time to move on to phase 2 of the project.

In this second phase, we're going to add (in order of increasing complexity):

persistent count file
This stores the count to a file every time the count changes. It lets you shutdown and restart the resource manager without losing your count.
font selection
We're going to give the client the ability to choose from different fonts. Currently, we'll add only one additional font, because adding more fonts is a simple matter of font design.
ability to render in plain text
For simplicity, sometimes it's nice to get the data in a completely different manner, so this modification lets you use cat to view (and not increase) the count.
ability to write() to the resource
This lets you set the current value of the counter just by writing an ASCII text string to the counter resource.

Why these particular features, and not others? They're incremental, and they are more or less independent of each other, which means we can examine them one at a time, and understand what kind of impact they have on the code base. And, most of them are useful. :-)

The biggest modification is the ability to write() to the resource. What I mean by that is that we can set the counter's value by writing a value to it:

# echo 1234 >/dev/webcounter.gif

This will reset the counter value to 1234.

This modification will illustrate some aspects of accumulating data from a client's write() function, and then seeing how this data needs to be processed in order to interact correctly with the resource manager. We'll also look at extending this functionality later.

All of the modifications take place within main.c (with the exception of the font-selection modification, which also adds two new files, 8x8.c and 8x8.h).