#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
/*
#include <signal.h>
*/

#define MAIN

#include "inc.h"
extern jmp_buf env;

main(argc,argv)
   
    int argc;
    char *argv[];
    
        {int i,j = 1,flg = 0; 
      
        printf("FM-BBS SYSTEM    Copyright by A.Mizushima\n");
        if ( argc < 3 ) { printf("Usage FORWARD port_No. 相手ID\n");
					      exit(1);
					    }
		printf("ファイル交換処理  Ver_1.1\n");
	    devdrv = atoi(argv[1]);
		idcpy(hiscall,argv[2]);
		printf("to=%sdev=%d\n",hiscall,devdrv);
 /*     signal(SIGINT,SIG_IGN);  */
        if  ( config_read() ) { return(0); }

		setstr();
		hischk();   
		mctype = chkmc();
		if ( ! slave && rsopen() )  exit(1);

        nwdate();

        junle();
        chgjyo("BEGIN");

        while(1)
             { if ( setjmp(env) )
                  { if (fp1) fclose(fp1);
                    chgjyo("ABEND");
					break;
                  }
                        /* ｷｮｳｾｲ disconne , ｼﾞｭｼﾝ ﾀｲﾑｱｳﾄ ﾄﾞｷ ﾉ ﾓﾄﾞﾘｻｷ */

        	    if ( slave ) { sndstat();
                               filrec();
                               filsend();
                             }
                  else       { if ( hiscon() ) { flg = 1; break; }
							   rcvstat();
                               filsend();
                               filrec();
                               while( chkcd() ) { rsans(3); }
                             }                       
				reccont();
                log();

                chgjyo("WAIT");
				break;
             }  
		  if ( ! slave ) rsclose();          
          remove(forward_fil); remove(temp_fil); remove(rcv_fil);
          exit(flg);
        }
