From a6ad0d0a9668cd8bc5ec9255e8d79a8bd81ef1ed Mon Sep 17 00:00:00 2001 From: Dietrich Epp Date: Wed, 17 Mar 2021 01:43:00 -0400 Subject: [PATCH] Copy C++ files with SyncFiles GitOrigin-RevId: e1b21d525476815ba8b10780eb2e69b57264a212 --- README.md | 10 +++++++++- sync.c | 24 +++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f988490..2652564 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ SyncFiles is a tool for MPW (Macintosh Programmer’s Workshop) which synchroniz - Sets the modification timestamp of the destination file to match the timestamp of the source file. -- Only synchronizes files which match hard-coded patterns: copies the Makefile and any files matching `*.c`, `*.h`, or `*.r`. +- Only synchronizes files which match hard-coded patterns. - Converts files to UTF-8 and LF line endings for Unix systems; converts to Mac OS Roman and CR line endings for Macintosh systems. @@ -18,6 +18,14 @@ SyncFiles is a tool for MPW (Macintosh Programmer’s Workshop) which synchroniz There is a hard-coded maximum file size of 64 KiB. +## File Patterns + +Copies files named Makefile, and files with the following extensions: + +- C: `.c` `.h` + +- C++: `.cc` `.cp` `.cpp` `.cxx` `.hh` `.hpp` `.hxx` + ## 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/sync.c b/sync.c index 635e8de..8941047 100644 --- a/sync.c +++ b/sync.c @@ -124,6 +124,7 @@ static int filter_name(const unsigned char *name) { int len, i, stem; const unsigned char *ext; char temp[32]; + unsigned char c0, c1, c2; if (EqualString(name, "\pmakefile", false, true)) { return 1; @@ -139,7 +140,28 @@ static int filter_name(const unsigned char *name) { ext = name + stem + 1; switch (len - stem) { case 1: - if (ext[0] == 'c' || ext[0] == 'h' || ext[0] == 'r') { + // .c .h .r + c0 = ext[0]; + if (c0 == 'c' || c0 == 'h' || c0 == 'r') { + return 1; + } + break; + case 2: + // .cc .cp .hh + c0 = ext[0]; + c1 = ext[1]; + if (c0 == 'c' && (c1 == 'c' || c1 == 'p') || + c0 == 'h' && c1 == 'h') { + return 1; + } + break; + case 3: + // .cpp .hpp .cxx .hxx + c0 = ext[0]; + c1 = ext[1]; + c2 = ext[2]; + if ((c0 == 'c' || c0 == 'h') && + (c1 == 'p' && c2 == 'p' || c1 == 'x' && c2 == 'x')) { return 1; } break;