home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 419b.lha / TERMLIB / tputs.c < prev    next >
C/C++ Source or Header  |  1990-10-05  |  2KB  |  75 lines

  1. /* TERMLIB: Terminal independant database.
  2.  *
  3.  * Module: tputs
  4.  *
  5.  * Purpose: decode padding information
  6.  *
  7.  * Calling conventions: cp = string to be padded, affcnt = # of items
  8.  *            affected (lines, characters, whatever),
  9.  *            outc = routine to output 1 character.
  10.  *
  11.  * Returned values: none
  12.  *
  13.  * Notes
  14.  *        cp has padding information ahead of it, in the form
  15.  *    nnnTEXT or nnn*TEXT. nnn is the number of milliseconds to delay,
  16.  *    and may be a decimal (nnn.mmm). If the asterisk is given, then
  17.  *    the delay is multiplied by afcnt. The delay is produced by outputting
  18.  *    a number of nulls (or other padding char) after printing the
  19.  *    TEXT.
  20.  *
  21.  */
  22. #include <stdio.h>
  23. #include <ctype.h>
  24. #include "termlib.h"
  25.  
  26. /* tputs.c (libtermlib.a)
  27.  *
  28.  */
  29.  
  30. long _bauds[16]={
  31.     0,    50,    75,    110,
  32.     134,    150,    200,    300,
  33.     600,    1200,    1800,    2400,
  34.     4800,    9600,    19200,    19200 };
  35.  
  36. tputs(cp, affcnt, outc)
  37. char *cp;                                                 /* string to print */
  38. int affcnt;                                      /* Number of lines affected */
  39. int (*outc)();                              /* routine to output 1 character */
  40. {
  41.     long    frac,                    /* 10^(#digits after decimal point) */
  42.         counter,                                           /* digits */
  43.         atol();
  44.  
  45.     if(isdigit(*cp)) {
  46.         counter = 0;
  47.         frac = 1000;
  48.         while(isdigit(*cp))
  49.             counter = counter * 10L + (long)(*cp++ - '0');
  50.         if(*cp=='.')
  51.             while(isdigit(*++cp)) {
  52.                 counter = counter * 10L + (long)(*cp++ - '0');
  53.                 frac = frac * 10;
  54.             }
  55.         if(*cp!='*') {                 /* multiply by affected lines */
  56.             if(affcnt>1) affcnt = 1;
  57.         } 
  58.         else
  59.             cp++;
  60.  
  61.         /* Calculate number of characters for padding counter/frac ms delay */
  62.         if(ospeed)
  63.             counter = (counter * _bauds[ospeed] * (long)affcnt) / frac;
  64.  
  65.         while(*cp)                                  /* output string */
  66.             (*outc)(*cp++);
  67.         if(ospeed)
  68.             while(counter--)            /* followed by pad characters */
  69.                 (*outc)(PC);
  70.     } 
  71.     else
  72.         while(*cp)
  73.             (*outc)(*cp++);
  74. }
  75.