home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / c / curses / src / wgetstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-30  |  2.7 KB  |  99 lines

  1. /* -*-C-*-
  2.  *
  3.  *
  4.  * Filename : wgetstr.c
  5.  *
  6.  * Author   : Simon J Raybould.    (sie@fulcrum.bt.co.uk).
  7.  *
  8.  * Date     : Friday 23rd August 1991.
  9.  *
  10.  * Desc     : Read a string from the keyboard, provide del facility.
  11.  *
  12.  *
  13.  * THIS CODE IS NOT PUBLIC DOMAIN
  14.  * ==============================
  15.  * 
  16.  * This code is copyright Simon J Raybould 1991, all rights are reserved.
  17.  * All code, ideas, data structures and algorithms remain the property of the
  18.  * author. Neither the whole nor sections of this code may be used as part
  19.  * of other code without the authors consent. If you wish to use some of this
  20.  * code then please email me at (sie@fulcrum.bt.co.uk).
  21.  *
  22.  * This source is not public domain, so you do not have any right to alter it
  23.  * or sell it for personal gain. The source is provided purely for reference
  24.  * purposes. You may re-compile the source with any compiler you choose.
  25.  * You must not distribute altered copies without the authors consent. My
  26.  * intention is that the source will help people isolate any bugs much more
  27.  * effectivly.
  28.  *
  29.  * Disclaimer
  30.  * ==========
  31.  *
  32.  * No implication is made as to this code being fit for any purpose at all.
  33.  * I (the author) shall not be held responsible for any loss of data or damage 
  34.  * to property that may result from its use or misuse.
  35.  *
  36.  *
  37.  * Revision History
  38.  * ================
  39.  *
  40.  * $Log:    wgetstr.c,v $
  41.  * Revision 1.2  92/06/10  23:45:00  sie
  42.  * Added serial support.
  43.  * 
  44.  * Revision 1.1  91/09/07  11:50:18  sie
  45.  * Initial revision
  46.  * 
  47.  *
  48.  */
  49.  
  50. static char *rcsid = "$Header: SRC:lib/curses/src/RCS/wgetstr.c,v 1.2 92/06/10 23:45:00 sie Exp $";
  51.  
  52. #include "acurses.h"
  53.  
  54.  
  55. wgetstr(WINDOW *WinPtr, char *ptr)
  56. {
  57.   char done = FALSE, *BuffStart;
  58.   unsigned char CbreakSet;  /* Used to restore after */
  59.   
  60.   if(!(CursesFlags & CFLAG_INITSCR))  /* Haven't called initscr() */
  61.     return ERR;
  62.   
  63.   BuffStart = ptr;
  64.   
  65.   /* Will need to be in CBREAK mode for this */
  66.   CbreakSet = CursesFlags & CFLAG_CBREAK;
  67.   cbreak();
  68.   while(!done) {
  69.     switch(*ptr = wgetch(WinPtr)) {
  70.     case -1:  /* wgetch() returned ERROR */
  71.       *ptr = '\0';
  72.       if(!CbreakSet)        /* if wasn't set then unset cbreak */
  73.     nocbreak();
  74.       return -1;
  75.     case '\n':
  76.     case '\r':
  77.       *ptr = '\0';
  78.       done = TRUE;
  79.       break;
  80.     case '\b':
  81.       if(--ptr < BuffStart)  /* Don't move before start */
  82.     ptr = BuffStart;
  83.       else if(CursesFlags & CFLAG_ECHO) {
  84.     /* Do BS SP BS processing */
  85.     mvcur(CursorLine, CursorCol, CursorLine, CursorCol - 1);  /* BS */
  86.     DoEcho(WinPtr, ' ');          /* SP */
  87.     mvcur(CursorLine, CursorCol, CursorLine, CursorCol - 1);  /* BS */
  88.       }
  89.       break;
  90.     default:
  91.       ptr++;
  92.       break;
  93.     }
  94.   }
  95.   if(!CbreakSet)        /* if wasn't set then unset cbreak */
  96.     nocbreak();
  97.   return 0;
  98. }
  99.