📄 ckcfn3.c
字号:
freesbuf(n) int n; { /* Release send-buffer for packet n. */ int i; debug(F101,"freesbuf","",n); if (n < 0 || n > 63) /* No such packet. */ return(-1); i = sseqtbl[n]; /* Get the window slot number. */ if (i > -1 && i <= wslots) { sseqtbl[n] = -1; /* If valid, remove from seqtbl */ sbufnum++; /* and count one more free buffer */ sbufuse[i] = 0; /* and mark it as free, */ if (what & (W_SEND|W_REMO)) /* decrement active slots */ wcur--; /* for statistics and display. */ } else { debug(F101," sseqtbl[n]","",sseqtbl[n]); return(-1); }/* The following is done only so dumped buffers will look right. */ if (1) { *s_pkt[i].bf_adr = '\0'; /* Zero the buffer data field */ s_pkt[i].pk_seq = -1; /* Invalidate the sequence number */ s_pkt[i].pk_len = 0; /* Data field length now zero. */ s_pkt[i].pk_typ = ' '; /* Blank the packet type too. */ s_pkt[i].pk_rtr = 0; /* And the retries field. */ } return(1);}intfreerbuf(i) int i; { /* Release receive-buffer slot "i". */ int n;/* NOTE !! Currently, this function frees the indicated buffer, but *//* does NOT erase the data. The program counts on this. Will find a *//* better way later.... */ debug(F101,"freerbuf, slot","",i); if (i < 0 || i >= wslots) { /* No such slot. */ debug(F101,"freerbuf no such slot","",i); return(-1); } n = r_pkt[i].pk_seq; /* Get the packet sequence number */ debug(F101,"freerbuf, packet","",n); if (n > -1 && n < 64) /* If valid, remove from seqtbl */ rseqtbl[n] = -1; if (rbufuse[i] != 0) { /* If really allocated, */ rbufuse[i] = 0; /* mark it as free, */ rbufnum++; /* and count one more free buffer. */ if (what & W_RECV) /* Keep track of current slots */ wcur--; /* for statistics and display */ debug(F101,"freerbuf, new rbufnum","",rbufnum); }/* The following is done only so dumped buffers will look right. */ if (1) { /* *r_pkt[i].bf_adr = '\0'; */ /* Zero the buffer data field */ r_pkt[i].pk_seq = -1; /* And from packet list */ r_pkt[i].pk_len = 0; /* Data field length now zero. */ r_pkt[i].pk_typ = ' '; /* Blank the packet type too. */ r_pkt[i].pk_rtr = 0; /* And the retries field. */ } return(1);}/* This is like freerbuf, except it's called with a packet sequence number *//* rather than a packet buffer index. */VOIDfreerpkt(seq) int seq; { int k; debug(F101,"freerpkt seq","",seq); k = rseqtbl[seq]; debug(F101,"freerpkt k","",k); if (k > -1) { k = freerbuf(k); debug(F101,"freerpkt freerbuf","",k); }}/* C H K W I N -- Check if packet n is in window. *//* Returns: *//* 0 if it is in the current window, *//* +1 if it would have been in previous window (e.g. if ack was lost), *//* -1 if it is outside any window (protocol error), *//* -2 if either of the argument packet numbers is out of range. *//* Call with packet number to check (n), lowest packet number in window *//* (bottom), and number of slots in window (slots). */intchkwin(n,bottom,slots) int n, bottom, slots; { int top, prev; debug(F101,"chkwin packet","",n); debug(F101,"chkwin winlo","",bottom); debug(F101,"chkwin slots","",slots);/* 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%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_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); }#endif /* DEBUG */ return(0);}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%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_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); }#endif /* DEBUG */ return(0);}/*** 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]; }#ifdef STRATUS if (atcreo) { /* File creator */ data[i++] = '$'; data[i++] = tochar(x.creator.len); /* Copy from attr structure */ for (j = 0; j < x.creator.len; j++) data[i++] = x.creator.val[j]; } if (atacto) { /* File account */ data[i++] = '%'; data[i++] = tochar(x.account.len); /* Copy from attr structure */ for (j = 0; j < x.account.len; j++) data[i++] = x.account.val[j]; } if (atfrmo) { /* Packet data format */ data[i++] = '/'; data[i++] = tochar(x.recfm.len); /* Copy from attr structure */ for (j = 0; j < x.recfm.len; j++) data[i++] = x.recfm.val[j]; }#endif /* STRATUS */ 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 CK_LABELED if (binary != XYFT_L#ifdef VMS && binary != XYFT_I#endif /* VMS */ ) binary = XYFT_B;#endif /* CK_LABELED */ } 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 */ data[i++] = '*'; /* Encoding */ data[i++] = tochar(1); /* Length of value is 1 */ data[i++] = 'A'; /* A for ASCII */ } else { tp = tcsinfo[tcharset].designator; if ((tp != NULL) && (aln = (int)strlen(tp)) > 0) { data[i++] = '*'; /* Encoding */ data[i++] = tochar(aln+1); /* Length of designator. */ data[i++] = 'C'; /* Text in specified charset. */ for (j = 0; j < aln; j++) /* Copy designator */ 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 */#ifdef CK_RESEND if (sendmode == SM_RESEND) { data[i++] = '+'; /* Disposition */ data[i++] = tochar(1); data[i++] = 'R'; /* is RESEND */ }#endif /* CK_RESEND */ data[i++] = '@'; /* End of Attributes */ data[i++] = SP; /* Length 0 */ 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", /* 0 */ "size", /* 1 */ "2", /* 2 */ "3", /* 3 */ "4", /* 4 */ "5", /* 5 */ "6", /* 6 */ "7", /* 7 */ "8", /* 8 */ "9", /* 9 */ ":", /* : */ ";", /* ; */ "<", /* < */ "=", /* = */ ">", /* > */ "name", /* ? */ "@"};static int nreason = sizeof(reason) / sizeof(char *);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -