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

📄 zcurses.c

📁 一个通讯程序源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*+-------------------------------------------------------------------------	zcurses.c -- ecu file transfer program curses interface  000000000011111111112222222222333333333344444444445555555550  01234567890123456789012345678901234567890123456789012345678900.-[ prog+rev ]-- <dir> ------------------------------------.01|  ZMODEM_6____  _40_____________________________________  |02|  File ### of ###: _38__________________________________  |03|  File position:  _8______ length: _8______  -rwxrwxrwx   |04|  _55____________________________________________________ | transaction05|  _55____________________________________________________ | last rx/tx hdr06|  Comm I/O: rx _8______  tx _8______ bytes                |07|  Baud rate: _5___ BINARY blklen: _____ comm mode: RAW-g  |08|  Time:    started: __:__:__ this file: __:__:__ window:  |09|  __:__:__ elapsed: __:__:__            __:__:__ ________ |10|  Errors: this file: _3_ total: _4__ files skipped: _3_   |11|  _55____________________________________________________ |  err str12|  _55____________________________________________________ |  comment str13|  _55____________________________________________________ |  remote info14`----------------------------------------------------------'14|  FE ___ OE ___ rcvd ________ xmtd ________ RTS _ CTS _      FASI15|  flow xmtr CTS ____ XOFF ____ rcvr RTS ____ XOFF ____16|  queues: xmtr _____ of _____  rcvr _____ of _____14|  Output queue depth  ______  RTS _  CTS _                   sun15|  Input queue depth   ______  Input queue avail ______   Defined functions:	clear_area(w,row,col,len)	clear_area_char(w,row,col,len,fillchar)	determine_output_mode()	dumbtty_newline()	get_elapsed_time(elapsed_secs)	get_tod(type,tod)	mode_map(file_mode,mode_str)	report_comm_baud_rate(baud_rate)	report_error_count()	report_file_byte_io(count)	report_file_close(skipped)	report_file_open_length(length)	report_file_open_mode(file_mode)	report_file_open_tod()	report_file_rcv_started(filename,length,last_mod_time,file_mode)	report_file_send_open(filename,filestat)	report_file_xfer_rate(text,count,final)	report_init(title)	report_last_rxhdr(rptstr,error_flag)	report_last_txhdr(rptstr,error_flag)	report_mode(comm_mode)	report_protocol_crc_type(str)	report_protocol_type(str)	report_rx_ind(status)	report_rx_tx_count()	report_rxblklen(blklen)	report_rxpos(pos)	report_str(rptstr,error_flag)	report_top_line(topstr)	report_transaction(str)	report_transfer_progress(filepos,initfpos)	report_tx_ind(status)	report_txblklen(blklen)	report_txpos(pos)	report_uninit(sig)	report_window()	report_xfer_mode(str)	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 *//*:02-09-1992-16:08-root@n4hgf-ruling characters only on  SCO (tcap curses) *//*:01-05-1992-17:27-wht@n4hgf-properly display progress for resumed transfers *//*:09-02-1991-01:12-wht@n4hgf2-show sun driver information *//*:08-28-1991-14:08-wht@n4hgf2-SVR4 cleanup by aega84!lh *//*:08-23-1991-18:33-wht@n4hgf2-disable force no curses for tty vs. line speed *//*:08-21-1991-06:23-wht@n4hgf-sun porting *//*:07-25-1991-12:59-wht@n4hgf-ECU release 3.10 *//*:06-15-1991-05:47-root@n4hgf-report per-file xfer rate *//*:05-25-1991-14:51-wht@n4hgf-FAS/i display *//*:04-24-1991-01:22-wht@n4hgf-handle dumbtty and single file xfer >= 1 hour *//*:02-03-1991-17:27-wht@n4hgf-show elapsed time during no curses xfer *//*:01-04-1991-15:54-wht@n4hgf-dumbtty per-file xfer rate was wrong *//*:12-18-1990-21:26-wht@n4hgf-better output control *//*:12-04-1990-04:07-wht@n4hgf-handle slow terminal using faster line *//*:12-04-1990-03:04-wht@n4hgf-choose ruling chars based on multiscreen or not *//*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller *//*:08-14-1990-20:41-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#if defined(FASI)#  include <local/fas.h>#endif	/* FASI */#include "../pc_scr.h"#ifdef USE_PROTOS# include "protos.h"#endiflong time();void report_error_count();extern char *tzname[];struct tm *localtime();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;#if defined(FASI)#define WIN_LINES	18#else#if defined(sun)#define WIN_LINES	17#else#define WIN_LINES	15#endif	/* sun */#endif	/* FASI */#define WIN_COLS	60#define WIN_TOPY	2#define WIN_LEFTX	8extern char curr_dir[];extern char *bottom_label;extern int Filcnt;extern int ecusz_flag;	/* ecusz == 1, ecurz == 0 */extern int force_dumbtty;extern int skip_count;extern int npats;extern int iofd;extern long rxpos;extern int log_packets;extern long Txpos;extern long Rxpos;extern long initial_filepos;WINDOW	*win;int (*original_sigint_handler)();int (*original_sigquit_handler)();int (*original_sigterm_handler)();int report_init_complete;int report_verbosity;int dumbtty;int dumbtty_pos;int this_file_errors;long this_file_xfer_count;int total_errors;int show_window;long current_seconds;long start_seconds;long this_file_start_seconds;long elapsed_seconds;unsigned long total_data_bytes_xfered;unsigned int zcurses_baud_rate;char s128[128];#if defined(FASI)struct fas_info fip_start;#endif /* FASI */char *win_template[] ={/*00000000001111111111222222222233333333334444444444555555555 *//*01234567890123456789012345678901234567890123456789012345678 *//*.----------------------------------------------------------. */  "                                                          ",	/* 1 */  "  File ### of ###: _____________________________________  ",	/* 2 */  "  File position:  ________ length: ________               ",	/* 3 */  "                                                          ",	/* 4 */  "  tx: ______________________  rx: ______________________  ",	/* 5 */  "  Comm I/O: rx ________  tx ________ bytes                ",	/* 6 */  "  Baud rate: _____ ______ blklen: _____ comm mode: ______ ",	/* 7 */  "  Time:    started: __:__:__ this file: __:__:__          ", /* 8 */  "  __:__:__ elapsed: __:__:__            __:__:__          ", /* 9 */  "  Errors: this file: ___ total: ____ files skipped: ___   ", /* 10 */  "                                                          ",	/* 11 */  "                                                          ",	/* 12 */  "                                                          ",	/* 13 */#if defined(FASI)  "  FE ___ OE ___ rcvd ________ xmtd ________ RTS _ CTS _   ",  "  flow xmtr CTS ____ XOFF ____ rcvr RTS ____ XOFF ____    ",  "  queues: xmtr _____ of _____  rcvr _____ of _____        ",#endif	/* FASI */#if defined(sun)  "  Output queue depth  ______  RTS _  CTS _                ",  "  Input queue depth   ______  Input queue avail ______    ",#endif/*`----------------------------------------------------------' */(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 *get_tod(type,tod)  time of day types:	0		hh:mm	1		hh:mm:ss	2		mm-dd-yyyy hh:mm  static string address is returned  if tod != (char *)0, time is returned there too------------------------------------------------------------------------*/char *get_tod(type,tod)int type;char *tod;{	static char tod_str[32];	long cur_time = time((long *)0);	struct tm *lt = localtime(&cur_time);	switch(type)	{		case 0:			sprintf(tod_str,"%02d:%02d",lt->tm_hour,lt->tm_min);			break;		default:		case 1:			sprintf(tod_str,"%02d:%02d:%02d",				lt->tm_hour,lt->tm_min,lt->tm_sec);			break;		case 2:			sprintf(tod_str,"%02d-%02d-%04d %02d:%02d",				lt->tm_mon + 1,lt->tm_mday,lt->tm_year + 1900,				lt->tm_hour,lt->tm_min);			break;	}	if(tod != (char *)0)		strcpy(tod,tod_str);	return(tod_str);}	/* end of get_tod *//*+-----------------------------------------------------------------------	mode_map(file_mode,mode_str)	build drwxrwxrwx string------------------------------------------------------------------------*/char *mode_map(file_mode,mode_str)unsigned short file_mode;char *mode_str;{register unsigned ftype = file_mode & S_IFMT;register char *rtn;static char result[12];	rtn = (mode_str == (char *)0) ? result : mode_str;	/*               drwxrwxrwx */	/*               0123456789 */	strcpy(rtn,"----------");	switch(ftype)	{		case S_IFIFO:	*rtn = 'p'; break; /* FIFO (named pipe) */		case S_IFDIR:	*rtn = 'd'; break; /* directory */		case S_IFCHR:	*rtn = 'c'; break; /* character special */		case S_IFBLK:	*rtn = 'b'; break; /* block special */		case S_IFREG:	*rtn = '-'; break; /* regular */#if defined(S_IFLNK)		case S_IFLNK:	*rtn = 'l'; break; /* symbolic link */#endif#if defined(S_IFSOCK)		case S_IFSOCK:	*rtn = 's'; break; /* socket */#endif#if defined(S_IFNAM)		case S_IFNAM:						/* name space entry */#if defined(S_IFNAM)			if(file_mode & S_INSEM)				/* semaphore */			{				*rtn = 's';				break;			}#endif#if defined(S_INSHD)			if(file_mode & S_INSHD)				/* shared memory */			{				*rtn = 'm';				break;			}			break;#endif#endif		default:		*rtn = '?'; break;	/* ??? */	}	if(file_mode & 000400) *(rtn + 1) = 'r';	if(file_mode & 000200) *(rtn + 2) = 'w';	if(file_mode & 000100) *(rtn + 3) = 'x';	if(file_mode & 004000) *(rtn + 3) = 's';	if(file_mode & 000040) *(rtn + 4) = 'r';	if(file_mode & 000020) *(rtn + 5) = 'w';	if(file_mode & 000010) *(rtn + 6) = 'x';	if(file_mode & 002000) *(rtn + 6) = 's';	if(file_mode & 000004) *(rtn + 7) = 'r';	if(file_mode & 000002) *(rtn + 8) = 'w';	if(file_mode & 000001) *(rtn + 9) = 'x';	if(file_mode & 001000) *(rtn + 9) = 't';	return(rtn);}	/* end of mode_map *//*+-------------------------------------------------------------------------	dumbtty_newline()--------------------------------------------------------------------------*/voiddumbtty_newline(){	if(dumbtty_pos)		printf("\r\n");	dumbtty_pos = 0;}	/* end of dumbtty_newline *//*+-------------------------------------------------------------------------	clear_area(w,row,col,len)--------------------------------------------------------------------------*/clear_area(w,row,col,len)WINDOW	*w;int row;int col;int len;{	if(dumbtty)		return;	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;{	if(dumbtty)		return;	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 17 length 42--------------------------------------------------------------------------*/voidreport_top_line(topstr)char *topstr;{char s42[42];	if(dumbtty)	{		dumbtty_newline();		dumbtty_pos = printf("%s",topstr);		fflush(stdout);		return;	}	clear_area(win,1,17,42);	if(strlen(topstr) < 40)		waddstr(win,topstr);	else	{		strncpy(s42,topstr,40);		s42[40] = 0;		waddstr(win,s42);	}}	/* end of report_top_line *//*+-------------------------------------------------------------------------	report_xfer_mode(modestr)  BINARY/ASCII   protocol xfer type: row 7 col 20 length 6--------------------------------------------------------------------------*/report_xfer_mode(str)char *str;{char s10[10];	if(dumbtty)		return;	if(strlen(str) > 6)	{		strncpy(s10,str,6);		s10[7] = 0;		str = s10;	}	clear_area(win,7,20,6);	waddstr(win,str);	wrefresh(win);}	/* end of report_xfer_mode *//*+-------------------------------------------------------------------------	report_protocol_type(str)  protocol type:  row 1 col 3 length 6 string--------------------------------------------------------------------------*/report_protocol_type(str)register char *str;{char s10[10];	if(dumbtty)	{		return;	}	if(strlen(str) > 6)	{		strncpy(s10,str,6);		s10[7] = 0;		str = s10;	}	clear_area(win,1,3,6);	waddstr(win,str);	wrefresh(win);}	/* end of report_protocol_type *//*+-------------------------------------------------------------------------	report_protocol_crc_type(str)  protocol crc type:  row 1 col 9 length 6--------------------------------------------------------------------------*/report_protocol_crc_type(str)register char *str;{char s8[8];	if(dumbtty)	{		return;	}	if(strlen(str) > 6)	{		strncpy(s8,str,6);		s8[7] = 0;		str = s8;	}	clear_area(win,1,9,6);	waddstr(win,str);	wrefresh(win);}	/* end of report_protocol_crc_type *//*+-------------------------------------------------------------------------	report_uninit(sig)--------------------------------------------------------------------------*/voidreport_uninit(sig)int sig;		/* if -1, called by normal code, else kill() value */{	float rate = 0.0;	float eff = 0.0;	if(report_init_complete)	{		current_seconds = time((long *)0);		elapsed_seconds = current_seconds - start_seconds;		if(elapsed_seconds && (zcurses_baud_rate > 50))		{			rate = (float)total_data_bytes_xfered /				(float)elapsed_seconds;			if(zcurses_baud_rate)				eff  = 100.0 * (rate / ((float)zcurses_baud_rate / 10.0));		}		if(rate > 0.01)		{			sprintf(s128,"XFERINFO transaction rate ~= %.0f ch/sec (%.0f%%)",			    rate,(eff > 0.5) ? eff : 0.0);			if(log_packets)			{				write(log_packets,"info: ",6);				write(log_packets,s128,strlen(s128));				write(log_packets,"\n",1);			}			report_top_line(s128 + 9);#if defined(WHT)			ecu_log_event(getppid(),s128);#endif		}		if(dumbtty)			dumbtty_newline();		else		{			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);		}		report_init_complete = 0;	}}	/* end of report_uninit *//*+-------------------------------------------------------------------------	determine_output_mode()--------------------------------------------------------------------------*/intdetermine_output_mode(){#if defined(CONS_GET)	int monitor_type;#endif	struct stat dn;	struct stat tty_stat;#ifdef NO_PTY_CURSES	struct stat pty_stat;#endif	if(force_dumbtty)	{		dumbtty = 1;		report_verbosity = 1;		report_init_complete = 1;		return(1);	}#ifndef M_SYSV	/* these are always set thus for non-SCO */	vanilla_ruling();#endif#if defined(CONS_GET)

⌨️ 快捷键说明

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