diff --git a/SyncFiles CW4.mcp b/SyncFiles CW4.mcp index 21fb0c8..2201834 100644 Binary files a/SyncFiles CW4.mcp and b/SyncFiles CW4.mcp differ diff --git a/macos/choose_directory.c b/macos/choose_directory.c index 0fae2cb..5aab28e 100644 --- a/macos/choose_directory.c +++ b/macos/choose_directory.c @@ -5,7 +5,6 @@ #include "macos/error.h" #include "macos/resources.h" -#include "macos/strutil.h" #include @@ -53,7 +52,10 @@ static void SelectCurrentDirectory(struct ChooseDirReply *reply) directory = reply->directory; directory->vRefNum = ci.dirInfo.ioVRefNum; directory->parID = ci.dirInfo.ioDrParID; - StrCopy(directory->name, sizeof(directory->name), name); + if (name[0] >= sizeof(directory->name)) { + EXIT_INTERNAL(); + } + memcpy(directory->name, name, name[0] + 1); reply->status = kCDCurrent; } diff --git a/macos/error.h b/macos/error.h index ea61257..78d8cba 100644 --- a/macos/error.h +++ b/macos/error.h @@ -35,10 +35,6 @@ void ExitAssert(const unsigned char *file, int line, // EXIT_INTERNAL shows an internal error message and quits the program. #define EXIT_INTERNAL() ExitAssert("\p" __FILE__, __LINE__, NULL) -// EXIT_ASSERT shows an assertion error and quits the program. The message may -// be NULL. -#define EXIT_ASSERT(str) ExitAssert("\p" __FILE__, __LINE__, str) - // ASSERT checks that the given condition is true. Otherwise, it displays an // error message and quits the program. #define ASSERT(p) \ diff --git a/macos/main.c b/macos/main.c index 83599f0..9fb37f0 100644 --- a/macos/main.c +++ b/macos/main.c @@ -265,7 +265,7 @@ void main(void) Handle menuBar; menuBar = GetNewMBar(rMBAR_Main); if (menuBar == NULL) { - EXIT_ASSERT(NULL); + EXIT_INTERNAL(); } SetMenuBar(menuBar); DisposeHandle(menuBar); diff --git a/macos/project.c b/macos/project.c index 9177110..27b235c 100644 --- a/macos/project.c +++ b/macos/project.c @@ -9,7 +9,6 @@ #include "macos/main.h" #include "macos/path.h" #include "macos/resources.h" -#include "macos/strutil.h" #include "macos/tempfile.h" #include diff --git a/macos/strutil.c b/macos/strutil.c deleted file mode 100644 index 4b6dd50..0000000 --- a/macos/strutil.c +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright 2022 Dietrich Epp. -// This file is part of SyncFiles. SyncFiles is licensed under the terms of the -// Mozilla Public License, version 2.0. See LICENSE.txt for details. -#include "macos/strutil.h" - -#include "macos/error.h" - -#include - -#include -#include - -static unsigned char *StrPtrAppend(unsigned char *ptr, unsigned char *end, - const unsigned char *str) -{ - unsigned i, len, rem; - - len = str[0]; - rem = end - ptr; - if (len > rem) { - len = rem; - } - str++; - for (i = 0; i < len; i++) { - *ptr++ = *str++; - } - return ptr; -} - -static void StrAppendVFormat(unsigned char *dest, const unsigned char *msg, - va_list ap) -{ - const unsigned char *mptr = msg + 1, *mend = mptr + msg[0]; - unsigned char *ptr = dest + 1 + dest[0], *end = dest + 256; - unsigned char c, temp[16]; - const unsigned char *pstrvalue; - int ivalue; - -next: - while (mptr < mend) { - c = *mptr++; - if (c == '%' && mptr < mend) { - switch (*mptr) { - case '%': - mptr++; - break; - case 'd': - mptr++; - ivalue = va_arg(ap, int); - NumToString(ivalue, temp); - ptr = StrPtrAppend(ptr, end, temp); - goto next; - case 'S': - mptr++; - pstrvalue = va_arg(ap, const unsigned char *); - ptr = StrPtrAppend(ptr, end, pstrvalue); - goto next; - } - } - if (ptr == end) { - break; - } - *ptr++ = c; - } - - *dest = ptr - dest - 1; -} - -void StrFormat(unsigned char *dest, const unsigned char *msg, ...) -{ - va_list ap; - - dest[0] = 0; - va_start(ap, msg); - StrAppendVFormat(dest, msg, ap); - va_end(ap); -} - -void StrAppendFormat(unsigned char *dest, const unsigned char *msg, ...) -{ - va_list ap; - - va_start(ap, msg); - StrAppendVFormat(dest, msg, ap); - va_end(ap); -} - -void StrCopy(unsigned char *dest, int dest_size, unsigned char *src) -{ - int len = src[0] + 1; - if (len > dest_size) { - EXIT_ASSERT(NULL); - } - BlockMoveData(src, dest, len); -} - -struct StrRef { - const unsigned char *src; - int len; -}; - -void StrSubstitute(unsigned char *str, const unsigned char *param) -{ - int i, n, end; - struct StrRef refs[3]; - - n = str[0]; - for (i = 0; i < n - 1; i++) { - if (str[i + 1] == '^' && str[i + 2] == '1') { - refs[0].src = str + 1; - refs[0].len = i; - refs[1].src = param + 1; - refs[1].len = param[0]; - refs[2].src = str + i + 3; - refs[2].len = n - i - 2; - goto concat; - } - } - return; - -concat: - n = 0; - for (i = 0; i < 3; i++) { - n += refs[i].len; - } - str[0] = n > 255 ? 255 : n; - for (i = 3; i > 0;) { - i--; - end = n; - n -= refs[i].len; - if (end > 255) { - end = 255; - } - if (n < end) { - memmove(str + 1 + n, refs[i].src, end - n); - } - } -} diff --git a/macos/strutil.h b/macos/strutil.h deleted file mode 100644 index cfb5b9c..0000000 --- a/macos/strutil.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2022 Dietrich Epp. -// This file is part of SyncFiles. SyncFiles is licensed under the terms of the -// Mozilla Public License, version 2.0. See LICENSE.txt for details. -#ifndef MACOS_STRUTIL_H -#define MACOS_STRUTIL_H - -// StrFormat writes a formatted string to another string, replacing it. -void StrFormat(unsigned char *dest, const unsigned char *msg, ...); - -// StrAppend appends a formatted string to another string. -// -// %% - literal % -// %d - int argument -// %S - Pascal string argument -void StrAppendFormat(unsigned char *dest, const unsigned char *msg, ...); - -// StrCopy copies a Pascal string. Aborts the program if the string does not fit -// in the destination buffer. -void StrCopy(unsigned char *dest, int dest_size, unsigned char *src); - -// StrSubstitute substitute ^1 in the string with param. -void StrSubstitute(unsigned char *str, const unsigned char *param); - -#endif