3838#include <string.h>
3939
4040static char * errfill (const char * , const char * , const char * );
41- static void display_error (error_code_t ecode , enum error_severity sev ,
42- int eline , const char * op1 , const char * op2 ,
43- int col , const char * srcFile );
41+ static void display_error (error_code_t ecode , enum error_severity sev ,
42+ int eline , const char * op1 , const char * op2 , int col ,
43+ const char * srcFile );
4444
4545static int ndiags [5 ];
4646static int maxfilsev = 0 ; /* max severity for entire source file */
@@ -84,8 +84,8 @@ error(error_code_t ecode, enum error_severity sev, int eline, const char *op1,
8484}
8585
8686static void
87- display_error (error_code_t ecode , enum error_severity sev , int eline ,
88- const char * op1 , const char * op2 , int col , const char * srcFile )
87+ display_error (error_code_t ecode , enum error_severity sev , int eline ,
88+ const char * op1 , const char * op2 , int col , const char * srcFile )
8989{
9090 static char sevlett [5 ] = {'X' , 'I' , 'W' , 'S' , 'F' };
9191 char * formatstr ;
@@ -115,7 +115,7 @@ display_error(error_code_t ecode, enum error_severity sev, int eline,
115115 formatstr = "%s-%c-%04d-%s (%s: %d.%d)" ;
116116 else
117117 formatstr = "%s-%c-%04d-%s (%s: %d)" ;
118- }else
118+ } else
119119 formatstr = "%s-%c-%04d-%s (%s)" ;
120120 } else
121121 formatstr = "%s-%c-%04d-%s" ;
@@ -129,22 +129,22 @@ display_error(error_code_t ecode, enum error_severity sev, int eline,
129129
130130 if (!XBIT (0 , 0x40000000 ) && col <= 0 && srcFile == NULL )
131131 snprintf (& buff [1 ], sizeof (buff ) - 1 , formatstr , version .lang ,
132- sevlett [sev ], ecode , errfill (msgstr , op1 , op2 ),
133- gbl . curr_file , eline );
132+ sevlett [sev ], ecode , errfill (msgstr , op1 , op2 ), gbl . curr_file ,
133+ eline );
134134 else {
135135 static char * sevtext [5 ] = {"X" , "info" , "warning" , "error" , "error" };
136136 if (col > 0 && (srcFile != NULL || gbl .curr_file != NULL )) {
137137 snprintf (& buff [1 ], sizeof (buff ) - 1 , "\n%s:%d:%d: %s %c%04d: %s" ,
138138 (srcFile != NULL ) ? srcFile : gbl .curr_file , eline , col ,
139- sevtext [sev ], sevlett [sev ], ecode , errfill (msgstr , op1 , op2 ));
139+ sevtext [sev ], sevlett [sev ], ecode , errfill (msgstr , op1 , op2 ));
140140 } else if (srcFile != NULL ) {
141- snprintf (& buff [1 ], sizeof (buff ) - 1 , "\n%s:%d: %s %c%04d: %s" ,
142- srcFile , eline , sevtext [sev ], sevlett [sev ],
143- ecode , errfill (msgstr , op1 , op2 ));
141+ snprintf (& buff [1 ], sizeof (buff ) - 1 , "\n%s:%d: %s %c%04d: %s" , srcFile ,
142+ eline , sevtext [sev ], sevlett [sev ], ecode ,
143+ errfill (msgstr , op1 , op2 ));
144144 } else if (gbl .curr_file != NULL ) {
145145 snprintf (& buff [1 ], sizeof (buff ) - 1 , "%s(%d) : %s %c%04d : %s" ,
146- gbl .curr_file , eline , sevtext [sev ],
147- sevlett [ sev ], ecode , errfill (msgstr , op1 , op2 ));
146+ gbl .curr_file , eline , sevtext [sev ], sevlett [ sev ], ecode ,
147+ errfill (msgstr , op1 , op2 ));
148148 } else
149149 snprintf (& buff [1 ], sizeof (buff ) - 1 , "%s : %s %c%04d : %s" , "" ,
150150 sevtext [sev ], sevlett [sev ], ecode , errfill (msgstr , op1 , op2 ));
@@ -292,7 +292,7 @@ interrf(enum error_severity sev, const char *fmt, ...)
292292 va_start (ap , fmt );
293293 size = vsnprintf (NULL , 0 , fmt , ap );
294294 va_end (ap );
295- NEW (buffer , char , size + 1 );
295+ NEW (buffer , char , size + 1 );
296296 va_start (ap , fmt );
297297 vsprintf (buffer , fmt , ap );
298298 va_end (ap );
@@ -335,9 +335,10 @@ dassert_err(const char *filename, int line, const char *expr, const char *txt)
335335 * Prints information on behalf of failed asrt.
336336 * \param file: filename: name of file where assertion failed.
337337 * \param line: line number where assertion failed
338- */
338+ */
339339void
340- asrt_failed (const char * filename , int line ) {
340+ asrt_failed (const char * filename , int line )
341+ {
341342 fprintf (stderr , "asrt failed. line %d, file %s\n" , line , filename );
342343 /* Call interr so that we have a common place to set a breakpoint when
343344 running under a debugger. */
@@ -478,11 +479,11 @@ error_max_severity()
478479 * \param ptoken is the token string we are processing.
479480 *
480481 * \return the last substring, else NULL
481- */
482+ */
482483char *
483- getDeduceStr (char * ptoken )
484+ getDeduceStr (char * ptoken )
484485{
485- char * lastToken ;
486+ char * lastToken ;
486487 if (ptoken != NULL ) {
487488 lastToken = strrchr (ptoken , ' ' );
488489 if (lastToken != NULL ) {
@@ -497,7 +498,7 @@ getDeduceStr(char * ptoken)
497498/** \brief Construct and issue an "enhanced" error message.
498499 *
499500 * Construct error message and issue it to user terminal and to listing file
500- * if appropriate. This is an "enhanced" error message which means we will
501+ * if appropriate. This is an "enhanced" error message which means we will
501502 * also display the source line, column number, and location of the error.
502503 *
503504 * Note: First five arguments are the same as function error().
@@ -511,82 +512,82 @@ getDeduceStr(char * ptoken)
511512 * \param op1 String to be expanded into error message * or 0
512513 *
513514 * \param op2 String to be expanded into error message * or 0
514- *
515- * \param col The column number where the error occurred at if
515+ *
516+ * \param col The column number where the error occurred at if
516517 * available, else 0.
517518 *
518519 * \param deduceCol The operand to use (1 for op1, 2 for op2) to deduce the
519520 * the column number when the col argument is not available.
520521 * Setting this to 0 disables column deduction.
521- *
522+ *
522523 * \param uniqDeduct If set, this function will only deduce the column if
523524 * the operand specified in deduceCol only occurs once
524525 * in the source line. Otherwise, it will use the first
525526 * occurrence of the operand in the source line.
526527 *
527528 * \param deduceVal If this is a non-NULL character pointer, then use this
528529 * string for column deduction instead of op1 or op2.
529- *
530+ *
530531 */
531532void
532- errWithSrc (error_code_t ecode , enum error_severity sev , int eline ,
533- const char * op1 , const char * op2 , int col , int deduceCol ,
533+ errWithSrc (error_code_t ecode , enum error_severity sev , int eline ,
534+ const char * op1 , const char * op2 , int col , int deduceCol ,
534535 bool uniqDeduct , const char * deduceVal )
535536{
536537 int i , len ;
537538 char * srcFile = NULL ;
538- char * srcLine = NULL ;
539- int srcCol = 0 ;
540- int contNo = 0 ;
539+ char * srcLine = NULL ;
540+ int srcCol = 0 ;
541+ int contNo = 0 ;
541542
542- if (!XBIT (1 ,1 )) {
543+ if (!XBIT (1 , 1 )) {
543544 /* Generate old error messages */
544545 display_error (ecode , sev , eline , op1 , op2 , 0 , NULL );
545546 return ;
546547 }
547- if (eline > 0 ) {
548- srcLine = get_src_line (eline , & srcFile , col , & srcCol , & contNo );
549- if (srcFile && (len = strlen (srcFile )) > 0 ) {
548+ if (eline > 0 ) {
549+ srcLine = get_src_line (eline , & srcFile , col , & srcCol , & contNo );
550+ if (srcFile && (len = strlen (srcFile )) > 0 ) {
550551 /* trim trailing whitespace on srcFile */
551- char * cp ;
552- for (cp = (srcFile + (len - 1 )); cp != srcFile ; -- cp ) {
552+ char * cp ;
553+ for (cp = (srcFile + (len - 1 )); cp != srcFile ; -- cp ) {
553554 if (!isspace (* cp ))
554555 break ;
555556 }
556557 if (cp != srcFile ) {
557- * (cp + 1 ) = '\0' ;
558+ * (cp + 1 ) = '\0' ;
558559 }
559- }
560+ }
560561 if (deduceCol > 0 ) {
561562 /* try to deduce column number */
562- char * op ;
563- char * srcLC = strdup (srcLine );
564- char * p ;
563+ char * op ;
564+ char * srcLC = strdup (srcLine );
565+ char * p ;
565566 if (deduceVal != NULL ) {
566567 op = strdup (deduceVal );
567568 } else {
568569 op = strdup ((deduceCol == 1 ) ? op1 : op2 );
569570 }
570571 len = strlen (srcLC );
571- for ( i = 0 ; i < len ; ++ i ) {
572+ for ( i = 0 ; i < len ; ++ i ) {
572573 srcLC [i ] = tolower (srcLC [i ]);
573574 }
574575 len = strlen (op );
575- for ( i = 0 ; i < len ; ++ i ) {
576+ for ( i = 0 ; i < len ; ++ i ) {
576577 op [i ] = tolower (op [i ]);
577578 }
578- p = strstr (srcLC , op );
579+ p = srcCol == 0 ? strstr (srcLC , op ) : strstr ( srcLC + ( srcCol - 1 ) , op );
579580 col = 0 ;
580581 if (p != NULL ) {
581582 if (uniqDeduct ) {
582- char * q = strstr (p + 1 , op );
583- if (q == NULL ) {
583+ char * q = strstr (p + 1 , op );
584+ if (q == NULL ) {
584585 /* op only occurs once in srcLine, so we can deduce col */
585- col = (int )(p - srcLC )+ 1 ;
586+ col = (int )(p - srcLC ) + 1 ;
586587 }
587588 } else {
588589 /* found op in srcLine, so we can deduce col */
589- col = (int )(p - srcLC )+ 1 ;
590+ col = (int )(p - srcLC ) + 1 ;
590591 }
591592 }
592593 FREE (op );
@@ -595,41 +596,40 @@ errWithSrc(error_code_t ecode, enum error_severity sev, int eline,
595596 }
596597 if (!deduceCol || col == 0 )
597598 col = srcCol ;
598- display_error (ecode , sev , contNo + eline , op1 , op2 , col , srcFile );
599+ display_error (ecode , sev , contNo + eline , op1 , op2 , col , srcFile );
599600 if (col > 0 && srcLine != NULL ) {
600601 LOGICAL isLeadingChars ;
601602 int numLeadingTabs ;
602603 len = strlen (srcLine );
603- for (numLeadingTabs = i = 0 , isLeadingChars = TRUE; i < len ; ++ i ) {
604- if (i == (col - 1 )) {
604+ for (numLeadingTabs = i = 0 , isLeadingChars = TRUE; i < len ; ++ i ) {
605+ if (i == (col - 1 )) {
605606 isLeadingChars = FALSE;
606607 }
607608 if (isLeadingChars && srcLine [i ] == '\t' ) {
608609 /* Keep track of tabs that appear before column number. */
609- fputc ('\t' ,stderr );
610+ fputc ('\t' , stderr );
610611 ++ numLeadingTabs ;
611612 } else if (srcLine [i ] == '\n' ) {
612613 break ;
613614 } else {
614- fputc (srcLine [i ],stderr );
615+ fputc (srcLine [i ], stderr );
615616 }
616617 }
617- fputc ('\n' ,stderr );
618+ fputc ('\n' , stderr );
618619
619620 /* When we first computed col, we counted a tab as one space. So, we need
620621 * to subtract one from col as we print out the leading tabs.
621622 */
622- for ( i = 0 ; i < numLeadingTabs ; ++ i ) {
623- fputc ('\t' ,stderr );
623+ for ( i = 0 ; i < numLeadingTabs ; ++ i ) {
624+ fputc ('\t' , stderr );
624625 }
625626 col -= numLeadingTabs ;
626627
627- for (i = 0 ; i < (col - 1 ); ++ i )
628- fputc (' ' ,stderr );
629- fputs ("^\n" ,stderr );
630- }
631- else {
632- fputc ('\n' ,stderr );
628+ for (i = 0 ; i < (col - 1 ); ++ i )
629+ fputc (' ' , stderr );
630+ fputs ("^\n" , stderr );
631+ } else {
632+ fputc ('\n' , stderr );
633633 }
634634 FREE (srcLine );
635635 FREE (srcFile );
0 commit comments