⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scurses.c

📁 一个通讯程序源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*+-------------------------------------------------------------------------	scurses.c -- ecu file transfer program curses interface  000000000011111111112222222222333333333344444444445555555550  01234567890123456789012345678901234567890123456789012345678900.----------------------------------------------------------.01|  SEAlink_6____  _39____________________________________  |02|  File ### of ###: _38__________________________________  |03|  File position:  _8______ length: _8______               |04|  _55____________________________________________________ | transaction05|  _55____________________________________________________ | last rx/tx hdr06|  Comm I/O: rx _8______  tx _8______ bytes                |07|  Baud rate: _5___ BINARY blklen: _____ comm mode: CBREAK |08|  Time started: session: HH:MM:SS  this file: HH:MM:SS    |09|                elpased: HH:MM:SS       time: HH:MM:SS    |10|  Error counts: this file:  _4__  total: _6____           |11|  _55____________________________________________________ |  err str12|  _55____________________________________________________ |  comment str13|  _55____________________________________________________ |  remote info14`----------------------------------------------------------'  Defined functions:	clear_area(w,row,col,len)	clear_area_char(w,row,col,len,fillchar)	get_elapsed_time(elapsed_secs)	hhmmss(tod)	report_error_count()	report_file_byte_io(count)	report_file_close()	report_file_open_length(length)	report_file_open_tod()	report_file_rcv_started(filename,length,last_mod_time)	report_file_send_open(filename,filestat)	report_init(title)	report_last_rxhdr(rptstr,error_flag)	report_last_txhdr(rptstr,error_flag)	report_line(baud_rate,mode)	report_protocol_crc_type(str)	report_rx_ind(status)	report_rx_tx_count()	report_rxpos(pos)	report_str(rptstr,error_flag)	report_top_line(topstr)	report_transaction(str)	report_tx_ind(status)	report_txpos(pos)	report_uninit()	vanilla_ruling()------------------------------------------------------------------------*//*+:EDITS:*//*:09-10-1992-14:00-wht@n4hgf-ECU release 3.20 *//*:08-22-1992-15:39-wht@n4hgf-ECU release 3.20 BETA *//*:04-24-1992-21:15-wht@n4hgf-sort out vannilla vs. at ruling *//*:02-09-1992-16:08-root@n4hgf-ruling characters only on  SCO (tcap curses) *//*:08-28-1991-14:08-wht@n4hgf2-SVR4 cleanup by aega84!lh *//*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 *//*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller *//*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */#include "../ecucurses.h"#include "../ecu_types.h"#include "../ecu_stat.h"#include <ctype.h>#include <signal.h>#include <time.h>#include <sys/timeb.h>#if defined(M_SYSV)#   include <sys/machdep.h>#else#if defined(ISC) || defined(SVR4)#  include <sys/at_ansi.h>#  include <sys/kd.h>#endif#endif#include "../pc_scr.h"#ifdef USE_PROTOS# include "protos.h"#endiflong time();extern char *tzname[];struct tm *localtime();#define WIN_LINES	15#define WIN_COLS	60#define WIN_TOPY	2#define WIN_LEFTX	8extern char curr_dir[];extern char s128[];extern int Filcnt;extern int Restricted;extern int sending_flag;	/* send == 1, receive == 0 */extern int npaths;extern long rxpos;extern int log_packets;WINDOW	*win;int (*original_sigint_handler)();int (*original_sigquit_handler)();int (*original_sigterm_handler)();int curses_installed = 0;		/* curses not yet active */int this_file_errors = 0;int total_errors = 0;long current_seconds;long start_seconds;long elapsed_seconds;unsigned long total_data_chars_xfered = 0L;unsigned char sTL = at_TL;unsigned char sTR = at_TR;unsigned char sBL = at_BL;unsigned char sBR = at_BR;unsigned char sLT = at_LT;unsigned char sRT = at_RT;unsigned char sVR = at_VR;unsigned char sHR = at_HR;char *win_template[] ={/*00000000001111111111222222222233333333334444444444555555555 *//*01234567890123456789012345678901234567890123456789012345678 *//*.----------------------------------------------------------. */  "  SEAlink                                                 ",	/* 1 */  "  File ### of ###: _____________________________________  ",	/* 2 */  "  File position:  ________ length: ________               ",	/* 3 */  "                                                          ",	/* 4 */  "  tx: ______________________  rx: ______________________  ",	/* 5 */  "  Comm I/O: rx ________  tx ________ bytes                ",	/* 6 */  "  Baud rate: _____ BINARY blklen: 128   comm mode: ______ ",	/* 7 */  "  Time started: session: --:--:--  this file: --:--:--    ",	/* 8 */  "                elapsed: --:--:--    current: --:--:--    ",	/* 9 */  "  Error counts: this file:  ____  total: ______           ",	/* 10 */  "                                                          ",	/* 11 */  "                                                          ",	/* 12 */  "                                                          ",	/* 13 *//*`----------------------------------------------------------' */(char *)0};/*+-------------------------------------------------------------------------	vanilla_ruling() - use ordinary ruling characters--------------------------------------------------------------------------*/voidvanilla_ruling(){	sTL = vanilla_TL;	sTR = vanilla_TR;	sBL = vanilla_BL;	sBR = vanilla_BR;	sLT = vanilla_LT;	sRT = vanilla_RT;	sVR = vanilla_VR;	sHR = vanilla_HR;}	/* end of vanilla_ruling *//*+-----------------------------------------------------------------------	char *get_elapsed_time(elapsed_secs)	hh:mm:ss returned  static string address is returned------------------------------------------------------------------------*/char *get_elapsed_time(elapsed_secs)long elapsed_secs;{	static char elapsed_time_str[10];	long hh,mm,ss;	hh = elapsed_secs / 3600;	elapsed_secs -= hh * 3600;	mm = elapsed_secs / 60L;	elapsed_secs -= mm * 60L;	ss = elapsed_secs;	sprintf(elapsed_time_str,"%02ld:%02ld:%02ld",hh,mm,ss);	return(elapsed_time_str);}	/* end of get_elapsed_time *//*+-----------------------------------------------------------------------	char *hhmmss(tod) - get time of day in form "hh:mm:ss"  static string address is returned  if tod != (char *)0, time is returned there too------------------------------------------------------------------------*/char *hhmmss(tod)char *tod;{	long cur_time = 0;	struct tm *lt;			/* local time */	static char tod_str[32];	cur_time = time((long *)0);	lt = localtime(&cur_time);	sprintf(tod_str,"%02d:%02d:%02d",lt->tm_hour,lt->tm_min,lt->tm_sec);	if(tod != (char *)0)		strcpy(tod,tod_str);	return(tod_str);}	/* end of hhmmss *//*+-------------------------------------------------------------------------	clear_area(w,row,col,len)--------------------------------------------------------------------------*/clear_area(w,row,col,len)WINDOW	*w;int row;int col;int len;{	wmove(w,row,col);	while(len-- > 0)		waddch(w,' ');	wmove(w,row,col);}	/* end of clear_area *//*+-------------------------------------------------------------------------	clear_area_char(w,row,col,len,fillchar)--------------------------------------------------------------------------*/clear_area_char(w,row,col,len,fillchar)WINDOW	*w;int row;int col;int len;char fillchar;{	wmove(w,row,col);	while(len-- > 0)		waddch(w,fillchar);	wmove(w,row,col);}	/* end of clear_area_char *//*+-------------------------------------------------------------------------	report_top_line(topstr)   top line: row 1 col 18 length 39--------------------------------------------------------------------------*/voidreport_top_line(topstr)char *topstr;{char s42[42];	clear_area(win,1,18,39);	if(strlen(topstr) < 39)		waddstr(win,topstr);	else	{		strncpy(s42,topstr,39);		s42[39] = 0;		waddstr(win,s42);	}}	/* end of report_top_line *//*+-------------------------------------------------------------------------	report_protocol_crc_type(str)  protocol crc type:  row 1 col 10 length 6--------------------------------------------------------------------------*/report_protocol_crc_type(str)register char *str;{char s8[8];	if(strlen(str) > 6)	{		strncpy(s8,str,6);		s8[6] = 0;		str = s8;	}	clear_area(win,1,10,6);	waddstr(win,str);	wrefresh(win);	if(log_packets)	{		write(log_packets,"chk:  ",6);		write(log_packets,str,strlen(str));		write(log_packets,"\n",1);	}}	/* end of report_protocol_crc_type *//*+-------------------------------------------------------------------------	report_error_count()	DOES NOT PERFORM A REFRESH CYCLE  this file: row 10 col 29 len 4  total:     row 10 col 42 len 6--------------------------------------------------------------------------*/voidreport_error_count(){	char tmp[16];	clear_area(win,10,29,4);	sprintf(tmp,"%4d",this_file_errors);	waddstr(win,tmp);	clear_area(win,10,42,6);	sprintf(tmp,"%6d",total_errors);	waddstr(win,tmp);	wrefresh(win);}	/* end of report_error_count *//*+-------------------------------------------------------------------------	report_uninit()--------------------------------------------------------------------------*/voidreport_uninit(){float total = (float)total_data_chars_xfered;	if(curses_installed)	{		if((total_data_chars_xfered != 0L) && (elapsed_seconds != 0L))		{			sprintf(s128,"Data xfer rate ~= %6.0f chars/sec",			    total / (float)elapsed_seconds);			if(log_packets)			{				write(log_packets,"info: ",6);				write(log_packets,s128,strlen(s128));				write(log_packets,"\n",1);			}			report_top_line(s128);		}		report_file_byte_io(0L);		report_rx_tx_count();		wmove(win,WIN_LINES - 1,WIN_COLS - 1);		wrefresh(win);		endwin();		fprintf(stderr,"\r\n\r\n\r\n");		fflush(stderr);		curses_installed = 0;	}}	/* end of report_uninit *//*+-------------------------------------------------------------------------	report_init(title)--------------------------------------------------------------------------*/voidreport_init(title)char *title;{register int itmp;#if defined(CONS_GET)int monitor_type;#endif	if(curses_installed)		return;#if defined(M_SYSV)	if(ioctl(0,CONS_GET,&monitor_type) < 0)	/* not multiscreen */#ifdef M_SYSV	/* SCO non AT console */		vanilla_ruling();#endif#else	vanilla_ruling();#endif	initscr();	crmode();	noecho();	nonl();	clear();	curses_installed = 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,' ');	waddstr(win,title);	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	waddstr(win," dir: ");	waddstr(win,curr_dir);	waddch(win,' ');	itmp = 0;	while(1)	{		if(win_template[itmp] == (char *)0)			break;		wmove(win,itmp + 1,1);		waddstr(win,win_template[itmp++]);	}	if(sending_flag)	{		clear_area(win,2,15,3);		sprintf(s128,"%3d",npaths);		waddstr(win,s128);	}	else	/* ecurz */	{		clear_area(win,2,11,8);	/* clear "of ###" */		waddstr(win,":");	}	clear_area(win,1,11,47);	report_error_count();	clear_area(win,8,26,8);		/* starting time */	waddstr(win,hhmmss((char *)0));	start_seconds = time((long *)0);	current_seconds = start_seconds;	wrefresh(win);}	/* end of report_init *//*+-------------------------------------------------------------------------	report_rx_ind(status)--------------------------------------------------------------------------*/voidreport_rx_ind(status)int status;{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -