home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / ADJSCROL.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  98 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  ADJSCROL.C - Display lines to the screen, adjusting the scroll rate
  5. **
  6. **  public domain demo by Bob Stout
  7. */
  8.  
  9. #include <stdio.h>
  10. #include "more.h"
  11.  
  12. static int cols;
  13. static long pause = 500;                  /* Default to 1/2 second      */
  14.  
  15. /*
  16. **  adj_scroll() - Display a line, dynamically adjusting the scroll rate
  17. **
  18. **  Parameters: 1 - Line to display
  19. **
  20. **  Returns: Key_ESC ('\x1b') if ESC pressed, else 0
  21. **
  22. **  Notes: Reads screen size from BIOS
  23. **         Handles long line wrapping
  24. **         Key_ESC to exit via calling function
  25. **         Key_PGUP to speed scrolling
  26. **         Key_PGDN to slow scrolling
  27. */
  28.  
  29. int adj_scroll(char *str)
  30. {
  31.       char linebuf[256];
  32.       int ch;
  33.  
  34.       if (!cols)
  35.             cols = SCREENCOLS;
  36.  
  37.       if (strlen(str) == ((size_t)cols + 1) && LAST_CHAR(str) == '\n')
  38.                   LAST_CHAR(str) = NUL;
  39.  
  40.       while (strlen(str) > (size_t)cols)
  41.       {
  42.             strn1cpy(linebuf, str, cols);
  43.             linebuf[cols] = NUL;
  44.             adj_scroll(linebuf);
  45.             strMove(str, str + cols);
  46.       }
  47.  
  48.       fputs(str, stderr);
  49.       delay((int)pause);
  50.  
  51.       if (EOF != (ch = ext_inkey()))
  52.       {
  53.  
  54.             switch (ch)
  55.             {
  56.             case Key_ESC:
  57.                   return ch;
  58.  
  59.             case Key_PGUP:
  60.                   pause *= 3L;            /* Reduce pause by 25%        */
  61.                   pause /= 4L;
  62.                   break;
  63.  
  64.             case Key_PGDN:
  65.                   pause *= 125L;          /* Increase pause by 25%      */
  66.                   pause /= 100L;
  67.                   break;
  68.             }
  69.       }
  70.       return 0;
  71. }
  72.  
  73. #ifdef TEST
  74.  
  75. #include "errors.h"                             /* For cant()           */
  76.  
  77. main(int argc, char *argv[])
  78. {
  79.       FILE *fp;
  80.       char buf[512];
  81.  
  82.       while (--argc)
  83.       {
  84.             fp = cant(*++argv, "r");
  85.  
  86.             while (!feof(fp))
  87.             {
  88.                   if (NULL == fgets(buf,  512, fp))
  89.                         break;
  90.                   if (Key_ESC == adj_scroll(buf))
  91.                         break;
  92.             }
  93.       }
  94.       return 0;
  95. }
  96.  
  97. #endif /* TEST */
  98.