home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / GOTODOS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  1.8 KB  |  100 lines

  1. /*
  2.  * gotodos.c
  3.  * contains: gotodos(),kbflush(),getyn(),escape()
  4.  *
  5.  *   Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  6.  *
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include "gfuncts.h"
  12. #include "ibmkeys.h"
  13.  
  14.  
  15. /*
  16.  *  void
  17.  * gotodos(void)
  18.  *
  19.  * DESCRIPTION
  20.  *  Clear the screen, display a message in the middle of the screen, and
  21.  *  a response is solicited (y/n).  If 'y', an immediate exit is taken
  22.  *  to DOS.  Otherwise, the function returns.
  23.  *
  24.  * MODIFICATIONS
  25.  *
  26.  */
  27. void GF_CONV gotodos()
  28. {
  29.     cls();
  30.     atsay(12,10,"Do you want to exit to DOS ? (y/n) ");
  31.     if(getyn()==YES)
  32.         exit(0);
  33. }
  34.  
  35. /*
  36.  *  void
  37.  * kbflush(void)
  38.  *
  39.  * DESCRIPTION
  40.  *  This functions removes all characters from the keyboard queue
  41.  *  via rom bios.
  42.  */
  43. void GF_CONV kbflush()
  44. {
  45.     while(gfkbhit())
  46.         kbfetch();
  47. }
  48.  
  49. /*
  50.  *  char
  51.  * getyn()
  52.  *
  53.  * DESCRIPTION
  54.  *  The keyboard is read using getkey(), a 'y' or 'Y' or 'n' or 'N' or
  55.  *  ESC or Ctrl-Break must be entered to return from this function.  Y/N
  56.  *  entries also cause "YES" or "NO" to be displayed on stdout.
  57.  *
  58.  * RETURNS
  59.  *  0 = 'n' or 'N' entered
  60.  *  1 = 'y' or 'Y' entered
  61.  *  0x1b (ESC) = ESC entered
  62.  *  2 = Ctrl-Break entered
  63.  */
  64. char GF_CONV getyn()
  65. {
  66.     unsigned c;
  67.     
  68.     while (FOREVER) {
  69.         c = getkey();
  70.         if ((c=='y')||(c=='Y')) {
  71.             prints("YES");
  72.             return YES;
  73.         } else if((c=='n')||(c=='N')) {
  74.             prints("NO");
  75.             return NO;
  76.         }
  77.         else if(c==ESC)
  78.             return ESC;
  79.         else if(c==0)
  80.             return 2;    /* Ctrl-Break */
  81.     }
  82. }
  83.  
  84. /*
  85.  *  void
  86.  * escape(void)
  87.  *
  88.  * DESCRIPTION
  89.  *  The keyboard is tested (via gfkbhit()); If there is no keystroke return
  90.  *  If there is a keystroke, fetch it and test for ESCAPE, if so exit to
  91.  *  dos.
  92.  */
  93. void GF_CONV escape()
  94. {
  95.     if(!gfkbhit())
  96.         return;
  97.     else if(getkey()==ESC)
  98.         exit(0);
  99. }
  100.