home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / cvs-1.8.7-src.tgz / tar.out / fsf / cvs / os2 / getpass.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  1KB  |  68 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "cvs.h"
  4.  
  5. #define INCL_BASE
  6. #define INCL_SUB
  7. #define INCL_KBD
  8. #include <os2.h>
  9.  
  10. /* Only define this if you're testing and want to compile this file
  11.    standalone. */
  12. /* #define DIAGNOSTIC */
  13.  
  14. /* Turn off keyboard echo.  Does not check error returns. */
  15. static void
  16. EchoOff (void)
  17. {
  18.   KBDINFO KbdInfo;
  19.   
  20.   KbdGetStatus (&KbdInfo, 0);
  21.   KbdInfo.fsMask = (KbdInfo.fsMask & ~KEYBOARD_ECHO_ON) | KEYBOARD_ECHO_OFF;
  22.   KbdSetStatus (&KbdInfo, 0);
  23. }
  24.  
  25. /* Turn on keyboard echo.  Does not check error returns. */
  26. static void
  27. EchoOn( void )
  28. {
  29.   KBDINFO KbdInfo;
  30.   
  31.   KbdGetStatus (&KbdInfo, 0);
  32.   KbdInfo.fsMask = (KbdInfo.fsMask & ~KEYBOARD_ECHO_OFF) | KEYBOARD_ECHO_ON;
  33.   KbdSetStatus (&KbdInfo, 0);
  34. }
  35.  
  36. char *
  37. getpass (char *prompt)
  38. {
  39.   static char Buf[80];
  40.   STRINGINBUF StringInBuf;
  41.   
  42.   printf ("%s", prompt);
  43.   fflush (stdout);
  44.  
  45.   EchoOff ();
  46.  
  47.   StringInBuf.cb = sizeof (Buf) - 1;
  48.   StringInBuf.cchIn = 0;
  49.   KbdStringIn ((PSZ) Buf, &StringInBuf, IO_WAIT, 0);
  50.   Buf[StringInBuf.cchIn] = '\0';
  51.  
  52.   EchoOn ();
  53.  
  54.   return Buf;
  55. }
  56.  
  57.  
  58. #ifdef DIAGNOSTIC
  59. main()
  60. {
  61.   char *s;
  62.   s = getpass ("Input password (no echo): ");
  63.   printf ("String was \"%s\"\n", s);
  64.   fflush (stdout);
  65. }
  66. #endif /* DIAGNOSTIC */
  67.  
  68.