#include <setjmp.h>
#include <ctype.h>
#include <string.h>
#include <conio.h>

#include "extern.h"

extern jmp_buf env;

rswait()     /* receive sentence from RS232C  RS232C->*rsent */

        {int i = 0 , ix = 0, ibuff, ch = 0;
         
         kanji = 0;
         
         t_mset(3);    /*  3分間着信なければ異常終了  */
                   
         while(1)
             {if ( t_itrpt() )
                 { return(1);
                 }
                                             /* ﾀｲﾑ･ｱｳﾄ ｼｮﾘ */

	 		 if( kbhit() )
                    {  ch = getch();
                       if ( ch == 0x18 )
						  { return(1);
						  }
						ch = NULL;
					    continue;
					}

              while( rshit() ) 
                  {  
		             ch = rsbread();
               
                     if ( ch != 0x0d && iscntrl(ch) )
                        { continue; }
                                          
                      *(rsent + i) = ch;
                      if ( moniflg ) putchar(ch);
					  if ( ch == 0x0d ) *(rsent + i) = '\n';
                      i++; 
                      if ( ch == 0x0d || i > 255 )    break;
                  }
            if ( ch == 0x0d )  { addlf(ch); break; }
            if ( i > 255 ) break;
           }           
         *(rsent + i) = NULL;
	     return(0);
       }

