#include <conio.h>
#include <stdlib.h>
#include <ctype.h>

#include "extern.h"

rswait()         /* Ü¯Á µÖËÞ ºÈ¸Ä Ö³·­³ ¹Ý¼­Â */        
       { int ix = 0,ch;
         short itime;
         int wcnt = 0;

         dspjyo();
         while(1)
         {
         wcnt++;
         if ( wcnt > 2000 )
            {
             nwdate();   /* ¼Þº¸ ÊÝÀÞÝ ¼ bbs stop */
             itime = td[3] * 100 + td[4];

             if ( itime > *(resttime) && itime < *(resttime + 1) )
                return(9);
             if ( itime > *(resttime + 2) && itime < *(resttime + 3) )
                bbscall();
             wcnt = 0;
         /*  if ( chkcd() )  longjmp(env,-1); */
                                            /* con ¼Þ®³À² ÃÞ ±ÚÊÞ abend */

            }   
         
         while (rshit())
            { ch = rsbread();
              if ( moniflg ) 
                 { if (! iscntrl(ch) ) putchar(ch);
                   if ( ch == 0x0d  )  { putchar(ch);
					 addlf(ch);
				       }                   
                 }
                 
              if ( ix == 7 ) 
                 {
				break;
                  }
             else
               { if ( *(cneted + ix) == ch) { ix++; }
                  else ix = 0; }                /* ºÈ¸Ä Î³º¸ ¹Ý¼­Â */
            }
         if ( ix == 7 ) 
			{ while(1)
				{ if ( rshit() )
					{ ch = rsbread(); putchar(ch);
					  if ( ch == '\n' ) { addlf(ch); break; }
					}
				}
			  break;
			}
       
         if ( kbhit() )                      /* sysop key ÎÞ°ÄÞ ¹Ý¼­Â */
            {  ch = getch();
               if ( ch == 0x18 )              /* ctrl-x  for BBS end */
				  {	 return(9);
				  }
			   rsbwrite(ch); putchar(ch); addlf(ch);
            }
      }
         
     return(1);
   }
        


bbscall()
	{
		int i;

		if ( next_bbs == 9999 )  return(0);
		fpw = fopen(CALLMAS,"r");
		if ( fpw == NULL ) return(0);
		for ( i = 1 ; ; i++ )
			{ if ( fgets(fbuff,255,fpw) == NULL )
				 { next_bbs == 9999;
				   fclose(fpw);
				   return(0);
				 }
			  if ( i != next_bbs ) continue;
			  substr(fbuff,0,8,hiscall);
			  break;
			}
		fclose(fpw);

		rsclose();
		if ( exeforward() <= 0 ) next_bbs++;
		rsopen();
		return(0);
	}

