home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / HARDDISK / BADCLU.ZIP / AE.ZIP / USAGE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-05  |  1.4 KB  |  65 lines

  1. /**********************************************************************
  2.  *  
  3.  *  usage.c
  4.  *  
  5.  *  by J. Alan Eldridge 04/05/90
  6.  *  
  7.  *  this code is placed in the public domain
  8.  *  
  9.  *  prints usage messages for user, pausing after N lines,
  10.  *  then exits with value passed to it
  11.  *  
  12.  *********************************************************************/
  13.  
  14. #include <stdio.h>
  15. #include <conio.h>
  16.  
  17. #include "getargs.h"
  18.  
  19. #define CR      '\r'
  20. #define NL      '\n'
  21. #define ESC     0x1b
  22.  
  23. int 
  24. show_txt_w_pause(
  25.     char    **msg_arr,
  26.     int     nlines)
  27. {
  28.     static char pause[] = "<RETURN> for more, <ESC> to quit ";
  29.     int     n;
  30.     int     c;
  31.     char    *cp;
  32.     int     retval;
  33.         
  34.     retval = n = 0;
  35.     while (cp = *msg_arr++) {
  36.         if (++n == nlines) {
  37.             fputs(pause, stderr);
  38.             do {
  39.                 c = getch();
  40.             } while (c != NL && c != ESC && c != CR);
  41.             for (n = 0; n < sizeof(pause) - 1; n++)
  42.                 fputs("\b \b", stderr);
  43.             if (c == ESC) {
  44.                 retval = -1;
  45.                 break;
  46.             }
  47.             n = 0;
  48.         }
  49.         fputs(cp, stderr);
  50.         fputc('\n', stderr);
  51.     }
  52.     return retval;
  53. }    
  54.  
  55. void
  56. usage(
  57.     char    **msg_arr,
  58.     int     nlines,
  59.     int     ecode)
  60. {
  61.     show_txt_w_pause(msg_arr, nlines);
  62.     exit(ecode);
  63. }
  64.  
  65.