Support \r as additional line separator on Mac OS X
authorKen Raeburn <raeburn@mit.edu>
Thu, 9 Jan 2003 00:17:27 +0000 (00:17 +0000)
committerKen Raeburn <raeburn@mit.edu>
Thu, 9 Jan 2003 00:17:27 +0000 (00:17 +0000)
* prof_parse.c (profile_parse_file) [PROFILE_SUPPORTS_FOREIGN_NEWLINES]: Look
for \r and treat it as a line break.
* prof_int.h: Don't include prof_err.h.
(PROFILE_SUPPORTS_FOREIGN_NEWLINES) [macintosh]: Define new macro.

ticket: 1237
status: open

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15100 dc483132-0cff-0310-8789-dd5450dbe970

src/util/profile/ChangeLog
src/util/profile/prof_int.h
src/util/profile/prof_parse.c

index 3b72fdb469805b24e899ecdf516d3f08bae14360..3d71969e5b0fc58eda0e41a2b1d479c7f9acc3b7 100644 (file)
@@ -1,3 +1,12 @@
+2003-01-08  Ken Raeburn  <raeburn@mit.edu>
+
+       * prof_parse.c (profile_parse_file)
+       [PROFILE_SUPPORTS_FOREIGN_NEWLINES]: Look for \r and treat it as a
+       line break.
+       * prof_int.h: Don't include prof_err.h.
+       (PROFILE_SUPPORTS_FOREIGN_NEWLINES) [macintosh]: Define new
+       macro.
+
 2002-12-31  Ken Raeburn  <raeburn@mit.edu>
 
        * prof_file.c (r_access): New function.
index 0a966c8a7c112ef9c2c9cf4a7d2e67a939fb2dea..4ea8fa546309807302e1c2da0f3a12af390601c6 100644 (file)
@@ -9,14 +9,12 @@
 #include <Kerberos/FullPOSIXPath.h>
 #include <CoreServices/CoreServices.h>
 #define USE_PTHREADS
+#define PROFILE_SUPPORTS_FOREIGN_NEWLINES
 #else
 #include "com_err.h"
 #endif
 
 #include "profile.h"
-#ifndef ERROR_TABLE_BASE_prof
-#include "prof_err.h"
-#endif
 
 #if defined(_WIN32)
 #define SIZEOF_INT      4
index 019fabe25722f25529a3537c49fe429359d6081b..56f1c30f0441c6ba87a8728057cdf6507189f4fe 100644 (file)
@@ -239,11 +239,61 @@ errcode_t profile_parse_file(f, root)
        while (!feof(f)) {
                if (fgets(bptr, BUF_SIZE, f) == NULL)
                        break;
+#ifndef PROFILE_SUPPORTS_FOREIGN_NEWLINES
                retval = parse_line(bptr, &state);
                if (retval) {
                        free (bptr);
                        return retval;
                }
+#else
+               {
+                   char *p, *end;
+
+                   if (strlen(bptr) >= BUF_SIZE - 1) {
+                       /* The string may have foreign newlines and
+                          gotten chopped off on a non-newline
+                          boundary.  Seek backwards to the last known
+                          newline.  */
+                       long offset;
+                       char *c = bptr + strlen (bptr);
+                       for (offset = 0; offset > -BUF_SIZE; offset--) {
+                           if (*c == '\r' || *c == '\n') {
+                               *c = '\0';
+                               fseek (f, offset, SEEK_CUR);
+                               break;
+                           }
+                           c--;
+                       }
+                   }
+
+                   /* First change all newlines to \n */
+                   for (p = bptr; *p != '\0'; p++) {
+                       if (*p == '\r')
+                            *p = '\n';
+                   }
+                   /* Then parse all lines */
+                   p = bptr;
+                   end = bptr + strlen (bptr);
+                   while (p < end) {
+                       char* newline;
+                       char* newp;
+
+                       newline = strchr (p, '\n');
+                       if (newline != NULL)
+                           *newline = '\0';
+
+                       /* parse_line modifies contents of p */
+                       newp = p + strlen (p) + 1;
+                       retval = parse_line (p, &state);
+                       if (retval) {
+                           free (bptr);
+                           return retval;
+                       }
+
+                       p = newp;
+                   }
+               }
+#endif
        }
        *root = state.root_section;