📄 ckcpro.w
字号:
} else BEGIN ssdata; /* All ok, switch to send-data state */ }}<ssattr>Y { /* Got ACK to A packet */ ffc = 0L; /* Reset file byte counter */ if (rsattr(rdatap) < 0) { /* Was the file refused? */ discard = 1; /* Set the discard flag */ clsif(); /* Close the file */ sxeof((CHAR *)"D"); /* send EOF with "discard" code */ BEGIN sseof; /* switch to send-EOF state */ } else { if (window(wslotn) < 0) { /* Allocate negotiated window slots */ errpkt((CHAR *)"Can't open window"); RESUME; } if ((x = sdata()) == -2) { /* File accepted, send data */ return(success = 0); /* Failed */ } else if (x == -1) { /* EOF */ clsif(); /* If not ok, close input file, */ window(1); /* put window size back to 1, */ seof((CHAR *)""); /* send EOF packet, */ BEGIN sseof; /* and switch to EOF state. */ } else BEGIN ssdata; /* All ok, switch to send-data state */ }}<ssdata>Y { /* Got ACK to Data packet */ canned(rdatap); /* Check if file transfer cancelled */ if ((x = sdata()) == -2) { /* Try to send next data */ return(success = 0); /* Failed */ } else if (x == -1) { /* EOF - finished sending data */ clsif(); /* Close file */ window(1); /* Set window size back to 1... */ if (cxseen || czseen) /* If interrupted */ seof((CHAR *)"D"); /* send special EOF packet */ else /* otherwise */ seof((CHAR *)""); /* regular EOF packet */ BEGIN sseof; /* and enter send-eof state */ }}<sseof>Y { /* Got ACK to EOF */ success = (cxseen == 0 && czseen == 0); /* Transfer status... */ if (success && rejection > 0) /* If rejected, succeed if */ if (rejection != '#' && /* reason was date */ rejection != 1 && rejection != '?') /* or name; */ success = 0; /* fail otherwise. */ cxseen = 0; /* This goes back to zero. */ if (success && moving) { /* If MOVE'ing */ tlog(F110," deleting",filnam,0); /* delete the file */ zdelet(filnam); } if (gnfile() > 0) { /* Any more files to send? */ if (sfile(xflg)) /* Yes, try to send next file header */ BEGIN ssfile; /* if ok, enter send-file state */ else { /* otherwise */ errpkt((CHAR *)"Can't open file"); /* send error message */ RESUME; /* and quit */ } } else { /* No next file */ tsecs = gtimer(); /* get statistics timers */ seot(); /* send EOT packet */ BEGIN sseot; /* enter send-eot state */ }}<sseot>Y { /* Got ACK to EOT */ debug(F101,"sseot justone","",justone); RESUME; /* All done, just quit */}E { /* Got Error packet, in any state */ char *s = ""; if (pktmsg) /* Or we sent one. */ if (*pktmsg) /* If so, this was the message. */ s = (char *)pktmsg; if (!*s) /* We received an Error packet */ s = (char *)rdatap; /* with this message. */ if (!*s) /* Hopefully we'll never see this. */ s = "Unknown error"; ermsg(s); /* Issue the message. */ success = 0; /* For IF SUCCESS/FAIL. */ debug(F101,"ckcpro.w justone at E pkt","",justone); x = quiet; quiet = 1; /* Close files silently, */ clsif(); clsof(1); /* discarding any output file. */ tsecs = gtimer(); /* Get timers */ quiet = x; /* restore quiet state *//* If we are executing commands from a command file or macro, let the command file or macro decide whether to exit, based on SET { TAKE, MACRO } ERROR.*/ if (#ifndef NOSPL cmdlvl == 0#else tlevel < 0#endif /* NOSPL */ ) if (backgrd && !server) fatal("Protocol error"); xitsta |= what; /* Save this for doexit(). */#ifdef CK_TMPDIR/* If we were cd'd temporarily to another device or directory ... */ if (f_tmpdir) { int x; x = zchdir((char *) savdir); /* ... restore previous directory */ f_tmpdir = 0; /* and remember we did it. */ debug(F111,"ckcpro.w E tmpdir restoring",savdir,x); }#endif /* CK_TMPDIR */ RESUME;}q { success = 0; QUIT; } /* Ctrl-C interrupt during packets. */. { /* Anything not accounted for above */ errpkt((CHAR *)"Unexpected packet type"); /* Give error message */ xitsta |= what; /* Save this for doexit(). */ RESUME; /* and quit */}%%/* P R O T O -- Protocol entry function */VOIDproto() { extern int b_save, f_save;#ifdef OS2 extern int cursorena[], cursor_save; extern BYTE vmode;#endif /* OS2 *//* This is simply a wrapper for the real protocol function just below, that saves any items that might be changed automatically by protocol negotiations, but which should not be sticky, and then restores them upon exit from protocol mode.*/#ifdef OS2 cursor_save = cursorena[vmode] ; cursorena[vmode] = 0 ;#endif /* OS2 */ b_save = binary; /* SET FILE TYPE */ f_save = fncnv; /* SET FILE NAMES */ xxproto(); /* Call the real protocol function */ fncnv = f_save; binary = b_save;#ifdef OS2 cursorena[vmode] = cursor_save ;#endif /* OS2 */}static VOIDxxproto() { int x; long lx;#ifdef CK_XYZ#ifdef XYZ_INTERNAL_PROTOTYP( int pxyz, (int) );#endif /* XYZ_INTERNAL */#endif /* CK_XYZ */ debug(F101,"xxproto entry justone","",justone);/* Set up the communication line for file transfer. */ if (local && (speed < 0L) && (network == 0)) { screen(SCR_EM,0,0L,"Sorry, you must 'set speed' first"); return; } x = -1; if (ttopen(ttname,&x,mdmtyp,cdtimo) < 0) { debug(F111,"failed: proto ttopen local",ttname,local); screen(SCR_EM,0,0L,"Can't open line"); success = 0; return; } if (x > -1) local = x; debug(F111,"proto ttopen local",ttname,local); lx = (local && !network) ? speed : -1;#ifdef NETCONN#ifdef CK_SPEED/* If we are a TELNET client, force quoting of IAC. Note hardwired "1" rather than NP_TELNET symbol, so we don't have to schlurp in ckcnet.h.*/ if (network && ttnproto == 1) { ctlp[255] = ctlp[CR] = 1; if (parity == 'e' || parity == 'm') ctlp[127] = 1; }#endif /* CK_SPEED */#endif /* NETCONN */ if (ttpkt(lx,flow,parity) < 0) { /* Put line in packet mode, */ screen(SCR_EM,0,0L,"Can't condition line"); success = 0; return; } /* Send remote side "receive" startup string, if any */ if (local && sstate == 's') { char *s; s = binary ? ptab[protocol].h_b_init : ptab[protocol].h_t_init; if (s) if (*s) { char tmpbuf[356]; int stuff = -1, stuff2 = -1, len = 0; extern int tnlm; sprintf(tmpbuf, s, fspec); /* We need this for XMODEM... */ strcat(tmpbuf, "\015"); if (tnlm) /* TERMINAL NEWLINE ON */ stuff = LF; /* Stuff LF */#ifdef NETCONN#ifdef TCPSOCKET /* TELNET NEWLINE MODE */ if (network) { if (ttnproto == NP_TELNET) { switch (me_binary ? tn_b_nlm : tn_nlm) { case TNL_CR: break; case TNL_CRNUL: break; case TNL_CRLF: stuff2 = stuff; stuff = LF; break; } }#ifdef RLOGCODE else if (ttnproto == NP_RLOGIN) { switch (tn_b_nlm) { /* Always BINARY */ case TNL_CR: break; case TNL_CRNUL: stuff2 = stuff; stuff = NUL; break; case TNL_CRLF: stuff2 = stuff; stuff = LF; break; } }#endif /* RLOGCODE */ }#endif /* TCPSOCKET */#endif /* NETCONN */ len = strlen(tmpbuf); if (stuff >= 0) { tmpbuf[len++] = stuff; if (stuff2 >= 0) tmpbuf[len++] = stuff2; tmpbuf[len] = NUL; } ttol((CHAR *)tmpbuf,len); } }#ifdef CK_XYZ if (protocol != PROTO_K) { /* Non-Kermit protocol selected */ char tmpbuf[356]; char * s = "";#ifdef XYZ_INTERNAL /* Internal */ success = !pxyz(sstate); #else#ifdef CK_REDIR /* External */ switch (sstate) { case 's': /* 'Tis better to SEND... */ s = binary ? ptab[protocol].p_b_scmd : ptab[protocol].p_t_scmd; break; case 'v': /* ... than RECEIVE */ s = binary ? ptab[protocol].p_b_rcmd : ptab[protocol].p_t_rcmd; break; } if (!s) s = ""; if (*s) { sprintf(tmpbuf,s,(sstate == 's') ? fspec : cmarg2); ttruncmd(tmpbuf); } else { printf("?Sorry, no external protocol defined for %s\r\n", ptab[protocol].p_name ); }#else printf("Sorry, only Kermit protocol is supported in this version of Kermit\n" );#endif /* CK_REDIR */#endif /* XYZ_INTERNAL */ return; }#endif /* CK_XYZ */#ifdef NTSIGX conraw(); connoi();#else if (!local) connoi(); /* No console interrupts if remote */#endif /* NTSIG */ if (sstate == 'x') { /* If entering server mode, */ server = 1; /* set flag, */ debug(F101,"server backgrd","",backgrd); debug(F101,"server quiet","",quiet); if (!quiet && !backgrd) { debug(F100,"SHOULD NOT SEE THIS IF IN BACKGROUND!","",0); if (!local) { /* and issue appropriate message. */ conoll(srvtxt); conoll("KERMIT READY TO SERVE..."); } else { conol("Entering server mode on "); conoll(ttname); conoll("Type Ctrl-C to quit."); if (srvdis) intmsg(-1L); } }#ifdef TCPSOCKET#ifndef NOLISTEN#ifndef NOSPL if (network && tcpsrfd > 0) { dooutput("KERMIT READY TO SERVE...\015\012"); }#endif /* NOSPL */#endif /* NOLISTEN */#endif /* TCPSOCKET */ } else server = 0;#ifdef VMS if (!quiet && !backgrd) /* So message doesn't overwrite prompt */ conoll(""); if (local) conres(); /* So Ctrl-C will work */#endif /* VMS *//* If in remote mode, not shushed, not in background, and at top command level, issue a helpful message telling what to do...*/ if (!local && !quiet && !backgrd) { if (sstate == 'v') { conoll("Return to your local Kermit and give a SEND command."); conoll(""); conoll("KERMIT READY TO RECEIVE..."); } else if (sstate == 's') { conoll("Return to your local Kermit and give a RECEIVE command."); conoll(""); conoll("KERMIT READY TO SEND..."); } else if ( sstate == 'g' || sstate == 'r' || sstate == 'h' || sstate == 'j' || sstate == 'c' ) { conoll("Return to your local Kermit and give a SERVER command."); conoll(""); conoll((sstate == 'r' || sstate == 'j' || sstate == 'h') ? "KERMIT READY TO GET..." : "KERMIT READY TO SEND SERVER COMMAND..."); } }#ifdef COMMENT if (!local) sleep(1);#endif /* COMMENT *//* The 'wart()' function is generated by the wart program. It gets a character from the input() routine and then based on that character and the current state, selects the appropriate action, according to the state table above, which is transformed by the wart program into a big case statement. The function is active for one transaction.*/ rtimer(); /* Reset elapsed-time timer */ resetc(); /* & other per-transaction counters. */ debug(F101,"proto calling wart, justone","",justone); wart(); /* Enter the state table switcher. */ if (server) { /* Back from packet protocol. */ if (!quiet && !backgrd) { /* Give appropriate message */ conoll(""); conoll("C-Kermit server done"); } }/* Note: the following is necessary in case we have just done a remote-mode file transfer, in which case the controlling terminal modes have been changed by ttpkt(). In particular, special characters like Ctrl-C and Ctrl-\ might have been turned off (see ttpkt). So this call to ttres() is essential.*/#ifdef OS2 ttres(); /* Reset the communication device */#else if (!local) { msleep(500); ttres(); /* Reset the communication device */ }#endif /* OS2 */ screen(SCR_TC,0,0L,""); /* Transaction complete */ server = 0; /* Not a server any more */}static intsgetinit(reget) int reget; { if (!ENABLED(en_get)) { /* Only if not disabled! */ errpkt((CHAR *)"GET disabled"); return(-1); } else { /* OK to go ahead. */#ifdef WHATAMI debug(F101,"sgetinit whatru","",whatru); if (whatru & WM_FLAG) { /* Did we get WHATAMI info? */ debug(F101,"sgetinit binary (1)","",binary);#ifdef VMS if (binary != XYFT_I && binary != XYFT_L)#else#ifdef OS2 if (binary != XYFT_L)#endif /* OS2 */#endif /* VMS */ binary = (whatru & WM_FMODE) ? /* Yes, set transfer mode */ XYFT_B : XYFT_T; /* automatically */ debug(F101,"sgetinit binary (2)","",binary); fncnv = (whatru & WM_FNAME) ? 1 : 0; /* And name conversion */ }#endif /* WHATAMI */ srvptr = srvcmd; /* Point to server command buffer */ decode(rdatap,putsrv,0); /* Decode the GET command into it */ /* Accept multiple filespecs */ cmarg2 = ""; /* Don't use cmarg2 */ cmarg = ""; /* Don't use cmarg */#ifndef NOMSEND /* New way. */ nfils = fnparse((char *)srvcmd); /* Use cmlist instead */#else nfils = 0 - zxpand((char *)srvcmd);#endif /* NOMSEND */ nakstate = 0; /* Now I'm the sender! */ if (reget) sendmode = SM_RESEND; if (sinit() > 0) { /* Send Send-Init */ timint = chktimo(rtimo,timef); /* Switch to per-packet timer */ return(0); /* If successful, switch state */ } else return(-1); /* Else back to server command wait */ }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -