📄 ckuusx.c
字号:
char buffer[40]; long et; /* Elapsed time, entire batch */ long pd; /* Percent done, this file */ long tp; /* Transfer rate, entire batch */ long ps; /* Packet size, current packet */ long myffc, mytfc; /* Local copies of byte counters */ et = gtimer(); /* Elapsed time */ ps = (what == W_RECV) ? rpktl+1 : spktl+1; /* Packet length */ pd = -1; /* Percent done. */ if (c == NUL) { /* Still going, figure % done */ if (fsize == 0L) return; /* Empty file, don't bother */ pd = (fsize > 99L) ? (ffc / (fsize / 100L)) : 0L; if (pd > 100) pd = 100; /* Expansion */ } else pd = 100; /* File complete, so 100%. */#ifndef CK_CPS/* fsecs = time (from gtimer) that this file started (set in sfile()). Rate so far is ffc / (et - fsecs), estimated time for remaining bytes is (fsize - ffc) / ( ffc / (et - fsecs )).*/ tp = (ffc > 0L) ? (fsize - ffc) * (et - fsecs) / ffc : 0L;#endif /* CK_CPS */ myffc = (ffc > 0) ? ffc - 1L : ffc; /* No, I don't know why... */ if (myffc < 0L) myffc = 0L;#ifdef CK_CPS mytfc = (pd < 100) ? tfc + myffc : tfc; tp = (et > 0) ? mytfc / et : 0; /* Transfer rate */ if (c && (tp == 0)) /* Watch out for subsecond times */ tp = myffc;#endif /* CK_CPS */ if (pd > -1L) sprintf(buffer, "%c%9ld%5ld%%%8ld%8ld ", CR, myffc, pd, tp, ps); else sprintf(buffer, "%c%9ld %8ld%8ld ", CR, myffc, tp, ps); conol(buffer); hpos = 31; } else { /* SERIAL display */ long i, k; if (ffc - oldffc < 1024) /* Update display every 1K */ return; oldffc = ffc; /* Time for new display */ k = (ffc / 1024L) - dots; /* How many K so far */ for (i = 0L; i < k; i++) { if (hpos++ > 77) { /* Time to wrap? */ conoll(""); hpos = 0; } conoc('.'); /* Print a dot for this K */ dots++; /* Count it */ } }}/* S C R E E N -- Screen display function *//* screen(f,c,n,s) f - argument descriptor c - a character or small integer n - a long integer s - a string. Fill in this routine with the appropriate display update for the system. FILE DISPLAY SERIAL: Default, works on any terminal, even hardcopy. FILE DISPLAY CRT: Works on any CRT, writes over current line. FILE DISPLAY FULLSCREEN: Requires terminal-dependent screen control.*/VOID#ifdef CK_ANSICscreen(int f, char c,long n,char *s)#elsescreen(f,c,n,s) int f; char c; long n; char *s;#endif /* CK_ANSIC *//* screen */ { char buf[80]; int len; /* Length of string */#ifdef UNIX#ifndef NOJC int obg;_PROTOTYP( VOID conbgt, (int) ); if (local) { obg = backgrd; /* Previous background status */ conbgt(1); /* See if running in background */ if (!backgrd && obg) { /* Just came into foreground? */ concb((char)escape); /* Put console back in CBREAK mode */ conint(trap,stptrap); /* Turn interrupts back on. */ } }#endif /* NOJC */#endif /* UNIX */ if ((f != SCR_WM) && (f != SCR_EM)) /* Always update warnings & errors */ if (!displa || quiet || backgrd || fdispla == XYFD_N || (server && !srvdis)) return;#ifdef CK_CURSES if (fdispla == XYFD_C) { /* If fullscreen display selected */ screenc(f,c,n,s); /* call the fullscreen version */ return; }#endif /* CK_CURSES */ len = (int)strlen(s); /* Length of string */ switch (f) { /* Handle our function code */case SCR_FN: /* Filename */#ifdef MAC conoll(""); conol(s); conoc(SP); hpos = len + 1;#else strncpy(fbuf,s,80); newdpy = 1; /* New file so refresh display */#endif /* MAC */ return;case SCR_AN: /* As-name */#ifdef MAC if (hpos + len > 75) { conoll(""); hpos = 0; } conol("=> "); conol(s); if ((hpos += (len + 3)) > 78) { conoll(""); hpos = 0; }#else strncpy(abuf,s,80);#endif /* MAC */ return;case SCR_FS: /* File-size */#ifdef MAC sprintf(buf,", Size: %ld",n); conoll(buf); hpos = 0;#endif /* MAC */ return;case SCR_XD: /* X-packet data */#ifdef MAC conoll(""); conoll(s); hpos = 0;#else strncpy(fbuf,s,80);#endif /* MAC */ return;case SCR_ST: /* File status */ switch (c) { case ST_OK: /* Transferred OK */ showpkt('Z'); /* Update numbers one last time */ if ((hpos += 5) > 78) conoll(""); /* Wrap screen line if necessary. */ conoll(" [OK]"); hpos = 0; /* Print OK message. */ if (fdispla == XYFD_S) { /* We didn't show Z packet when */ conoc('Z'); /* it came, so show it now. */ hpos = 1; } return; case ST_DISC: /* Discarded */ if ((hpos += 12) > 78) conoll(""); conoll(" [discarded]"); hpos = 0; return; case ST_INT: /* Interrupted */ if ((hpos += 14) > 78) conoll(""); conoll(" [interrupted]"); hpos = 0; return; case ST_SKIP: /* Skipped */ if ((hpos += 10) > 78) conoll(""); conol(" [skipped]"); hpos = 0; return; case ST_ERR: /* Error */ conoll(""); conol("Error: "); conoll(s); hpos = 0; return; case ST_REFU: /* Refused */ conoll(""); conol("Refused: "); conoll(s); hpos = 0; return; case ST_INC: /* Incomplete */ if ((hpos += 12) > 78) conoll(""); conoll(" [incomplete]"); hpos = 0; return; default: conoll("*** screen() called with bad status ***"); hpos = 0; return; }#ifdef MACcase SCR_PN: /* Packet number */ sprintf(buf,"%s: %ld",s,n); conol(buf); hpos += (int)strlen(buf); return;#endif /* MAC */case SCR_PT: /* Packet type or pseudotype */ if (c == 'Y') return; /* Don't bother with ACKs */ if (c == 'D') { /* In data transfer phase, */ showpkt(NUL); /* show progress. */ return; }#ifndef AMIGA if (hpos++ > 77) { /* If near right margin, */ conoll(""); /* Start new line */ hpos = 0; /* and reset counter. */ }#endif /* AMIGA */ if (c == 'Z' && fdispla == XYFD_S) return; else conoc(c); /* Display the packet type. */#ifdef AMIGA if (c == 'G') conoll(""); /* New line after G packets */#endif /* AMIGA */ return;case SCR_TC: /* Transaction complete */ conoc(BEL); conoll(""); return;case SCR_EM: /* Error message */ conoll(""); conoc('?'); conoll(s); hpos = 0; return;case SCR_WM: /* Warning message */ conoll(""); conoll(s); hpos = 0; return;case SCR_TU: /* Undelimited text */ if ((hpos += len) > 77) { conoll(""); hpos = len; } conol(s); return;case SCR_TN: /* Text delimited at beginning */ conoll(""); conol(s); hpos = len; return;case SCR_TZ: /* Text delimited at end */ if ((hpos += len) > 77) { conoll(""); hpos = len; } conoll(s); return;case SCR_QE: /* Quantity equals */ sprintf(buf,"%s: %ld",s,n); conoll(buf); hpos = 0; return;case SCR_CW: /* Close fullscreen window */ return; /* No window to close */default: conoll("*** screen() called with bad object ***"); hpos = 0; return; }}/* E R M S G -- Nonfatal error message *//* Should be used only for printing the message text from an Error packet. */VOIDermsg(msg) char *msg; { /* Print error message */ if (local) screen(SCR_EM,0,0L,msg); tlog(F110,"Protocol Error:",msg,0L);}VOIDdoclean() { /* General cleanup upon exit */#ifndef NOICP#ifndef NOSPL extern struct mtab *mactab; /* For ON_EXIT macro. */ extern int nmac;#endif /* NOSPL */#endif /* NOICP */#ifdef DEBUG if (deblog) { /* Close any open logs. */ debug(F100,"Debug Log Closed","",0); *debfil = '\0'; deblog = 0; zclose(ZDFILE); }#endif /* DEBUG */ if (pktlog) { *pktfil = '\0'; pktlog = 0; zclose(ZPFILE); } if (seslog) { *sesfil = '\0'; seslog = 0; zclose(ZSFILE); }#ifdef TLOG if (tralog) { tlog(F100,"Transaction Log Closed","",0L); *trafil = '\0'; tralog = 0; zclose(ZTFILE); }#endif /* TLOG */#ifndef NOICP#ifndef NOSPL zclose(ZRFILE); /* READ and WRITE files, if any. */ zclose(ZWFILE);#ifndef NODIAL if (dialfd) fclose(dialfd); /* Dial directory, if any. */#endif /* NODIAL *//* If a macro named "on_exit" is defined, execute it. Also remove it from the macro table, in case its definition includes an EXIT or QUIT command, which would cause much recursion and would prevent the program from ever actually EXITing.*/ if (nmac) { /* Any macros defined? */ int k; /* Yes */ k = mlook(mactab,"on_exit",nmac); /* Look up "on_exit" */ if (k >= 0) { /* If found, */ *(mactab[k].kwd) = NUL; /* poke its name from the table, */ if (dodo(k,"") > -1) /* set it up, */ parser(1); /* and execute it */ } }#endif /* NOSPL */#endif /* NOICP *//* Put console terminal back to normal. This is done here because the ON_EXIT macro calls the parser, which meddles with console terminal modes.*/ ttclos(0); /* Close external line, if any */ if (local) { strcpy(ttname,dftty); /* Restore default tty */ local = dfloc; /* And default remote/local status */ } conres(); /* Restore console terminal. */#ifdef COMMENT/* Should be no need for this, and maybe it's screwing things up? */ connoi(); /* Turn off console interrupt traps */#endif /* COMMENT */ syscleanup(); /* System-dependent cleanup, last */}/* D O E X I T -- Exit from the program. *//* First arg is general, system-independent symbol: GOOD_EXIT or BAD_EXIT. If second arg is -1, take 1st arg literally. If second arg is not -1, work it into the exit code.*/VOIDdoexit(exitstat,what) int exitstat, what; {#ifdef VMS char envstr[64]; static $DESCRIPTOR(symnam,"CKERMIT_STATUS"); static struct dsc$descriptor_s symval; int i;#endif /* VMS */ debug(F101,"doexit exitstat","",exitstat); debug(F101,"doexit what","",what); doclean(); /* First, clean up everything */#ifdef VMS if (what == -1) what = 0; /* Since we set two different items */ sprintf(envstr,"%d", exitstat | what); symval.dsc$w_length = (int)strlen(envstr); symval.dsc$a_pointer = envstr; symval.dsc$b_class = DSC$K_CLASS_S; symval.dsc$b_dtype = DSC$K_DTYPE_T; i = 2; /* Store in global table */ LIB$SET_SYMBOL(&symnam, &symval, &i); if (exitstat == BAD_EXIT) exitstat = SS$_ABORT | STS$M_INHIB_MSG; if (exitstat == GOOD_EXIT) exitstat = SS$_NORMAL | STS$M_INHIB_MSG; exit(exitstat);#else /* Not VMS */ if (what == -1) /* Take 1st arg literally */ exit(exitstat); /* e.g. user-supplied exit code */ else /* otherwise */ exit(exitstat | what); /* OR in the bits */#endif /* VMS */}/* Set up interrupts */VOIDsetint() { conint(trap,stptrap); /* Turn on console terminal interrupts. */ bgchk(); /* Check background status */}VOIDbgchk() { /* Check background status */ if (bgset < 0) pflag = !backgrd; /* Set prompt flag */ else /* based on foreground/background */ pflag = (bgset == 0 ? 1 : 0); /* Message flag on only if at top level, pflag is on, and QUIET is OFF */ if (#ifndef NOSPL cmdlvl == 0#else tlevel < 0#endif /* NOSPL */ ) msgflg = (pflag == 0) ? 0 : !quiet; else msgflg = 0;}#ifdef DEBUG/* D E B U G -- Enter a record in the debugging log *//* Call with a format, two strings, and a number: f - Format, a bit string in range 0-7. If bit x is on, then argument number x is printed. s1 - String, argument number 1. If selected, printed as is. s2 - String, argument number 2. If selected, printed in brackets. n - Int, argument 3. If selected, printed preceded by equals sign. f=0 is special: print s1,s2, and interpret n as a char.*/#define DBUFL 2300static char *dbptr = (char *)0;intdodebug(f,s1,s2,n) int f; char *s1, *s2; long n; { char *sp; if (!deblog) return(0); /* If no debug log, don't. */ if (!dbptr) { dbptr = malloc(DBUFL+1); if (!dbptr) return(0); } sp = dbptr; if (!s1) s1="(NULL)"; if (!s2) s2="(NULL)"; switch (f) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -