]> Shamusworld >> Repos - rmac/commitdiff
Fixed ignored last line with no EOL bug. (bug #19)
authorShamus Hammons <jlhamm@acm.org>
Fri, 14 Mar 2014 14:05:35 +0000 (09:05 -0500)
committerShamus Hammons <jlhamm@acm.org>
Fri, 14 Mar 2014 14:05:35 +0000 (09:05 -0500)
token.c
version.h

diff --git a/token.c b/token.c
index e35e9bfc787697ea21e767f4a94397fb7ba223bb..4039c8ebdd4a620d55f953b97e23985715816810 100644 (file)
--- a/token.c
+++ b/token.c
@@ -795,11 +795,17 @@ char * GetNextLine(void)
                // Scan for next end-of-line; handle stupid text formats by treating
                // \r\n the same as \n. (lone '\r' at end of buffer means we have to
                // check for '\n').
+#if 0
                i = 0;
                j = fl->ifcnt;
                d = &fl->ifbuf[fl->ifind];
 
                for(p=d; i<j; i++, p++)
+#else
+               d = &fl->ifbuf[fl->ifind];
+
+               for(p=d, i=0, j=fl->ifcnt; i<j; i++, p++)
+#endif
                {
                        if (*p == '\r' || *p == '\n')
                        {
@@ -808,15 +814,12 @@ char * GetNextLine(void)
                                if (*p == '\r')
                                {
                                        if (i >= j)
-                                       {
-                                               break;                          // Look for '\n' to eat 
-                                       }
+                                               break;                  // Need to read more, then look for '\n' to eat 
                                        else if (p[1] == '\n')
-                                       {
                                                i++;
-                                       }
                                }
 
+                               // Cover up the newline with end-of-string sentinel
                                *p = '\0';
 
                                fl->ifind += i;
@@ -827,11 +830,19 @@ char * GetNextLine(void)
 
                // Handle hanging lines by ignoring them (Input file is exhausted, no
                // \r or \n on last line)
+               // Shamus: This is retarded. Never ignore any input!
                if (!readamt && fl->ifcnt)
                {
+#if 0
                        fl->ifcnt = 0;
                        *p = '\0';
                        return NULL;
+#else
+                       // Really should check to see if we're at the end of the buffer! :-P
+                       fl->ifbuf[fl->ifind + fl->ifcnt] = '\0';
+                       fl->ifcnt = 0;
+                       return &fl->ifbuf[fl->ifind];
+#endif
                }
 
                // Truncate and return absurdly long lines.
@@ -856,7 +867,9 @@ char * GetNextLine(void)
                        fl->ifind = fl->ifcnt & 1;
                }
 
-               if ((readamt = read(fl->ifhandle, &fl->ifbuf[fl->ifind + fl->ifcnt], QUANTUM)) < 0)
+               readamt = read(fl->ifhandle, &fl->ifbuf[fl->ifind + fl->ifcnt], QUANTUM);
+
+               if (readamt < 0)
                        return NULL;
 
                if ((fl->ifcnt += readamt) == 0)
index 089d546d7d1b28616dab5aa26b15b295a30e7683..f07b812b1e460401bce919671591254e3f085753 100644 (file)
--- a/version.h
+++ b/version.h
@@ -13,6 +13,6 @@
 
 #define MAJOR   1                      // Major version number
 #define MINOR   2                      // Minor version number
-#define PATCH   11                     // Patch release number
+#define PATCH   12                     // Patch release number
 
 #endif // __VERSION_H__