Copy C++ files with SyncFiles

GitOrigin-RevId: e1b21d525476815ba8b10780eb2e69b57264a212
This commit is contained in:
Dietrich Epp 2021-03-17 01:43:00 -04:00
parent c058e68d93
commit a6ad0d0a96
2 changed files with 32 additions and 2 deletions

View File

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

24
sync.c
View File

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