summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKen Raeburn <raeburn@mit.edu>2003-01-09 00:17:27 +0000
committerKen Raeburn <raeburn@mit.edu>2003-01-09 00:17:27 +0000
commite27712f995136503de95b9f48d97f526b48a465e (patch)
tree6b4f4764a6e4aeb46584ecd354394f317c352a21 /src
parentadafd55a957ecacfcd206e7f639cab9e06960a1c (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/util/profile/ChangeLog9
-rw-r--r--src/util/profile/prof_int.h4
-rw-r--r--src/util/profile/prof_parse.c50
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 <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.
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 <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
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;