From e27712f995136503de95b9f48d97f526b48a465e Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Thu, 9 Jan 2003 00:17:27 +0000 Subject: [PATCH] Support \r as additional line separator on Mac OS X * 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 | 9 +++++++ src/util/profile/prof_int.h | 4 +-- src/util/profile/prof_parse.c | 50 +++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog index 3b72fdb46..3d71969e5 100644 --- a/src/util/profile/ChangeLog +++ b/src/util/profile/ChangeLog @@ -1,3 +1,12 @@ +2003-01-08 Ken Raeburn + + * 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 * prof_file.c (r_access): New function. diff --git a/src/util/profile/prof_int.h b/src/util/profile/prof_int.h index 0a966c8a7..4ea8fa546 100644 --- a/src/util/profile/prof_int.h +++ b/src/util/profile/prof_int.h @@ -9,14 +9,12 @@ #include #include #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 diff --git a/src/util/profile/prof_parse.c b/src/util/profile/prof_parse.c index 019fabe25..56f1c30f0 100644 --- a/src/util/profile/prof_parse.c +++ b/src/util/profile/prof_parse.c @@ -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; -- 2.26.2