tags 379146 + patch
kthxbye

On Fri, Jul 21, 2006 at 19:26:01 +0200, Pierre Habouzit wrote:

> Package: headache
> Version: 1.03-8
> Severity: grave
> 
>   when you configure headeache to generate 'line' setups, like:
> 
>   | ".*\\.c" -> lines line:"*" width:1 open:"/*" close:"*/" begin:" * " 
> last:" "
> 
>   it is unable to recognize its previous headers, and creates new ones
>   ever and ever again.
> 
That's because headache fails to detect the end of the header.
The "remove" function created in make_lines (lines 144-156 of model.ml)
at first tries to find the header (if there's no header, it doesn't, so
everything works fine), and then if it has found it loops on the input
file looking for a line which *begins* with ten times the "line"
parameter from the config file ('*' in your example) followed by the
"close" parameter ("*/" in your example).
Obviously, there's no such line (because the "line" character appears
more than ten times), so the end of the header is never detected, and
the remove function deletes the whole file, before a new header is
readded.
The part of the attached patch applying to model.ml fixes this issue by
looking for a line which *ends* with the correct substring.
The patch to main.ml makes headache close the file descriptor on the
header file after reading it, and adds a newline at the end of an error
message.

Cheers,
Julien
diff -Nru headache-1.03/main.ml headache-1.03.new/main.ml
--- headache-1.03/main.ml       2004-03-29 11:16:22.000000000 +0200
+++ headache-1.03.new/main.ml   2006-09-16 01:57:34.000000000 +0200
@@ -89,7 +89,7 @@
       let line = input_line ic in
       line :: loop ()
     with
-      End_of_file -> []
+      End_of_file -> close_in ic; []
   in
   loop ()
 
@@ -221,4 +221,4 @@
     main ()
   with
     Sys_error msg ->
-      eprintf "%s: %s" Sys.argv.(0) msg
+      eprintf "%s: %s\n" Sys.argv.(0) msg
diff -Nru headache-1.03/model.ml headache-1.03.new/model.ml
--- headache-1.03/model.ml      2004-03-29 11:16:22.000000000 +0200
+++ headache-1.03.new/model.ml  2006-09-16 01:47:06.000000000 +0200
@@ -138,6 +138,8 @@
   let regexp_end = 
     Str.regexp_string (sprintf "%s%s" (String.make 10 line_char) close_comment)
   in
+  let end_length = 10 + String.length close_comment
+  in
 
   let regexp_blank = Str.regexp "^[ ]*$" in
 
@@ -146,7 +148,11 @@
       let line = input_line ic in
       if Str.string_match regexp_begin line 0
       then begin
-       while not (Str.string_match regexp_end (input_line ic) 0) do () done;
+       while
+          let s = input_line ic in
+            not (Str.string_match regexp_end s
+                   (max 0 (String.length s - end_length)))
+        do () done;
        ""
       end
       else if Str.string_match regexp_blank line 0 

Attachment: signature.asc
Description: Digital signature

Reply via email to