📄 ckuusx.c
字号:
#ifdef CK_NEWTERMstatic FILE *ck_stdout = NULL;static int ck_fd = -1;#endif /* CK_NEWTERM */static long pct = 100, oldpct = 0; /* Percent done */static int oldtyp = 0, oldwin = -1, oldtry = -1, oldlen = -1;#ifdef CK_ANSICvoidscreenc(int f, char c,long n,char *s)#else#ifdef MYCURSESVOID#elseint#endif /* MYCURSES */screenc(f,c,n,s)int f; /* argument descriptor */char c; /* a character or small integer */long n; /* a long integer */char *s; /* a string */#endif /* CK_ANSIC *//* screenc() */ { static int q = 0; static long fsiz = -1L; /* Copy of file size */ static long fcnt = 0L; /* File count */ static long fbyt = 0L; /* Total file bytes */ int len; /* Length of string */ int x; /* Worker */ if (cinit == 0 || cendw > 0) { /* Handle borderline cases... */ if (f == SCR_CW) { /* Close window, but it's not open */ ft_win = 0; return; } if (f == SCR_EM || (f == SCR_PT && c == 'E')) { /* Fatal error before window open */ conoll(""); conoc('?'); conoll(s); return; /* Regular display */ } } if (cinit == 0) { /* Only call initscr() once */ cendw = 1; /* New window needs repainting */#ifdef COMMENT if (!initscr()) { /* Oops, can't initialize window? *//* In fact, this doesn't happen. "man curses" says initscr() halts the entire program if it fails, which is true on the systems where I've tested it. It will fail if your terminal type is not known to it. That's why SET FILE DISPLAY FULLSCREEN calls tgetent() to make sure the terminal type is known before allowing a curses display.*/ fprintf(stderr,"CURSES INITSCR ERROR\r\n"); fdispla = XYFD_R; /* Go back to regular display */ return; } else { cinit++; /* Window initialized ok */ debug(F100,"CURSES INITSCR OK","",0); }#else /* Save some memory. */#ifdef CK_NEWTERM /* (From Andy Fyfe <andy@vlsi.cs.caltech.edu>) System V curses seems to reserve the right to alter the buffering on the output FILE* without restoring it. Fortunately System V curses provides newterm(), an alternative to initscr(), that allows us to specify explicitly the terminal type and input and output FILE pointers. Thus we duplicate stdout, and let curses have the copy. The original remains unaltered. Unfortunately, newterm() seems to be particular to System V. */ s = getenv("TERM"); if (ck_fd < 0) { ck_fd = dup(fileno(stdout)); ck_stdout = (ck_fd >= 0) ? fdopen(ck_fd, "w") : NULL; } if (ck_stdout == NULL || newterm(s, ck_stdout, stdin) == 0) { fprintf(stderr, "Fullscreen display not supported for terminal type: %s\r\n",s); fdispla = XYFD_R; /* Go back to regular display */ return; }#else initscr(); /* Initialize curses. */#endif /* CK_NEWTERM */ cinit++; /* Remember curses was initialized. */#endif /* COMMENT */ } ft_win = 1; /* Window is open */ if (cendw) { /* endwin() was called previously */#ifdef VMS initscr(); /* (or should have been!) */ clear(); touchwin(stdscr); refresh();#else /* All others... */ clear();#endif /* VMS */ move(CW_BAN,0); /* Display the banner */ if (*myhost) printw("%s, %s",versio,(char *)myhost); else printw("%s",versio); move(CW_DIR,3); printw("Current Directory: %s",zgtdir()); if (network) { move(CW_LIN,9); printw("Remote Host: %s",ttname); } else { move(CW_LIN,0); printw("Communication Device: %s",ttname); } move(CW_SPD,1); printw("Communication Speed: "); move(CW_SPD,22); /* Speed */ if (network) { printw("(network)"); } else { if (speed < 0L) speed = ttgspd(); if (speed > 0L) { if (speed == 8880) printw("75/1200"); else printw("%ld",speed); } else printw("unknown"); } move(CW_PAR,14); printw("Parity: %s",parnam((char)parity)); move(CW_TYP,11); printw("File Type:"); move(CW_SIZ,11); printw("File Size:"); move(CW_PCD, 8); printw("Percent Done:"); move(CW_TR, 1); printw("Estimated Time Left:"); move(CW_WS, 8); printw("Window Slots:"); move(CW_PT, 9); printw("Packet Type:"); move(CW_PC, 8); printw("Packet Count:"); move(CW_PL, 7); printw("Packet Length:"); move(CW_PR, 2); printw("Packet Retry Count:"); move(CW_PB, 2); printw("Packet Block Check:"); move(CW_ERR,10); printw("Last Error:"); move(CW_MSG, 8); printw("Last Message:");#ifdef ATTSV#ifndef aegis#ifndef datageneral#define CK_NEED_SIG#endif /* datageneral */#endif /* aegis */#endif /* ATTSV */#ifdef POSIX#ifndef CK_NEED_SIG#define CK_NEED_SIG#endif /* CK_NEED_SIG */#endif /* POSIX */#ifdef CK_NEED_SIG move(CW_INT, 0); printw("<%s>X to cancel file, <%s>Z to cancel group, <%s><CR> to resend packet", dbchr(escape), dbchr(escape), dbchr(escape)); move(CW_INT + 1, 0); printw("<%s>E to send Error packet, or Ctrl-C to quit immediately.", dbchr(escape));#else move(CW_INT, 0);#ifdef OS2 printw( "X to cancel file, Z to cancel group, <Enter> to resend packet,");#else printw("X to cancel file, Z to cancel group, <CR> to resend packet,");#endif /* OS2 */ move(CW_INT + 1, 0); printw("E to send Error packet, or Ctrl-C to quit immediately.");#endif /* CK_NEED_SIG */ refresh(); cendw = 0; } len = strlen(s); /* Length of argument string */ debug(F101,"SCREENC switch","",f); /* Handle our function code */ switch (f) { case SCR_FN: /* Filename */ fsiz = -1L; /* Invalidate previous file size */ move(CW_PCD,22); /* Erase percent done from last time */ clrtoeol(); move(CW_SIZ,22); /* Erase file size from last time */ clrtoeol(); move(CW_ERR,22); /* And last error message */ clrtoeol(); if (what == W_SEND) { /* If we're sending... */ move(CW_NAM,13); printw("Sending:"); } else if (what == W_RECV) { /* If we're receiving... */ move(CW_NAM,11); printw("Receiving:"); } else { /* If we don't know... */ move(CW_NAM,11); /* (should never see this) */ printw("File Name:"); } move(CW_NAM,22); /* Display the filename */ if (len > 57) { printw("%.54s..",s); len = 57; } else printw("%s",s); q = len; /* Remember name length for later */ clrtoeol(); scrft(); /* Display file type */ refresh(); return; case SCR_AN: /* File as-name */ if (q + len < 58) { /* Will fit */ move(CW_NAM, 22 + q); printw(" => %s",s); } else { /* Too long */ move(CW_NAM, 22); /* Overwrite previous name */ q = 0; len = 54; printw(" => %.51s..", s); /* Truncate */ } q += len + 4; /* Remember horizontal position */ clrtoeol(); refresh(); return; case SCR_FS: /* File size */ fsiz = n; move(CW_SIZ,22); if (fsiz > -1L) printw("%ld",n); clrtoeol(); scrft(); /* File type */ refresh(); return; case SCR_PT: /* Packet type or pseudotype */ if (spackets < 5) { /* Things that won't change after the 4th packet */ move(CW_PAR,22); printw("%s",parnam((char)parity)); clrtoeol(); clrtoeol(); move(CW_PB, 22); /* Block check on this packet */ if (bctu == 4) printw("B"); else printw("%d",bctu); clrtoeol(); } x = (what == W_RECV) ? /* Packet length */ rpktl+1 : spktl+1; if (x != oldlen) { /* But only if it changed. */ move(CW_PL, 22); printw("%d",x); clrtoeol(); oldlen = x; } move(CW_PC, 22); /* Packet count (always). */ printw("%d",spackets); /* WARNING: this can slow us way */ clrtoeol(); /* down with short packets. */ if (wcur != oldwin) { /* Window slots, if changed. */ move(CW_WS, 22); printw("%d of %d",wcur,wslotr); clrtoeol(); oldwin = wcur; } if (retrans != oldtry) { /* Retry count, if changed */ move(CW_PR, 22); printw("%d",retrans); clrtoeol(); oldtry = retrans; } if (c != oldtyp && c != 'Y' && c != 'N') { /* Sender's packet type */ move(CW_PT,22); printw("%c",c); clrtoeol(); oldtyp = c; } switch (c) { /* Now handle specific packet types */ case 'S': /* Beginning of transfer */ fcnt = fbyt = 0L; /* Clear counters */ break; case 'D': /* Data packet */ if (fsiz > 0L) { /* Show percent done if known */ long s, x; oldpct = pct; /* Remember previous percent */ pct = (fsiz > 99L) ? (ffc / (fsiz / 100L)) : 0L; /* New one */ if (pct > 100L || /* Allow expansion */ oldpct == 99L && pct < 0L) /* other boundary conditions */ pct = 100L; if (pct != oldpct) { /* Only do this 100 times per file */ move(CW_PCD,22); printw("%ld", pct); clrtoeol(); /* Time remaining for this file */ s = (long) ((unsigned) gtimer() - fsecs); /* Secs so far */ if (s > 0L) { /* Time remaining must be calculated using the smallest possible quantities, to prevent overflow: (seconds_so_far * percent_left) / percent_done. And avoid divide_by_zero. */ x = (pct > 0L) ? ((s * (100 - pct)) / pct) : -1L; if (x > -1L) { move(CW_TR,22); printw("%s",hhmmss(x)); clrtoeol(); } } } } break; case 'E': /* Error packet */#ifdef COMMENT move(CW_ERR,22); /* Print its data field */ if (*s) printw("%s",s); clrtoeol();#endif /* COMMENT */ fcnt = fbyt = 0; /* So no bytes for this file */ break; case 'Q': /* Crunched packet */ move(CW_ERR,22); printw("Damaged Packet"); clrtoeol(); break; case 'T': /* Timeout */ move(CW_ERR,22); printw("Timeout"); clrtoeol(); break; default: /* Others, do nothing */ break; } refresh(); return; case SCR_ST: /* File transfer status */ move(CW_PCD,22); /* Update percent done */ if (c == ST_OK) { /* OK, print 100 % */ pct = 100; printw("100"); } else if (fsiz > 0L) /* Not OK, update final percent */ printw("%ld",( ffc * 100L ) / fsiz); clrtoeol(); move(CW_MSG,22); /* Remove any previous message */ clrtoeol(); refresh(); move(CW_TR, 22); clrtoeol(); refresh(); switch (c) { /* Print new status message */ case ST_OK: /* Transfer OK */ fcnt++; /* Count this file */ if (ffc > 0L) /* For some reason ffc is off by 1 */ fbyt += ffc - 1L; /* Count its bytes */ move(CW_MSG,22); printw("Transfer OK"); /* Say Transfer was OK */ clrtoeol(); refresh(); return; case ST_DISC: /* Discarded */ move(CW_ERR,22); printw("File discarded"); clrtoeol(); refresh(); return; case ST_INT: /* Interrupted */ move(CW_ERR,22); printw("Transfer interrupted"); clrtoeol(); refresh(); return; case ST_SKIP: /* Skipped */ move(CW_ERR,22); printw("File skipped"); clrtoeol(); refresh(); return; case ST_ERR: /* Error message */ move(CW_ERR,22); printw("%s",s); clrtoeol(); refresh(); return; case ST_REFU: /* Refused */ move(CW_ERR,22); if (*s) printw("Refused, %s",s); else printw("Refused"); clrtoeol(); refresh(); return; case ST_INC: move(CW_ERR,22); printw("Incomplete"); clrtoeol(); refresh(); return; default: /* Bad call */ move(CW_ERR,22); printw("*** screen() called with bad status ***"); clrtoeol(); refresh(); return; } case SCR_TC: /* Transaction complete */ move(CW_MSG,22); /* Print statistics in message line */ if (tsecs > 0) printw("Files: %ld, Total Bytes: %ld, %ld cps", fcnt, fbyt, ((fbyt * 10L) / (long) tsecs) / 10L); else printw("Files: %ld, Total Bytes: %ld",fcnt,fbyt); clrtoeol(); move(CW_TR, 1); printw(" Elapsed Time: %s",hhmmss((long)tsecs)); clrtoeol(); move(23,0); clrtoeol(); /* Clear instructions lines */ move(22,0); clrtoeol(); /* to make room for prompt. */ refresh();#ifndef VMSCURSE endwin();#endif /* VMSCURSE */ pct = 100; oldpct = 0; /* Reset these for next time. */ oldtyp = 0; oldwin = -1; oldtry = -1; oldlen = -1; cendw = 1; conoc(BEL); /* Close window, then beep. */ ft_win = 0; /* Window closed. */ return; case SCR_EM: /* Error packet (fatal) */ move (CW_ERR,22); printw("? %s",s); conoc(BEL); clrtoeol(); refresh(); return; case SCR_QE: /* Quantity equals */ case SCR_TU: /* Undelimited text */ case SCR_TN: /* Text delimited at start */ case SCR_TZ: /* Text delimited at end */ return; /* (ignored in fullscreen display) */ case SCR_XD: /* X-packet data */ move(CW_NAM,22); printw("%s",s); clrtoeol(); refresh(); return; case SCR_CW: /* Close Window */ clrtoeol(); move(23,0); clrtoeol(); move(22,0); clrtoeol(); refresh(); pct = 100; oldpct = 0; /* Reset these for next time. */ oldtyp = 0; oldwin = -1; oldtry = -1; oldlen = -1;#ifndef VMSCURSE endwin();#endif /* VMSCURSE */ ft_win = 0; /* Flag that window is closed. */ cendw = 1; return; default: /* Bad call */ move (CW_ERR,22); printw("*** screen() called with bad function code ***"); clrtoeol(); refresh(); return; }}#endif /* CK_CURSES */#endif /* MAC */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -