diff --git a/Makefile b/Makefile index f2c6c97..263063d 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ COptions-68K = {COptions} {Sym-68K} SrcFiles = ∂ convert.c ∂ + convert_line_endings.c ∂ copy.c ∂ file.c ∂ mac_from_unix.c ∂ @@ -20,6 +21,7 @@ SrcFiles = ∂ ObjFiles-PPC = ∂ convert.c.x ∂ + convert_line_endings.c.x ∂ copy.c.x ∂ file.c.x ∂ mac_from_unix.c.x ∂ @@ -29,6 +31,7 @@ ObjFiles-PPC = ∂ ObjFiles-68K = ∂ convert.c.o ∂ + convert_line_endings.c.o ∂ copy.c.o ∂ file.c.o ∂ mac_from_unix.c.o ∂ @@ -94,7 +97,7 @@ Dependencies ƒ $OutOfDate {SrcFiles} #*** Dependencies: Cut here *** -# These dependencies were produced at 4:16:36 AM on Wed, Mar 24, 2021 by MakeDepend +# These dependencies were produced at 3:40:21 AM on Fri, Mar 26, 2021 by MakeDepend :convert.c.x :convert.c.o ƒ ∂ :convert.c ∂ @@ -102,6 +105,10 @@ Dependencies ƒ $OutOfDate :defs.h ∂ :mac_from_unix_data.h +:convert_line_endings.c.x :convert_line_endings.c.o ƒ ∂ + :convert_line_endings.c ∂ + :convert.h + :copy.c.x :copy.c.o ƒ ∂ :copy.c ∂ :convert.h diff --git a/README.md b/README.md index 0025fcb..c1492ed 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ SyncFiles is a tool for MPW (Macintosh Programmer’s Workshop) which synchroniz - Only synchronizes files which match hard-coded patterns. -- Converts text files to UTF-8 and LF line endings for Unix systems; converts to Mac OS Roman and CR line endings for Macintosh systems. +- Converts text files to UTF-8 and LF line endings for Unix systems; converts to Mac OS Roman and CR line endings for Macintosh systems. XML files are not re-encoded. - For resource files, converts by copying the Macintosh resource fork to the data fork. @@ -24,8 +24,12 @@ Copies files named Makefile, and files with the following extensions: - C++: `.cc` `.cp` `.cpp` `.cxx` `.hh` `.hpp` `.hxx` +- Plain text: `.txt` + - Resource: `.rsrc` +- XML: `.xml` (CR-LF conversion only, no encoding conversion) + ## Usage Operates in push or pull mode. The tool runs from inside the classic Macintosh environment, so the “push” mode copies from Macintosh to Unix, and the “pull” mode copies from Unix to Macintosh. It is assumed that the Macintosh directory is on a normal disk volume. diff --git a/convert.h b/convert.h index 82fafec..fa80d6c 100644 --- a/convert.h +++ b/convert.h @@ -47,3 +47,7 @@ int mac_from_unix(short srcRef, short destRef, void *srcBuf, void *destBuf); // Raw data copy. int copy_data(short srcRef, short destRef, void *buf); + +// Convert line endings but don't change encoding. +int convert_line_endings(short srcRef, short destRef, void *buf, + unsigned char srcEnding, unsigned char destEnding); diff --git a/convert_line_endings.c b/convert_line_endings.c new file mode 100644 index 0000000..b7d01f9 --- /dev/null +++ b/convert_line_endings.c @@ -0,0 +1,26 @@ +#include "convert.h" + +int convert_line_endings(short srcRef, short destRef, void *buf, + unsigned char srcEnding, unsigned char destEnding) { + unsigned char *ptr, *end; + long count; + int r, r2; + + do { + count = kBufferBaseSize; + r = convert_read(srcRef, &count, buf); + if (r == kConvertError) { + return 1; + } + for (ptr = buf, end = ptr + count; ptr != end; ptr++) { + if (*ptr == srcEnding) { + *ptr = destEnding; + } + } + r2 = convert_write(destRef, count, buf); + if (r2 != kConvertOK) { + return 1; + } + } while (r != kConvertEOF); + return 0; +} diff --git a/defs.h b/defs.h index e2bfb90..dee147b 100644 --- a/defs.h +++ b/defs.h @@ -82,6 +82,7 @@ typedef enum { typedef enum { kTypeUnknown, kTypeText, // Text file: convert CR/LF and encoding. + kTypeTextUTF8, // Text file: convert CR/LF only. kTypeResource, // Resource file: copy resource fork to data fork. } file_type; diff --git a/file.c b/file.c index d8270e1..7d4cc6a 100644 --- a/file.c +++ b/file.c @@ -199,6 +199,7 @@ int sync_file(struct file_info *file, operation_mode mode, short srcVol, // Create the temporary file. switch (file->type) { case kTypeText: + case kTypeTextUTF8: creator = 'MPS '; fileType = 'TEXT'; break; @@ -270,6 +271,18 @@ int sync_file(struct file_info *file, operation_mode mode, short srcVol, r = mac_from_unix(srcRef, destRef, gSrcBuffer, gDestBuffer); } break; + case kTypeTextUTF8: { + unsigned char srcEnding, destEnding; + if (mode == kModePush) { + srcEnding = 0x0d; + destEnding = 0x0a; + } else { + srcEnding = 0x0a; + destEnding = 0x0d; + } + r = convert_line_endings(srcRef, destRef, gSrcBuffer, srcEnding, + destEnding); + } break; case kTypeResource: r = copy_data(srcRef, destRef, gSrcBuffer); break; diff --git a/sync.c b/sync.c index 784f940..0faa0ff 100644 --- a/sync.c +++ b/sync.c @@ -117,6 +117,7 @@ struct extension_info { file_type type; }; +// clang-format off static const struct extension_info kExtensions1[] = { {'c', kTypeText}, {'h', kTypeText}, @@ -134,11 +135,14 @@ static const struct extension_info kExtensions3[] = { {'cxx', kTypeText}, {'hpp', kTypeText}, {'hxx', kTypeText}, + {'txt', kTypeText}, + {'xml', kTypeTextUTF8}, }; static const struct extension_info kExtensions4[] = { {'rsrc', kTypeResource}, }; +// clang-format on static file_type file_type_from_extension(unsigned long extension, const struct extension_info *info,