home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / lib_term / center.c next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.8 KB  |  106 lines

  1. #include <strings.h>
  2.  
  3. void center(line, string, mode)
  4. int line;
  5. char *string;
  6. int mode;
  7.  
  8. /*
  9.  ---------------------------------------------------------------------------
  10.  
  11.    Last revision - 
  12.     17 January 1985 - GWS
  13.     Change to use screen width from termcap.
  14.  
  15.      2 April 1984 - GWS
  16.  
  17.  
  18.    NAME
  19.      center - center string in screen on specified line
  20.  
  21.    SYNOPSIS
  22.     void center(line, string, mode)
  23.     int line;
  24.     char *string;
  25.     int mode;
  26.  
  27.    DESCRIPTION
  28.     This routine uses the termcap(3x) routines to center and
  29.     optionally emphasize a string.  'Line' is the terminal line
  30.     number on which the string is to be placed, numbered starting
  31.     with 1.  'Mode' takes one of three values:
  32.         0 - no control characters sent
  33.         1 - underline mode turned on before and off after 'string'
  34.         2 - stand-out mode turned on before and off after 'string'
  35.     A call to InitTerm must be made before the first call to center.
  36.  
  37.    SEE ALSO
  38.     termcap(3x), InitTerm, underline, StandOut 
  39.  
  40.    DIAGNOSTICS
  41.     none 
  42.  
  43.    BUGS
  44.     does not check for string too long to fit on one line 
  45.  
  46.    AUTHOR
  47.      George W. Sherouse
  48.      31 March 1984
  49.  
  50.  ---------------------------------------------------------------------------
  51. */
  52.  
  53. {
  54.     int col;
  55.     int cookie;
  56.  
  57.     int strlen();
  58.     void gotoxy();
  59.     void underline();
  60.     void StandOut();
  61.  
  62.     col = (tgetnum("co") - strlen(string)) / 2;
  63.     switch (mode)
  64.     {
  65.     case 0:
  66.     break;
  67.     case 1:
  68.     cookie = tgetnum("ug");
  69.     if (cookie > 0)
  70.         col -= cookie;
  71.     break;
  72.     case 2:
  73.     cookie = tgetnum("sg");
  74.     if (cookie > 0)
  75.         col -= cookie;
  76.     break;
  77.     }
  78.     gotoxy(col, line);
  79.     switch (mode)
  80.     {
  81.     case 0:
  82.     break;
  83.     case 1:
  84.     underline(1);
  85.     break;
  86.     case 2:
  87.     StandOut(1);
  88.     break;
  89.     }
  90.  
  91.     printf(string);
  92.  
  93.     switch (mode)
  94.     {
  95.     case 0:
  96.     break;
  97.     case 1:
  98.     underline(0);
  99.     break;
  100.     case 2:
  101.     StandOut(0);
  102.     break;
  103.     }
  104.     return;
  105. }
  106.