From 8514bbfff6b89a128ccd8fab6b16bf2bb155048d Mon Sep 17 00:00:00 2001 From: Dietrich Epp Date: Sat, 6 May 2023 20:25:00 -0400 Subject: [PATCH] Remove unused code The strutil code has mostly been replaced by the new `PStrBuilder` type, and the remaining function from strutil was really just a checked memcpy in one place which is now moved inline. The `EXIT_ASSERT` macro is obsolete and has been removed. --- SyncFiles CW4.mcp | Bin 322973 -> 322973 bytes macos/choose_directory.c | 6 +- macos/error.h | 4 -- macos/main.c | 2 +- macos/project.c | 1 - macos/strutil.c | 138 --------------------------------------- macos/strutil.h | 24 ------- 7 files changed, 5 insertions(+), 170 deletions(-) delete mode 100644 macos/strutil.c delete mode 100644 macos/strutil.h diff --git a/SyncFiles CW4.mcp b/SyncFiles CW4.mcp index 21fb0c874d75cc7ce2caca7176331680a9dbd761..22018344e43d7bf34f8b964bad5628b726a7c684 100644 GIT binary patch delta 399 zcmbPxTX^nm;SH>;>@`WV7#KWHZ{}eYXJV9`tio9I#&BQW2z>50m3PG&fgx*k`XQtLX7Q+5Qkxk|fu>9>)7U(*><824o0ULbX0^uV%<6@) zY+%(I(-*E{R@}V7<2K`Dp4(zT4}*=^ywKw}<7Ab)Vh~k6(+{3y5(TPy&N$iTK3LWN z|1a)>Rc#J=xPWuB!iNmT$!p#OOuq6)qxs64_A74~ftYFgl{d@^&lyv;f4$5i&B!=q zy5LnHow8l`D$8U>#ud{KUSknwTr&OUHIV4^uh&?d8D~tlyw0M}DgyLc%J$srECyl# Dr}>3J delta 433 zcmXYtPbfrD6vpql?(>XZjFcH3p@v5Jmy{Gylv!zF(j>C8@l1-8#!g{n;Vf>6dX`E| z-Ng_a3uQTynKTI{rA$*K3-O$pQTMy&oL_z4sk4`^+)G!+G)<5Gjx#pqR)*%`V4_d& z(Y(M|HHP(pI+HP0&*>wzQ_0U7HKYz%(alYj(yz#;?9vB835_Ak0bZmT?waG!b(oq@_u)Pa;1Z@|{@ zp!~9Um)Z&w8jbK`?l>~`2qEQ}+^NAtww3}6c@*JI>S&3)r^^YRPxgu2)Y&CYDt86fevohb^vfEE9|5hlQ{thl9W#oKNL0>tD+Qh4A{ b-X(KXekR2b*s?bzI<#84v=yIEiO#A&@hF<( 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