⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zreceive.c

📁 communication source code Zmodem
💻 C
📖 第 1 页 / 共 3 页
字号:
         begin

            /*--------------------------------------------------------------*/
            /* Set buffer length (0=unlimited, don't wait).                 */
            /* Also set capability flags                                    */
            /*--------------------------------------------------------------*/
            Z_PutLongIntoHeader(0L);
            Txhdr[ZF0] = CANFDX|CANOVIO;
            Z_SendHexHeader(Tryzhdrtype, Txhdr);

AGAIN:

            switch (Z_GetHeader(Rxhdr))
               begin
                  case ZFILE:    /*-----------------------------------------*/
                                 /*                                         */
                                 /*-----------------------------------------*/
                                 Zconv = Rxhdr[ZF0];
                                 Tryzhdrtype = ZRINIT;
                                 if (RZ_ReceiveData(Secbuf,WAZOOMAX)==GOTCRCW)
                                    return ZFILE;
                                 Z_SendHexHeader(ZNAK, Txhdr);
                                 goto AGAIN;

                  case ZSINIT:   /*-----------------------------------------*/
                                 /*                                         */
                                 /*-----------------------------------------*/
                                 if (RZ_ReceiveData(Attn, ZATTNLEN) == GOTCRCW)
                                    Z_SendHexHeader(ZACK, Txhdr);
                                 else Z_SendHexHeader(ZNAK, Txhdr);
                                 goto AGAIN;

                  case ZFREECNT: /*-----------------------------------------*/
                                 /*                                         */
                                 /*-----------------------------------------*/
                                 Z_PutLongIntoHeader(DiskAvail);
                                 Z_SendHexHeader(ZACK, Txhdr);
                                 goto AGAIN;

                  case ZCOMMAND: /*-----------------------------------------*/
                                 /* Paranoia is good for you...             */
                                 /* Ignore command from remote, but lie and */
                                 /* say we did the command ok.              */
                                 /*-----------------------------------------*/
                                 if (RZ_ReceiveData(Secbuf,WAZOOMAX)==GOTCRCW)
                                    begin
                                       status_line("!Ignoring `%s'", Secbuf);
                                       Z_PutLongIntoHeader(0L); 
                                       do
                                          begin
                                             Z_SendHexHeader(ZCOMPL, Txhdr);
                                          end
                                       while (++errors<10 && Z_GetHeader(Rxhdr) != ZFIN);
                                       RZ_AckBibi();
                                       return ZCOMPL;
                                    end
                                 else Z_SendHexHeader(ZNAK, Txhdr);
                                 goto AGAIN;

                  case ZCOMPL:   /*-----------------------------------------*/
                                 /*                                         */
                                 /*-----------------------------------------*/
                                 goto AGAIN;

                  case ZFIN:     /*-----------------------------------------*/
                                 /*                                         */
                                 /*-----------------------------------------*/
                                 RZ_AckBibi();
                                 return ZCOMPL;

                  case ZCAN:
                  case RCDO:     /*-----------------------------------------*/
                                 /*                                         */
                                 /*-----------------------------------------*/
                                 return ERROR;
               end /* switch */

         end /* for */

      return ERROR;

   end /* RZ_InitReceiver */




/*--------------------------------------------------------------------------*/
/* RZFILES                                                                  */
/* Receive a batch of files using ZMODEM protocol                           */
/*--------------------------------------------------------------------------*/
static int pascal RZ_ReceiveBatch(xferinfo)
   FILE *xferinfo;
   begin
      register int c;

      set_xy("");
      while(1)
         begin
            switch (c = RZ_ReceiveFile(xferinfo))
               begin
                  case ZEOF:
                  case ZSKIP:
                              switch (RZ_InitReceiver())
                                 begin
                                    case ZCOMPL:   return OK;
                                    default:       return ERROR;
                                    case ZFILE:    break;
                                 end /* switch */
                              break;

                  default:
                              fclose(Outfile);
                              Outfile  = NULL;
                              unlink(Filename);
                              errno    = 0;
                              return c;
               end /* switch */

         end /* while */

   end /* RZ_ReceiveBatch */




/*--------------------------------------------------------------------------*/
/* RZ RECEIVE FILE                                                          */
/* Receive one file; assumes file name frame is preloaded in Secbuf         */
/*--------------------------------------------------------------------------*/
static int pascal RZ_ReceiveFile(xferinfo)
   FILE *xferinfo;
   begin
      register int   c;
      int            n;
      long           rxbytes;

      EOFseen=FALSE;
      if (RZ_GetHeader() == ERROR)  return (Tryzhdrtype = ZSKIP);

      n        = 10;
      rxbytes  = 0L;

      while(1)
         begin
            Z_PutLongIntoHeader(rxbytes);
            Z_SendHexHeader(ZRPOS, Txhdr);
NxtHdr:
            switch (c = Z_GetHeader(Rxhdr))
               begin
                  case ZDATA:    /*-----------------------------------------*/
                                 /* Data Packet                             */
                                 /*-----------------------------------------*/
                                 if (Rxpos != rxbytes)
                                    begin
                                       if ( --n < 0) return ERROR;
                                       z_message(NULL);
                                       cprintf("Bad pos; %ld/%ld",rxbytes,Rxpos);
                                       Z_PutString(Attn);
                                       continue;
                                    end
MoreData:
                                 switch (c = RZ_ReceiveData(Secbuf,WAZOOMAX))
                                    begin
                                       case ZCAN:
                                       case RCDO:  /*-----------------------*/
                                                   /* CAN or CARRIER        */
                                                   /*-----------------------*/
                                                   z_log(Cancelled_msg);
                                                   return ERROR;

                                       case ERROR: /*-----------------------*/
                                                   /* CRC error             */
                                                   /*-----------------------*/
                                                   if (--n<0)
                                                      begin
                                                         z_log( FUBAR_msg );
                                                         return ERROR;
                                                      end
                                                   show_loc(rxbytes,n);
                                                   Z_PutString(Attn);
                                                   continue;

                                       case TIMEOUT: /*---------------------*/
                                                   /*                       */
                                                   /*-----------------------*/
                                                   if (--n<0)
                                                      begin
                                                         z_log( TIME_msg );
                                                         return ERROR;
                                                      end
                                                   show_loc(rxbytes,n);
                                                   continue;

                                       case GOTCRCW: /*---------------------*/
                                                   /* End of frame          */
                                                   /*-----------------------*/
                                                   n = 10;
                                                   if (RZ_SaveToDisk(&rxbytes)==ERROR)
                                                      return ERROR;
                                                   Z_PutLongIntoHeader(rxbytes);
                                                   Z_SendHexHeader(ZACK, Txhdr);
                                                   goto NxtHdr;

                                       case GOTCRCQ: /*---------------------*/
                                                   /* Zack expected         */
                                                   /*-----------------------*/
                                                   n = 10;
                                                   if (RZ_SaveToDisk(&rxbytes)==ERROR)
                                                      return ERROR;
                                                   Z_PutLongIntoHeader(rxbytes);
                                                   Z_SendHexHeader(ZACK, Txhdr);
                                                   goto MoreData;

                                       case GOTCRCG: /*---------------------*/
                                                   /* Non-stop              */
                                                   /*-----------------------*/
                                                   n = 10;
                                                   if (RZ_SaveToDisk(&rxbytes)==ERROR)
                                                      return ERROR;
                                                   goto MoreData;

                                       case GOTCRCE: /*---------------------*/
                                                   /* Header to follow      */
                                                   /*-----------------------*/
                                                   n = 10;
                                                   if (RZ_SaveToDisk(&rxbytes)==ERROR)
                                                      return ERROR;
                                                   goto NxtHdr;
                                    end /* switch */

                  case ZNAK:
                  case TIMEOUT:  /*-----------------------------------------*/
                                 /* Packed was probably garbled             */
                                 /*-----------------------------------------*/
                                 if ( --n < 0)
                                    begin
                                       z_log( "Garbled packet" );
                                       return ERROR;
                                    end
                                 show_loc(rxbytes,n);
                                 continue;

                  case ZFILE:    /*-----------------------------------------*/
                                 /* Sender didn't see our ZRPOS yet         */
                                 /*-----------------------------------------*/
                                 RZ_ReceiveData(Secbuf, WAZOOMAX);
                                 continue;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -