PERFORCE change 40315 for review

Andrew Reisse areisse at FreeBSD.org
Thu Oct 23 17:21:54 GMT 2003


http://perforce.freebsd.org/chv.cgi?CH=40315

Change 40315 by areisse at areisse_ibook on 2003/10/23 10:21:52

	checkpolicy reports errors using the original file and line number

Affected files ...

.. //depot/projects/trustedbsd/sedarwin/sebsd_cmds/checkpolicy/policy_scan.l#2 edit

Differences ...

==== //depot/projects/trustedbsd/sedarwin/sebsd_cmds/checkpolicy/policy_scan.l#2 (text+ko) ====

@@ -11,9 +11,34 @@
 static char linebuf[2][255];
 static unsigned int lno = 0;
 
+static char   policydb_curfile[1024] = "<input>";
 unsigned long policydb_lineno = 1;
 
 unsigned int policydb_errors = 0;
+
+static void set_file (const char *in)
+{
+  policydb_lineno = 0;
+  const char *p = in;
+  p += 5;
+  while (*p == ' ' || (*p >= '0' && *p <= '9') || *p == '"')
+    {
+      if (*p >= '0' && *p <= '9')
+	policydb_lineno = (*p - '0') + policydb_lineno * 10;
+      p++;
+    }
+  char *pp = policydb_curfile;
+
+  while (*p != '"' && *p != '\n' && *p)
+    {
+      *pp = *p;
+      pp++;
+      *pp = 0;
+      p++;
+    }
+  policydb_lineno--;
+}
+ 
 %}
 %array
 letter  [A-Za-z]
@@ -130,6 +155,7 @@
 {letter}({letter}|{digit}|_)*	{ return(IDENTIFIER); }
 {letter}({letter}|{digit}|_|"."|"-")*	{ return(USER_IDENTIFIER); }
 {digit}{digit}*                 { return(NUMBER); }
+#line[ ]{digit}{digit}*[^\n]*      { set_file (yytext); }
 #[^\n]*                         { /* delete comments */ }
 [ \t\f]+			{ /* delete whitespace */ }
 "==" 				{ return(EQUALS); }
@@ -154,9 +180,10 @@
 %%
 int yyerror(char *msg)
 {
-	fprintf(stderr, "ERROR '%s' at token '%s' on line %ld:\n%s\n%s\n",
+	fprintf(stderr, "ERROR '%s' at token '%s' on line %s:%ld:\n%s\n%s\n",
 			msg,
 			yytext,
+                        policydb_curfile,
 			policydb_lineno,
 			linebuf[0], linebuf[1]);
 	policydb_errors++;
@@ -165,9 +192,10 @@
 
 int yywarn(char *msg)
 {
-	fprintf(stderr, "WARNING '%s' at token '%s' on line %ld:\n%s\n%s\n",
+	fprintf(stderr, "WARNING '%s' at token '%s' on line %s:%ld:\n%s\n%s\n",
 			msg,
 			yytext,
+                        policydb_curfile,
 			policydb_lineno,
 			linebuf[0], linebuf[1]);
 	return 0;
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message



More information about the trustedbsd-cvs mailing list