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

📄 ckcfn3.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
/* First do the easy and common cases, where the windows are not split. */    if (n < 0 || n > 63 || bottom < 0 || bottom > 63)      return(-2);    if (n == bottom) return(0);		/* In a perfect world... */    top = bottom + slots;		/* Calculate window top. */    if (top < 64 && n < top && n >= bottom)      return(0);			/* In current window. */    prev = bottom - slots;		/* Bottom of previous window. */    if (prev > -1 && n < bottom && n > prev)      return(1);			/* In previous. *//* Now consider the case where the current window is split. */    if (top > 63) {			/* Wraparound... */	top -= 64;			/* Get modulo-64 sequence number */	if (n < top || n >= bottom) {	    return(0);			/* In current window. */	} else {			/* Not in current window. */	    if (n < bottom && n >= prev) /* Previous window can't be split. */	      return(1);		/* In previous window. */	    else	      return(-1);		/* Not in previous window. */	}    }/* Now the case where current window not split, but previous window is. */     if (prev < 0) {			/* Is previous window split? */	prev += 64;			/* Yes. */	if (n < bottom || n >= prev)	  return(1);			/* In previous window. */    } else {				/* Previous window not split. */	if (n < bottom && n >= prev)	  return(1);			/* In previous window. */    }    /* It's not in the current window, and not in the previous window... */    return(-1);				/* So it's not in any window. */}intdumpsbuf() {				/* Dump send-buffers */#ifdef DEBUG    int j, x;				/* to debug log. */    if (! deblog) return(0);    x = zsoutl(ZDFILE,"SEND BUFFERS:");    if (x < 0) {	deblog = 0;	return(0);    }    x=zsoutl(ZDFILE,"buffer inuse address length data type seq flag retries");    if (x < 0) {	deblog = 0;	return(0);    }    for ( j = 0; j < wslots; j++ ) {	sprintf(xbuf,"%4d%6d%10d%5d%6d%4c%5d%5d%6d\n",	       j,	       sbufuse[j],	       s_pkt[j].bf_adr, 	       s_pkt[j].bf_len,	       s_pkt[j].pk_len,	       s_pkt[j].pk_typ,	       s_pkt[j].pk_seq,	       s_pkt[j].pk_flg,	       s_pkt[j].pk_rtr	       );	if (zsout(ZDFILE,xbuf) < 0)  {	    deblog = 0;	    return(0);	}	if (s_pkt[j].pk_adr) {	    x = (int)strlen((char *) s_pkt[j].pk_adr);	    if (x)	      sprintf(xbuf,"[%.72s%s]\n",s_pkt[j].pk_adr, x > 72 ? "..." : "");	    else	      sprintf(xbuf,"[(empty string)]\n");	} else {	    sprintf(xbuf,"[(null pointer)]\n");	}	if (zsout(ZDFILE,xbuf) < 0) {	    deblog = 0;	    return(0);	}    }    sprintf(xbuf,"free: %d, winlo: %d\n", sbufnum, winlo);    if (zsout(ZDFILE,xbuf) < 0) {	deblog = 0;	return(0);    }    return(0);#endif /* DEBUG */}intdumprbuf() {				/* Dump receive-buffers */#ifdef DEBUG    int j, x;    if (! deblog) return(0);    if (zsoutl(ZDFILE,"RECEIVE BUFFERS:") < 0) {	deblog = 0;	return(0);    }    x=zsoutl(ZDFILE,"buffer inuse address length data type seq flag retries");    if (x < 0) {	deblog = 0;	return(0);    }    for ( j = 0; j < wslots; j++ ) {	sprintf(xbuf,"%4d%6d%10d%5d%6d%4c%5d%5d%6d\n",	       j,	       rbufuse[j],	       r_pkt[j].bf_adr, 	       r_pkt[j].bf_len,	       r_pkt[j].pk_len,	       r_pkt[j].pk_typ,	       r_pkt[j].pk_seq,	       r_pkt[j].pk_flg,	       r_pkt[j].pk_rtr	       );	if (zsout(ZDFILE,xbuf) < 0) {	    deblog = 0;	    return(0);	}	x = (int)strlen((char *)r_pkt[j].bf_adr);	sprintf(xbuf,"[%.72s%s]\n",r_pkt[j].bf_adr, x > 72 ? "..." : "");	if (zsout(ZDFILE,xbuf) < 0)  {	    deblog = 0;	    return(0);	}    }    sprintf(xbuf,"free: %d, winlo: %d\n", rbufnum, winlo);    if (zsout(ZDFILE,xbuf) < 0)  {	deblog = 0;	return(0);    }    return(0);#endif /* DEBUG */}/*** Some misc functions also moved here from the other ckcfn*.c modules ***//*** to even out the module sizes. ***//* Attribute Packets. *//*  Call with xp == 0 if we're sending a real file (F packet),  or xp != 0 for screen data (X packet).  Returns 0 on success, -1 on failure.*/intsattr(xp) int xp; {			/* Send Attributes */    int i, j, aln;    char *tp;    struct zattr x;    if (zsattr(&x) < 0) return(-1);	/* Get attributes or die trying */    if (nxtpkt() < 0) return(-1);	/* Next packet number */    i = 0;				/* i = Data field character number */    if (atsido) {			/* System type */	data[i++] = '.';	data[i++] = tochar(x.systemid.len); /*  Copy from attr structure */	for (j = 0; j < x.systemid.len; j++)	  data[i++] = x.systemid.val[j];    }    if (attypo) {			/* File type */	data[i++] = '"';	if (#ifdef VMS	binary == XYFT_I || binary == XYFT_L || /* IMAGE or LABELED */	!strncmp(x.recfm.val,"F",1)		/* or RECFM=Fxxxxxx */#else	binary				/* User said SET FILE TYPE BINARY  */#endif /* VMS */	    ) {				/* Binary */	    data[i++] = tochar(2);	/*  Two characters */	    data[i++] = 'B';		/*  B for Binary */	    data[i++] = '8';		/*  8-bit bytes (note assumption...) */#ifdef VMS	    if (binary != XYFT_I && binary != XYFT_L) binary = XYFT_B;#endif /* VMS */	} else {			/* Text */	    data[i++] = tochar(3);	/*  Three characters */	    data[i++] = 'A';		/*  A = (extended) ASCII with CRLFs */	    data[i++] = 'M';		/*  M for carriage return */	    data[i++] = 'J';		/*  J for linefeed */#ifdef VMS	    binary = XYFT_T;		/* We automatically detected text */#endif /* VMS */#ifdef NOCSETS	    data[i++] = '*';		/* Encoding */	    data[i++] = tochar(1);	/* Length of value is 1 */	    data[i++] = 'A';		/* A for ASCII */#else	    if (tcharset == TC_TRANSP)	/* Transfer character set */	      tp = NULL;	    else	      tp = tcsinfo[tcharset].designator;	    if ((tp != NULL) && (aln = (int)strlen(tp)) > 0) {		data[i++] = '*';	/* Encoding */		data[i++] = tochar(aln+1); /*  Length of charset designator. */		data[i++] = 'C';	/*  Text in specified character set. */		for (j = 0; j < aln; j++) /*  Designator from tcsinfo struct */		  data[i++] = *tp++;	  /*  Example: *&I6/100 */	    }#endif /* NOCSETS */	}    }    if ((xp == 0) && (x.length > -1L)) { /* If it's a real file */	if (atdato && (aln = x.date.len) > 0) {	/* Creation date, if any */	    data[i++] = '#';	    data[i++] = tochar(aln);	    for (j = 0; j < aln; j++)	      data[i++] = x.date.val[j];	}	if (atleno) {	    data[i] = '!';			/* File length in K */	    sprintf((char *) &data[i+2],"%ld",x.lengthk);	    aln = (int)strlen((char *)(data+i+2));	    data[i+1] = tochar(aln);	    i += aln + 2;	    data[i] = '1';			/* File length in bytes */	    sprintf((char *) &data[i+2],"%ld",x.length);	    aln = (int)strlen((char *)(data+i+2));	    data[i+1] = tochar(aln);	    i += aln + 2;	}	if (atblko && fblksiz) {		/* Blocksize, if set */	    data[i] = '(';	    sprintf((char *) &data[i+2],"%d",fblksiz);	    aln = (int)strlen((char *)(data+i+2));	    data[i+1] = tochar(aln);	    i += aln + 2;	}    }#ifndef NOFRILLS    if ((rprintf || rmailf) && atdiso) { /* MAIL, or REMOTE PRINT?  */	data[i++] = '+';		/* Disposition */        data[i++] = tochar((int)strlen(optbuf) + 1); /* Options, if any */	if (rprintf)	  data[i++] = 'P';		/* P for Print */	else	  data[i++] = 'M';		/* M for Mail */	for (j = 0; optbuf[j]; j++)	/* Copy any options */	  data[i++] = optbuf[j];    }#endif /* NOFRILLS */    data[i] = '\0';			/* Make sure it's null-terminated */    aln = (int)strlen((char *)data);	/* Get overall length of attributes *//* Change this code to break attribute data up into multiple packets! */    j = (spsiz < 95) ? (92 - bctl) : (spsiz - 2 - bctl);    if (aln > j) {			/* Check length of result */	spack('A',pktnum,0,(CHAR *)"");	/* send an empty attribute packet */	debug(F101,"sattr pkt too long","",aln); /* if too long */	debug(F101,"sattr spsiz","",spsiz);    } else {				/* Otherwise */	spack('A',pktnum,aln,data);	/* send the real thing. */	debug(F111,"sattr",data,aln);    }    return(0);}static char *refused = "";static char *reason[] = {    "size", "type", "date", "creator", "account", "area", "password",    "blocksize", "access", "encoding", "disposition", "protection",    "protection", "origin", "format", "sys-dependent", "size" };static int nreason = sizeof(reason) / sizeof(char *);char *getreason(s) char *s; {			/* Decode attribute refusal reason */    char c, *p;    p = s;    if (*p++ != 'N') return("");	/* Should start with N */    if ((c = *p) > SP) {		/* get reason, */	c -= '!';			/* get offset */	p = ((unsigned int) ((CHAR) c) <= nreason) ? reason[c] : "unknown";    }    return(p);}intrsattr(s) CHAR *s; {			/* Read response to attribute packet */    debug(F111,"rsattr: ",s,*s);    if (*s == 'N') {			/* If it's 'N' followed by anything, */	refused = getreason((char *)s);	/* they are refusing, get reason. */	debug(F110,"refused",refused,0);	tlog(F110,"refused",refused,0L);	return(-1);	    } else refused = "";    return(0);}intgattr(s, yy) CHAR *s; struct zattr *yy; { /* Read incoming attribute packet */    char c;    int aln, i;#define ABUFL 40			/* Temporary buffer for conversions */    char abuf[ABUFL];#define FTBUFL 10			/* File type buffer */    static char ftbuf[FTBUFL];#define DTBUFL 40			/* File creation date */    static char dtbuf[DTBUFL];#define TSBUFL 10			/* Transfer syntax */    static char tsbuf[TSBUFL];#define IDBUFL 10			/* System ID */    static char idbuf[IDBUFL];#ifndef DYNAMIC#define DSBUFL 100			/* Disposition */    static char dsbuf[DSBUFL];#define SPBUFL 512			/* System-dependent parameters */    static char spbuf[SPBUFL];#else#define DSBUFL 100			/* Disposition */    static char *dsbuf = NULL;#define SPBUFL 512			/* System-dependent parameters */    static char *spbuf = NULL;#endif /* DYNAMIC */#define RPBUFL 20			/* Attribute reply */    static char rpbuf[RPBUFL];    char *rp;				/* Pointer to reply buffer */    int retcode;			/* Return code *//* fill in the attributes we have received */    rp = rpbuf;				/* Initialize reply buffer */    *rp++ = 'N';			/* for negative reply. */    retcode = 0;			/* Initialize return code. */    while (c = *s++) {			/* Get attribute tag */	aln = xunchar(*s++);		/* Length of attribute string */	switch (c) {	  case '!':			/* File length in K */	    for (i = 0; (i < aln) && (i < ABUFL); i++) /* Copy it */	      abuf[i] = *s++;	    abuf[i] = '\0';		/* Terminate with null */	    if (i < aln) s += (aln - i); /* If field was too long for buffer */	    yy->lengthk = atol(abuf);	/* Convert to number */	    break;	  case '"':			/* file type */	    for (i = 0; (i < aln) && (i < FTBUFL); i++)	      ftbuf[i] = *s++;		/* Copy it into a static string */	    ftbuf[i] = '\0';	    if (i < aln) s += (aln - i);	    if (attypi) {		/* TYPE attribute is enabled? */		yy->type.val = ftbuf;	/* Pointer to string */		yy->type.len = i;	/* Length of string */		debug(F101,"gattr file type",tsbuf,i);		if (		    *ftbuf != 'A' && *ftbuf != 'B' /* Unknown type? */#ifdef VMS/* or (VMS) our FILE TYPE is LABELED and the incoming file is text... */		    || binary == XYFT_L && *ftbuf == 'A'#endif /* VMS */		    		    ) {		    discard = 1;	/* Reject the file */		    retcode = -1;		    *rp++ = c;		    break;		}/*  The following code moved here from opena() so we set binary mode  as soon as requested by the attribute packet.  That way when the first  data packet comes, the mode of transfer can be displayed correctly  before opena() is called.*/		if (bsavef) {		/* If somehow file mode */		    binary = bsave;	/* was saved but not restored, */		    bsavef = 0;		/* restore it. */		    debug(F101,"gattr restoring binary","",binary);		}		if (yy->type.val[0] == 'A') { /* Check received attributes. */		    bsave = binary;	/* ASCII.  Save global file type */		    bsavef = 1;		/* ( restore it in clsof() ) */		    binary = XYFT_T;	/* Set current type to Text. */		    debug(F100,"gattr attribute A = text","",binary); /*  */		} else if (yy->type.val[0] == 'B') {		    bsave = binary;	/* Binary.  Save global file type */		    bsavef = 1;#ifdef VMS		    if (binary != XYFT_L && binary != XYFT_U) /* VMS cases */#endif /* VMS */		      binary = XYFT_B;		    debug(F101,"gattr attribute B = binary","",binary);		}	    }	    break;	  case '#':			/* File creation date */	    for (i = 0; (i < aln) && (i < DTBUFL); i++)	      dtbuf[i] = *s++;		/* Copy it into a static string */	    if (i < aln) s += (aln - i);	    dtbuf[i] = '\0';	    if (atdati) {		yy->date.val = dtbuf;	/* Pointer to string */		yy->date.len = i;	/* Length of string */		if (fncact == XYFX_U) {	/* Receiving in update mode? */		    if (zstime(filnam,yy,1) > 0) { /* Compare dates */			discard = 1;	/* If incoming file is older, */			*rp++ = c;	/* discard it, reason = date. */			retcode = -1;	/* Rejection notice. */		    }		}					    }	    break;	  case '(':			/* File Block Size */	    for (i = 0; (i < aln) && (i < ABUFL); i++) /* Copy it */	      abuf[i] = *s++;	    abuf[i] = '\0';		/* Terminate with null */	    if (i < aln) s += (aln - i);	    if (atblki)	      yy->blksize = atol(abuf); /* Convert to number */	    break;	  case '*':			/* Encoding (transfer syntax) */	    for (i = 0; (i < aln) && (i < TSBUFL); i++)	      tsbuf[i] = *s++;		/* Copy it into a static string */	    if (i < aln) s += (aln - i);	    tsbuf[i] = '\0';	    if (atenci) {		yy->encoding.val = tsbuf; /* Pointer to string */		yy->encoding.len = i;	/* Length of string */		debug(F101,"gattr encoding",tsbuf,i);		switch (*tsbuf) {#ifndef NOCSETS		  case 'A':		/* Normal (maybe extended) ASCII */		    tcharset = TC_USASCII; /* Transparent chars untranslated */		    break;		  case 'C':		/* Specified character set */		    for (i = 0; i < ntcsets; i++) { 			if (!strcmp(tcsinfo[i].designator,tsbuf+1)) break;		    }		    debug(F101,"gattr xfer charset lookup","",i);		    if (i == ntcsets) {	/* If unknown character set, */			debug(F110,"gattr: xfer charset unknown",tsbuf+1,0);			if (!unkcs) {	/* and SET UNKNOWN DISCARD, */			    retcode = -1; /* reject the file. */			    *rp++ = c;			}		    } else {			tcharset = tcsinfo[i].code; /* if known, use it */			rx = xlr[tcharset][fcharset]; /* xlation function */		    }		    debug(F101,"gattr tcharset","",tcharset);		break;#endif /* NOCSETS */	      default:			/* Something else. */		debug(F110,"gattr unk encoding attribute",tsbuf,0);		if (!unkcs) {		/* If SET UNK DISC */		    retcode = -1;	/* reject the file */		    *rp++ = c;		}		break;		}	    }	    break;	  case '+':			/* disposition */#ifdef DYNAMIC	    if (!dsbuf)		if ((dsbuf = malloc(DSBUFL+1)) == NULL)		    fatal("gtattr: no memory for dsbuf");#endif /* DYNAMIC */	    for (i = 0; (i < aln) && (i < DSBUFL); i++)

⌨️ 快捷键说明

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