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

📄 main.c

📁 在SCO UNIX制定界面程序 可根据文件配制菜单,而不必修改源程序,非常方便
💻 C
字号:

#include <stdio.h>
#include <signal.h>
#include <fcntl.h>

#include "menu.h"
#include "mytools.h"
#include "color.h"
#include "db_struct_c.h"
#include "macro_def.h"

extern int sql_run(), misc_audit();
char	audit_title[40];

void killed();
char	GV_title[128];
char	GV_copyright[128];

char	GV_root[256];

extern struct	termio stdin_tty;
extern struct	termio stdout_tty;

struct  termio  old_term, new_term; /****environ variable****/

main(argc, argv)
char	**argv;
{
        FILE *pMenuFp, *pAddFp;
        char sMainMenuFile[128], sAddMenuFile[128], sSqlStr[80];
        int iRet, i;
        S_sys_param SSy;
        int iStartMenuNo=1;
	char	cTestMenu = 0;
	char	c;

	char	*pStringP;
	int	y, m, d, fd;
	char	sCurrDate[11], sCurrTime[11];

	getdatef( sCurrDate, "/" );
	gettimef( sCurrTime, ":" );
	if ( memcmp( argv[1], "-v", 2 ) == 0 ) 
	{
		printf("中国北京亚大通讯网络有限责任公司 1983-2003\n");
		printf("==========================================\n");
		printf("%s 当前版本 V1.0 !\n", argv[0]);
		printf("%s 当前时间 %s %s\n", argv[0], sCurrDate, sCurrTime);
		printf("==========================================\n");
		printf("本软件属于中国北京亚大通讯网络有限责任公司\n");
		exit(1);
	}


	pStringP = ( char * )getenv( "WORKDIR" );
	if ( pStringP == NULL ) 
	{
		fprintf( stderr, "环境变量WORKDIR未置!\n" );
		exit( 2 );
	} else
		strcpy( GV_root, pStringP );

	strcpy( exec_name, argv[0] );

	/* 定义帮助文件 */
	sprintf( GV_help_file, "/view/settle.help" );

	/*
	 * 缺省主菜单为SMenu[0]
	 * 若命令行使用选项"-menu",则可直接从某个子菜单开始运行,
	 * 可用于测试等。
	 */
	if ( memcmp( argv[1],"-menu",5 ) == 0 )
		iStartMenuNo = atoi( argv[2] );
	else
		iStartMenuNo = 0;

	/*
	 * 打开菜单定义文件
	 */
	sprintf( sMainMenuFile, "%s%s", GV_root, MENU_f );
	pMenuFp = fopen( sMainMenuFile, "r" );
	if ( pMenuFp == NULL ) 
	{
		printf( "%s 菜单文件为空!\n", sMainMenuFile );
		exit( 1 );
	}

	/*
	 * 打开附加菜单项定义文件
	 * 可能不存在附加定义文件,pAddFp==NULL,get_menu()中会判断
	 */
	sprintf( sAddMenuFile, "%s%s", GV_root, MENU_add );
	pAddFp = fopen( sAddMenuFile, "r" );

	/*
	 * 若命令行使用选项"-cTestMenu",则
	 * 可用于测试附加菜单项信息文件Menu.add及
	 * 菜单结构定义文件nas.menu是否正确。
	 */
	if ( memcmp( argv[1],"-cTestMenu", 10 ) == 0 ) 
		cTestMenu = 1;
	else
		cTestMenu = 0;


	/*
	 * 连接数据库$DBNAME
	 */
	if ( db_open() == -1 ) 
	{
		printf( "error open database!\n" );
		fclose( pMenuFp );
		exit( -1 );
	}

	/*
	 * 锁等待10秒钟
	 */
	set_lock_wait( 10 );


	ioctl( 0, TCGETA, &stdin_tty );
	ioctl( 1, TCGETA, &stdout_tty );
	ioctl( 0, TCGETA, &old_term );


	signal( SIGINT, SIG_IGN );
	signal( SIGQUIT, SIG_IGN );
	signal( SIGTERM, SIG_IGN );

	signal( SIGUSR1, killed );

	printf( "\033[2J" );
	fflush( stdout );

	/*
	 * 初始屏幕
	 */
	zut_win_initscr();

	clearok( stdscr, TRUE );
	leaveok( stdscr, TRUE );

	/* 从sysparam.tab中获取系统版本信息, G_system, G_comp, G_tele */
	get_version_info();

	wclear( stdscr );
	wmove( stdscr, 10, 0 );
	/*
	 * 先从文件Menu.add中获取增加的菜单项及菜单结构
	 *
	 * 然后从文件MENU_F中获取本次实际运行的菜单结构
	 * (可考虑根据不同的角色存放不同的文件)
	 */
	iRet = GetMenu( pMenuFp, pAddFp );
	if ( iRet == -1 ) 
	{
		if ( pAddFp != NULL )
			printw( "\n附加菜单文件%s\n\t或菜单定义文件%s", sAddMenuFile, sMainMenuFile );
		else
			printw( "\n菜单定义文件%s", sMainMenuFile );
		printf( "内容有错!\n请维护人员查阅日志文件/tmp/Menu.err并进行修正!\n" );
		if ( cTestMenu == 1 )
			printw( "\n是否继续运行系统,查看效果?(Y/N)" );
		else
			printw( "\n是否继续运行系统?(Y/N)" );
		c = getch();
		if ( c != 'Y' && c != 'y' ) 
		{
			if ( pAddFp != NULL )
				fclose( pAddFp );
			fclose( pMenuFp );
			zut_win_endwin();
			db_close();
			exit( 0 );
		}
	} else if ( iRet < 0 ) {
		if ( pAddFp != NULL )
			printw( "\n附加菜单文件%s\n\t或菜单定义文件%s内容有不合理处!\n", sAddMenuFile, sMainMenuFile );
		else
			printw( "\n菜单定义文件%s内容有不合理处!\n", sMainMenuFile );
		printf( "虽无大碍,但最好请维护人员查阅日志文件/tmp/Menu.err并进行修正!\n" );
		if ( cTestMenu == 1 )
			printw( "\n是否继续运行系统,查看效果?(Y/N)" );
		else
			printw( "\n是否继续运行系统?(Y/N)" );
		c = getch();
		if ( c != 'Y' && c != 'y' ) 
		{
			if ( pAddFp != NULL )
				fclose( pAddFp );
			fclose( pMenuFp );
			zut_win_endwin();
			db_close();
			exit( 0 );
		}
	} else 
	{
		if ( cTestMenu == 1 ) 
		{
			if ( pAddFp != NULL )
				printw( "\n附加菜单文件%s\n\t或菜单定义文件%s", sAddMenuFile, sMainMenuFile );
			else
				printw( "\n菜单定义文件%s", sMainMenuFile );
			printw( "一切正常。\n现可正式运行程序,看是否定义得如您所意。\n" );
			printw( "\n是否运行系统,查看效果?(Y/N)" );
			c = getch();
			if ( c != 'Y' && c != 'y' ) 
			{
				if ( pAddFp != NULL )
					fclose( pAddFp );
				fclose( pMenuFp );
				zut_win_endwin();
				db_close();
				exit( 0 );
			}
		}
	}

	if ( pAddFp != NULL )
		fclose( pAddFp );

	/*
	 * 操作员注册
	 */
	if ( OperLogin() == -1 ) 
	{
		zut_win_endwin();
		db_close();
		fclose( pMenuFp );
		exit( 0 );
	}

	
	/*
	 * 进入系统界面
	 */
	DealMenu(iStartMenuNo, pMenuFp);

	/*
	 * 还原屏幕设置
	 */
	zut_win_endwin();

	/*
	 * 置操作员为签退状态
	 */
	sprintf( sSqlStr, "update center_oper set log_stat = \'O\' where oper_no = \'%s\'", G_oper_no );
	sql_run( sSqlStr );
	misc_audit( "注销", NULL, 0, 0 );
	/*
	 * 退出系统, 关闭数据库
	 */
	db_close();
	fclose( pMenuFp );

	ioctl( 0, TCSETAW, &stdin_tty );
	ioctl( 1, TCSETAW, &stdout_tty );
	printf( "\nProgram Over.\n" );

	exit( 0 );
}

Eexit( ord )
{
	int	i;

	clear();
	refresh();
	endwin();
	ioctl( 0, TCSETAW, &stdin_tty );
	ioctl( 1, TCSETAW, &stdout_tty );
	exit( 0 );
}


int	startshell()
{
	char sFileName[128];
	struct	termio Sstdin_term;
	struct	termio Sstdout_term;

	sprintf( sFileName, "/tmp/.shell.%d", getpid() );
	scr_dump( sFileName );
	db_close();

	ioctl( 0, TCGETA, &Sstdin_term );
	ioctl( 1, TCGETA, &Sstdout_term );

	system( "clear;stty sane" );
	putenv( "PS1=MATCH $ " );
	signal( SIGINT, SIG_DFL );
//	system( "echo Type EXIT and press ENTER to quit this Unix Shell and return to NAS" );
	system( "echo 键入exit并且回车,或者按CTRL-D键,可以退出命令行重新回到主界面 " );
	system( "sh" );
	signal( SIGINT, SIG_IGN );

	ioctl( 0, TCSETAW, &Sstdin_term );
	ioctl( 1, TCSETAW, &Sstdout_term );

	if ( db_open() == -1 ) 
	{
		printf( "Error Open Database!\n" );
		exit( -1 );
	}

	scr_restore( sFileName );
	unlink( sFileName );
	touchwin( curscr );
	wrefresh( curscr );
	return( 0 );
}

/*
int	query(int item_no)
{
	int i, j;
	FILE *fp;
	char path[128], filename[192];
	char mode[9], command[256];


	strcpy(path, getenv("WORKDIR"));

	sprintf(filename, "%s/rep/", path);
	switch (item_no) {
	    case 36:
		strcat(filename, "merch.rep");
		break;
	    case 37:
		strcat(filename, "terminal.rep");
		break;
	    case 38:
		strcat(filename, "cardtype.rep");
		break;
	    case 39:
		strcat(filename, "route.rep");
		break;
	    case 40:
		strcat(filename, "hmd.rep");
		break;
	    case 41:
		strcat(filename, "vip.rep");
		break;
	    case 42:
		strcat(filename, "program.rep");
		break;
	    case 43:
		strcat(filename, "posls.rep");
		break;
	    case 44:
		strcat(filename, "history_ls.rep");
		break;
	    case 45:
		strcat(filename, "audit.rep");
		break;
	    case 119:
		strcat(filename, "merch_card.rep");
		break;
	    case 120:
		strcat(filename, "err_tran_ls.rep");
		break;
	    case 121:
		strcat(filename, "edc_settle.rep");
		break;

	    default:
		return(-1);
	}
	fp = fopen(filename, "r");
	if (fp == NULL) return(-1);
	fclose(fp);


	i = 0;
	while (1) {
	    j = SMenu[0].iMenuItemSet[i];
	    if (j == -1) break;
	    if (i == SMenuActiveStatus[0].iItem) mode[i] = '2';
	    else mode[i] = SMenuItem[j].iPower + '0';
	    i++;
	}
	mode[i] = 0;

	sprintf(command, "%s/bin/Lrep %s %s %s %s %s",
		path, mode, filename, G_bankid, G_oper_no, G_cen_bankid);

	db_close();

	sprintf( sFileName, "/tmp/.query.%d", getpid() );
	scr_dump( sFileName );

	system( command );

	if ( db_open() == -1 )  
	{
		errcall( ERROR, "Error Open Database!" );
		exit( -1 );
	}

	scr_restore( sFileName );
	unlink( sFileName );
	touchwin( curscr );
	wrefresh( curscr );

	return( 0 );
}
*/

void killed()
{
	char	sSqlStr[80];

	errcall( ERROR, "Recived a SIGUSR1 signal" );
	clear();
	refresh();
	endwin();
	/*
	 * 置操作员为签退状态
	 */
	sprintf( sSqlStr, "update center_oper set log_stat = \'O\' where oper_no = \'%s\'", G_oper_no );
	sql_run( sSqlStr );
	misc_audit( "强行注销", NULL, 0, 0 );
	/*
	 * 退出系统, 关闭数据库
	 */
	db_close();
	ioctl( 0, TCSETAW, &stdin_tty );
	ioctl( 1, TCSETAW, &stdout_tty );
	exit( 0 );
}

int	term_seemonit()
{
	char sFileName[128];

	sprintf( sFileName, "/tmp/.seemonit.%d", getpid() );
	scr_dump( sFileName );
	db_close();
	

	signal( SIGINT, SIG_DFL );
	system( "seemonit" );

	signal( SIGINT, SIG_IGN );
	if ( db_open() == -1 ) 
	{
		printf( "Error Open Database!\n" );
		exit( -1 );
	}
	scr_restore( sFileName );
	unlink( sFileName );
	touchwin( curscr );
	wrefresh( curscr );
	return( 0 );
}

⌨️ 快捷键说明

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