📄 ckcfns.c
字号:
size = (dp-data); /* End of file */ *dp = '\0'; /* Mark the end of the data. */ debug(F111,"getpkt eof/eot",data,size); /* Fell thru before packet full, */ return(size); /* return partially filled last packet. */}/* T I N I T -- Initialize a transaction */inttinit() { int x;#ifndef NOCSETS if (tcharset == TC_TRANSP) { /* Character set translation */ rx = sx = NULL; /* Transparent, no translation */#ifdef KANJI } else if (tcharset == TC_JEUC) { rx = sx = NULL; /* Transparent, no translation */ #endif /* KANJI */ } else { /* otherwise */ rx = xlr[tcharset][fcharset]; /* Input translation function */ sx = xls[tcharset][fcharset]; /* Output translation function */ } debug(F101,"tinit tcharset","",tcharset); debug(F101,"tinit fcharset","",fcharset);#ifdef COMMENT debug(F101,"tinit sx ","",sx); debug(F101,"tinit rx ","",rx);#endif /* COMMENT */#endif /* NOCSETS */ myinit[0] = '\0'; /* Haven't sent init string yet */ autopar = 0; /* Automatic parity detection flag */ retrans = 0; /* Packet retransmission count */ sndtyp = 0; /* No previous packet */ xflg = 0; /* Reset x-packet flag */ rqf = -1; /* Reset 8th-bit-quote request flag */ memstr = 0; /* Reset memory-string flag */ memptr = NULL; /* and pointer */ bctu = bctl = 1; /* Reset block check type to 1 */ ebq = MYEBQ; /* Reset 8th-bit quoting stuff */ ebqflg = 0; if (savmod) { /* If global file mode was saved, */ binary = savmod; /* restore it, */ savmod = 0; /* unsave it. */ } pktnum = 0; /* Initial packet number */ cxseen = czseen = discard = 0; /* Reset interrupt flags */ *filnam = '\0'; /* Clear file name */ spktl = 0; /* And its length */ nakstate = 0; /* Assume not in a NAK'ing state */ numerrs = 0; /* Transmission error counter */ if (server) /* If acting as server, */ timint = srvtim; /* Use server timeout interval. */ else /* Otherwise */ timint = chktimo(rtimo,timef); /* Begin by using local value */ spsiz = spsizr; /* Initial send-packet size */ wslots = 1; /* One window slot */ wslotn = 1; /* No window negotiated yet */ winlo = 0; /* Packet 0 is at window-low */ x = mksbuf(1); /* Make a 1-slot send-packet buffer */ if (x < 0) return(x); x = getsbuf(0); /* Allocate first send-buffer. */ debug(F101,"tinit getsbuf","",x); if (x < 0) return(x); dumpsbuf(); x = mkrbuf(wslots); /* & a 1-slot receive-packet buffer. */ if (x < 0) return(x); what = W_NOTHING; /* Doing nothing so far... */ lsstate = 0; /* Initialize locking shift state */ return(0);}VOIDpktinit() { /* Initialize packet sequence */ pktnum = 0; /* number & window low. */ winlo = 0;}/* R I N I T -- Respond to S or I packet */VOIDrinit(d) CHAR *d; { char *tp; ztime(&tp); tlog(F110,"Transaction begins",tp,0L); /* Make transaction log entry */ if (binary) tlog(F100,"Global file mode = binary","",0L); else tlog(F100,"Global file mode = text","",0L); filcnt = 0; /* Init file counter */ spar(d); ack1(rpar());#ifdef datageneral if ((local) && (!quiet)) /* Only do this if local & not quiet */ consta_mt(); /* Start the asynch read task */#endif /* datageneral */}/* R E S E T C -- Reset per-transaction character counters */VOIDresetc() { rptn = 0; /* Repeat counts */ fsecs = flci = flco = 0L; /* File chars in and out */ tfc = tlci = tlco = 0L; /* Total file, line chars in & out */#ifdef COMMENT fsize = -1L; /* File size */#else if (what != W_SEND) fsize = -1L; debug(F101,"resetc fsize","",fsize);#endif /* COMMENT */ timeouts = retrans = 0; /* Timeouts, retransmissions */ spackets = rpackets = 0; /* Packet counts out & in */ crunched = 0; /* Crunched packets */ wmax = 1; /* Maximum window size used */}/* S I N I T -- Get & verify first file name, then send Send-Init packet *//* Returns: 1 if send operation begins successfully 0 if send operation fails*/#ifdef DYNAMICchar *cmargbuf = NULL;#elsechar cmargbuf[256];#endif /* DYNAMIC */char *cmargp[2];intsinit() { int x; /* Worker int */ char *tp, *xp, *m; /* Worker string pointers */ filcnt = 0; /* Initialize file counter */ sndsrc = nfils; /* Source for filenames */#ifdef DYNAMIC if (!cmargbuf && !(cmargbuf = malloc(256))) fatal("sinit: no memory for cmargbuf");#endif /* DYNAMIC */ cmargbuf[0] = NUL; /* Initialize name buffer */ debug(F101,"sinit nfils","",nfils); debug(F110,"sinit cmarg",cmarg,0); debug(F110,"sinit cmarg2",cmarg2,0); if (nfils == 0) { /* Sending from stdin or memory. */ if ((cmarg2 != NULL) && (*cmarg2)) { cmarg = cmarg2; /* If F packet, "as-name" is used */ cmarg2 = ""; /* if provided */ } else cmarg = "stdin"; /* otherwise just use "stdin" */ strcpy(cmargbuf,cmarg); cmargp[0] = cmargbuf; cmargp[1] = ""; cmlist = cmargp; nfils = 1; }#ifdef COMMENT if (nfils < 1) { /* Filespec pointed to by cmarg */ if (nfils < 0) sndsrc = 1; nfils = 1; /* Change it to cmlist */ strcpy(cmargbuf,cmarg); /* so we have a consistent way */ cmargp[0] = cmargbuf; /* of going thru the file list. */ cmargp[1] = ""; cmlist = cmargp; }/* At this point, cmlist contains the list of filespecs to send */ debug(F111,"sinit *cmlist",*cmlist,nfils); xp = *cmlist; /* Save this for messages */#else xp = (nfils < 0) ? cmarg : *cmlist;#endif x = gnfile(); /* Get first filename. */ m = NULL; /* Error message pointer */ debug(F101,"sinit gnfil","",x); switch (x) { case -5: m = "Too many files match wildcard"; break; case -4: m = "Cancelled"; break; case -3: m = "Read access denied"; break; case -2: m = "File is not readable"; break; case -1: m = iswild(filnam) ? "No files match" : "File not found"; break; case 0: m = "No filespec given!" ; break; default: break; } debug(F101,"sinit nfils","",nfils); debug(F110,"sinit filnam",filnam,0); debug(F110,"sinit cmdstr",cmdstr,0); if (x < 1) { /* Didn't get a file. */ if (server) /* Doing GET command */ errpkt((CHAR *)m); /* so send Error packet. */ else /* Doing SEND command */ screen(SCR_EM,0,0l,m); /* so print message. */ tlog(F110,xp,m,0L); /* Make transaction log entry. */ freerbuf(rseqtbl[0]); /* Free the buffer the GET came in. */ return(0); /* Return failure code */ } if (!local && !server) sleep(delay); /* Delay if requested */#ifdef datageneral if ((local) && (!quiet)) /* Only do this if local & not quiet */ consta_mt(); /* Start the asynch read task */#endif /* datageneral */ freerbuf(rseqtbl[0]); /* Free the buffer the GET came in. */ sipkt('S'); /* Send the Send-Init packet. */ ztime(&tp); /* Get current date/time */ tlog(F110,"Transaction begins",tp,0L); /* Make transaction log entry */ debug(F111,"sinit ok",filnam,0); return(1);}int#ifdef CK_ANSICsipkt(char c) /* Send S or I packet. */#elsesipkt(c) char c;#endif/* sipkt */ { CHAR *rp; int k; debug(F101,"sipkt pktnum","",pktnum); k = sseqtbl[pktnum]; /* Find slot for this packet */ debug(F101,"sipkt k","",k); if (k < 0) { /* No slot? */ k = getsbuf(winlo = pktnum); /* Make one. */ debug(F101,"sipkt getsbuf","",k); } ttflui(); /* Flush pending input. */ rp = rpar(); /* Get protocol parameters. */ return(spack(c,pktnum,(int)strlen((char *)rp),rp)); /* Send them. */}/* X S I N I T -- Retransmit S-packet *//* For use in the GET-SEND sequence, when we start to send, but receive another copy of the GET command because the receiver didn't get our S packet. This retransmits the S packet and frees the receive buffer for the ACK. The only reason this special case is necessary is that packet number zero is being re-used.*/VOIDxsinit() { int k; k = rseqtbl[0]; debug(F101,"xsinit k","",k); if (k > -1) freerbuf(k); resend(0);} /* R C V F I L -- Receive a file *//* Incoming filename is in data field of F packet. This function decodes it into the srvcmd buffer, substituting an alternate "as-name", if one was given. Then it does any requested transformations (like converting to lowercase), and finally if a file of the same name already exists, takes the desired collision action.*/#ifdef pdp11#define XNAMLEN 65#else#define XNAMLEN 256#endif /* pdp11 */intrcvfil(n) char *n; { char xname[XNAMLEN], *xp; /* Buffer for constructing name */#ifdef DTILDE char *dirp, *tilde_expand();#endif /* DTILDE */ lsstate = 0; /* Cancel locking-shift state */ srvptr = srvcmd; /* Decode file name from packet. */ decode(rdatap,putsrv,0); /* Don't xlate charsets. */ if (*srvcmd == '\0') /* Watch out for null F packet. */ strcpy((char *)srvcmd,"NONAME");#ifdef DTILDE dirp = tilde_expand((char *)srvcmd); /* Expand tilde, if any. */ if (*dirp != '\0') strcpy((char *)srvcmd,dirp);#endif /* DTILDE */ screen(SCR_FN,0,0l,(char *)srvcmd); /* Put it on screen if local */ debug(F110,"rcvfil",(char *)srvcmd,0); /* Debug log entry */ debug(F101,"rcvfil cmarg2","",cmarg2); tlog(F110,"Receiving",(char *)srvcmd,0L); /* Transaction log entry */ if (cmarg2 != NULL) { /* Check for alternate name */ if (*cmarg2 != '\0') { strcpy((char *)srvcmd,cmarg2); /* Got one, use it. */ } } else cmarg2 = "";/* NOTE: Much of this code should be moved to opena(), where the file is actually opened, AFTER we have received the Attribute packet(s). That way, if the file is mail, or is being sent to the printer, we don't have to fuss with collision options, etc, but instead we just pipe the data straight into lpr or mail (in UNIX anyway), and then we can also have nice subject lines for mail messages by using whatever is in the file header packet data field, whether it's a legal filename or not.*/ if ((int)strlen((char *)srvcmd) > XNAMLEN) /* Watch out for overflow */ *(srvcmd + XNAMLEN - 1) = NUL; xp = xname; /* OK to proceed. */ if (fncnv && !*cmarg2) zrtol((char *)srvcmd,xp); /* convert name to local form */ else /* otherwise, */ strcpy(xname,(char *)srvcmd); /* use it literally */ cmarg2 = ""; /* Remove alternate name */ debug(F110,"rcvfil as",xname,0);#ifdef COMMENT /* Old code... */ if (warn) { /* File collision avoidance? */ if (zchki(xname) != -1) { /* Yes, file exists? */ znewn(xname,&xp); /* Yes, make new name. */ strcpy(xname,xp); debug(F110," exists, new name ",xname,0); } }#endif /* COMMENT *//* Filename collision action section. */ if (#ifdef UNIX strcmp(xname,"/dev/null") && /* It's not the null device? */#endif /* UNIX */ (zchki(xname) != -1) /* File of same name exists? */ ) { debug(F111,"rcvfil exists",xname,fncact); switch (fncact) { /* Yes, do what user said. */ case XYFX_A: /* Append */ debug(F100,"rcvfil append","",0); break; case XYFX_Q: /* Query (Ask) */ break; /* not yet implemented */ case XYFX_B: /* Backup (rename old file) */ znewn(xname,&xp); /* Get new unique name */ debug(F110,"rcvfil backup",xname,0); debug(F110,"rcvfil backup",xp,0); if (zrename(xname,xp) < 0) { debug(F110,"rcvfil rename fails",xname,0); return(0); } break; case XYFX_D: /* Discard (refuse new file) */ discard = 1; debug(F101,"rcvfil discard","",discard); break; /* not yet implemented */ case XYFX_R: /* Rename new file */ znewn(xname,&xp); /* Make new name. */ strcpy(xname,xp); debug(F110,"rcvfil rename",xname,0); case XYFX_X: /* Replace old file */ debug(F100,"rcvfil overwrite","",0); break; case XYFX_U: /* Refuse if older */ debug(F100,"rcvfil update","",0); break; /* Not here, we don't have */ /* the attribute packet yet. */ default: debug(F101,"rcvfil bad collision action","",fncact); break; } } debug(F110,"rcvfil: xname",xname,0); screen(SCR_AN,0,0l,xname); /* Display it */ strcpy(n,xname); /* Return pointer to actual name. */#ifndef NOICP#ifndef MAC/* Why not Mac? */ strcpy(fspec,xname); /* Here too for \v(filespec) */#endif /* MAC */#endif /* NOICP */ debug(F110,"rcvfil: n",n,0); ffc = 0L; /* Init per-file counters */ fsecs = gtimer(); /* Time this file started */ filcnt++; intmsg(filcnt); return(1); /* Always succeeds */}/* R E O F -- Receive End Of File packet for incoming file *//* Closes the received file. Returns: 0 on success. -1 if file could not be closed. 2 if disposition was mail, mail was sent, but temp file not deleted. 3 if disposition was print, file was printed, but not deleted. -2 if disposition was mail and mail could not be sent -3 if disposition was print and file could not be printed*/intreof(f,yy) char *f; struct zattr *yy; { int x; char *p; char c; debug(F111,"reof fncact",f,fncact);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -