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

📄 lint.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
#if CXREF    fprintf( stderr, "%s, line %d: ", ftitle, lineno );#else    filename = strip( ftitle );    if ( htmpname != NULL && iscfile( filename ) == true )		fprintf( stderr, "(%d)  ", lineno );    else		fprintf( stderr, "%s(%d): ", filename, lineno );#endif}/* beg_file() and fpe_catch() * Used to do stuff to handle floating point exceptions * generated during floating point constant folding */beg_file(){	extern int fpe_catch();	/*	 * Catch floating exceptions generated by the constant	 * folding code.	 */	(void) signal( SIGFPE, fpe_catch );}fpe_catch(){	/*	 * Floating exception generated by constant folding.	 */	/* "floating point constant folding causes exception" */	UERROR( MESSAGE( 125 ) );#if CXREF	exit( 2 );#else	lerror( "", CCLOSE | HCLOSE | FATAL );	/* note that no error message is printed */#endif}/* a number of dummy routines, unneeded by lint */#ifndef CXREF/* fldty - check field type (called from pcc) */fldty(p) struct symtab *p;{	/* for a field to be portable, it must be unsigned int */	/* "the only portable field type is unsigned int" */	if( pflag && BTYPE(p->stype) != UNSIGNED ) UERROR( MESSAGE( 83 ) );}#endif/* fldal - field alignment (called from pcc)  *		called for alignment of funny types (e.g. arrays, pointers)  */fldal(t) TWORD t;{	if( t == ENUMTY )	/* this should be thought through better... */		return( ALINT );/* jwf try this */#ifdef gcos	if( !ISPTR(t) )	#endif		/* "illegal field type" */		UERROR( MESSAGE( 57 ) );	return(ALINT);}/* main - driver for the first pass */main( argc, argv ) int	argc; char	*argv[ ];{#if CXREF	/* definitions for CXREF */	char *cp;	int n = 1;#endif    char	 *p;    int		i;#ifndef CXREF    extern 	tmpopen( );    extern char *htmpname;#endif	char stdbuf[BUFSIZ];	/*stderr output buffer*/	setbuf(stderr, stdbuf);    /* handle options */#ifndef CXREF    /* 28 feb 80  reverse the sense of hflag and cflag */    hflag = 1;	/*    cflag = 1;		9/25/80	undo the (28 feb 80) change to cflag */    /* 31 mar 80  reverse the sense of brkflag */    brkflag = 1;#endif	for( i = 1; i < argc && argv[i][0] == '-'; i++ )		for( p=argv[i]; *p; ++p ){			switch( *p ){			case '-':				continue;			case '\0':				break;#if CXREF			case 'd':				++ddebug;				continue;			case 'I':				++idebug;				continue;			case 'b':				++bdebug;				continue;			case 't':				++tdebug;				continue;			case 'e':				++edebug;				continue;			case 'x':				++xdebug;				continue;			case 'f':	/* filename sent to cpp */				p++;				if (*p == '\0') {					i++;					if (i >= argc) {						fprintf(stderr, "Missing argument to \"-f\"\n");						exit(2);					}					p = argv[i];				}				infile[0] = '"';	/* put quotes around name */				cp = &infile[1];				while (*cp++ = *p++) ;	/* copy filename */				*--cp = '"';				*++cp = '\0';				break;			case 'i':	/* actual input filename */				p++;				if (*p == '\0') {					i++;					if (i >= argc) {						fprintf(stderr, "Missing argument to \"-i\"\n");						exit(2);					}					p = argv[i];				}				if (freopen(p,"r",stdin) == NULL) {					fprintf(stderr, "Can't open %s\n",p);					exit(1);				}				break;			case 'o':				p++;				if (*p == '\0') {					i++;					if (i >= argc) {						fprintf(stderr, "Missing argument to \"-o\"\n");						exit(2);					}					p = argv[i];				}				if ((outfp = fopen(p,"a")) == NULL) {					fprintf(stderr, "Can't open %s\n",p);					exit(2);				}				break;#else	/* ifndef CXREF */			case 'b':				brkflag = 0;				continue;			case 'p':				pflag = 1;				cflag = 1;	/* added 9/25/80 */				continue;			case 'q':				qflag = 1;				continue;			case 'c':				cflag = 1;				continue;			case 'L':		/*undocumented; make input look like library*/				libflag = 1;			case 'v':				vflag = 0;				continue;			case 'x':				xflag = 0;				continue;			case 'a':				aflag = 0;			case 'u':		/* second pass option */			case 'n':		/* done in shell script */				continue;			case 'T':		/* second pass option */			case 'X':		/* second pass option */				break;			case 'z':				zflag = 1;				continue;			case 'P':	/* debugging, done in second pass */				continue;			case 'C':				Cflag = 1;				if( p[1] ) libname = p + 1;				while( p[1] ) p++;				continue;			case 's':				/* for the moment, -s triggers -h */			case 'h':				if (strncmp(p, "host=", 5) == 0) {					if (strcmp(p+5, "sparc") == 0 ||					    strcmp(p+5, "sun4") == 0) 						host = sparcAL;					if (strcmp(p+5, "mc68020") == 0 ||					    strcmp(p+5, "sun3") == 0    ||					    strcmp(p+5, "mc68010") == 0 ||					    strcmp(p+5, "sun2") == 0) 						host = mc68020AL;					if (strcmp(p+5, "i386") == 0 ||					    strcmp(p+5, "sun386") == 0) 						host = i386AL;					while( p[1] ) p++;					continue;				} else {					hflag = 0;					continue;				}			case 't':				if (strncmp(p, "target=", 7) == 0) {					if (strcmp(p+7, "sparc") == 0  ||					    strcmp(p+7, "sun4") == 0) 						target = sparcAL;					if (strcmp(p+7, "mc68020") == 0 ||					    strcmp(p+7, "sun3") == 0    ||					    strcmp(p+7, "mc68010") == 0 ||					    strcmp(p+7, "sun2") == 0) 						target = mc68020AL;					while( p[1] ) p++;					continue;				} else {					werror( "option %c now default: see `man 1 lint'", *p );					continue;				}			case 'H':				p++;				if (*p == '\0') {					i++;					if (i >= argc)						uerror("Missing argument to \"-H\"\n");					p = argv[i];				}				htmpname = p;				break;			default:				uerror( "illegal option: %c", *p );				continue;#endif	/* ifndef CXREF */				};			break;			}#ifndef CXREF	/*	 * Decide whether you're S5 or pre-S3, and patch up if pre-S3.	 * "Patching up" involves the following:	 * - toggling the values of aflag, brkflag, hflag, and xflag	 * - allowing "-c" to set cflag	 * - forcing msgs to come out one per line, instead of	 *	being nicely formatted as is the S5 default	 */	if( htmpname == NULL ) {		aflag = !aflag;		brkflag = !brkflag;		hflag = !hflag;		xflag = !xflag;	} else {		/*		 * "cflag" true and "pflag" false means the "-c" option		 * was specified.  This option disappeared in S5, so we		 * complain about it.		 */		if( cflag && !pflag )			fprintf(stderr,"lint: -c option ignored - no longer available\n");	}	/* process file name */	if( argv[i] ) {		p = strip( argv[i] );		strncpy( sourcename, p, LFNM );	}    tmpopen( );#endif#if CXREF	n = mainp1(argc, argv);	if (feof(stdout) || ferror(stdout))		perror("cxref.xpass");	return( n );#else	/* set sizes and alignment */	if( !pflag ){		/* set sizes and alignments to those of target machine */		curalign = &altable[target];	} else {		/* set sizes and alignments to "portable" values */		curalign = &portalign;	}	/* recognize funny name when I see it */	builtin_va_alist_name = hash( "__builtin_va_alist" );		return( mainp1( argc, argv ) );#endif}/* ctype - are there any funny types? */ctype( type ) TWORD type;{  /* this is appropriate for sunrise/68000 mapping, since "we know"   * that long == int   */	if (qflag){		switch( BTYPE(type) ){		case ENUMTY:	/* no such thing */			MODTYPE(type,UNSIGNED);			break;		case LONG:	/* don't waste my time */			MODTYPE(type,INT);			break;		case ULONG:	/* don't waste my time */			MODTYPE(type,UNSIGNED);			break;				}	}	return( type );}#ifndef CXREF/*ARGSUSED*/allocate_static( id, sz ){	register struct symtab *s;	/* put out a static variable declaration */	s = STP(id);	if (s == NULL) return;	outdef( s, libflag?LIB:LDC, USUAL );	}/* commdec - common declaration */commdec( id ){	/* 10/14/80 - the compiler complains, and so should lint *//* this check is not quite right, e.g.,		void (*f)(); *		-- tsize() performs a similar check, but will return *		before so if we've got a pointer. *	so, let tsize figure it out. * *	if( dimtab[ STP(id)->sizoff ] == 0 ) */	register struct symtab *q = STP(id);	if (q == NULL) return;	(void) tsize(q->stype, q->dimoff, q->sizoff);	/* put out a common declaration */	outdef( q, libflag?LIB:LDC, USUAL );}#endif	/* #ifndef CXREF */isitfloat ( s ) char *s;{	/* s is a character string;	   if floating point is implemented, set dcon to the value of s */	/* lint version */	dcon = atof( s );	return( FCON );}#ifndef CXREF/* fldcon - check assignment of a constant to a field */fldcon( p ) register NODE *p;{	/* check to see if the assignment is going to overflow,	  or otherwise cause trouble */	register s;	CONSZ v;	if( !hflag && !pflag ) return;	s = UPKFSZ(p->in.left->tn.rval);	v = p->in.right->tn.lval;	switch( p->in.left->in.type ){	case CHAR:	case INT:	case SHORT:	case LONG:	case ENUMTY:		if( v>=0 && (v>>(s-1))==0 ) return;		/* "precision lost in assignment to (possibly sign-extended) field" */		WERROR( MESSAGE( 93 ) );	default:		return;	case UNSIGNED:	case UCHAR:	case USHORT:	case ULONG:		/* "precision lost in field assignment" */		if( v<0 || (v>>s)!=0 ) WERROR( MESSAGE( 94 ) );	}}/* outdef - output a definition for the second pass */outdef( p, lty, mode ) struct symtab *p;{	/* if mode is > USUAL, it is the number of args */	extern char	*strncat( );	char *fname;	TWORD t;	int line;	static union rec rc;	if( mode == NOFILE ){		/*  fname = "???"; */		fname = p->sfile;		line = p->suse;	}	else if( mode == SVLINE ){		fname = ftitle;		line = -p->suse;		}	else {		fname = ftitle;		line = lineno;		}	fsave( fname );	rc.l.decflag = lty;	t = p->stype;	if( mode == DECTY ) t = DECREF(t);	rc.l.type.aty = t;	rc.l.type.extra = 0;	rc.l.type.extra1 = 0;	astype( &rc.l.type, p->sizoff );	rc.l.nargs = (mode>USUAL) ? mode : 0;	rc.l.fline = line;	fwrite( (char *)&rc, sizeof(rc), 1, stdout );	rc.l.name = ( p->sclass == STATIC ) ? p->sname : exname( p->sname );	fwrite( rc.l.name, strlen( rc.l.name ) + 1, 1, stdout );}#else	/* if CXREF */bbcode()	/* CXREF */{	/* code for beginning a new block */	blocknos[blockptr] = nextblock++;	fprintf(outfp, "B%d\t%05d\n", blocknos[blockptr], lineno);	blockptr++;}becode()	/* CXREF */{	/* code for ending a block */	if (--blockptr < 0)		uerror("bad nesting");	else		fprintf( outfp, "E%d\t%05d\n", blocknos[blockptr], lineno);}#endif	/* ifndef CXREF *//* some useless functions */intprtdcon(){;}/*ARGSUSED*/voiddo_pragma(pragma_id, args)	int pragma_id;	NODE *args;{	if (args != NIL) tfree(args);}intlookup_pragma(id)	struct symtab *id;{	return 1;}void init_pragmas() {;}

⌨️ 快捷键说明

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