
/* Free the table created by ArgvToXmStringTable() */
void
FreeXmStringTable(argv)
XmStringTable argv;
{
register int i;
if (!argv)
return;
for (i = 0; argv[i]; i++)
XmStringFree (argv[i]);
XtFree (argv);
}
The output of this program is shown in the figure.
Output of xcal.c
The principal function in the source code is set_month(). In this function, we call popen() to run the UNIX
program cal and read its input into a buffer. Since we know ahead of time about how much text we are going to read,
text is declared with ample space (BUFSIZ). Each line is read consecutively until fgets() returns NULL, at
which time we close the opened process using pclose() and convert the text buffer into a compound string. This
compound string specifies a font list element tag and it includes newlines because fgets() does not strip newline
characters from the strings it retrieves.
The program displays the calendar for the month corresponding to the selected item in the List, but only as a single
Label widget. If we wanted to display individual days using different fonts (with Sundays grayed out, for example),
then the text buffer would have to be parsed. In this case, separate compound strings would be created using a
different font for the Sunday dates only. Since this exercise is more about manipulating compound strings than it is
about Label widgets, we refer you to Chapter 19, Compound Strings, for a detailed ...