home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_06_04 / v6n4071a.txt < prev    next >
Text File  |  1989-09-28  |  2KB  |  43 lines

  1. /* hilevel.c */             /******************************************/
  2. #define DELETE 127                   /* DELETE on most keyboards.     */
  3. #define DELSEQ "\b \b"               /* Backspace,space,backspace.    */
  4. #define IXMAX 256                    /* Max length of input line.     */
  5.  
  6. void rt_putc(c) int c ;     /*** Send a byte to remote terminal. ******/
  7. { while( !txready() ) ;              /* Wait until ready.             */
  8.   txbyte(c) ;                        /* Send it.                      */
  9.   if(c == '\l') rt_putc('\r') ;      /* If LF, send CR too.           */
  10. }
  11.  
  12. int rt_getc()               /********  Get a byte from remote. ********/
  13. { while( !rxready() )   ;            /* Wait until byte available.    */
  14.   return(rxbyte()) ;                 /* Read and return it.           */
  15. }
  16.  
  17. void rt_puts(s) char *s ;   /*******  Send a string to remote, ********/
  18. { while( *s ) rt_putc(*s++) ;        /* no automatic newline.         */
  19. }
  20.  
  21. int rt_gets(s) char *s ;    /**** Get a line from remote, with  *******/
  22. {int ix,c ;                          /* some editing, up to CR.       */
  23.  for(ix=0,c=rt_getc() ; c != '\r' && ix < IXMAX ; c = rt_getc() )   /**/
  24.    { if( c < 32 ) continue ;         /* Ignore CTRL chrs except CR.   */
  25.      if( c == DELETE && ix > 0 )     /* Backup-erase on DELETE.       */
  26.        { rt_puts(DELSEQ) ;                                          /**/
  27.          ix-- ;                                                     /**/
  28.        }                                                            /**/
  29.      else                                                           /**/
  30.        { s[ix++] = c ;               /* Record input byte, and        */
  31.          rt_putc(c) ;                /* echo to remote.               */
  32.        }                                                            /**/
  33.    }                                                                /**/
  34.  s[ix] = '\0' ;                      /* Replace CR with Null.         */
  35.  rt_putc('\l') ;                     /* Echo CR-LF.                   */
  36.  return(ix) ;                        /* Return string length.         */
  37. }
  38.  
  39. /***** For formatted output use sprintf(s,...) ; rt_puts(s) ; *********/
  40.  
  41. /***** For formatted input use rt_gets(s) ; sscanf(s,...) ;   *********/
  42.  
  43.