📄 ckcfns.c
字号:
char *fnsv = "C-Kermit functions, 6.0.133, 6 Sep 96";/* C K C F N S -- System-independent Kermit protocol support functions. *//* ...Part 1 (others moved to ckcfn2,3 to make this module smaller) *//* Author: Frank da Cruz <fdc@columbia.edu>, Columbia University Academic Information Systems, New York City. Copyright (C) 1985, 1996, Trustees of Columbia University in the City of New York. The C-Kermit software may not be, in whole or in part, licensed or sold for profit as a software product itself, nor may it be included in or distributed with commercial products or otherwise distributed by commercial concerns to their clients or customers without written permission of the Office of Kermit Development and Distribution, Columbia University. This copyright notice must not be removed, altered, or obscured.*//* System-dependent primitives defined in: ck?tio.c -- terminal i/o cx?fio.c -- file i/o, directory structure*/#include "ckcsym.h" /* Needed for Stratus VOS */#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 */#ifdef OS2#include <io.h>#endif /* OS2 */#ifdef VMS#include <errno.h>#endif /* VMS *//* Externals from ckcmai.c */extern int spsiz, spmax, rpsiz, timint, srvtim, rtimo, npad, ebq, ebqflg, rpt, rptq, rptflg, capas, keep, fncact, pkttim, autopar, spsizr, xitsta;extern int pktnum, bctr, bctu, bctl, fmask, clfils, sbufnum, protocol, size, osize, spktl, nfils, warn, timef, spsizf, sndtyp, rcvtyp, success;extern int parity, turn, network, what, whatru, fsecs, justone, slostart, delay, displa, xflg, mypadn, remfile, moving;extern long filcnt, ffc, flci, flco, tlci, tlco, tfc, fsize, sendstart, rs_len;extern long filrej, oldcps, cps, ccu, ccp;extern int fblksiz, frecl, frecfm, forg, fcctrl;extern int spackets, rpackets, timeouts, retrans, crunched, wmax, wcur;extern int hcflg, binary, fncnv, b_save, f_save, server, cxseen, czseen;extern int nakstate, discard, rejection, local;extern int rq, rqf, sq, wslots, wslotn, wslotr, winlo, urpsiz, rln;extern int fnspath, fnrpath;extern int atcapr, atcapb, atcapu;extern int lpcapr, lpcapb, lpcapu;extern int swcapr, swcapb, swcapu;extern int lscapr, lscapb, lscapu;extern int rscapr, rscapb, rscapu;extern int rptena, rptmin;extern int sseqtbl[];extern int numerrs;extern long rptn;extern int maxtry;extern int stdouf;extern int sendmode;#ifdef OS2extern struct zattr iattr;#endif /* OS2 */#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;extern char *versio;extern char whoareu[], * cksysid;#ifndef NOSERVERextern int ngetpath;extern char * getpath[];#endif /* NOSERVER */#ifdef DYNAMIC extern CHAR *srvcmd;#else extern CHAR srvcmd[];#endif /* DYNAMIC */extern CHAR padch, mypadc, eol, seol, feol, ctlq, myctlq, sstate, myrptq;extern CHAR *data, padbuf[], stchr, mystch;extern CHAR *srvptr;extern CHAR *rdatap;extern char *cmarg, *cmarg2, *hlptxt, **cmlist, filnam[], fspec[];#ifndef NOMSENDextern struct filelist * filehead, * filenext;extern int addlist;#endif /* NOMSEND */_PROTOTYP( CHAR *rpar, (void) );_PROTOTYP( int lslook, (unsigned int b) ); /* Locking Shift Lookahead */_PROTOTYP( int szeof, (CHAR *s) );_PROTOTYP( VOID fnlist, (void) );_PROTOTYP( static int nxtdir, (void) );_PROTOTYP( static int nxtdel, (void) );/* 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;extern long crcta[], crctb[]; /* CRC-16 generation tables *//* Variables defined in this module but shared by other modules.*/long crc16 = 0L; /* File CRC = \v(crc16) */int docrc = 1;int xfrbel = 1;char * rf_err = "Error receiving file"; /* rcvfil() error message */#ifdef CK_SPEEDshort ctlp[256] = { /* Control-Prefix table */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* C0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* G0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, /* DEL */ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* C1 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* G1 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 /* 255 */};#endif /* CK_SPEED */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 */int funcstr; /* Flag for input from function */int bestlen = 0;int maxsend = 0;#ifdef pdp11CHAR myinit[32]; /* Copy of my Send-Init data */#elseCHAR myinit[100]; /* Copy of my Send-Init data */#endif /* pdp11 *//* Variables local to this module */#ifdef TLOG#ifndef XYZ_INTERNALstatic#endif /* XYZ_INTERNAL */char *fncnam[] = { "rename", "replace", "backup", "append", "discard", "ask", "update", ""};#endif /* TLOG */static char *memptr; /* Pointer for memory strings */#ifdef CK_ANSIstatic int (*funcptr)(char *); /* Pointer for function strings */#elsestatic int (*funcptr)();#endif /* CK_ANSI */#ifdef pdp11static char cmdstr[50]; /* System command string. */#elsestatic char cmdstr[256];#endif /* pdp11 */static int drain; /* For draining stacked-up ACKs. */static int first; /* Flag for first char from input */static CHAR t; /* Current character */#ifdef COMMENTstatic CHAR next; /* Next character */#endif /* COMMENT */static int ebqsent = 0; /* 8th-bit prefix bid that I sent */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 COMMENT#define ENCBUFL 200#ifndef pdp11CHAR encbuf[ENCBUFL];#else/* This is gross, but the pdp11 root segment is out of space *//* Will allocate it in ckuusr.c. */extern CHAR encbuf[];#endif /* pdp11 */#endif /* COMMENT *//* Encode packet data from a string in memory rather than from a file. Returns 0 on success, -1 if the string could not be completely encoded into the currently negotiated data field length.*/intencstr(s) CHAR* s; {#ifdef COMMENT int m; char *p; CHAR *dsave; if (!s) s = (CHAR *)""; 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()... */ *data = NUL; /* In case s is empty */ getpkt(spsiz,0); /* Fill a packet from the string. */ data = dsave; /* (sorry...) */ memstr = m; /* Restore memory string flag */ memptr = p; /* and pointer */ first = 1; /* Put this back as we found it. */ return(0);#else/* Recoded 30 Jul 94 to use the regular data buffer and the negotiated maximum packet size. Previously we were limited to the length of encbuf[]. Also, to return a failure code if the entire encoded string would not fit.*/ int m, rc, slen; char *p; if (!s) s = (CHAR *)""; /* Watch out for null pointers. */ slen = strlen((char *)s); /* Length of source string. */ rc = 0; /* Return code. */ 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. */ *data = NUL; /* In case s is empty */ getpkt(spsiz,0); /* Fill a packet from the string. */ if (#ifdef COMMENT *memptr#else memptr < (char *)(s + slen)#endif /* COMMENT */ ) { /* This means we didn't encode */ rc = -1; /* the whole string. */ debug(F101,"encstr string too big","",size); } else debug(F101,"encstr fits OK, size","",size); memstr = m; /* Restore memory string flag */ memptr = p; /* and pointer */ first = 1; /* Put this back as we found it. */ return(rc);#endif /* COMMENT */}#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: this routine 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 */ {#ifndef NOSPL extern char * qbufp; /* If REMOTE QUERY active, */ extern int query, qbufn; /* also store response in */ if (query && qbufn++ < 1024) { /* query buffer. */ *qbufp++ = c; *qbufp = NUL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -