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

📄 ckcfns.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
char *fnsv = "C-Kermit functions, 5A(080) 24 Nov 92";/*  C K C F N S  --  System-independent Kermit protocol support functions.  *//*  ...Part 1 (others moved to ckcfn2,3 to make this module small enough) *//*  Author: Frank da Cruz (fdc@columbia.edu, FDCCU@CUVMA.BITNET),  Columbia University Center for Computing Activities.  First released January 1985.  Copyright (C) 1985, 1992, Trustees of Columbia University in the City of New  York.  Permission is granted to any individual or institution to use this  software as long as it is not sold for profit.  This copyright notice must be  retained.  This software may not be included in commercial products without  written permission of Columbia University.*//* System-dependent primitives defined in:   ck?tio.c -- terminal i/o   cx?fio.c -- file i/o, directory structure*/#include "ckcsym.h"			/* Once needed this for Mac... */#include "ckcasc.h"			/* ASCII symbols */#include "ckcdeb.h"			/* Debug formats, typedefs, etc. */#include "ckcker.h"			/* Symbol definitions for Kermit */#include "ckcxla.h"			/* Character set symbols *//* Externals from ckcmai.c */extern int spsiz, spmax, rpsiz, timint, srvtim, rtimo, npad, ebq, ebqflg, rpt, rptq, rptflg, capas, keep, fncact, pkttim, autopar, spsizr;extern int pktnum, bctr, bctu, bctl, fmask, clfils, sbufnum, size, osize, spktl, nfils, warn, timef, spsizf, sndtyp, success;extern int parity, turn, network, what, fsecs, delay, displa, xflg, mypadn;extern long filcnt, ffc, flci, flco, tlci, tlco, tfc, fsize, speed;extern int fblksiz, frecl, frecfm, forg, fcctrl;extern int spackets, rpackets, timeouts, retrans, crunched, wmax;extern int hcflg, binary, savmod, fncnv, local, server, cxseen, czseen;extern int nakstate, discard;extern int rq, rqf, sq, wslots, wslotn, wslotr, winlo, urpsiz, rln;extern int atcapr, atcapb, atcapu;extern int lpcapr, lpcapb, lpcapu;extern int swcapr, swcapb, swcapu;extern int lscapr, lscapb, lscapu;extern int bsave, bsavef;extern int sseqtbl[];extern int numerrs;extern long rptn;extern int maxtry;#ifndef NOCSETSextern int tcharset, fcharset;extern int ntcsets;extern struct csinfo tcsinfo[], fcsinfo[];#endif /* NOCSETS */extern int  atenci, atenco, atdati, atdato, atleni, atleno, atblki, atblko,  attypi, attypo, atsidi, atsido, atsysi, atsyso, atdisi, atdiso; extern int bigsbsiz, bigrbsiz;#ifdef DYNAMIC  extern CHAR *srvcmd;#else  extern CHAR srvcmd[];#endif /* DYNAMIC */extern CHAR padch, mypadc, eol, seol, ctlq, myctlq, sstate;extern CHAR *recpkt, *data, padbuf[], stchr, mystch;extern CHAR *srvptr;extern CHAR *rdatap;extern char *cmarg, *cmarg2, *hlptxt, **cmlist, filnam[], fspec[];_PROTOTYP( CHAR *rpar, (void) );_PROTOTYP( int lslook, (unsigned int b) );	/* Locking Shift Lookahead */_PROTOTYP( int szeof, (CHAR *s) );/* International character sets */#ifndef NOCSETS/* Pointers to translation functions */#ifdef CK_ANSICextern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Character set */extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* translation functions */#elseextern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])();	/* Character set */extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])();	/* translation functions. */#endif /* CK_ANSIC */_PROTOTYP( CHAR (*rx), (CHAR) );	/* Input translation function */_PROTOTYP( CHAR (*sx), (CHAR) );	/* Output translation function */_PROTOTYP( CHAR ident, (CHAR) );	/* Identity translation function */#endif /* NOCSETS *//* Windowing things */extern int rseqtbl[];			/* Rec'd-packet sequence # table *//* (PWP) external def. of things used in buffered file input and output */#ifdef DYNAMICextern char *zinbuffer, *zoutbuffer;#elseextern char zinbuffer[], zoutbuffer[];#endifextern char *zinptr, *zoutptr;extern int zincnt, zoutcnt;/* Variables defined in this module, but shared by ckcfn3, to which *//* several functions have been moved... */int sndsrc;		/* Flag for where to get names of files to send: */					/* -1: znext() function */					/*  0: stdin */					/* >0: list in cmlist */int  memstr;				/* Flag for input from memory string */#ifdef pdp11CHAR myinit[25];			/* Copy of my Send-Init data */#elseCHAR myinit[100];			/* Copy of my Send-Init data */#endif /* pdp11 *//* Variables local to this module */static char *memptr;			/* Pointer for memory strings */#ifdef pdp11static char cmdstr[50];			/* System command string. */#elsestatic char cmdstr[100];#endif /* pdp11 */static int drain;			/* For draining stacked-up ACKs. */static int first;			/* Flag for first char from input */static CHAR t,				/* Current character */    next;				/* Next character */static int lsstate = 0;			/* Locking shift state */static int lsquote = 0;			/* Locking shift quote */#ifdef datageneralextern int quiet;#endif/*  E N C S T R  --  Encode a string from memory. *//*  Call this instead of getpkt() if source is a string, rather than a file.  Note: Character set translation is never done in this case.*/#ifdef pdp11#define ENCBUFL 100#else#define ENCBUFL 200#endif /* pdp11 */CHAR encbuf[ENCBUFL];intencstr(s) CHAR* s; {    int m; char *p;    CHAR *dsave;    if ((m = (int)strlen((char *)s)) > ENCBUFL) {	debug(F111,"encstr string too long for buffer",s,ENCBUFL);	s[ENCBUFL] = '\0';    }    if (m > spsiz-bctl-3) {	debug(F111,"encstr string too long for packet",s,spsiz-bctl-3);	s[spsiz-bctl-3] = '\0';    }    m = memstr; p = memptr;		/* Save these. */    memptr = (char *)s;			/* Point to the string. */    memstr = 1;				/* Flag memory string as source. */    first = 1;				/* Initialize character lookahead. */    dsave = data;			/* Boy is this ugly... */    data = encbuf + 7;			/* Why + 7?  See spack()... */#ifdef COMMENT    getpkt(spsiz-bctl-3,0);		/* Fill a packet from the string. */#else    getpkt(spsiz,0);#endif /* COMMENT */    data = dsave;			/* (sorry...) */    memstr = m;				/* Restore memory string flag */    memptr = p;				/* and pointer */    first = 1;				/* Put this back as we found it. */    return(0);}#ifdef COMMENT/*  We don't use this routine any more -- the code has been incorporated  directly into getpkt() to reduce per-character function call overhead.  Also, watch out: it hasn't been updated since it was commented out a  long time ago.*//* E N C O D E - Kermit packet encoding procedure */VOIDencode(a) CHAR a; {			/* The current character */    int a7;				/* Low order 7 bits of character */    int b8;				/* 8th bit of character */ #ifndef NOCSETS    if (!binary && sx) a = (*sx)(a);	/* Translate. */#endif /* NOCSETS */    if (rptflg)	{   	    		/* Repeat processing? */        if (a == next && (first == 0)) { /* Got a run... */	    if (++rpt < 94)		/* Below max, just count */                return;	    else if (rpt == 94) {	/* Reached max, must dump */                data[size++] = rptq;                data[size++] = tochar(rpt);		rptn += rpt;		/* Count, for stats */                rpt = 0;	    }        } else if (rpt == 1) {		/* Run broken, only 2? */            rpt = 0;			/* Yes, reset repeat flag & count. */	    encode(a);			/* Do the character twice. */	    if (size <= maxsize) osize = size;	    rpt = 0;	    encode(a);	    return;	} else if (rpt > 1) {		/* More than two */            data[size++] = rptq;	/* Insert the repeat prefix */            data[size++] = tochar(++rpt); /* and count. */	    rptn += rpt;            rpt = 0;			/* Reset repeat counter. */        }    }    a7 = a & 0177;			/* Isolate ASCII part */    b8 = a & 0200;			/* and 8th (parity) bit. */    if (ebqflg && b8) {			/* Do 8th bit prefix if necessary. */        data[size++] = ebq;        a = a7;    }    if ((a7 < SP) || (a7==DEL))	{	/* Do control prefix if necessary */        data[size++] = myctlq;	a = ctl(a);    }    if (a7 == myctlq)			/* Prefix the control prefix */        data[size++] = myctlq;    if ((rptflg) && (a7 == rptq))	/* If it's the repeat prefix, */        data[size++] = myctlq;		/* quote it if doing repeat counts. */    if ((ebqflg) && (a7 == ebq))	/* Prefix the 8th bit prefix */        data[size++] = myctlq;		/* if doing 8th-bit prefixes */    data[size++] = a;			/* Finally, insert the character */    data[size] = '\0';			/* itself, and mark the end. */}#endif /* COMMENT *//*  Output functions passed to 'decode':  */int			       /*  Put character in server command buffer  */#ifdef CK_ANSICputsrv(char c)#elseputsrv(c) register char c;#endif /* CK_ANSIC *//* putsrv */ {    *srvptr++ = c;    *srvptr = '\0';		/* Make sure buffer is null-terminated */    return(0);}int					/*  Output character to console.  */#ifdef CK_ANSICputtrm(char c)#elseputtrm(c) register char c;#endif /* CK_ANSIC *//* puttrm */ {    conoc(c);    return(0);}int					/*  Output char to file. */#ifdef CK_ANSICputfil(char c)#elseputfil(c) register char c;#endif /* CK_ANSIC *//* putfil */ {    if (zchout(ZOFILE, (char) (c & fmask)) < 0) {	czseen = 1;   			/* If write error... */	debug(F101,"putfil zchout write error, setting czseen","",1);	return(-1);    }    return(0);}/* D E C O D E  --  Kermit packet decoding procedure *//* Call with string to be decoded and an output function. Returns 0 on success, -1 on failure (e.g. disk full). This is the "inner loop" when receiving files, and must be coded as  efficiently as possible.  Note some potential problems:  if a packet is badly formed, having a prefixed sequence ending prematurely, this function, as coded, could read past the end of the packet.  This has never happened, thus the additional (time-consuming) tests have not been added.*/static CHAR *xdbuf;	/* Global version of decode()'s buffer pointer */                        /* for use by translation functions. *//* Function for pushing a character onto decode()'s input stream. */VOID#ifdef CK_ANSICzdstuff(CHAR c)#elsezdstuff(c) CHAR c;#endif /* CK_ANSIC *//* zdstuff */ {	    xdbuf--;				/* Back up the pointer. */    *xdbuf = c;				/* Stuff the character. */}int#ifdef CK_ANSICdecode(CHAR *buf, int (*fn)(char), int xlate)#elsedecode(buf,fn,xlate) register CHAR *buf; register int (*fn)(); int xlate;#endif /* CK_ANSIC *//* decode */ {    register unsigned int a, a7, a8, b8; /* Various copies of current char */    int t;				/* Int version of character */    int ssflg;				/* Character was single-shifted *//*  Catch the case in which we are asked to decode into a file that is not open,  for example, if the user interrupted the transfer, but the other Kermit  keeps sending.*/    if ((cxseen || czseen || discard) && (fn == putfil))      return(0);    xdbuf = buf;			/* Make global copy of pointer. */    rpt = 0;				/* Initialize repeat count. */    while ((a = *xdbuf++ & 0xFF) != '\0') { /* Get next character. */	if (a == rptq && rptflg) {	/* Got a repeat prefix? */	    rpt = xunchar(*xdbuf++ & 0xFF); /* Yes, get the repeat count, */	    rptn += rpt;	    a = *xdbuf++ & 0xFF;	/* and get the prefixed character. */	}	b8 = lsstate ? 0200 : 0;	/* 8th-bit value from SHIFT-STATE */	if (ebqflg && a == ebq) {	/* Have 8th-bit prefix? */	    b8 ^= 0200;			/* Yes, invert the 8th bit's value, */	    ssflg = 1;			/* remember we did this, */	    a = *xdbuf++ & 0xFF;	/* and get the prefixed character. */	} else ssflg = 0;	if (a == ctlq) {		/* If control prefix, */	    a  = *xdbuf++ & 0xFF;	/* get its operand */	    a7 = a & 0x7F;		/* and its low 7 bits. */	    if ((a7 >= 0100 && a7 <= 0137) || a7 == '?') /* Controllify */	      a = ctl(a);		/* if in control range. */	    if (lscapu) {		/* If doing locking shifts... */		if (lsstate)		/* If SHIFTED */		  a8 = (a & ~b8) & 0xFF; /* Invert meaning of 8th bit */		else			/* otherwise */		  a8 = a | b8;		/* OR in 8th bit */		/* If we're not in a quoted sequence */		if (!lsquote && (!lsstate || !ssflg)) {		    if (a8 == DLE) {	/* Check for DLE quote */			lsquote = 1;	/* prefixed by single shift! */			continue;		    } else if (a8 == SO) { /* Check for Shift-Out */			lsstate = 1;	/* SHIFT-STATE = SHIFTED */			continue;		    } else if (a8 == SI) { /* or Shift-In */			lsstate = 0;	/* SHIFT-STATE = UNSHIFTED */			continue;		    }		} else lsquote = 0;	    }	}	a |= b8;			/* OR in the 8th bit */	if (rpt == 0) rpt = 1;		/* If no repeats, then one */	if (!binary) {			/* If in text mode, */#ifdef NLCHAR	    if (a == CR) continue;	/* Discard carriage returns, */    	    if (a == LF) a = NLCHAR; 	/* convert LF to system's newline. */#endif /* NLCHAR */#ifndef NOCSETS				/* Character-set translation */#ifdef KANJI				/* For Kanji transfers, */	    if (tcharset != TC_JEUC)	/* postpone translation. */#endif /* KANJI */	      if (xlate && rx) a = (*rx)((CHAR) a); /* Translate charset */#endif /* NOCSETS */    	}	if (fn == putfil) { /* (PWP) speedup via buffered output and a macro */	    for (; rpt > 0; rpt--) {	/* Output the char RPT times */#ifndef NOCSETS

⌨️ 快捷键说明

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