mirror of
https://github.com/depp/syncfiles.git
synced 2025-01-02 14:31:56 +00:00
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.
This commit is contained in:
parent
b1bcae531b
commit
8514bbfff6
Binary file not shown.
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#include "macos/error.h"
|
#include "macos/error.h"
|
||||||
#include "macos/resources.h"
|
#include "macos/resources.h"
|
||||||
#include "macos/strutil.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -53,7 +52,10 @@ static void SelectCurrentDirectory(struct ChooseDirReply *reply)
|
|||||||
directory = reply->directory;
|
directory = reply->directory;
|
||||||
directory->vRefNum = ci.dirInfo.ioVRefNum;
|
directory->vRefNum = ci.dirInfo.ioVRefNum;
|
||||||
directory->parID = ci.dirInfo.ioDrParID;
|
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;
|
reply->status = kCDCurrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,10 +35,6 @@ void ExitAssert(const unsigned char *file, int line,
|
|||||||
// EXIT_INTERNAL shows an internal error message and quits the program.
|
// EXIT_INTERNAL shows an internal error message and quits the program.
|
||||||
#define EXIT_INTERNAL() ExitAssert("\p" __FILE__, __LINE__, NULL)
|
#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
|
// ASSERT checks that the given condition is true. Otherwise, it displays an
|
||||||
// error message and quits the program.
|
// error message and quits the program.
|
||||||
#define ASSERT(p) \
|
#define ASSERT(p) \
|
||||||
|
@ -265,7 +265,7 @@ void main(void)
|
|||||||
Handle menuBar;
|
Handle menuBar;
|
||||||
menuBar = GetNewMBar(rMBAR_Main);
|
menuBar = GetNewMBar(rMBAR_Main);
|
||||||
if (menuBar == NULL) {
|
if (menuBar == NULL) {
|
||||||
EXIT_ASSERT(NULL);
|
EXIT_INTERNAL();
|
||||||
}
|
}
|
||||||
SetMenuBar(menuBar);
|
SetMenuBar(menuBar);
|
||||||
DisposeHandle(menuBar);
|
DisposeHandle(menuBar);
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include "macos/main.h"
|
#include "macos/main.h"
|
||||||
#include "macos/path.h"
|
#include "macos/path.h"
|
||||||
#include "macos/resources.h"
|
#include "macos/resources.h"
|
||||||
#include "macos/strutil.h"
|
|
||||||
#include "macos/tempfile.h"
|
#include "macos/tempfile.h"
|
||||||
|
|
||||||
#include <Aliases.h>
|
#include <Aliases.h>
|
||||||
|
138
macos/strutil.c
138
macos/strutil.c
@ -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 <NumberFormatting.h>
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
|
Loading…
Reference in New Issue
Block a user