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

📄 lerror.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lintstatic	char sccsid[] = "@(#)lerror.c 1.1 92/07/30 SMI"; /* from S5R2 1.4 */#endif/* lerror.c *	This file was added to support lint message buffering.  Message *	buffering works in the following fashion: * *	A message is printed out via lwerror (warning error) or luerror *	(exceptions: lint errors, output via lerror, and compiler *	errors, output via cerror).  lwerror and luerror check the *	type of the message, and determine the appropriate routine to call. *	There are three message "types" :  the message is to be buffered, *	the message is not to be buffered, or the message is from a header file. * *	All (non-header file) buffered messages go into the ctmpfile.  This file *	is "dumped" before lint1 completes.  Non-header unbuffered messages *	are printed immediately.  Header file messages are always buffered *	in the htmpfile.  The rationale is to complain about header files *	only once.  This means that the htmpfile is saved between calls *	to lint1.  The second pass, lint2, is responsible for dumping these *	messages. * *	Functions: *	========== *		bufhdr - buffer a header file message *		bufsource - buffer a source file message *		catchsig - set signals so they are caught *		hdrclose - close header file *		iscfile - checks to see if file is source or header *		lerror - lint error message routine *		luerror - lint uerror message *		lwerror - lint werror message (warning) *		onintr - handle interrupts *		tmpopen - open temp files and set up signal processing *		unbuffer - dump the ctmpfile buffered messages */# include	<stdio.h># include	"messages.h"# include	"lerror.h"# include	<signal.h>extern void	exit();extern char	*strncpy( );extern char	*malloc();extern int	lineno;extern char	*ftitle;extern char	*savestr();/* iscfile *  compares name with sourcename (file name from command line) *  if it is the same then *    if fileflag is false then print the source file name as a title *    return true *  otherwise return false */static enum boolean	fileflag = false;enum booleaniscfile( name ) char *name;{	extern char	sourcename[ ];	if ( !strcmp( name, sourcename ) ) {		if ( fileflag == false ) {			fileflag = true;			fprintf( stderr, "\n%s\n==============\n", name );		}		return( true );	}	return( false );}/* onintr - cleans up after an interrupt  */onintr( ){	(void) signal(SIGINT, SIG_IGN);	(void) signal(SIGHUP, SIG_IGN);	(void) signal(SIGQUIT, SIG_IGN);	(void) signal(SIGPIPE, SIG_IGN);	(void) signal(SIGTERM, SIG_IGN);	putc( '\n', stderr );	lerror( "", CCLOSE | HCLOSE | FATAL );	/* note that no error message is printed */}/* catchsig - set up traps to field interrupts *	the onintr routine is the trap handler */catchsig( ){	if ((signal(SIGINT, SIG_IGN)) == SIG_DFL)		(void) signal(SIGINT, onintr);	if ((signal(SIGHUP, SIG_IGN)) == SIG_DFL)		(void) signal(SIGHUP, onintr);	if ((signal(SIGQUIT, SIG_IGN)) == SIG_DFL)		(void) signal(SIGQUIT, onintr);	if ((signal(SIGPIPE, SIG_IGN)) == SIG_DFL)		(void) signal(SIGPIPE, onintr);	if ((signal(SIGTERM, SIG_IGN)) == SIG_DFL)		(void) signal(SIGTERM, onintr);}/* tmpopen - open temp files etc. *  open source message buffer file for writing *  open header message file for updating *    if open fails, open it for writing *  otherwise *    initialize header file name and count list from header message file * *  if opens succeed return success *  otherwise return failure */static char	ctmpname[ TMPLEN + 16 ] = "";char		*htmpname = NULL;static FILE	*ctmpfile = NULL;static FILE	*htmpfile = NULL;static HDRITEM	hdrlist[ NUMHDRS ];static char	*hstrtab;tmpopen( ){	register int hstrtab_len;	register int i;	sprintf( ctmpname, "%s/clint%d", TMPDIR, getpid( ) );	catchsig( );	if ( (ctmpfile = fopen( ctmpname, "w" )) == NULL )		lerror( "cannot open message buffer file", ERRMSG | FATAL );	if ( htmpname == NULL )		return;	if ( (htmpfile = fopen( htmpname, "r+" )) == NULL ) {		/* the file does not exist -- create it */		/* and write out initial (empty) header information */		if ( (htmpfile = fopen( htmpname, "w" )) == NULL )			lerror( "cannot open header message buffer file",			  CCLOSE | FATAL | ERRMSG );		if (fwrite((char *) hdrlist, sizeof(HDRITEM), NUMHDRS, htmpfile)		  != NUMHDRS )			lerror("cannot write header message buffer file",			  HCLOSE | CCLOSE | ERRMSG | FATAL );		putw( 0, htmpfile );	/* empty string table */		if ( ferror( htmpfile ) )			lerror("cannot write header message buffer file",			  HCLOSE | CCLOSE | ERRMSG | FATAL );	}	else {		/* the file already exists -- initialize header information */		rewind( htmpfile );		if ( fread((char *) hdrlist, sizeof( HDRITEM ), NUMHDRS, htmpfile)		  != NUMHDRS ) 			lerror( "cannot read header message buffer file",			  CCLOSE | HCLOSE | FATAL | ERRMSG );		hstrtab_len = getw( htmpfile );		if ( ferror( htmpfile ) || feof( htmpfile ) )			lerror( "cannot read header message buffer file",			  CCLOSE | HCLOSE | FATAL | ERRMSG );		if (hstrtab_len != 0) {			hstrtab = malloc( (unsigned) hstrtab_len );			if ( hstrtab == NULL )				lerror( "cannot allocate space for string table",				  CCLOSE | HCLOSE | FATAL | ERRMSG );			if ( fseek( htmpfile, (long) -hstrtab_len, 2 )			  != OKFSEEK ) 				lerror( "cannot seek in header message buffer file",				  CCLOSE | HCLOSE | FATAL | ERRMSG );			if ( fread( hstrtab, sizeof( char ), hstrtab_len, htmpfile)			  != hstrtab_len )				lerror( "cannot read header message buffer file",				  CCLOSE | HCLOSE | FATAL | ERRMSG );			for ( i = 0; i < NUMHDRS && hdrlist[i].soffset != 0; i++ ) {				hdrlist[i].hname = hstrtab + hdrlist[i].hoffset;				hdrlist[i].srcname = hstrtab + hdrlist[i].soffset;			}		}		if ( fseek( htmpfile, (long) -hstrtab_len, 2 ) != OKFSEEK ) 			lerror( "cannot seek in header message buffer file",			  CCLOSE | HCLOSE | FATAL | ERRMSG );	}}/* hdrclose - write header file name/count to header message buffer file, *	write the string table, then close the file */hdrclose( ){	register int i;	register int hstrtab_len;	register int len;	HDRITEM tmphdrlist[ NUMHDRS ];	if ( htmpfile == NULL )		return;	hstrtab_len = 0;	for ( i = 0; i < NUMHDRS && hdrlist[i].srcname != NULL; i++ ) {		len = strlen(hdrlist[i].hname) + 1;	/* 1 for null byte */		tmphdrlist[i].hoffset = hstrtab_len;		hstrtab_len += len;		if ( fwrite( hdrlist[i].hname, sizeof( char ), len, htmpfile )		  != len )			lerror("cannot write header message buffer file", HCLOSE | ERRMSG );		len = strlen(hdrlist[i].srcname) + 1;	/* 1 for null byte */		tmphdrlist[i].soffset = hstrtab_len;		hstrtab_len += len;		if ( fwrite( hdrlist[i].srcname, sizeof( char ), len, htmpfile )		  != len )			lerror("cannot write header message buffer file", HCLOSE | ERRMSG );		tmphdrlist[i].hcount = hdrlist[i].hcount;	}	for (; i < NUMHDRS; i++) {		tmphdrlist[i].hoffset = 0L;		tmphdrlist[i].soffset = 0L;		tmphdrlist[i].hcount = hdrlist[i].hcount;	}	rewind( htmpfile );	if ( fwrite( (char *) tmphdrlist, sizeof( HDRITEM ), NUMHDRS, htmpfile )	  != NUMHDRS )		lerror( "cannot write header message buffer file", HCLOSE | ERRMSG );	putw( hstrtab_len, htmpfile );	if ( ferror( htmpfile ) )		lerror("cannot write header message buffer file", HCLOSE | ERRMSG );}/* lerror - lint error message routine *  if code is [CH]CLOSE error close and unlink appropriate files *  if code is FATAL exit */lerror( message, code ) char *message; int code;{	if ( code & ERRMSG ) 		fprintf( stderr, "lint error: %s\n", message );	if ( code & CCLOSE ) 		if ( ctmpfile != NULL ) {			fclose( ctmpfile );			unlink( ctmpname );		}	if ( code & HCLOSE ) 		if ( htmpfile != NULL ) {			fclose( htmpfile );			unlink( htmpname );		}	if ( code & FATAL ) 		exit( FATAL );}/* lwerror - lint warning error message *	if the message is to be buffered, call the appropriate routine: *    bufhdr( ) for a header file *    bufsource( ) for a source file * *  if not, call werror( ) *//* VARARGS1 */lwerror( msgndx, arg1, arg2 ) int	msgndx;{	extern char		*strip( );	extern enum boolean	iscfile( );	extern char		*msgtext[ ];	extern short	msgbuf[ ];	char		*filename;	if ( htmpname == NULL ) werror( msgtext[ msgndx ], arg1, arg2 );	else {		filename = strip( ftitle );		if ( iscfile( filename ) == true ) 			if ( msgbuf[ msgndx ] == 0 ) 				werror( msgtext[ msgndx ], arg1, arg2 );			else 				bufsource( WERRTY, msgndx, arg1, arg2 );		else			bufhdr( WERRTY, filename, msgndx, arg1, arg2 );

⌨️ 快捷键说明

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