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

📄 ckcfns.c

📁 linux终端仿真程序
💻 C
📖 第 1 页 / 共 5 页
字号:
        return(size = 0);    }/*  Here we handle characters that were encoded for the last packet but  did not fit, and so were saved in the "leftover" array.*/    dp = data;				/* Point to packet data buffer */    for (p1 = leftover; (*dp = *p1) != '\0'; p1++, dp++) /* Copy leftovers */    	;    *leftover = '\0';			/* Delete leftovers */    if (first == -1)			/* Handle EOF */      return(size = (dp - data));  /* Now fill up the rest of the packet. */    rpt = 0;				/* Initialize character repeat count */    while (first > -1) {		/* Until EOF... */#ifndef NOCSETS#ifdef KANJI	if (!binary && xlate && tcharset == TC_JEUC) {	    if ((x = zkanji(memstr ? kgetm : kgetf)) < 0) {	        first = -1;	        if (x == -2) cxseen = 1;	    } else if (!memstr) ffc++;	    rnext = (CHAR) (x & fmask);	} else {#endif /* KANJI */#endif /* not NOCSETS */	if (memstr) {			/* Get next char from memory string */	    if ((x = *memptr++) == '\0') /* End of string means EOF */	      first = -1;		/* Flag EOF for next time. */	    rnext = (CHAR) (x & fmask);	/* Apply file mask */	} else if (funcstr) {		/* Get next char from function */	    if ((x = (*funcptr)()) < 0) /* End of string means EOF */	      first = -1;		/* Flag EOF for next time. */	    rnext = (CHAR) (x & fmask);	/* Apply file mask */	} else {	    if ((x = zminchar()) < 0) { /* Real file, check for EOF */		first = -1;		/* Flag eof for next time. */		if (x == -2) cxseen = 1; /* If error, cancel this file. */	    } else {		ffc++;		/* Count the character */		if (docrc && what == W_SEND) {	/* Accumulate file crc */		    z = crc16 ^ (long)((CHAR)x & 0xff);		    crc16 = (crc16 >> 8) ^		      (crcta[(z & 0xF0) >> 4] ^ crctb[z & 0x0F]);		}			    }	    rnext = (CHAR) (x & fmask);	/* Apply file mask */	} #ifndef NOCSETS#ifdef KANJI	}#endif /* KANJI */#endif /* not NOCSETS */#ifndef NOCSETS#ifdef KANJI	if (tcharset != TC_JEUC)#endif /* KANJI */	    if (!binary && sx && xlate) {		rnext = (*sx)(rnext); /* Translate */		debug(F101,"getpkt xlated rnext to","",rnext);	    }#endif /* not NOCSETS */	odp = dp;			/* Remember where we started. */	xxls = xxdl = xxrc = xxss = xxcq = NUL;	/* Clear these. *//*  Now encode the character according to the options that are in effect:    ctlp[]: whether this control character needs prefixing.    binary: text or binary mode.    rptflg: repeat counts enabled.    ebqflg: 8th-bit prefixing enabled.    lscapu: locking shifts enabled.*/	if (rptflg) {			/* Repeat processing is on? */	    if (		/*		 * If the next char is really CRLF, then we cannot		 * be doing a repeat (unless CR,CR,LF which becomes		 * "~ <n-1> CR CR LF", which is OK but not most efficient).		 * I just plain don't worry about this case.  The actual		 * conversion from NL to CRLF is done after the rptflg if...		 */	    (binary || (feol && (rnext != feol))) &&	    (rt == rnext) && (first == 0)) { /* Got a run... */		if (++rpt < 94) {	/* Below max, just count */		    continue;		/* go back and get another */		}		else if (rpt == 94) {	/* Reached max, must dump */		    xxrc = (CHAR) tochar(rpt); /* Put the repeat count here */		    rptn += rpt;	/* Accumulate it for statistics */		    rpt = 0;		/* And reset it */		}	    } else if (rpt > 1) {	/* More than two */		xxrc = (CHAR) tochar(++rpt); /* and count. */		rptn += rpt;		rpt = 0;		/* Reset repeat counter. */	    }	    /*	      If (rpt == 1) we must encode exactly two characters.	      This is done later, after the first character is encoded.	    */	}	if (!binary && feol && (rt == feol)) { /* It's the newline character */	    if (lscapu && lsstate) {	/* If SHIFT-STATE is SHIFTED */		if (ebqflg) {		/* If single shifts enabled, */		    *dp++ = (CHAR) ebq;	/* insert a single shift. */		} else {		/* Otherwise must shift in. */		    *dp++ = myctlq;	/* Insert shift-out code */		    *dp++ = 'O';		    lsstate = 0;	/* Change shift state */		}	    }#ifdef CK_SPEED	    if (ctlp[CR]) {		*dp++ = myctlq;		/* Insert carriage return directly */		*dp++ = 'M';		ccp++;	    } else {		*dp++ = CR;		/* Perhaps literally */		ccu++;	    }#else /* !CK_SPEED */	    *dp++ = myctlq;		/* Insert carriage return directly */	    *dp++ = 'M';	    ccp++;#endif /* CK_SPEED */	    rt = LF;			/* Now make next char be linefeed. */	}/*  Now handle the 8th bit of the file character.  If we have an 8-bit  connection, we preserve the 8th bit.  If we have a 7-bit connection,  we employ either single or locking shifts (if they are enabled).*/	a7 = rt & 0177;			/* Get low 7 bits of character */	if (rt & 0200) {		/* 8-bit character? */	    if (lscapu) {		/* Locking shifts enabled? */		if (!lsstate) {		/* Not currently shifted? */		    x = lslook(0200);	/* Look ahead */		    if (x != 0 || ebqflg == 0) { /* Locking shift decision */			xxls = 'N';	   /* Need locking shift-out */			lsstate = 1;	   /* and change to shifted state */		    } else if (ebqflg) {   /* Not worth it */			xxss = (CHAR) ebq; /* Use single shift */		    }		}		rt = (CHAR) a7;		/* Replace character by 7-bit value */	    } else if (ebqflg) {	/* 8th bit prefixing is on? */		xxss = (CHAR) ebq;	/* Insert single shift */		rt = (CHAR) a7;		/* Replace character by 7-bit value */	    }/*  In case we have a 7-bit connection and this is an 8-bit character, AND  neither locking shifts nor single shifts are enabled, then the character's  8th bit will be destroyed in transmission, and a block check error will  occur.*/	} else if (lscapu) {		/* 7-bit character */	    if (lsstate) {		/* Comes while shifted out? */		x = lslook(0);		/* Yes, look ahead */		if (x || ebqflg == 0) {	/* Time to shift in. */		    xxls = 'O';		/* Set shift-in code */		    lsstate = 0;	/* Exit shifted state */		} else if (ebqflg) {	/* Not worth it, stay shifted out */		    xxss = (CHAR) ebq;	/* Insert single shift */		}	    }	}	/* If data character is significant to locking shift protocol... */	if (lscapu && (a7 == SO || a7 == SI || a7 == DLE))	  xxdl = 'P';			/* Insert datalink escape */	if (#ifdef CK_SPEED	    /*	      Thwart YET ANOTHER unwanted, unneeded, and unloved sign	      extension.  This one was particularly nasty because it prevented	      255 (Telnet IAC) from being prefixed on some platforms -- e.g.	      VMS with VAX C -- but not others, thus causing file transfers to	      fail on Telnet connections by sending bare IACs.  Not to mention	      the stray memory reference.  Whoever thought it was a good idea	      for characters to be signed (by default or at all) should have	      thunk again.  (Sep 96)	    */	    ctlp[(rt & 0xff)]		/* Lop off any "sign" extension */#else	    (a7 < SP) || (a7 == DEL)#endif /* CK_SPEED */	    ) {				/* Do control prefixing if necessary */	    xxcq = myctlq;		/* The prefix */	    ccp++;			/* Count it */	    rt = (CHAR) ctl(rt);	/* Uncontrollify the character */	}#ifdef CK_SPEED	else if ((a7 < SP) || (a7 == DEL)) /* Count an unprefixed one */	  ccu++;#endif /* CK_SPEED */	if (a7 == myctlq)		/* Always prefix the control prefix */	  xxcq = myctlq;	if ((rptflg) && (a7 == rptq))	/* If it's the repeat prefix, */	  xxcq = myctlq;		/* prefix it if doing repeat counts */	if ((ebqflg) && (a7 == ebq))	/* Prefix the 8th-bit prefix */	  xxcq = myctlq;		/* if doing 8th-bit prefixes *//* Now construct the entire sequence */	if (xxls) { *dp++ = myctlq; *dp++ = xxls; } /* Locking shift */	odp2 = dp;				    /* (Save this place) */	if (xxdl) { *dp++ = myctlq; *dp++ = xxdl; } /* Datalink escape */	if (xxrc) { *dp++ = (CHAR) rptq; *dp++ = xxrc; } /* Repeat count */	if (xxss) { *dp++ = (CHAR) ebq; }           /* Single shift */	if (xxcq) { *dp++ = myctlq; }	    	    /* Control prefix */	*dp++ = rt;			/* Finally, the character itself */	if (rpt == 1) {			/* Exactly two copies? */	    rpt = 0;	    p2 = dp;			/* Save place temporarily */	    for (p1 = odp2; p1 < p2; p1++) /* Copy the old chars over again */	      *dp++ = *p1;	    if ((p2-data) <= bufmax) odp = p2; /* Check packet bounds */	}	rt = rnext;			/* Next character is now current. *//* Done encoding the character.  Now take care of packet buffer overflow. */	if ((dp-data) >= bufmax) {	/* If too big, save some for next. */	    size = (dp-data);		/* Calculate the size. */	    *dp = '\0';			/* Mark the end. */	    if ((dp-data) > bufmax) {	/* if packet is overfull */		/* copy the part that doesn't fit into the leftover buffer, */		/* taking care not to split a prefixed sequence. */		for (p1 = leftover, p2=odp; (*p1 = *p2) != '\0'; p1++,p2++)		    ;		debug(F111,"getpkt leftover",leftover,size);		debug(F101,"getpkt osize","",(odp-data));		size = (odp-data);	/* Return truncated packet. */		*odp = '\0';		/* Mark the new end */	    }	    t = rt;			/* save for next time */#ifdef COMMENT	    next = rnext;	#endif /* COMMENT */	    return(size);	}    }					/* Otherwise, keep filling. */    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;#ifdef CK_TIMERS    extern int rttflg;#endif /* CK_TIMERS */    extern int rcvtimo;    extern char whoareu[];    if (server)      moving  = 0;    bestlen = 0;    maxsend = 0;    debug(F101,"tinit bestlen","",bestlen);    whoareu[0] = NUL;    debug(F100,"tinit setting justone=0","",0);    justone = 0;#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 */    retrans = 0;			/* Packet retransmission count */    sndtyp = 0;				/* No previous packet */    xflg = 0;				/* Reset x-packet flag */    memstr = 0;				/* Reset memory-string flag */    memptr = NULL;			/*  and buffer pointer */    funcstr = 0;			/* Reset "read from function" flag */    funcptr = NULL;			/*  and function pointer */    bctu = bctl = 1;			/* Reset block check type to 1 */    autopar = 0;			/* Automatic parity detection flag */    rqf = -1;				/* Reset 8th-bit-quote request flag */    ebq = MYEBQ;			/* Reset 8th-bit quoting stuff */    ebqflg = 0;				/* 8th bit quoting not enabled */    ebqsent = 0;			/* No 8th-bit prefix bid sent yet */    sq = 'Y';				/* 8th-bit prefix bid I usually send */    binary = b_save;			/* Back to what user last said */    fncnv = f_save;			/* ... */    pktnum = 0;				/* Initial packet number to send */    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 */#ifdef CK_TIMERS    if (rttflg)				/* Using round-trip timers? */      rttinit();#else    rcvtimo = timint;#endif /* CK_TIMERS */    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 */    whatru = 0;    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 */    tlog(F110,"Global file mode:", binary ? "binary" : "text", 0L);    tlog(F110,"Collision action:", fncnam[fncact],0);    tlog(F100,"","",0);    filcnt = filrej = 0;		/* Init file counters */    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 */    ccu = ccp = 0L;			/* Control-char statistics */#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 */    wcur = 0;				/* Current window size */    wmax = 0;				/* Maximum window size used */}/*  S I N I T  --  Get & verify first file name, then send Send-Init packet *//*

⌨️ 快捷键说明

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