< ] [ GCL Home ] [ CGI Tutorial ] [ Home ] [ > ]

The Graphic Counter Language, Page 2

Before explaining how to create counters with GCL, let me explain a little about what GCL is and what it does.

As you already know, GCL is an acronym for Graphic Counter Language. Indeed, GCL is a special purpose language designed to work with World Wide Web pages. That means it is a CGI language (for more about CGI, see my CGI tutorial).

GCL will take a GCL source file, read it, and produce a counter. It will also write a new version of the source file. That way, next time you run it, the counter will be updated, that is the count will be increased by one. However, you can override this any time you want. To see the override in action, let’s take a look at the counter you have seen on page 1. This time, let’s make it display the code number of my favorite spy:

Now, let’s see what happens if we display more than three digits:

As you can see, the counter now contains a comma separating the thousands from the hundreds. This is optional.

Creating Counters

To create a counter with GCL, you start by creating several graphics. At the minimum, you need 10 graphics, one for each digit. Other graphics are optional. We will talk about them as the need arises. For our example, we need a separate graphic containing the picture of a comma. We also need a “tile” graphic which contains the white noise in the background.

To produce the digits, I started by creating a blank button using my button maker. Then I used Corel Paint to place the digits on the face of the button. I saved the images in files n0.gif through n9.gif.

That alone is enough to create a simple counter using GCL. Assuming that your GCL program (named just gcl, in lower case) is placed in your /usr/bin directory, you would start your program code by typing this at beginning of the source code file:

#!/usr/bin/gcl

This alone is not part of the language. Rather, it tells the Unix shell where to find the GCL program. On my system, I called the program for this counter marble.gcl. Upon seeing the first line, the Unix shell will invoke gcl as if the following command were entered:

/usr/bin/gcl marble.gcl

Believe it or not, even if you had nothing else in the source file, GCL would produce a tiny GIF graphic and send it out to the browser. Not having any other instructions, GCL would just create a single pixel GIF. This is to prevent the browser from having to wait for something that never comes.

Of course, we do have the ten GIF files. We need to tell GCL what their file names are, where they are located, what digits they represent, and that they are in GIF format. Assuming the graphics are in the /usr/pix directory, we do that by entering the following lines next:

## Declare the "digit" files
#0 "/usr/pix/n0.gif" gif
#1 "/usr/pix/n1.gif" gif
#2 "/usr/pix/n2.gif" gif
#3 "/usr/pix/n3.gif" gif
#4 "/usr/pix/n4.gif" gif
#5 "/usr/pix/n5.gif" gif
#6 "/usr/pix/n6.gif" gif
#7 "/usr/pix/n7.gif" gif
#8 "/usr/pix/n8.gif" gif
#9 "/usr/pix/n9.gif" gif

The order in which we list them is unimportant. Nor do they need to be on separate lines. We could do something like:

#1"/usr/pix/n5.gif"
gif#4
"/usr/pix/n4.gif"gif#2"/usr/pix/n2.gif"


gif
#5
"/usr/pix/n5.gif"gif#1"/usr/pix/n1.gif"
gif
[etc...]

Admittedly, the first version is much easier for us to read even if GCL does not care...

Note that I entered #1 twice, each time listing a different file. This is perfectly all right. GCL will use whichever file was listed last.

This is a deliberate feature of GCL. I will explain its purpose later on when talking about making changes to source files.

Also note I preceded the list with ## Declare the "digit" files. This is a GCL comment. A comment starts with a hash mark (#) and extends to the end of the line.

Obviously, each line of the file list starts with a hash mark too. In this case, the hash mark is immediately followed by a single digit. It is, therefore, a very good idea to start comments with two hash marks.

Setting Permissions

At this point we have a perfectly valid GCL program. All we need to do is change the file permissions. We need to let Unix know this is an executable program. We also need to let anyone read it and write to it. Otherwise, GCL could not change it, and the counter would always show a zero. We change the permissions with the following Unix command:

chmod 777 marble.gcl

We can now enter it to our HTML code. Assuming, it is in the /cgi-bin directory of our web page, we would insert the following at the place where we want the counter to show up:

<img src="/cgi-bin/marble.gcl">

If we now loaded our web page, we would see the counter which would look exactly like n0.gif. If, after that, we would read the marble.gcl file, we would see that it has changed. It would look like this:

#!/usr/bin/gcl
#0 "/usr/pix/n0.gif" gif
#1 "/usr/pix/n1.gif" gif
#2 "/usr/pix/n2.gif" gif
#3 "/usr/pix/n3.gif" gif
#4 "/usr/pix/n4.gif" gif
#5 "/usr/pix/n5.gif" gif
#6 "/usr/pix/n6.gif" gif
#7 "/usr/pix/n7.gif" gif
#8 "/usr/pix/n8.gif" gif
#9 "/usr/pix/n9.gif" gif
count = 1

The next time we would load our web page, the counter would look like n1.gif, etc. Once we come to number 10, the counter would look like n1.gif immediately followed by n0.gif. The source file would be changed to:

#!/usr/bin/gcl
#0 "/usr/pix/n0.gif" gif
#1 "/usr/pix/n1.gif" gif
#2 "/usr/pix/n2.gif" gif
#3 "/usr/pix/n3.gif" gif
#4 "/usr/pix/n4.gif" gif
#5 "/usr/pix/n5.gif" gif
#6 "/usr/pix/n6.gif" gif
#7 "/usr/pix/n7.gif" gif
#8 "/usr/pix/n8.gif" gif
#9 "/usr/pix/n9.gif" gif
count = 11

The value of “count” would always be the number to be displayed the next time the program is run.

Copyright © 1999 G. Adam Stanislav
All rights reserved

Don’t take my word for it. Below is a counter which is created by the code we have seen so far. Hit the reload button to see it change. Then click on the counter to get to page 3.

< ] [ GCL Home ] [ CGI Tutorial ] [ Home ] [ > ]