📄 ckcfn3.c
字号:
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);}/* S A T T R -- Send an Attribute Packet *//* Sends attribute packet(s) for the current file. If the info will not fit into one packet, it can be called repeatedly until all the fields that will fit are sent. Call with: xp == 0 if we're sending a real file (F packet), or: xp != 0 for screen data (X packet). And: flag == 1 for first A packet flag == 0 for subsequent A packets. Returns: 1 or greater if an A packet was sent, or: 0 if an S-packet was not sent because there was no data to send or there was no data left that was short enough to send, or: -1 on any kind of error.*//* (don't) #define TSOFORMAT *//* which was only for making C-Kermit send TSO-Kermit-like A packets *//* to try to track down a problem somebody reported... */intsattr(xp, flag) int xp, flag; { /* Send Attributes */ static int max; /* Maximum length for Attributes */ static short done[95]; /* Field-complete array */ static struct zattr x; /* File attribute struct */ /* Some extra flags are used because the "done" array is sparse */ int i, j, rc, aln, left = 0, numset = 0, xbin = 0; /* Workers */ char *tp, c; debug(F101,"sattr flag","",flag); if (!flag) /* No more attributes to send */ if (done[xunchar('@')]) return(0); /* Initialize Attribute mechanism */ if (flag) { /* First time here for this file? */ for (j = 0; j < 95; j++) /* Init array of completed fields */ done[j] = 0; max = maxdata(); /* Get maximum data field length */ rc = zsattr(&x); /* Get attributes for this file */ debug(F101,"sattr zsattr","",rc); if (rc < 0) /* Can't get 'em so don't send 'em */ return(0); debug(F101,"sattr init max","",max); }#ifdef CALIBRATE if (calibrate) { x.lengthk = calibrate / 1024L; x.length = calibrate; }#endif /* CALIBRATE */ if (nxtpkt() < 0) /* Got 'em, get next packet number */ return(-1); /* Bad news if we can't */ i = 0; /* Init data field character number */ /* Do each attribute using first-fit method, marking as we go */ /* This is rather long and repititious - could be done more cleverly */ if (atsido && !done[xunchar(c = '.')]) { /* System type */ if (max - i >= x.systemid.len + 2) { /* Enough space ? */ data[i++] = c; /* Yes, add parameter */ data[i++] = tochar(x.systemid.len); /* Add length */ for (j = 0; j < x.systemid.len; j++) /* Add data */ data[i++] = x.systemid.val[j]; numset++; /* Count that we did at least one */ done[xunchar(c)] = 1; /* Mark this attribute as done */ } else /* No */ left++; /* so mark this one left to do */ }#ifdef STRATUS if (atcreo && !done[xunchar(c = '$')]) { /* Creator */ if (max - i >= x.creator.len + 2) { /* Enough space ? */ data[i++] = c; data[i++] = tochar(x.creator.len); for (j = 0; j < x.creator.len; j++) data[i++] = x.creator.val[j]; numset++; done[xunchar(c)] = 1; } else left++; } if (atacto && !done[xunchar(c = '%')]) { /* File account */ if (max - i >= x.account.len + 2) { data[i++] = c; data[i++] = tochar(x.account.len); for (j = 0; j < x.account.len; j++) data[i++] = x.account.val[j]; numset++; done[xunchar(c)] = 1; } else left++; } if (atfrmo && !done[xunchar(c = '/')]) { /* Packet data format */ if (max - i >= x.recfm.len + 2) { data[i++] = c; data[i++] = tochar(x.recfm.len); /* Copy from attr structure */ for (j = 0; j < x.recfm.len; j++) data[i++] = x.recfm.val[j]; numset++; done[xunchar(c)] = 1; } else left++; }#endif /* STRATUS */ xbin = /* Is the transfer in binary mode? */#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 */ ; if (attypo && !done[xunchar(c = '"')]) { /* File type */ if (max - i >= 5) { /* Max length for this field */ data[i++] = c; if (xbin) { /* 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 */#ifdef TSOFORMAT data[i++] = tochar(1); /* One character */ data[i++] = 'A'; /* A = (extended) ASCII with CRLFs */#else 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 */#endif /* TSOFORMAT */#ifdef VMS binary = XYFT_T; /* We automatically detected text */#endif /* VMS */ } numset++; done[xunchar(c)] = 1; } else left++; }#ifdef TSOFORMAT if (attypo && !xbin && !done[xunchar(c = '/')]) { /* Record format */ if (max - i >= 5) { data[i++] = c; data[i++] = tochar(3); /* Three characters */ data[i++] = 'A'; /* A = variable with CRLFs */ data[i++] = 'M'; /* M for carriage return */ data[i++] = 'J'; /* J for linefeed */ } }#endif /* TSOFORMAT */ if (attypo && !xbin && !done[xunchar(c = '*')]) { /* Text encoding */#ifdef NOCSETS if (max - i >= 3) { data[i++] = c; data[i++] = tochar(1); /* Length of value is 1 */ data[i++] = 'A'; /* A for ASCII */ numset++; done[xunchar(c)] = 1; } else left++;#else if (tcharset == TC_TRANSP) { /* Transfer character set */ if (max - i >= 3) { data[i++] = c; /* Encoding */ data[i++] = tochar(1); /* Length of value is 1 */ data[i++] = 'A'; /* A for ASCII */ numset++; done[xunchar(c)] = 1; } else left++; } else { tp = tcsinfo[tcharset].designator; if (!tp) tp = ""; aln = strlen(tp); if (aln > 0) { if (max - i >= aln + 2) { data[i++] = c; /* 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 */ numset++; done[xunchar(c)] = 1; } else left++; } else done[xunchar(c)] = 1; }#endif /* NOCSETS */ } if ((xp == 0 || calibrate) && (x.length > -1L)) { /* If it's a real file */ if (atdato && !calibrate && /* Creation date, if any */ !done[xunchar(c = '#')] && (aln = x.date.len) > 0) { if (max - i >= aln + 2) { data[i++] = c; data[i++] = tochar(aln); for (j = 0; j < aln; j++) data[i++] = x.date.val[j]; numset++; done[xunchar(c)] = 1; } else left++; } if (atleno && !done[xunchar(c = '!')]) { /* File length in K */ sprintf((char *) &data[i+2],"%ld",x.lengthk); aln = (int)strlen((char *)(data+i+2)); if (max - i >= aln + 2) { data[i] = c; data[i+1] = tochar(aln); i += aln + 2; numset++; done[xunchar(c)] = 1; } else { data[i] = NUL; left++; } } if (atleno && !done[xunchar(c = '1')]) { /* File length in bytes */ sprintf((char *) &data[i+2],"%ld",x.length); aln = (int)strlen((char *)(data+i+2)); if (max - i >= aln + 2) { data[i] = c; data[i+1] = tochar(aln); i += aln + 2; numset++; done[xunchar(c)] = 1; } else { data[i] = NUL; left++; } }#ifdef CK_PERMS if (atlpro && !done[xunchar(c = ',')] && /* Local protection */ (aln = x.lprotect.len) > 0 && !calibrate) { if (max - i >= aln + 2) { data[i++] = c; data[i++] = tochar(aln); for (j = 0; j < aln; j++) data[i++] = x.lprotect.val[j]; numset++; done[xunchar(c)] = 1; } else left++; } if (atgpro && !done[xunchar(c = '-')] && /* Generic protection */ (aln = x.gprotect.len) > 0 && !calibrate) { if (max - i >= aln + 2) { data[i++] = c; data[i++] = tochar(aln); for (j = 0; j < aln; j++) data[i++] = x.gprotect.val[j]; numset++; done[xunchar(c)] = 1; } else left++; }#endif /* CK_PERMS */ if (atblko && fblksiz && !done[xunchar(c = '(')] && !calibrate) { /* Blocksize */ sprintf((char *) &data[i+2],"%d",fblksiz); aln = (int)strlen((char *)(data+i+2)); if (max - i >= aln + 2) { data[i] = c; data[i+1] = tochar(aln); i += aln + 2; numset++; done[xunchar(c)] = 1; } else { data[i] = NUL; left++; } } }#ifndef NOFRILLS if ((rprintf || rmailf) && atdiso && /* MAIL, or REMOTE PRINT? */ !done[xunchar(c = '+')]) { aln = (int) strlen(optbuf) + 1; /* Options, if any */ if (max - i >= aln + 2) { data[i++] = c; /* Disposition */ data[i++] = tochar(aln); /* 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]; numset++; done[xunchar(c)] = 1; } else { data[i] = NUL; left++; } }#endif /* NOFRILLS */#ifdef CK_RESEND if (sendmode == SM_RESEND && !done[xunchar(c = '+')]) { if (max - i >= 3) { data[i++] = c; /* Disposition */ data[i++] = tochar(1); data[i++] = 'R'; /* is RESEND */ numset++; done[xunchar(c)] = 1; } else left++; }#endif /* CK_RESEND */ /* End of Attributes -- to be sent only after sending all others */ debug(F111,"sattr","@",i); debug(F101,"sattr numset","",numset); debug(F101,"sattr left","",left); if ((left == 0 || numset == 0) && !done[xunchar(c = '@')]) { if (max - i >= 3) { data[i++] = c; /* End of Attributes */ data[i++] = SP; /* Length 0 */ data[i] = NUL; /* Make sure it's null-terminated */ numset++; done[xunchar(c)] = 1; } } /* Finished - send the packet off if we have anything in it */ if (numset) { data[i] = NUL; /* Terminate last good field */ debug(F111,"sattr sending",data,left); aln = (int)strlen((char *)data); /* Get overall length of attributes */ return(spack('A',pktnum,aln,data)); /* Send it */ } else 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 *);int rejection = -1;char *getreason(s) char *s; { /* Decode attribute refusal reason */ char c, *p; if (rejection == 1) /* Kludge for SET FIL COLL DISCARD */ return("name"); /* when other Kermit doesn't... */ p = s; if (*p++ != 'N') return(""); /* Should start with N */ else if ((c = *p) > SP) { /* get reason, */ rejection = c; /* remember it, */ 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,"rsattr refused",refused,0); tlog(F110," refused:",refused,0L); return(-1); }#ifdef CK_RESEND if (sendmode == SM_RESEND && *s == '1') { /* RESEND length */ int n; long z; CHAR *p; p = s + 1; n = xunchar(*p++); debug(F101,"rsattr RESEND n","",n); z = 0L; while (n-- > 0) /* We assume the format is good. */ z = 10L * z + (long) (*p++ - '0'); debug(F101,"rsattr RESEND z","",z); if (z > 0L) sendstart = z; debug(F101,"rsattr RESEND sendstart","",sendstart); if (sendstart > 0L) if (zfseek(sendstart) < 0) /* Input file is already open. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -