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

📄 zreceive.c

📁 communication source code Zmodem
💻 C
📖 第 1 页 / 共 3 页
字号:
                  case ZEOF:     /*-----------------------------------------*/
                                 /* End of the file                         */
                                 /*-----------------------------------------*/
                                 if (Rxpos != rxbytes)
                                    begin
                                       status_line("-Bad EOF; %ld/%ld", rxbytes, Rxpos);
                                       continue;
                                    end
                                 throughput(2,rxbytes);
                                 errno = 0;

                                 fclose(Outfile);
                                 had_error(CLOSE_msg,Filename);

                                 status_line("=UL %s",Filename);

                                 Outfile  = NULL;
                                 if (xferinfo != NULL)
                                    begin
                                       fprintf(xferinfo, "%s\n", Filename);
                                       had_error(WRITE_msg,"XferInfo");
                                    end
                                 return c;

                  case ERROR:    /*-----------------------------------------*/
                                 /* Too much garbage in header search error */
                                 /*-----------------------------------------*/
                                 if ( --n < 0) return ERROR;
                                 show_loc(rxbytes,n);
                                 Z_PutString(Attn);
                                 continue;

                  default:       /*-----------------------------------------*/
                                 /*                                         */
                                 /*-----------------------------------------*/
                                 z_log( IDUNNO_msg );
                                 return ERROR;

               end /* switch */

         end /* while */

   end /* RZ_ReceiveFile */





/*--------------------------------------------------------------------------*/
/* RZ GET HEADER                                                            */
/* Process incoming file information header                                 */
/*--------------------------------------------------------------------------*/
static int pascal RZ_GetHeader()
   begin

      static char    suffix[] = ".001";

      register byte *p;
      register int   n;

      byte          *ourname;
      byte          *theirname;
      unsigned long  filesize;


      /*--------------------------------------------------------------------*/
      /* Setup the transfer mode                                            */
      /*--------------------------------------------------------------------*/
      isBinary  = (!RXBINARY && Zconv == ZCNL)? 0 : 1;


      /*--------------------------------------------------------------------*/
      /* Extract and verify filesize, if given.                             */
      /* Reject file if not at least 10K free                               */
      /*--------------------------------------------------------------------*/
      filesize = 0L;
      p        = Secbuf + 1 + strlen(Secbuf);
      if (*p) sscanf(p, "%ld", &filesize);
      if (filesize+10240 > DiskAvail)
         begin
            status_line("!Disk space");
            return ERROR;
         end

      /*--------------------------------------------------------------------*/
      /* Get and/or fix filename for uploaded file                          */
      /*--------------------------------------------------------------------*/
      p  = Filename+strlen(Filename)-1;     /* Find end of Opus upload path */
      while (p>=Filename && *p!='\\') p--;
      ourname = ++p;

      p = Secbuf+strlen(Secbuf)-1;      /* Find transmitted simple filename */
      while (p >= Secbuf && *p!='\\' && *p!='/' && *p!=':') p--;
      theirname = ++p;


      strcpy(ourname,theirname);          /* Start w/ our path & their name */

      if (dexists(Filename))
         begin                            /* If file already exists...      */
            p = ourname;
            while (*p && *p!='.') p++;    /* ...find the extension, if any  */
            for (n=0; n<4; n++)           /* ...fill it out if neccessary   */
               if (!*p)
                  begin
                     *p       = suffix[n];
                     *(++p)   = '\0';
                  end
               else p++;

            while (dexists(Filename))    /* ...If 'file.ext' exists suffix++ */
               begin
                  p = ourname+strlen(ourname)-1;
                  for (n=3; n--;)
                     begin
                        if (!isdigit(*p)) *p = '0';
                        if (++(*p) <= '9') break;
                        else *p-- = '0';
                     end /* for */
               end /* while */
         end /* if exist */


      errno = 0;
      if (strcmp(ourname,theirname))
         status_line("+Dupe renamed: %s",ourname);
   
      errno = 0;
      Outfile = fopen( Filename, write_binary );
      if (had_error(OPEN_msg,Filename)) return ERROR;

   	set_xy(NULL);
      cprintf("Z-Recv %s, %s%ldb, %d min.",
                  Filename,
                  (isBinary)? "": "ASCII ",
                  filesize,
                  (int)(filesize*10/cur_baud+27)/54);

      set_xy(NULL);

      throughput(0,0L);

      return OK;

   end /* RZ_GetHeader */





/*--------------------------------------------------------------------------*/
/* RZ SAVE TO DISK                                                          */
/* Writes the received file data to the output file.                        */
/* If in ASCII mode, stops writing at first ^Z, and converts all            */
/*   solo CR's or LF's to CR/LF pairs.                                      */
/*--------------------------------------------------------------------------*/
static int pascal RZ_SaveToDisk(rxbytes)
   unsigned long *rxbytes;
   begin
      static byte    lastsent;

      register byte *p;
      register int   count;

      count = RxCount;

      if (((KEYPRESS()) and (READKB()==27)))
         begin
            send_can();
            z_log( KBD_msg );
            return ERROR;
         end

      if (count!=z_size)
         begin
            gotoxy( locate_x+10, locate_y );
            cputs( ultoa(((unsigned long )(z_size=count)),e_input,10) );
            putch(' ');
         end

      errno = 0;

      if (isBinary)
         begin
            fwrite( Secbuf, count, 1, Outfile );
            if (errno) goto oops;
         end
      else
         begin
            if (EOFseen) return OK;
            for (p=Secbuf; --count>=0; ++p )
               begin
                  if ( *p == CPMEOF)
                     begin
                        EOFseen = TRUE;
                        return OK;
                     end
                  if ( *p=='\n' ) {
                     if (lastsent!='\r' && putc('\r', Outfile) == EOF)
                        goto oops;
                  } else {
                     if (lastsent=='\r' && putc('\n', Outfile) == EOF)
                        goto oops;
                  }
                  if (putc((lastsent=*p), Outfile) == EOF)  goto oops;
               end
         end

      *rxbytes += RxCount;
      
      gotoxy( locate_x, locate_y );
      cputs( ultoa(((unsigned long )(*rxbytes)),e_input,10) );
      return OK; 

oops:
      had_error(WRITE_msg,Filename);
      return ERROR;

   end /* RZ_SaveToDisk */



/*--------------------------------------------------------------------------*/
/* RZ ACK BIBI                                                              */
/* Ack a ZFIN packet, let byegones be byegones                              */
/*--------------------------------------------------------------------------*/
static void pascal RZ_AckBibi()
   begin
      register int n;

      Z_PutLongIntoHeader(0L);
      for (n=4; --n;)
         begin
            Z_SendHexHeader(ZFIN, Txhdr);
            switch (Z_GetByte(100))
               begin
                  case 'O':      Z_GetByte(1);    /* Discard 2nd 'O' */

                  case TIMEOUT:
                  case RCDO:     return;
               end /* switch */
         end /* for */

   end /* RZ_AckBibi */

⌨️ 快捷键说明

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