📄 zcurses.c
字号:
if(ioctl(0,CONS_GET,&monitor_type) < 0) /* not multiscreen */ {#endif#ifdef M_SYSV /* SCO non AT console */ vanilla_ruling();#endif /* * if tty (console) is not character special, only report * basic progress */ memset((char *)&dn,0,sizeof(dn)); stat("/dev/null",&dn); if(fstat(0,&tty_stat) || ((tty_stat.st_mode & S_IFMT) != S_IFCHR) || (dn.st_rdev == tty_stat.st_rdev)) { dumbtty = 1; report_verbosity = 0; report_init_complete = 1; return(1); }#ifdef NO_PTY_CURSES /* * if pty (must be xterm), send clear screen and no curses */ if(!stat("/dev/ttyp0",&pty_stat) && (pty_stat.st_rdev & 0xFF00) == (tty_stat.st_rdev & 0xFF00)) { static char ff[] = "\033[H\0332J\r\n"; write(2,ff,strlen(ff)); dumbtty = 1; report_verbosity = 1; report_init_complete = 1; return(1); }#endif /* * if non-multiscreen tty baud rate not at least that * of the attached line, use no curses, but do be a bit * more verbose than if tty not char special */#ifdef TTY_VS_LINE_SPEED_NO_CURSES test_tty_and_line_baud();#endif#if defined(CONS_GET) }#endif return(dumbtty);} /* end of determine_output_mode *//*+------------------------------------------------------------------------- report_init(title) "top line": row 1 col 11 len 21 file quan: row 2 col 15 len 3 row 2 col 12 len 7 clear "of ###" start time: row 8 col 21 len 8 "window:" row 8 col 50 len 7--------------------------------------------------------------------------*/voidreport_init(title)char *title;{ register int itmp; if(report_init_complete) return; start_seconds = time((long *)0); current_seconds = start_seconds; if(dumbtty) return;#if defined(FASI) (void)ioctl(iofd,FASIC_SIP,&fip_start);#endif /* FASI */ if(!initscr()) exit(254); if(!stdscr) exit(254); crmode(); noecho(); nonl(); clear(); report_init_complete = 1; win = newwin(WIN_LINES,WIN_COLS,WIN_TOPY,WIN_LEFTX); box(win,sVR,sHR);#ifndef SVR4 wmove(win,0,0); waddch(win,sTL); wmove(win,win->_maxy - 1,0); waddch(win,sBL); wmove(win,win->_maxy - 1,win->_maxx - 1); waddch(win,sBR); wmove(win,0,win->_maxx - 1); waddch(win,sTR);#endif wmove(win,0,2); wstandout(win); waddch(win,'['); waddch(win,' '); strcpy(s128,title); waddstr(win,s128); waddch(win,' '); waddch(win,']'); wstandend(win);#ifdef SVR4 whline(win, (unsigned long)(sHR & 0x00ff), 2); wmove(win,0, 8 + strlen(title));#else waddch(win,sHR); waddch(win,sHR);#endif waddch(win,' '); itmp = WIN_COLS - 2 - 7 - strlen(title); curr_dir[itmp] = 0; waddstr(win,curr_dir); waddch(win,' '); if(bottom_label) { strncpy(s128,bottom_label,WIN_COLS - 6); s128[WIN_COLS - 6] = 0; wmove(win,WIN_LINES - 1,2); waddch(win,' '); waddstr(win,s128); waddch(win,' '); } itmp = 0; while(1) { if(win_template[itmp] == (char *)0) break; wmove(win,itmp + 1,1); waddstr(win,win_template[itmp++]); } if(ecusz_flag) { clear_area(win,2,15,3); sprintf(s128,"%-3d",npats); waddstr(win,s128);#if defined(FORK_DEBUG) sprintf(s128,"DEBUG ecusz pid %d",getpid());#endif } else /* ecurz */ { clear_area(win,2,11,8); /* clear "of ###" */ waddstr(win,":");#if defined(FORK_DEBUG) sprintf(s128,"DEBUG ecurz pid %d",getpid());#endif }#if defined(FORK_DEBUG) ecu_log_event(getppid(),s128);#endif clear_area(win,1,11,21); report_error_count(); clear_area(win,8,21,8); /* starting time */ waddstr(win,get_tod(1,(char *)0)); if(show_window) { wmove(win,8,50); waddstr(win,"window:"); wmove(win,9,50); waddstr(win,"+0"); } wrefresh(win);} /* end of report_init *//*+------------------------------------------------------------------------- report_rx_ind(status)--------------------------------------------------------------------------*/voidreport_rx_ind(status)int status;{char *cptr; if(dumbtty) { if(report_verbosity && status) { printf("R"); if(++dumbtty_pos > 75) { dumbtty_newline(); current_seconds = time((long *)0); elapsed_seconds = current_seconds - this_file_start_seconds; cptr = get_elapsed_time(elapsed_seconds); dumbtty_pos = printf("%s elapsed ",cptr + ((elapsed_seconds < 3600L) ? 3 : 0)); } fflush(stdout); } return; } wmove(win,1,54); waddch(win,(status) ? 'R' : ' '); wmove(win,1,54); wrefresh(win);} /* end of report_rx_ind *//*+------------------------------------------------------------------------- report_tx_ind(status)--------------------------------------------------------------------------*/voidreport_tx_ind(status)int status;{char *cptr; if(dumbtty) { if(report_verbosity && status) { printf("T"); if(++dumbtty_pos > 75) { dumbtty_newline(); dumbtty_newline(); current_seconds = time((long *)0); elapsed_seconds = current_seconds - this_file_start_seconds; cptr = get_elapsed_time(elapsed_seconds); dumbtty_pos = printf("%s elapsed ",cptr + ((elapsed_seconds < 3600L) ? 3 : 0)); } fflush(stdout); } return; } wmove(win,1,56); waddch(win,(status) ? 'T' : ' '); wmove(win,1,56); wrefresh(win);} /* end of report_tx_ind *//*+------------------------------------------------------------------------- report_window() - if enable, show open widow size--------------------------------------------------------------------------*/voidreport_window(){ if(show_window && !dumbtty) { long ltmp; wmove(win,9,50); if((ltmp = (Txpos - Rxpos)) > 999999L) waddstr(win,">+999999"); else if(ltmp < -999999L) ; else { sprintf(s128,"%+-8ld",ltmp); waddstr(win,s128); if(log_packets) { write(log_packets,"window: ",8); write(log_packets,s128,strlen(s128)); write(log_packets,"\n",1); } } }} /* end of report_window *//*+------------------------------------------------------------------------- report_rx_tx_count() This function may be counted upon to perform wrefresh(win) rx char count: row 6 col 16 len 8 unsigned long tx char count: row 6 col 29 len 8 unsigned long session elapsed time: row 9 col 21 len 8 this file elapsed time: row 9 col 41 len 8 current tod: row 9 col 3 len 8 window: row 9 col 50 len 8If FASI, FE: row 14 col 6 len 4 OE: row 14 col 13 len 4 rcvd count: row 14 col 22 len 8 unsigned long xmtd count: row 14 col 36 len 8 unsigned long RTS status: row 14 col 48 len 1 CTS status: row 14 col 55 len 1 xmtr CTS count: row 15 col 18 len 4 xmtr XOFF count: row 15 col 28 len 4 rcvr CTS count: row 15 col 42 len 4 rcvr XOFF count: row 15 col 52 len 4 xmtr queue depth row 16 col 16 len 5 xmtr queue size row 16 col 25 len 5 (one time) rcvr queue depth row 16 col 37 len 5 rcvr queue size row 16 col 46 len 5 (one time)If sun, output queue depth row 14 col 23 len 6 RTS status row 14 col 35 len 1 CTS status row 14 col 42 len 1 input queue depth row 15 col 23 len 6 input queue avail row 15 col 49 len 6--------------------------------------------------------------------------*/report_rx_tx_count(){ extern unsigned long rx_char_count; extern unsigned long tx_char_count;#if defined(FASI) unsigned long ltmp; struct fas_info now;#endif /* FASI */#if defined(sun)uint output_queue;uint input_avail;uint input_size;uint modem_lines;#endif register char *cptr; if(dumbtty) { return; } sprintf(s128,"%-8ld",rx_char_count); wmove(win,6,16); waddstr(win,s128); sprintf(s128,"%-8ld",tx_char_count); wmove(win,6,29); waddstr(win,s128); /* now time of day */ wmove(win,9,3); cptr = get_tod(1,(char *)0); waddstr(win,cptr); current_seconds = time((long *)0); elapsed_seconds = current_seconds - start_seconds; cptr = get_elapsed_time(elapsed_seconds); wmove(win,9,21); waddstr(win,cptr); if(this_file_start_seconds) elapsed_seconds = current_seconds - this_file_start_seconds; else elapsed_seconds = 0; cptr = get_elapsed_time(elapsed_seconds); wmove(win,9,41); waddstr(win,cptr);#if defined(FASI) if(!ioctl(iofd,FASIC_SIP,&now)) { static int statics = 0; /* one time display flag */ if((ltmp = now.framing_errors - fip_start.framing_errors) > 999L) ltmp = 999L; sprintf(s128,"%-3lu",ltmp); wmove(win,14,6); waddstr(win,s128); if((ltmp = now.overrun_errors - fip_start.overrun_errors) > 999L) ltmp = 999L; sprintf(s128,"%-3lu",ltmp); wmove(win,14,13); waddstr(win,s128); ltmp = now.characters_received - fip_start.characters_received; sprintf(s128,"%-8lu",ltmp); wmove(win,14,22); waddstr(win,s128); ltmp = now.characters_transmitted - fip_start.characters_transmitted; sprintf(s128,"%-8lu",ltmp); wmove(win,14,36); waddstr(win,s128); wmove(win,14,49); waddch(win,(now.mcr & MC_SET_RTS) ? 'T' : 'F'); wmove(win,14,55); waddch(win,(now.msr & MS_CTS_PRESENT) ? 'T' : 'F'); ltmp = now.xmtr_hw_flow_count - fip_start.xmtr_hw_flow_count; if(ltmp > 9999L) ltmp = 9999L; sprintf(s128,"%-4lu",ltmp); wmove(win,15,17); waddstr(win,s128); ltmp = now.xmtr_sw_flow_count - fip_start.xmtr_sw_flow_count; if(ltmp > 9999L) ltmp = 9999L; sprintf(s128,"%-4lu",ltmp); wmove(win,15,27); waddstr(win,s128); ltmp = now.rcvr_hw_flow_count - fip_start.rcvr_hw_flow_count; if(ltmp > 9999L) ltmp = 9999L; sprintf(s128,"%-4lu",ltmp); wmove(win,15,41); waddstr(win,s128); ltmp = now.rcvr_sw_flow_count - fip_start.rcvr_sw_flow_count; if(ltmp > 9999L) ltmp = 9999L; sprintf(s128,"%-4lu",ltmp); wmove(win,15,51); waddstr(win,s128); if(now.xmit_ring_cnt > 99999) now.xmit_ring_cnt = 99999; sprintf(s128,"%-5u",now.xmit_ring_cnt); wmove(win,16,16); waddstr(win,s128); if(now.recv_ring_cnt > 99999) now.recv_ring_cnt = 99999; sprintf(s128,"%-5u",now.recv_ring_cnt); wmove(win,16,37); waddstr(win,s128); if(!statics) { statics = 1; ltmp = XMIT_BUFF_SIZE; if(ltmp > 99999) ltmp = 99999; sprintf(s128,"%-5lu",ltmp); wmove(win,16,25); waddstr(win,s128); ltmp = RECV_BUFF_SIZE; if(ltmp > 99999) ltmp = 99999; sprintf(s128,"%-5lu",ltmp); wmove(win,16,46); waddstr(win,s128); } }#endif /* FASI */#if defined(sun) output_queue = 0; ioctl(iofd,TIOCOUTQ,(int *)&output_queue); if(output_queue > 999999) output_queue = 999999; sprintf(s128,"%6u",output_queue); wmove(win,14,23); waddstr(win,s128); modem_lines = 0; ioctl(iofd,TIOCMGET,(int *)&modem_lines); wmove(win,14,35); waddch(win,(modem_lines & TIOCM_RTS) ? 'T' : 'F'); wmove(win,14,42); waddch(win,(modem_lines & TIOCM_CTS) ? 'T' : 'F'); input_size = 0; input_avail = 0; ioctl(iofd,TIOCISPACE,(int *)&input_avail); ioctl(iofd,TIOCISIZE,(int *)&input_size); if(input_size > 999999) input_size = 999999; if(input_avail > 999999) input_avail = 999999; sprintf(s128,"%6u",input_size - input_avail); wmove(win,15,23); waddstr(win,s128); sprintf(s128,"%6u",input_avail); wmove(win,15,49); waddstr(win,s128);#endif report_window(); wrefresh(win); /* calling procs expect this to occur always */} /* end of report_rx_tx_count *//*+------------------------------------------------------------------------- report_mode(comm_mode) comm mode row 7 col 52 length 6 3: save old tty stat, set raw mode with flow control 2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g 1: save old tty stat, set raw mode 0: restore original tty mode--------------------------------------------------------------------------*/voidreport_mode(comm_mode)int comm_mode;{char *cptr;char tmp[8]; if(dumbtty) { return; } clear_area(win,7,52,6); switch(comm_mode) { case 0: cptr = "NORMAL"; break; case 1: cptr = "RAW"; break; case 2: cptr = "RAW-g"; break; case 3: cptr = "RAW-f"; break; default: sprintf(tmp,"%5u",comm_mode); cptr = tmp; } waddstr(win,cptr); wrefresh(win); if(log_packets) { write(log_packets,"comm_mode: ",6); write(log_packets,cptr,strlen(cptr)); write(log_packets,"\n",1); }} /* end of report_mode *//*+------------------------------------------------------------------------- report_rxblklen(blklen) row 7 col 35 5 chars--------------------------------------------------------------------------*/voidreport_rxblklen(blklen)int blklen;{ char tmp[10]; if(dumbtty) { return; } sprintf(tmp,"%-5u",blklen); clear_area(win,7,35,5); waddstr(win,tmp); wrefresh(win);} /* end of report_rxblklen *//*+------------------------------------------------------------------------- report_txblklen(blklen) row 7 col 35 5 chars--------------------------------------------------------------------------*/voidreport_txblklen(blklen)int blklen;{ if(dumbtty) { return; } report_rxblklen(blklen);} /* end of report_txblklen *//*+------------------------------------------------------------------------- report_file_xfer_rate(text,count,final)--------------------------------------------------------------------------*/voidreport_file_xfer_rate(text,count,final)char *text;long count;int final;{ float rate = 0.0; float efficiency = 0.0; static long last_report = 0L; current_seconds = time((long *)0); if(!final && (current_seconds < (last_report + 5L))) return; last_report = current_seconds; elapsed_seconds = current_seconds - this_file_start_seconds; if(count && (elapsed_seconds > 0) && zcurses_baud_rate) { rate = (float)count / (float)elapsed_seconds; efficiency = 100.0 * (rate / ((float)zcurses_baud_rate / 10.0)); } if(efficiency > 120.0) /* interim hack for ecusz -r */ return; if(rate > 0.01) { if(efficiency < 0.5) sprintf(s128,"XFERINFO %s rate ~= %.0f ch/sec",text,rate); else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -