1: /* $Header$ */
   2: 
   3: /*
   4:  * Author: Peter J. Nicklin
   5:  */
   6: 
   7: /*
   8:  * slsprint() prints a list slslist on named output stream. The list is
   9:  * printed in ncol keys per line with column width colwidth. If tab is
  10:  * an integer YES, keys will be padded by tabs, otherwise blanks. If
  11:  * keys are padded by tabs, colwidth should be a multiple of TABSIZE.
  12:  */
  13: #include <stdio.h>
  14: #include "null.h"
  15: #include "slslist.h"
  16: #include "yesno.h"
  17: 
  18: #define TABSIZE 8
  19: 
  20: static int tabflag;
  21: 
  22: void
  23: slsprint(ncol, colwidth, tab, stream, slslist)
  24:     int ncol;           /* number of columns */
  25:     int colwidth;           /* maximum column width */
  26:     int tab;            /* tab or blank padding */
  27:     FILE *stream;           /* output stream */
  28:     SLSLIST *slslist;       /* pointer to list head block */
  29: {
  30:     int col;            /* column index	*/
  31:     int kc;             /* key count */
  32:     int kn;             /* key number */
  33:     int lastkn = 1;         /* last key number */
  34:     int nlcols;         /* number of longer columns */
  35:     int nrows;          /* maximum number of rows */
  36:     int row;            /* row index */
  37:     SLSBLK *curblk;         /* current list block */
  38:     void putkey();          /* put key on stream */
  39: 
  40:     tabflag = tab;
  41: 
  42:     nrows = slslist->nk/ncol + 1;
  43:     nlcols = slslist->nk % ncol;
  44:     curblk = slslist->head;
  45:     for (kc=1, row=1; row <= nrows; row++)
  46:         for (col = 1; col <= ncol && kc <= slslist->nk; col++, kc++)
  47:             {
  48:             if (col <= nlcols)
  49:                 kn = (nrows*(col-1)) + row;
  50:             else
  51:                 kn = ((nrows-1)*(col-1)) + nlcols + row;
  52: 
  53:             if (lastkn > kn)
  54:                 {
  55:                 curblk = slslist->head;
  56:                 lastkn = 1;
  57:                 }
  58:             for (; lastkn < kn; lastkn++)
  59:                 curblk = curblk->next;
  60: 
  61:             if (col == ncol || kc == slslist->nk)
  62:                 {
  63:                 fputs(curblk->key, stream);
  64:                 putc('\n', stream);
  65:                 }
  66:             else
  67:                 putkey(curblk->key, colwidth, stream);
  68:             }
  69: }
  70: 
  71: 
  72: 
  73: /*
  74:  * Putkey prints a key, left-justified in a field of colwidth characters.
  75:  * The key is padded on the right by tabs or blanks.
  76:  */
  77: static void
  78: putkey(key, colwidth, stream)
  79:     char *key;          /* key string */
  80:     int colwidth;           /* maximum column width */
  81:     FILE *stream;           /* output stream */
  82: {
  83:     while (*key != '\0' && colwidth-- > 0)
  84:         putc(*key++, stream);
  85: 
  86:     if (colwidth > 0)
  87:         if (tabflag == YES)
  88:             for (; colwidth > 0; colwidth -= TABSIZE)
  89:                 putc('\t', stream);
  90:         else while (colwidth-- > 0)
  91:             putc(' ', stream);
  92: }

Defined functions

putkey defined in line 77; used 2 times
slsprint defined in line 22; never used

Defined variables

tabflag defined in line 20; used 2 times

Defined macros

TABSIZE defined in line 18; used 1 times
  • in line 88
Last modified: 1985-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 794
Valid CSS Valid XHTML 1.0 Strict