home *** CD-ROM | disk | FTP | other *** search
- #include <string.h>
- #include <stdlib.h>
-
- /************************************************************************/
-
- #include "main.h"
- #include "File.h"
- #include "FormatNode.h"
-
- /************************************************************************/
- /* */
- /* Determine column widths for a node. */
- /* Returns a 0-terminated array of column widths */
- /* */
- /* The NextButton() function is expected to return the label of the */
- /* label of the next button. */
- /* "" tells us to start a new line */
- /* */
- /************************************************************************/
-
- int *
- FormatNode (char *(*NextLabel) (char *, void *),
- void *Parameters)
-
- {
- int *ColWidth;
- int Columns;
- char *ButtonLabel;
-
- Columns = *Arguments.Width / 4;
- ColWidth = xmalloc ((Columns + 1) * sizeof (*ColWidth));
-
- do
- {
- int Column;
- int LineWidth;
-
- memset (ColWidth, 0, (Columns + 1) * sizeof (*ColWidth));
- ButtonLabel = NULL;
-
- Column = 0;
- LineWidth = 0;
- while ((ButtonLabel = NextLabel (ButtonLabel, Parameters)))
- {
- size_t Width;
-
- if ((Width = strlen (ButtonLabel)))
- {
- if (Width > ColWidth[Column])
- ColWidth[Column] = Width;
- LineWidth += ColWidth[Column] + ((*Arguments.Version) >= 39);
- if (LineWidth > *Arguments.Width)
- {
- break;
- }
- Column++;
- if (Column == Columns)
- {
- Column = 0;
- LineWidth = 0;
- }
- else
- {
- LineWidth += 3;
- }
- }
- else
- {
- Column = 0;
- LineWidth = 0;
- }
- }
- free (ButtonLabel);
- }
- while (ButtonLabel && --Columns);
- return ColWidth;
- }
-
- /************************************************************************/
- /* */
- /* Print a table of buttons. */
- /* */
- /************************************************************************/
-
- void
- PrintNode (char *(*NextLabel) (char *, void *),
- void (*PrintLink) (void *),
- void *Parameters, int *ColWidth)
-
- {
- int Column;
- char *Label;
-
- Column = 0;
- Label = NULL;
- while ((Label = NextLabel (Label, Parameters)))
- {
- if (Label[0])
- {
- WPrintf ("@{\x22%s\x22 LINK ", Label);
- PrintLink (Parameters);
- WPrintf ("}");
- Column++;
- if (ColWidth[Column])
- {
- int i;
-
- for (i = 3 + ColWidth[Column - 1] - strlen (Label) - (*Arguments.Version >= 39); i > 0; i--)
- WPrintf (" ");
- }
- else
- {
- Column = 0;
- WPrintf ("\n");
- }
- }
- else
- {
- Column = 0;
- WPrintf ("\n");
- }
- }
- free (Label);
- if (Column)
- {
- WPrintf ("\n");
- }
- }
-