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

📄 ckcfns.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Block check */    x = 1;    if (rln >= 8) {	if (s[8] == 'B') x = 4;	else x = s[8] - '0';	if ((x < 1) || (x > 4)) x = 1;    }    bctr = x;/* Repeat prefix */    if (rln >= 9) {	rptq = s[9]; 	rptflg = ((rptq > 32 && rptq < 63) || (rptq > 95 && rptq < 127));    } else rptflg = 0;/* Capabilities */    atcapu = lpcapu = swcapu = 0;	/* Assume none of these */    if (lscapu != 2) lscapu = 0;	/* Assume no LS unless forced. */    y = 11;				/* Position of next field, if any */    if (rln >= 10) {        x = xunchar(s[10]);	debug(F101,"spar capas","",x);        atcapu = (x & atcapb) && atcapr;	lpcapu = (x & lpcapb) && lpcapr;	swcapu = (x & swcapb) && swcapr;	debug(F101,"spar lscapu","",lscapu);	debug(F101,"spar lscapr","",lscapr);	debug(F101,"spar ebqflg","",ebqflg);	if (lscapu != 2) lscapu = ((x & lscapb) && lscapr && ebqflg) ? 1 : 0;	debug(F101,"spar swcapr","",swcapr);	debug(F101,"spar swcapu","",swcapu);	debug(F101,"spar lscapu","",lscapu);	for (y = 10; (xunchar(s[y]) & 1) && (rln >= y); y++) ;	debug(F101,"spar y","",y);    }/* Long Packets */    debug(F101,"spar lpcapu","",lpcapu);    if (lpcapu) {        if (rln > y+1) {	    x = xunchar(s[y+2]) * 95 + xunchar(s[y+3]);	    debug(F101,"spar lp len","",x);	    if (spsizf) {		/* If overriding negotiations */		spsiz = (x < lpsiz) ? x : lpsiz; /* do this, */	    } else {			         /* otherwise */		spsiz = (x > MAXSP) ? MAXSP : x; /* do this. */	    }	    if (spsiz < 10) spsiz = 80;	/* Be defensive... */	}    }    /* (PWP) save current send packet size for optimal packet size calcs */    spmax = spsiz;    debug(F101,"spar lp spmax","",spmax);    timint = chktimo(timint,timef);	/* Recalculate the packet timeout! */    /* Sliding Windows... */    if (swcapr) {			/* Only if requested... */        if (rln > y) {			/* See what other Kermit says */	    x = xunchar(s[y+1]);	    debug(F101,"spar window","",x);	    wslotn = (x > MAXWS) ? MAXWS : x;/*  wslotn = negotiated size (from other Kermit's S or I packet).  wslotr = requested window size (from this Kermit's SET WINDOW command).*/	    if (wslotn > wslotr)	/* Use the smaller of the two */	      wslotn = wslotr;	    if (wslotn < 1)		/* Watch out for bad negotiation */	      wslotn = 1;	    if (wslotn > 1)	      swcapu = 1; /* We do windows... */	    debug(F101,"spar window after adjustment","",x);	} else {			/* No window size specified. */	    wslotn = 1;			/* We don't do windows... */	    debug(F101,"spar window","",x);	    swcapu = 0;	    debug(F101,"spar no windows","",wslotn);	}    }/* Now recalculate packet length based on number of windows.   *//* The nogotiated number of window slots will be allocated,    *//* and the maximum packet length will be reduced if necessary, *//* so that a windowful of packets can fit in the big buffer.   */    if (wslotn > 1) {			/* Shrink to fit... */	x = adjpkl(spsiz,wslotn,bigsbsiz);	if (x < spsiz) {	    spsiz = spmax = x;	    debug(F101,"spar sending, redefine spsiz","",spsiz);	}    }/* Record parameters in debug log */#ifdef DEBUG    if (deblog) sdebu(rln);#endif /* DEBUG */    numerrs = 0;			/* Start counting errors here. */    return(0);}/*  G N F I L E  --  Get name of next file to send  *//*  Expects global sndsrc to be:   -1: next filename to be obtained by calling znext().    0: no next file name    1: (or greater) next filename to be obtained from **cmlist.  Returns:    1, with name of next file in filnam.    0, no more files, with filnam set to empty string.   -1, file not found   -2, file is not readable   -3, read access denied   -4, cancelled   -5, too many files match wildcard*/intgnfile() {    int x; long y;    int retcode = 0;    debug(F101,"gnfile sndsrc","",sndsrc);    fsize = -1L;			/* Initialize file size */    if (sndsrc == 0) {			/* It's not really a file */	if (nfils > 0) {		/* It's a pipe, or stdin */	    strcpy(filnam, *cmlist);	/* Copy its "name" */	    nfils = 0;			/* There is no next file */	    return(1);			/* OK this time */	} else return(0);		/* but not next time */    }/* If file group interruption (C-Z) occurred, fail.  */    if (czseen) {	tlog(F100,"Transaction cancelled","",0L);        debug(F100,"gnfile czseen","",0);	return(-4);    }/* Loop through file list till we find a readable, sendable file */    y = -1L;				/* Loop exit (file size) variable */    while (y < 0L) {			/* Keep trying till we get one... */	if (sndsrc > 0) {		/* File list in cmlist */	    debug(F101,"gnfile nfils","",nfils);	    if (nfils-- > 0) {		/* Still some left? */		strcpy(filnam,*cmlist++);		debug(F111,"gnfile cmlist filnam",filnam,nfils);		if (!clfils) {		/* Expand only if not from cmdline */		    x = zxpand(filnam);		    debug(F101,"gnfile zxpand","",x);		    if (x == 1) {			znext(filnam);			goto gotnam;		    }		    if (x == 0) {			retcode = -1; /* None match */			continue;		    }		    if (x < 0) return(-5); /* Too many to expand */		    sndsrc = -1;	/* Change send-source to znext() */		}	    } else {			/* We're out of files. */		debug(F101,"gnfile done","",nfils);		*filnam = '\0';		return(retcode);	    }	}/* Otherwise, step to next element of internal wildcard expansion list. */	if (sndsrc < 0) {	    x = znext(filnam);	    debug(F111,"gnfile znext",filnam,x);	    if (x == 0) {		/* If no more, */		sndsrc = 1;		/* go back to list */		continue;	    }	}/* Get here with a filename. */gotnam:	if (sndsrc) {	    y = zchki(filnam);		/* Check if file readable */	    retcode = (int) y;		/* Possible return code */	    if (y == -1L) {		/* If not found */		debug(F110,"gnfile skipping:",filnam,0);		tlog(F111,filnam,"not sent, reason",(long)y);		screen(SCR_ST,ST_SKIP,0l,filnam);		continue;	    } else if (y < 0) {		continue;	    } else {		fsize = y;		return(1);	    }	} else return(1);		/* sndsrc is 0... */    }    *filnam = '\0';			/* Should never get here */    return(0);}/*  S N D H L P  --  Routine to send builtin help  */intsndhlp() {#ifndef NOSERVER    nfils = 0;				/* No files, no lists. */    xflg = 1;				/* Flag we must send X packet. */    strcpy(cmdstr,"help text");		/* Data for X packet. */    first = 1;				/* Init getchx lookahead */    memstr = 1;				/* Just set the flag. */    memptr = hlptxt;			/* And the pointer. */    if (binary) {			/* If file mode is binary, */	savmod = binary;		/*  remember to restore it later. */	binary = 0;			/*  turn it back to text for this, */    }    return(sinit());#else    return(0);#endif /* NOSERVER */}#ifdef OS2/*  S N D S P A C E -- send disk space message  */intsndspace(int drive) {#ifndef NOSERVER    static char spctext[64];    if (drive)      sprintf(spctext, " Drive %c: %ldK free\n", drive, 	      zdskspace(drive - 'A' + 1) / 1024L);    else      sprintf(spctext, " Free space: %ldK\n", zdskspace(0)/1024L);    nfils = 0;			/* No files, no lists. */    xflg = 1;			/* Flag we must send X packet. */    strcpy(cmdstr,"free space");/* Data for X packet. */    first = 1;			/* Init getchx lookahead */    memstr = 1;			/* Just set the flag. */    memptr = spctext;		/* And the pointer. */    if (binary) {		/* If file mode is binary, */        savmod = binary;	/*  remember to restore it later. */        binary = 0;		/*  turn it back to text for this, */    }    return(sinit());#else    return(0);#endif /* NOSERVER */}#endif /* OS2 *//*  C W D  --  Change current working directory  *//* String passed has first byte as length of directory name, rest of string is name.  Fails if can't connect, else ACKs (with name) and succeeds. */intcwd(vdir) char *vdir; {    char *cdd, *zgtdir(), *dirp;    vdir[xunchar(*vdir) + 1] = '\0';	/* Terminate string with a null */    dirp = vdir+1;    tlog(F110,"Directory requested: ",dirp,0L);    if (zchdir(dirp)) {		/* Try to change */	cdd = zgtdir();		/* Get new working directory. */	debug(F110,"cwd",cdd,0);	encstr((CHAR *)cdd);	ack1((CHAR *)(encbuf+7));	tlog(F110,"Changed directory to",cdd,0L);	return(1);     } else {	debug(F110,"cwd failed",dirp,0);	tlog(F110,"Failed to change directory to",dirp,0L);	return(0);    }}/*  S Y S C M D  --  Do a system command  *//*  Command string is formed by concatenating the two arguments.  */intsyscmd(prefix,suffix) char *prefix, *suffix; {    char *cp;    if (prefix == NULL || *prefix == '\0') return(0);    for (cp = cmdstr; *prefix != '\0'; *cp++ = *prefix++) ;    while (*cp++ = *suffix++) ;		/* copy suffix */    debug(F110,"syscmd",cmdstr,0);    if (zxcmd(ZIFILE,cmdstr) > 0) {	debug(F110,"syscmd zxcmd ok",cmdstr,0);	nfils = sndsrc = 0;		/* Flag that input is from stdin */	xflg = hcflg = 1;		/* And special flags for pipe */	if (binary) {			/* If file mode is binary, */	    savmod = binary;		/*  remember to restore it later. */	    binary = 0;			/*  turn it back to text for this, */	}	return (sinit());		/* Send S packet */    } else {	debug(F100,"syscmd zxcmd failed",cmdstr,0);	return(0);    }}/*  R E M S E T  --  Remote Set  *//*  Called by server to set variables as commanded in REMOTE SET packets.  *//*  Returns 1 on success, 0 on failure.  */intremset(s) char *s; {    int len, i, x, y;    char *p;    len = xunchar(*s++);		/* Length of first field */    p = s + len;			/* Pointer to second length field */    *p++ = '\0';			/* Zero out second length field */    x = atoi(s);			/* Value of first field */    debug(F111,"remset",s,x);    debug(F110,"remset",p,0);    switch (x) {			/* Do the right thing */      case 132:				/* Attributes (all, in) */	atcapr = atoi(p);	return(1);      case 133:				/* File length attributes */      case 233:				/* IN/OUT combined */      case 148:				/* Both kinds of lengths */      case 248:	atleni = atleno = atoi(p);	return(1);      case 134:				/* File Type (text/binary) */      case 234:	attypi = attypo = atoi(p);	return(1);      case 135:				/* File creation date */      case 235:	atdati = atdato = atoi(p);	return(1);      case 139:				/* File Blocksize */      case 239:	atblki = atblko = atoi(p);	return(1);      case 141:				/* Encoding / Character Set */      case 241:	atenci = atenco = atoi(p);	return(1);      case 142:				/* Disposition */      case 242:	atdisi = atdiso = atoi(p);	return(1);      case 145:				/* System ID */      case 245:	atsidi = atsido = atoi(p);	return(1);      case 147:				/* System-Dependent Info */      case 247:	atsysi = atsyso = atoi(p);	return(1);      case 232:				/* Attributes (all, out) */	atcapr = atoi(p);	return(1);      case 300:				/* File type (text, binary) */	binary = atoi(p);	return(1);      case 301:				/* File name conversion */	fncnv = 1 - atoi(p);		/* (oops) */	return(1);      case 302:				/* File name collision */	x = atoi(p);	if (x == XYFX_R) warn = 1;	/* Rename */	if (x == XYFX_X) warn = 0;	/* Replace */	fncact = x;	return(1);      case 310:				/* Incomplete File Disposition */	keep = atoi(p);			/* Keep, Discard */	return(1);      case 311:				/* Blocksize */	fblksiz = atoi(p);	return(1);      case 312:				/* Record Length */	frecl = atoi(p);	return(1);      case 313:				/* Record format */	frecfm = atoi(p);	return(1);      case 314:				/* File organization */	forg = atoi(p);	return(1);      case 315:				/* File carriage control */	fcctrl = atoi(p);	return(1);      case 400:				/* Block check */	y = atoi(p);	if (y < 5 && y > 0) {	    bctr = y;	    return(1);	} else if (*p == 'B') {	    bctr

⌨️ 快捷键说明

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