Angus Leeming <[EMAIL PROTECTED]> writes:

> I think that this version is more robust, but I haven't tried it out...

It works ;-)

> Angus
> 
>  <at>  <at>  -750,20 +750,30  <at>  <at> 
>         static regex reg5("Writing index file ([^ ]+).*");
> 
>         ifstream ifs(logfile.c_str());
> -       string line1, line2 = "";
> +       string line2;
>         while (ifs) {
>                 // Ok, the scanning of files here is not sufficient.
>                 // Sometimes files are named by "File: xxx" only
>                 // So I think we should use some regexps to find files 
> instead.
>                 // "(\([^ ]+\)"   should match the "(file " variant, note
>                 // that we can have several of these on one line.
>                 // "File: \([^ ]+\)" should match the "File: file" variant.
>                 // As a path name may be split across lines, we use a sliding
>                 // window comprising two lines at a time while scanning files.
> 
> -               line1 = line2;
> +               string const line1 = line2;
>                 getline(ifs, line2);
> +               if (!ifs)
> +                       break;
> +               // Is this rtrim needed? Doesn't getline() do it for you?

Angus, I am a C++ newbie and don't even know if getline() is some sort
of standard function or a LyX support function ...
The rtrim was already there and I didn't dare to get rid of it ;-)
 
>                 line2 = rtrim(line2, "\r");
> +               // I believe that the coding style is "int const len"...

Ok, changed.

>                 const int len = line2.length();
>                 const char endchar = len ? line2[len - 1] : 0;
> +               // Isn't line1 empty on the first iteration of this loop?

Yes, it is.

> +               // Also, move the line1.empty() test to the place
> +               // where you assign line1.

Really not, if I want to avoid an endless loop ;-)
I think that it logically belongs here because these are all checks to
see if we can move further down our sliding window.

>                 if (line1.empty()
>                     || line2.substr(0,8) == "Package:"
>                     || line2.substr(0,5) == "File:"
>                     || line2.substr(0,9) == "Language:"
>                     || endchar == '\\' || endchar == '/' || endchar == ')')
>                         continue;
> 
>                 string token = line1 + line2;
>                 smatch sub;
> 
>                 if (regex_match(token, sub, reg1)) {
> 

Attached the revised patch.

-- 
Enrico


--- src/LaTeX.C.orig    2006-03-14 05:04:34.000000000 +0100
+++ src/LaTeX.C 2006-03-16 21:04:04.000000000 +0100
@@ -688,7 +688,7 @@
                // On initial insert we want to do the update at once
                // since this file can not be a file generated by
                // the latex run.
-               if (fs::exists(foundfile))
+               if (fs::exists(foundfile) && !fs::is_directory(foundfile))
                        head.insert(foundfile, true);
 
                return;
@@ -750,20 +750,34 @@
        static regex reg5("Writing index file ([^ ]+).*");
 
        ifstream ifs(logfile.c_str());
+       string line2;
        while (ifs) {
                // Ok, the scanning of files here is not sufficient.
                // Sometimes files are named by "File: xxx" only
                // So I think we should use some regexps to find files instead.
                // "(\([^ ]+\)"   should match the "(file " variant, note
                // that we can have several of these on one line.
-               // "File: \([^ ]+\)" should match the "File: file" variant
-
-               string token;
-               getline(ifs, token);
-               token = rtrim(token, "\r");
-               if (token.empty())
+               // "File: \([^ ]+\)" should match the "File: file" variant.
+               // As a path name may be split across lines, we use a sliding
+               // window comprising two lines at a time while scanning files.
+
+               string const line1 = line2;
+               getline(ifs, line2);
+               if (!ifs)
+                       break;
+               line2 = rtrim(line2, "\r");
+               int const len = line2.length();
+               char const endchar = len ? line2[len - 1] : 0;
+               // Check whether we can slide further down our 2-line window
+               if (line1.empty()
+                   || line2.substr(0,5) == "File:"
+                   || line2.substr(0,6) == "(Font)"
+                   || line2.substr(0,8) == "Package:"
+                   || line2.substr(0,9) == "Language:"
+                   || endchar == '\\' || endchar == '/' || endchar == ')')
                        continue;
 
+               string token = line1 + line2;
                smatch sub;
 
                if (regex_match(token, sub, reg1)) {



Reply via email to