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

📄 ckcfns.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
    debug(F101,"reof discard","",discard);    success = 1;			/* Assume status is OK */    lsstate = 0;			/* Cancel locking-shift state */    if (#ifdef COMMENT/*  If the discard flag is set, for whatever reason, we discard it, right?*/	(fncact == XYFX_D || fncact == XYFX_U) &&#endif /* COMMENT */	discard != 0) {	   /* SET FILE COLLISION DISCARD or UPDATE */	debug(F101,"reof discarding","",0);	discard = 0;			/* We never opened it, */	return(0);			/* so we won't close it. */    }    if (cxseen == 0) cxseen = (*rdatap == 'D');	/* Got cancel directive? */    success = (cxseen || czseen) ? 0 : 1; /* Set SUCCESS flag appropriately */    x = clsof(cxseen || czseen);	/* Close the file (resets cxseen) */    if (x < 0) success = 0;		/* If failure to close, FAIL */    if (atcapu) zstime(f,yy,0);		/* Set file creation date *//* Handle dispositions from attribute packet... */#ifndef NOFRILLS    if (yy->disp.len != 0) {	p = yy->disp.val;	c = *p++;	if (c == 'M') {			/* Mail to user. */	    x = zmail(p,filnam);	/* Do the system's mail command */	    if (x < 0) success = 0;	/* Remember status */	    tlog(F110,"mailed",filnam,0L);	    tlog(F110," to",p,0L);	    zdelet(filnam);		/* Delete the file */	} else if (c == 'P') {		/* Print the file. */	    x = zprint(p,filnam);	/* Do the system's print command */	    if (x < 0) success = 0;	/* Remember status */	    tlog(F110,"printed",filnam,0L);	    tlog(F110," with options",p,0L);#ifndef VMS	    if (zdelet(filnam) && x == 0) x = 3; /* Delete the file */#endif /* VMS */	}    }#endif /* NOFRILLS */    debug(F101,"reof returns","",x);    *filnam = '\0';    return(x);}/*  R E O T  --  Receive End Of Transaction  */VOIDreot() {    cxseen = czseen = discard = 0;	/* Reset interruption flags */    tstats();}/*  S F I L E -- Send File header or teXt header packet  *//*  Call with x nonzero for X packet, zero for F packet  *//*  Returns 1 on success, 0 on failure                   */intsfile(x) int x; {#ifdef pdp11#define PKTNL 64#else#define PKTNL 256#endif /* pdp11 */    char pktnam[PKTNL+1];		/* Local copy of name */    char *s;    lsstate = 0;			/* Cancel locking-shift state */    if (nxtpkt() < 0) return(0);	/* Bump packet number, get buffer */    if (x == 0) {			/* F-Packet setup */    	if (*cmarg2 != '\0') {		/* If we have a send-as name, */	    strncpy(pktnam,cmarg2,PKTNL); /* copy it literally, */	    cmarg2 = "";		/* and blank it out for next time. */    	} else {			/* Otherwise use actual file name: */	    if (fncnv) {		/* If converting names, */	    	zltor(filnam,pktnam);	/* convert it to common form, */	    } else {			/* otherwise, */	    	strncpy(pktnam,filnam,PKTNL); /* copy it literally. */            }    	}    	debug(F110,"sfile",filnam,0);	/* Log debugging info */    	debug(F110," pktnam",pktnam,0);    	if (openi(filnam) == 0) 	/* Try to open the file */	  return(0); 		    	s = pktnam;			/* Name for packet data field */    } else {				/* X-packet setup */    	debug(F110,"sxpack",cmdstr,0);	/* Log debugging info */    	s = cmdstr;			/* Name for data field */    }    encstr((CHAR *)s);			/* Encode the name into encbuf[]. */					/* Send the F or X packet */    spack((char) (x ? 'X' : 'F'), pktnum, size, encbuf+7);    if (x == 0) {			/* Display for F packet */    	if (displa) {			/* Screen */	    screen(SCR_FN,'F',(long)pktnum,filnam);	    screen(SCR_AN,0,0l,pktnam);	    screen(SCR_FS,0,fsize,"");    	}    	tlog(F110,"Sending",filnam,0L);	/* Transaction log entry */    	tlog(F110," as",pktnam,0L);	if (binary) {			/* Log file mode in transaction log */	    tlog(F101," mode: binary","",(long) binary);	} else {			/* If text mode, check character set */	    tlog(F100," mode: text","",0L);#ifndef NOCSETS	    tlog(F110," file character set",fcsinfo[fcharset].name,0L);	    if (tcharset == TC_TRANSP)	      tlog(F110," xfer character set","transparent",0L);	    else	      tlog(F110," xfer character set",tcsinfo[tcharset].name,0L);#endif /* NOCSETS */	}    } else {				/* Display for X-packet */    	screen(SCR_XD,'X',(long)pktnum,cmdstr);	/* Screen */    	tlog(F110,"Sending from:",cmdstr,0L);	/* Transaction log */    }    intmsg(++filcnt);			/* Count file, give interrupt msg */    first = 1;				/* Init file character lookahead. */    ffc = 0L;				/* Init file character counter. */    fsecs = gtimer();			/* Time this file started */    debug(F101,"SFILE fsecs","",fsecs);    return(1);}/*  S D A T A -- Send a data packet *//*  Returns -1 if no data to send (end of file).  If there is data, a data  packet is sent, and sdata() returns 1.  For window size greater than 1, keep sending data packets until window  is full or characters start to appear from the other Kermit, whichever  happens first.  In the windowing case, when there is no more data left to send (or when  sending has been interrupted), sdata() does nothing and returns 0 each time  it is called until the current packet number catches up to the last data  packet that was sent.*/intsdata() {    int i, x, len;        debug(F101,"sdata entry, first","",first);    debug(F101," drain","",drain);/* The "drain" flag is used with window size > 1.  It means we have sent  *//* our last data packet.  If called and drain is not zero, then we return *//* 0 as if we had sent an empty data packet, until all data packets have  *//* been ACK'd, then then we can finally return -1 indicating EOF, so that *//* the protocol can switch to seof state.  This is a kludge, but at least *//* it's localized...  */    if (first == 1) drain = 0;		/* Start of file, init drain flag. */    if (drain) {			/* If draining... */	debug(F101,"sdata draining, winlo","",winlo);	if (winlo == pktnum)		/* If all data packets are ACK'd */	  return(-1);			/* return EOF indication */	else				/* otherwise */	  return(0);			/* pretend we sent a data packet. */    }    debug(F101,"sdata sbufnum","",sbufnum);    for (i = sbufnum; i > 0; i--) {        debug(F101,"sdata countdown","",i);	x = nxtpkt();			/* Get next pkt number and buffer */	debug(F101,"sdata packet","",pktnum);	if (x < 0) return(0);/***	dumpsbuf(); */	if (cxseen || czseen) {		/* If interrupted, done. */	    if (wslots > 1) {		drain = 1;		debug(F101,"sdata cx/zseen, drain","",cxseen);		return(0);	    } else {		return(-1);	    }	}#ifdef COMMENT	if (spsiz > 94)			/* Fill the packet's data buffer */	  len = getpkt(spsiz-bctl-6,1);	/* long packet */	else				/*  or */	  len = getpkt(spsiz-bctl-3,1);	/* short packet */#else	len = getpkt(spsiz,1);#endif /* COMMENT */	if (len == 0) {			/* Done if no data. */	    if (pktnum == winlo) return(-1);	    drain = 1;			/* But can't return -1 until all */	    debug(F101,"sdata eof, drain","",drain);	    return(0);			/* ACKs are drained. */	}	spack('D',pktnum,len,data);	/* Send the data packet. */	x = ttchk();			/* Peek at input buffer. */	debug(F101,"sdata ttchk","",x);	/* ACKs waiting, maybe?  */	if (x) return(1);		/* Yes, stop sending data packets */    }					/* and go try to read the ACKs. */    return(1);}/*  S E O F -- Send an End-Of-File packet *//*  Call with a string pointer to character to put in the data field, *//*  or else a null pointer or "" for no data.  *//*  There are two "send-eof" functions.  seof() is used to send the normal eof  packet at the end of a file's data (even if the file has no data), or when  a file transfer is interrupted.  sxeof() is used to send an EOF packet that  occurs because of attribute refusal.  The difference is purely a matter of  buffer allocation and packet sequence number management.  Both functions  act as "front ends" to the common send-eof function, szeof().*//* Code common to both seof() and sxeof() */intszeof(s) CHAR *s; {    lsstate = 0;			/* Cancel locking-shift state */    if ((s != NULL) && (*s != '\0')) {	spack('Z',pktnum,1,s);	tlog(F100," *** interrupted, sending discard request","",0L);    } else {	spack('Z',pktnum,0,(CHAR *)"");    }    discard = 0;			/* Turn off per-file discard flag */    return(0);}intseof(s) CHAR *s; {/*  ckcpro.w, before calling seof(), sets window size back to 1 and then calls  window(), which clears out the old buffers.  This is OK because the final  data packet for the file has been ACK'd.  However, sdata() has already  called nxtpkt(), which set the new value of pktnum which seof() will use.  So all we need to do here is is allocate a new send-buffer.*/    if (getsbuf(pktnum) < 0) {	/* Get a buffer for packet n */	debug(F101,"seof can't get s-buffer","",pktnum);	return(-1);    }    return(szeof(s));}/*  Version of seof() to be called when sdata() has not been called before.  The  difference is that this version calls nxtpkt() to allocate a send-buffer and  get the next packet number.*/intsxeof(s) CHAR *s; {    int x;    x = nxtpkt();			/* Get next pkt number and buffer */    if (x < 0)      debug(F101,"sxeof nxtpkt fails","",pktnum);    else      debug(F101,"sxeof packet","",pktnum);    return(szeof(s));}/*  S E O T -- Send an End-Of-Transaction packet */intseot() {    if (nxtpkt() < 0) return(-1);	/* Bump packet number, get buffer */    spack('B',pktnum,0,(CHAR *)"");	/* Send the EOT packet */    cxseen = czseen = discard = 0;	/* Reset interruption flags */    tstats();				/* Log timing info */    return(0);}/*   R P A R -- Fill the data array with my send-init parameters  */CHAR dada[20];				/* Use this instead of data[]. */					/* To avoid some kind of wierd */					/* addressing foulup in spack()... */					/* (which might be fixed now...) */CHAR *rpar() {    if (rpsiz > MAXPACK)		/* Biggest normal packet I want. */      dada[0] = tochar(MAXPACK);	/* If > 94, use 94, but specify */    else				/* extended packet length below... */      dada[0] = tochar(rpsiz);		/* else use what the user said. */    dada[1] = tochar(chktimo(pkttim,0)); /* When I want to be timed out */    dada[2] = tochar(mypadn);		/* How much padding I need (none) */    dada[3] = ctl(mypadc);		/* Padding character I want */    dada[4] = tochar(eol);		/* End-Of-Line character I want */    dada[5] = '#';			/* Control-Quote character I send */    switch (rqf) {			/* 8th-bit prefix */	case -1:	case  1: if (parity) ebq = sq = '&'; break;	case  0:	case  2: break;    }    debug(F000,"rpar 8bq sq","",sq);    debug(F000,"rpar 8bq ebq","",ebq);    if (lscapu == 2)			/* LOCKING-SHIFT FORCED */      dada[6] = 'N';			/* means no single-shift */    else      dada[6] = sq;    dada[7] = (bctr == 4) ? 'B' : bctr + '0'; /* Block check type */    if (rptflg)				/* Run length encoding */    	dada[8] = rptq;			/* If receiving, agree. */    else    	dada[8] = '~'; 		    /* CAPAS mask */    dada[9] = tochar((lscapr ? lscapb : 0) | /* Locking shifts */		     (atcapr ? atcapb : 0) | /* Attribute packets */		     (lpcapr ? lpcapb : 0) | /* Long packets */		     (swcapr ? swcapb : 0)); /* Sliding windows */    dada[10] = tochar(swcapr ? wslotr : 1);  /* Window size */    rpsiz = urpsiz - 1;			/* Long packets ... */    dada[11] = tochar(rpsiz / 95);	/* Long packet size, big part */    dada[12] = tochar(rpsiz % 95);	/* Long packet size, little part */    dada[13] = '\0';			/* Terminate the init string */#ifdef DEBUG    if (deblog) {	debug(F110,"rpar",dada,0);	rdebu(dada,(int)strlen((char *)dada));    }#endif /* DEBUG */    strcpy((char *)myinit,(char *)dada);    return(dada);			/* Return pointer to string. */}intspar(s) CHAR *s; {			/* Set parameters */    int x, y, lpsiz;    debug(F110,"entering spar",s,0);    s--;				/* Line up with field numbers. *//* Limit on size of outbound packets */    x = (rln >= 1) ? xunchar(s[1]) : 80;    lpsiz = spsizr;			/* Remember what they SET. */    if (spsizf) {			/* SET-command override? */	if (x < spsizr) spsiz = x;	/* Ignore LEN unless smaller */    } else {				/* otherwise */	spsiz = (x < 10) ? 80 : x;	/* believe them if reasonable */    }    spmax = spsiz;			/* Remember maximum size *//* Timeout on inbound packets */    if (timef) {	timint = rtimo;			/* SET SEND TIMEOUT value overrides */    } else {				/* Otherwise use requested value, */	x = (rln >= 2) ? xunchar(s[2]) : rtimo; /* if it is legal. */	timint = (x < 0) ? rtimo : x;    }    timint = chktimo(timint,timef);	/* Adjust if necessary *//* Outbound Padding */    npad = 0; padch = '\0';    if (rln >= 3) {	npad = xunchar(s[3]);	if (rln >= 4) padch = ctl(s[4]); else padch = 0;    }    if (npad) {	int i;	for (i = 0; i < npad; i++) padbuf[i] = dopar(padch);    }/* Outbound Packet Terminator */    seol = (rln >= 5) ? xunchar(s[5]) : CR;    if ((seol < 2) || (seol > 31)) seol = CR;/* Control prefix */    x = (rln >= 6) ? s[6] : '#';    myctlq = ((x > 32 && x < 63) || (x > 95 && x < 127)) ? x : '#';/* 8th-bit prefix */    rq = (rln >= 7) ? s[7] : 0;    if (rq == 'Y') rqf = 1;      else if ((rq > 32 && rq < 63) || (rq > 95 && rq < 127)) rqf = 2;        else rqf = 0;    debug(F000,"spar 8bq rq","",rq);    debug(F000,"spar 8bq sq","",sq);    debug(F000,"spar 8bq ebq","",ebq);    debug(F101,"spar 8bq rqf","",rqf);    switch (rqf) {	case 0: ebqflg = 0; break;	case 1: if (parity) { ebqflg = 1; ebq = '&'; } break;	case 2: if (ebqflg = (ebq == sq || sq == 'Y')) ebq = rq;    }    if (lscapu == 2) {     /* No single-shifts if LOCKING-SHIFT FORCED */	ebqflg = 0;	ebq = 'N';    }

⌨️ 快捷键说明

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