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

📄 ckcfns.c

📁 操作系统源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*  T I N I T  --  Initialize a transaction  */tinit() {    xflg = 0;				/* Reset x-packet flag */    memstr = 0;				/* Reset memory-string flag */    memptr = NULL;			/*  and pointer */    bctu = 1;				/* Reset block check type to 1 */    ebq = ebqflg = 0;			/* Reset 8th-bit quoting stuff */    if (savmod) {			/* If binary file mode was saved, */    	binary = 1;			/*  restore it, */	savmod = 0;			/*  unsave it. */    }    prvpkt = -1;			/* Reset packet number */    pktnum = 0;    cxseen = czseen = 0;		/* Reset interrupt flags */    *filnam = '\0';			/* Clear file name */    *sndpkt = '\0';			/* Clear retransmission buffer */    if (server) 			/* If acting as server, */	timint = 30;			/* Use 30 second timeout, */}/*  R I N I T  --  Respond to S packet  */rinit(d) char *d; {    char *tp;    ztime(&tp);    tlog(F110,"Transaction begins",tp,0l); /* Make transaction log entry */    filcnt = 0;				/* Init file counter */    spar(d);    ack1(rpar());#ifdef datageneral    if ((local) && (!quiet))            /* Only do this if local & not quiet */        consta_mt();                    /* Start the asynch read task */#endif}/*  S I N I T  --  Make sure file exists, then send Send-Init packet */sinit() {    int x; char *tp;    filcnt = 0;    sndsrc = nfils;			/* Where to look for files to send */    ztime(&tp);    tlog(F110,"Transaction begins",tp,0l); /* Make transaction log entry */    debug(F101,"sinit: sndsrc","",sndsrc);    if (sndsrc < 0) {			/* Must expand from 'send' command */	nfils = zxpand(cmarg);		/* Look up literal name. */	if (nfils < 0) {	    screen(SCR_EM,0,0l,"Too many files");	    return(0);        } else if (nfils == 0) {	/* If none found, */	    char xname[100];		/* convert the name. */	    zrtol(cmarg,xname);	    nfils = zxpand(xname); 	/* Look it up again. */	}	if (nfils < 1) {		/* If no match, report error. */	    if (server) 	    	errpkt("File not found");	    else		screen(SCR_EM,0,0l,"File not found");	    return(0);	}	x = gnfile();			/* Position to first file. */	if (x < 1) {	    if (!server) 	    	screen(SCR_EM,0,0l,"No readable file to send");            else	    	errpkt("No readable file to send");	    return(0);    	}     } else if (sndsrc > 0) {		/* Command line arglist -- */	x = gnfile();			/* Get the first file from it. */	if (x < 1) return(0);		/* (if any) */    } else if (sndsrc == 0) {		/* stdin or memory always exist... */	if ((cmarg2 != NULL) && (*cmarg2)) {	    strcpy(filnam,cmarg2);	/* If F packet, "as" name is used */	    cmarg2 = "";		/* if provided, */        } else				/* otherwise */	    strcpy(filnam,"stdin");	/* just use this. */    }    debug(F101,"sinit: nfils","",nfils);    debug(F110," filnam",filnam,0);    debug(F110," cmdstr",cmdstr,0);    ttflui();				/* Flush input buffer. */    if (!local && !server) sleep(delay);#ifdef datageneral    if ((local) && (!quiet))            /* Only do this if local & not quiet */        consta_mt();                    /* Start the asynch read task */#endif    sipkt('S');				/* Send the Send-Init packet. */    return(1);}sipkt(c) char c; {			/* Send S or I packet. */    CHAR *rp;    ttflui();				/* Flush pending input. */    rp = rpar();			/* Get parameters. */    spack(c,pktnum,strlen(rp),rp);}/*  R C V F I L -- Receive a file  */rcvfil() {    int x;    ffc = flci = flco = 0;		/* Init per-file counters */    srvptr = srvcmd;			/* Decode file name from packet. */    decode(rdatap,putsrv);    if (*srvcmd == '\0')		/* Watch out for null F packet. */    	strcpy(srvcmd,"NONAME");    screen(SCR_FN,0,0l,srvcmd);		/* Put it on screen */    tlog(F110,"Receiving",srvcmd,0l);	/* Transaction log entry */    if (cmarg2 != NULL) {               /* Check for alternate name */        if (*cmarg2 != '\0') {            strcpy(srvcmd,cmarg2);	/* Got one, use it. */	    *cmarg2 = '\0';        }    }    x = openo(srvcmd,filnam);		/* Try to open it */    if (x) {	tlog(F110," as",filnam,0l);	screen(SCR_AN,0,0l,filnam);	intmsg(++filcnt);#ifdef datageneral/* Need to turn on multi-tasking console interrupt task here, since multiple *//* files may be received. */        if ((local) && (!quiet))        /* Only do this if local & not quiet */            consta_mt();                /* Start the asynch read task */#endif    } else {        tlog(F110,"Failure to open",filnam,0l);	screen(SCR_EM,0,0l,"Can't open file");    }    return(x);				/* Pass on return code from openo */}/*  R E O F  --  Receive End Of File  */reof() {    int x;    if (cxseen == 0) cxseen = (*rdatap == 'D');	/* Got discard directive? */    x = clsof(cxseen | czseen);    if (cxseen || czseen) {	tlog(F100," *** Discarding","",0l);	cxseen = 0;    } else	fstats();    return(x);}/*  R E O T  --  Receive End Of Transaction  */reot() {    cxseen = czseen = 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                   */sfile(x) int x; {    char pktnam[100];			/* Local copy of name */    char *s;    if (x == 0) {			/* F-Packet setup */    	if (*cmarg2 != '\0') {		/* If we have a send-as name, */	    strcpy(pktnam,cmarg2);	/* 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, */	    	strcpy(pktnam,filnam);	/* 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 */    }    flci = flco = ffc = 0;		/* Init counters, etc. */    encstr(s);				/* Encode the name into data[]. */    nxtpkt(&pktnum);			/* Increment the packet number */    spack(x ? 'X' : 'F', pktnum, size, data); /* Send the F or X packet */    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,(long)fsize,"");    	}    	tlog(F110,"Sending",filnam,0l);	/* Transaction log entry */    	tlog(F110," as",pktnam,0l);    } 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. */    return(1);}/*  S D A T A -- Send a data packet *//*  Return -1 if no data to send, else send packet and return length  */sdata() {    int len;    if (cxseen || czseen) return(-1);	/* If interrupted, done. */    if ((len = getpkt(spsiz-bctu-3)) == 0) /* Done if no data. */    	return(-1);    nxtpkt(&pktnum);			/* Increment the packet number */    spack('D',pktnum,len,data);		/* Send the packet */    return(len);}/*  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.  */seof(s) char *s; {    nxtpkt(&pktnum);			/* Increment the packet number */    if ((s != NULL) && (*s != '\0')) {	spack('Z',pktnum,1,s);	tlog(F100," *** interrupted, sending discard request","",0l);    } else {	spack('Z',pktnum,0,"");	fstats();    }}/*  S E O T -- Send an End-Of-Transaction packet */seot() {    nxtpkt(&pktnum);			/* Increment the packet number */    spack('B',pktnum,0,"");		/* Send the EOT packet */    cxseen = czseen = 0;		/* Reset interruption flags */    tstats();				/* Log timing info */}/*   R P A R -- Fill the data array with my send-init parameters  */CHAR *rpar() {    if (rpsiz > 94)      data[1] = tochar(94);    else      data[1] = tochar(rpsiz);		/* Biggest packet I can receive */    data[2] = tochar(rtimo);		/* When I want to be timed out */    data[3] = tochar(mypadn);		/* How much padding I need (none) */    data[4] = ctl(mypadc);		/* Padding character I want */    data[5] = tochar(eol);		/* End-Of-Line character I want */    data[6] = '#';			/* Control-Quote character I send */    switch (rqf) {			/* 8th-bit prefix */	case -1:	case  1: if (parity) ebq = sq = '&'; break;	case  0:	case  2: break;    }    data[7] = sq;    data[8] = bctr + '0';		/* Block check type */    if (rptflg)				/* Run length encoding */    	data[9] = rptq;			/* If receiving, agree. */    else    	data[9] = '~'; 		    data[10] = tochar((atcapr?atcapb:0) | (lpcapr?lpcapb:0) | (swcapr?swcapb:0));    data[capas+1] = tochar(swcapr ? wsize : 0);	/* Window size */    rpsiz = urpsiz;			/* Long packets ... */    data[capas+2] = tochar(rpsiz / 95);	/* Long packet size, big part */    data[capas+3] = tochar(rpsiz % 95);	/* Long packet size, little part */    data[capas+4] = '\0';		/* Terminate the init string */    if (deblog) {	debug(F110,"rpar",data+1,0);	rdebu(capas+2);        }    return(data+1);			/* Return pointer to string. */}spar(s) char *s; {			/* Set parameters */    int x, lpsiz;    s--;				/* Line up with field numbers. */debug(F101,"spar rln","",rln);/* Limit on size of outbound packets */    x = (rln >= 1) ? xunchar(s[1]) : 80;    lpsiz = spsiz;			/* Remember what they SET. */    if (spsizf) {			/* SET-command override? */	if (x < spsiz) spsiz = x;	/* Ignore LEN unless smaller */    } else {				/* otherwise */	spsiz = (x < 10) ? 80 : x;	/* believe them if reasonable */    }/* Timeout on inbound packets */    if (!timef) {			/* Only if not SET-cmd override */	x = (rln >= 2) ? xunchar(s[2]) : 5;	timint = (x < 0) ? 5 : x;    }/* Outbound Padding */    npad = 0; padch = '\0';    if (rln >= 3) {	npad = xunchar(s[3]);	if (rln >= 4) padch = ctl(s[4]); else padch = 0;    }/* Outbound Packet Terminator */    seol = (rln >= 5) ? xunchar(s[5]) : '\r';    if ((seol < 2) || (seol > 31)) seol = '\r';/* 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;    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;    }/* Block check */

⌨️ 快捷键说明

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