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

📄 ckcfns.c

📁 C-Kermit源码。是使用串口/Modem和网络通讯的程序
💻 C
📖 第 1 页 / 共 5 页
字号:
char *fnsv = "C-Kermit functions, 7.0.187, 20 Dec 1999";char *nm[] =  { "Disabled", "Local only", "Remote only", "Enabled" };/*  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, 2000,    Trustees of Columbia University in the City of New York.    All rights reserved.  See the C-Kermit COPYING.TXT file or the    copyright text in the ckcmai.c module for disclaimer and permissions.*//* System-dependent primitives defined in:   ck?tio.c -- terminal (communications) 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 */#include "ckcnet.h"                     /* VMS definition of TCPSOCKET */int docrc  = 0;				/* Accumulate CRC for \v(crc16) */long crc16 = 0L;			/* File CRC = \v(crc16) */extern CHAR feol;extern int byteorder, xflg, remfile, what, fmask, cxseen, czseen;extern long ffc;#ifndef NOXFER/* (move these prototypes to the appropriate .h files...) */#ifdef COMMENT/* Not used */#ifdef VMS_PROTOTYP( int getvnum, (char *) );#endif /* VMS */#endif /* COMMENT */_PROTOTYP( static int bgetpkt, (int) );#ifndef NOCSETS_PROTOTYP( int lookup, (struct keytab[], char *, int, int *) );#endif /* NOCSETS */#ifndef NOSPL_PROTOTYP( int zzstring, (char *, char **, int *) );#endif /* NOSPL */#ifdef OS2ORUNIX_PROTOTYP( long zfsize, (char *) );#endif /* OS2ORUNIX */#ifdef OS2#include <io.h>#endif /* OS2 */#ifdef VMS#include <errno.h>#endif /* VMS *//* Externals from ckcmai.c */extern int srvcdmsg, srvidl, idletmo, bigendian;extern char * cdmsgfile[];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, clfils, sbufnum, protocol, size, osize, spktl, nfils, ckwarn, timef, spsizf, sndtyp, rcvtyp, success;extern int parity, turn, network, whatru, fsecs, justone, slostart, ckdelay, displa, mypadn, moving, recursive, nettype;extern long filcnt, flci, flco, tlci, tlco, tfc, fsize, sendstart, rs_len;extern long filrej, oldcps, cps, peakcps, ccu, ccp, calibrate, filestatus;extern int fblksiz, frecl, frecfm, forg, fcctrl, fdispla, skipbup;extern int spackets, rpackets, timeouts, retrans, crunched, wmax, wcur;extern int hcflg, binary, fncnv, b_save, f_save, server;extern int nakstate, discard, rejection, local, xfermode, interrupted;extern int rq, rqf, sq, wslots, wslotn, wslotr, winlo, urpsiz, rln;extern int fnspath, fnrpath, eofmethod, diractive, whatru2, wearealike;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, nzxopts;extern long rptn;extern int maxtry;extern int stdouf;extern int sendmode;extern int carrier, ttprty;#ifdef TCPSOCKETextern int ttnproto;#endif /* TCPSOCKET */#ifndef NOSPLextern int sndxin, sndxhi, sndxlo;#endif /* NOSPL */extern int g_binary, g_fncnv;#ifdef GFTIMERextern CKFLOAT fpfsecs;#endif /* GFTIMER */#ifdef OS2extern struct zattr iattr;#endif /* OS2 */#ifdef PIPESENDextern int pipesend, usepipes;#endif /* PIPESEND *//* Per-file text/binary-mode recognition */#ifdef PATTERNSextern int patterns;extern char *txtpatterns[];extern char *binpatterns[];#endif /* PATTERNS */#ifdef STREAMINGextern int streamrq, streaming, streamed, streamok;#endif /* STREAMING */extern int reliable, clearrq, cleared, urclear;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 *filefile;extern char whoareu[], * cksysid;#ifndef NOSERVERextern int ngetpath;extern char * getpath[];extern int fromgetpath;#endif /* NOSERVER */extern int inserver;#ifdef CK_LOGINextern int isguest;#endif /* CK_LOGIN */extern CHAR *srvcmd, * epktmsg;extern CHAR padch, mypadc, eol, seol, ctlq, myctlq, sstate, myrptq;extern CHAR *data, padbuf[], stchr, mystch;extern CHAR *srvptr;extern CHAR *rdatap;extern char *cmarg, *cmarg2, **cmlist, filnam[];extern char fspec[], *sfspec, *rfspec;extern int fspeclen;#ifndef NOMSENDextern struct filelist * filehead, * filenext;extern int addlist;#endif /* NOMSEND */_PROTOTYP( int lslook, (unsigned int b) );	/* Locking Shift Lookahead */_PROTOTYP( int szeof, (CHAR *s) );_PROTOTYP( VOID fnlist, (void) );#endif /* NOXFER *//* Character set Translation */#ifndef NOCSETSextern int tcharset, fcharset;extern int ntcsets, xlatype, cseqtab[];extern struct csinfo tcsinfo[], fcsinfo[];_PROTOTYP( CHAR ident, (CHAR) );	/* Identity translation function *//* Arrays of and pointers to character translation functions */#ifdef CK_ANSICextern CHAR (*rx)(CHAR); /* Pointer to input character translation function */extern CHAR (*sx)(CHAR); /* Pointer to output character translation function */extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Byte-to-Byte Send */extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])(CHAR); /* Byte-to-Byte Recv */#ifdef UNICODEextern int (*xut)(USHORT);	/* Translation function UCS to TCS */extern int (*xuf)(USHORT);	/* Translation function UCS to FCS */extern USHORT (*xtu)(CHAR);	/* Translation function TCS to UCS */extern USHORT (*xfu)(CHAR);	/* Translation function FCS to UCS */#endif /* UNICODE */#else /* The same declarations again for non-ANSI comilers... */extern CHAR (*rx)();extern CHAR (*sx)();extern CHAR (*xls[MAXTCSETS+1][MAXFCSETS+1])();extern CHAR (*xlr[MAXTCSETS+1][MAXFCSETS+1])();#ifdef UNICODEextern int (*xut)();extern int (*xuf)();extern USHORT (*xtu)();extern USHORT (*xfu)();#endif /* UNICODE */#endif /* CK_ANSIC */#endif /* NOCSETS *//* (PWP) external def. of things used in buffered file input and output */#ifdef DYNAMICextern char *zinbuffer, *zoutbuffer;#elseextern char zinbuffer[], zoutbuffer[];#endif /* DYNAMIC */extern char *zinptr, *zoutptr;extern int zincnt, zoutcnt, zobufsize;extern long crcta[], crctb[];		/* CRC-16 generation tables */extern int rseqtbl[];			/* Rec'd-packet sequence # table */#ifndef NOXFER/* Variables defined in this module but shared by other modules. */int xfrbel = 1;char * ofperms = "";			/* Output file permissions */int autopath = 0;			/* SET RECEIVE PATHNAMES AUTO flag */#ifdef CALIBRATE#define CAL_O 3#define CAL_M 253int cal_j = 0;CHARcal_a[] = { 16, 45, 98,  3, 52, 41, 14,  7, 76,165,122, 11,104, 77,166, 15,160, 93, 18, 19,112, 85, 54, 23,232,213, 90, 27, 12, 81,126, 31,  4,205, 34, 35,144, 73,110, 39, 28,133,218, 43,156, 65,102, 47, 84, 61, 50, 51,208,117, 86, 55,  8,245, 74, 59, 44,125,222, 63, 80,  1,162, 67,116,105,206, 71,120,  9,250, 75, 88, 97,  6, 79,100,221, 82, 83, 36, 89, 94, 87, 40, 21,106, 91,236,145,150, 95,228, 33,130, 99,148,137,198,103,108,169, 42,107,184,129, 78,111,  0, 49,114,115, 32,121,254,119,172, 57,138,123,152,177, 22,127,240,193,  2,131,176,  5, 38,135,204,229, 10,139,200,161,174,143,128, 17,146,147, 68,153, 30,151, 72,217,170,155, 24,209, 62,159, 64,225,194,163,244,201, 70,167,216,197,234,171,188,109,230,175,212,113,178,179,132,185,190,183,136,249,202,187, 92,241,118,191, 48,237, 66,195, 96,233,142,199,248, 37, 58,203, 60, 13,134,207, 20, 29,210,211,164,149,182,215,220, 25, 26,219,124,157,246,223,180,141,226,227,192,101,238,231, 56, 69,154,235,252,173, 46,239,224,253,242,243,196, 53,214,247,168,181,186,251,140,189,158,255};#endif /* CALIBRATE */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 or other list */					/* -9: calibrate */int  memstr;				/* Flag for input from memory string */int  funcstr;				/* Flag for input from function */int  bestlen = 0;int  maxsend = 0;int gnf_binary = 0;			/* Prevailing xfer mode for gnfile */#ifdef pdp11#define MYINITLEN 32#else#define MYINITLEN 100#endif /* pdp11 */CHAR myinit[MYINITLEN];			/* Copy of my Send-Init data *//* 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 VMSextern int batch;#elseextern int backgrd;#endif /* VMS */#ifdef CK_CTRLZstatic int lastchar = 0;#endif /* CK_CTRLZ */#ifdef CK_ANSICstatic int (*funcptr)(void);		/* Pointer for function strings */#elsestatic int (*funcptr)();#endif /* CK_ANSIC */#ifdef pdp11#define CMDSTRL 50static char cmdstr[50];			/* System command string. */#else#ifdef BIGBUFOK#define CMDSTRL 1024#else#define CMDSTRL 256#endif /* BIGBUFOK */static char cmdstr[CMDSTRL+1];#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 /* datageneral *//*  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 the length of the encoded string on success, -1 if the string  could not be completely encoded into the currently negotiated data  field length.*/int#ifdef CK_ANSICencstr(CHAR *s)#else /* CK_ANSIC */encstr(s) CHAR* s;#endif /* CK_ANSIC */{/*  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.  Modified 14 Jul 98 to return length of encoded string.*/    int m, rc, slen; char *p;    if (!data) {			/* Watch out for null pointers. */	debug(F100,"SERIOUS ERROR: encstr data == NULL","",0);	return(-1);    }    if (!s) s = (CHAR *)"";		/* Ditto. */    slen = strlen((char *)s);		/* Length of source string. */    debug(F111,"encstr",s,slen);    rc = 0;				/* Return code. */    m = memstr; p = memptr;		/* Save these. */    memptr = (char *)s;			/* Point to the string. */    debug(F101,"encstr memptr 1","",memptr);    memstr = 1;				/* Flag memory string as source. */    first = 1;				/* Initialize character lookahead. */    *data = NUL;			/* In case s is empty */    debug(F101,"encstr spsiz","",spsiz);    rc = getpkt(spsiz,0);		/* Fill a packet from the string. */    debug(F101,"encstr getpkt rc","",rc);    if (rc > -1 && memptr < (char *)(s + slen)) { /* Means we didn't encode */	rc = -1;			/* the whole string. */	debug(F101,"encstr string too big","",size);    }    debug(F101,"encstr getpkt rc","",rc);    memstr = m;				/* Restore memory string flag */    memptr = p;				/* and pointer */    first = 1;				/* Put this back as we found it. */    return(rc);}/*  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);}

⌨️ 快捷键说明

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