+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.
#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
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;