Add plain text and XML files to filter list

GitOrigin-RevId: 2c5ded355b43463d20e6e9e65c32a6c566df82a7
This commit is contained in:
Dietrich Epp 2021-03-26 03:47:15 -04:00
parent 4d82709bd4
commit 2768a0c856
7 changed files with 61 additions and 2 deletions

View File

@ -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

View File

@ -10,7 +10,7 @@ SyncFiles is a tool for MPW (Macintosh Programmers 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.

View File

@ -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);

26
convert_line_endings.c Normal file
View File

@ -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;
}

1
defs.h
View File

@ -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;

13
file.c
View File

@ -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;

4
sync.c
View File

@ -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,