📄 ecurz.c
字号:
stohdr(1L); zshhdr(ZACK,Txhdr); report_str("",-1); goto again; } zshhdr(ZNAK,Txhdr); goto again; case ZFREECNT: stohdr(getfree()); zshhdr(ZACK,Txhdr); report_str("",-1); goto again; case ZCOMMAND: if(zrdata(secbuf,1024) == GOTCRCW) { stohdr(-1L); purgeline(); /* dump impatient questions */ while(errors < 20) { zshhdr(ZCOMPL,Txhdr); if(zgethdr(Rxhdr,1) == ZFIN) break; } send_ZFIN(); return(ZCOMPL); } zshhdr(ZNAK,Txhdr); goto again; case ZCOMPL: goto again; default: continue; case ZFIN: send_ZFIN(); return(ZCOMPL); case ZCAN: return(ERROR); } } return(0);} /* end of tryz *//*+------------------------------------------------------------------------- rzfile() - receive a file with ZMODEM protocol assumes file name frame is in secbuf--------------------------------------------------------------------------*/intrzfile(){ register c,n; char s64[64]; Eofseen=0; rxfilepos = 0L; if(procheader(secbuf) == ERROR) { return(tryzhdrtype = ZSKIP); } n = 20; for(;;) { if(rxfilepos && !expect_zrpos) { sprintf(s64,"Sending ZRPOS (%ld)",rxfilepos); report_str(s64,1); } else report_str("Starting sender",0); expect_zrpos = 0; stohdr(rxfilepos); zshhdr(ZRPOS,Txhdr);nxthdr: report_receive_progress(rxfilepos); switch(c = zgethdr(Rxhdr,0)) { default: sprintf(s128,got_garbage_txt,c); report_str(s128,0); return(ERROR); case ZNAK: case TIMEOUT: if( --n < 0) { sprintf(s128,got_garbage_txt,c); report_str(s128,0); return(ERROR); } case ZFILE: zrdata(secbuf,1024); continue; case ZEOF: if(rclhdr(Rxhdr) != rxfilepos) { /* * Ignore eof if it's at wrong place - force * a timeout because the eof might have gone * out before we sent our zrpos. */ errors = 0; goto nxthdr; } if(can_on_eof) { send_cancel(0); send_cancel(0); close_and_report(); report_uninit(0); exit(0); } if(close_and_report()) { tryzhdrtype = ZFERR; return(ERROR); } report_str("End of file",0); return(c); case ERROR: /* Too much garbage in header search error */ if( --n < 0) { sprintf(s128,got_garbage_txt,c); report_str(s128,0); return(ERROR); } zmputs(Attn); continue; case ZSKIP: close_and_report(); sprintf(s128,"Sender SKIPPED file"); report_str(s128,-1); return(c); case ZDATA: if(rclhdr(Rxhdr) != rxfilepos) { if( --n < 0) { return(ERROR); } zmputs(Attn); continue; }moredata: report_receive_progress(rxfilepos); switch(c = zrdata(secbuf,1024)) { case ZCAN: sprintf(s128,got_garbage_txt,c); report_str(s128,0); return(ERROR); case ERROR: /* CRC error */ if( --n < 0) { sprintf(s128,got_garbage_txt,c); report_str(s128,0); return(ERROR); } zmputs(Attn); continue; case TIMEOUT: if( --n < 0) { sprintf(s128,got_garbage_txt,c); report_str(s128,0); return(ERROR); } continue; case GOTCRCW: n = 20; write_sec_to_disk(secbuf,Rxcount); rxfilepos += Rxcount; stohdr(rxfilepos); zshhdr(ZACK,Txhdr); sendline(XON); report_str("",-1); goto nxthdr; case GOTCRCQ: n = 20; write_sec_to_disk(secbuf,Rxcount); rxfilepos += Rxcount; stohdr(rxfilepos); zshhdr(ZACK,Txhdr); report_str("",-1); goto moredata; case GOTCRCG: n = 20; write_sec_to_disk(secbuf,Rxcount); rxfilepos += Rxcount; goto moredata; case GOTCRCE: n = 20; write_sec_to_disk(secbuf,Rxcount); rxfilepos += Rxcount; goto nxthdr; } } } /*NOTREACHED*/} /* end of rzfile *//*+------------------------------------------------------------------------- rzfiles() - receive file(s) with ZMODEM protocol--------------------------------------------------------------------------*/intrzfiles(){ register c; for(;;) { switch(c = rzfile()) { case ZEOF: case ZSKIP: switch(tryz()) { case ZCOMPL: return(OK); default: return(ERROR); case ZFILE: break; } continue; default: return(c); case ERROR: return(ERROR); } } /*NOTREACHED*/} /* end of rzfiles *//*+------------------------------------------------------------------------- close_and_report() - close the received file, set mod time and chmod(specifically exclude set uid and gid from chmod)--------------------------------------------------------------------------*/intclose_and_report(){ fflush(fout); fstat(fileno(fout),&fout_stat); report_file_byte_io((long)fout_stat.st_size - initial_filepos); report_file_close(0); if(fclose(fout)==ERROR) { if(errno > sys_nerr) sprintf(s128,"finish close errno %d",errno); else sprintf(s128,"finish close error: %s",sys_errlist[errno]); ecu_log_event(getppid(),s128); fout = (FILE *)0; return(ERROR); }#if defined(LOG_XFER) sprintf(s128,"RECEIVE success: %s (%ld bytes)",Pathname,fout_stat.st_size); ecu_log_event(getppid(),s128);#endif if(Modtime) { timep[0] = time(NULL); timep[1] = Modtime; utime(Pathname,timep); } if((Filemode & S_IFMT) == S_IFREG) { Filemode &= ~(S_ISUID | S_ISGID); chmod(Pathname,(unsigned short)(07777 & Filemode)); } return(OK);} /* end of close_and_report *//*+------------------------------------------------------------------------- sys2(shellcmd) - execute shell command Strip leading ! if present--------------------------------------------------------------------------*/intsys2(shellcmd)register char *shellcmd;{ if(*shellcmd == '!') ++shellcmd; return(system(shellcmd));} /* end of sys2 *//*+------------------------------------------------------------------------- main(argc,argv,envp)--------------------------------------------------------------------------*/main(argc,argv,envp)int argc;char **argv;char **envp;{ register char *cp; char **patts = (char **)0; char *getenv(); int exitcode = 0; gargv = argv; gargc = argc; signal(SIGINT,bye_bye); signal(SIGTERM,bye_bye);#if defined(SIGSTOP) /* * call Roto-Rooter on POSIX plots */ signal(SIGSTOP,SIG_IGN); signal(SIGTSTP,SIG_IGN); signal(SIGCONT,SIG_IGN); signal(SIGTTIN,SIG_IGN); signal(SIGTTOU,SIG_IGN);#endif get_curr_dir(curr_dir,sizeof(curr_dir)); Rxtimeout = 100; npats = 0; while(--argc) { cp = *++argv; if(*cp == '-') { while( *++cp) { switch(*cp) { case 'X': required_type = 1; Batch = 0; break; case 'Y': required_type = 1; Nozmodem = 1; Batch = 1; break; case 'Z': required_type = 1; Nozmodem = 0; Batch = 1; break; case '+': Lzmanag = ZMAPND; break; case 'a': Rxascii=1; break; case 'b': Rxbinary=1; break; case 'c': Crcflg=1; break; case 'e': Zctlesc = 1; break; case 'p': Lzmanag = ZMPROT; break; case '@': force_dumbtty = 1; break; case ',': log_packets = 1; break; case ':': can_on_eof = 1; break; case '.': if(--argc < 1) { usage("no iofd after -."); } iofd = atoi(*++argv); break; case 't': if(--argc < 1) { usage("no rcvr timeout after -t"); } Rxtimeout = atoi(*++argv); if(Rxtimeout<10 || Rxtimeout>1000) usage("illegal timeout: must be 10 <= t <= 1000"); break; case 'w': if(--argc < 1) { usage("no Zrwindow after -w"); } Zrwindow = atoi(*++argv); break; case 'C': if(--argc < 1) usage("no label after -C"); bottom_label = *++argv; break; case 'u': MakeLCPathname=0; break; case 'y': Rxclob=1; break; default: sprintf(s128,"Unknown switch -%c",*cp); usage(s128); } } } else if( !npats && argc>0) { if(argv[0][0]) { npats=argc; patts=argv; } } } if(determine_output_mode()) { setbuf(stdout,NULL); setbuf(stderr,NULL); } if(!required_type || !iofd) { printf("can only be run by ecu\n"); exit(255); } if(log_packets) { char log_packets_name[64]; int iargv; sprintf(log_packets_name,"/tmp/rz%05d.plog",getpid()); unlink(log_packets_name); log_packets = open(log_packets_name,O_CREAT|O_WRONLY,0644); if(log_packets < 0) log_packets = 0; else { write(log_packets,"exec: ",6); for(iargv = 0; iargv < gargc; iargv++) { write(log_packets,gargv[iargv],strlen(gargv[iargv])); write(log_packets," ",1); } write(log_packets,"\n",1); } } /* * learn tick rate for various timers */ init_Nap(); if(Batch && npats) usage("Cannot specify batch receive and filename"); if(npats > 1) usage("only one filename allowed"); sprintf(s128,"%s",numeric_revision + 4); report_init(s128); mode(1); signal(SIGINT,cancel_transaction); signal(SIGTERM,cancel_transaction); signal(SIGQUIT,cancel_transaction); if(wcreceive(npats,patts)==ERROR) { exitcode=0200; send_cancel(1); } mode(0); if(exitcode && !Zmodem) /* bellow again with all thy might. */ send_cancel(1); report_uninit(0); exit(exitcode);} /* end of main *//* vi: set tabstop=4 shiftwidth=4: *//* end of ecurz.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -