diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index bc20b44..b6ec9a9 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -3,7 +3,7 @@ { "name": "Linux", "includePath": ["${workspaceFolder}"], - "cStandard": "c89", + "cStandard": "c11", "intelliSenseMode": "linux-clang-x64", "compilerPath": "/usr/bin/clang" } diff --git a/.vscode/settings.json b/.vscode/settings.json index 699362f..bfeb99d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,9 @@ "editor.detectIndentation": false, "editor.tabSize": 4, "editor.insertSpaces": false, + "files.associations": { + "*.h": "c" + }, "[starlark]": { "editor.insertSpaces": true }, diff --git a/lib/crc32.h b/lib/crc32.h index 83ce3ab..417959c 100644 --- a/lib/crc32.h +++ b/lib/crc32.h @@ -6,7 +6,7 @@ #include "lib/defs.h" -/* Incrementally calculate a CRC32. This is the same CRC32 used by Gzip. */ +// Incrementally calculate a CRC32. This is the same CRC32 used by Gzip. UInt32 CRC32Update(UInt32 crc, const void *ptr, Size size); #endif diff --git a/lib/defs.h b/lib/defs.h index 670b1e5..589ae8f 100644 --- a/lib/defs.h +++ b/lib/defs.h @@ -3,34 +3,30 @@ // Mozilla Public License, version 2.0. See LICENSE.txt for details. #ifndef LIB_DEFS_H #define LIB_DEFS_H -/* defs.h - common definitions. */ +// defs.h - common definitions. -/*============================================================================== -Target information -==============================================================================*/ +// ============================================================================= +// Target information +// ============================================================================= /* - Note that this code does not need to be especially portable. It just runs on - Mac OS and development systems (for testing). We can assume that the - development system has GCC. + Macros we care about: - Macros we care about: + TARGET_OS_MAC OS is some Macintosh variant (broadly speaking) + TARGET_API_MAC_OS8 Targeting classic Mac OS (9.x and earlier) - TARGET_OS_MAC OS is some Macintosh variant (broadly speaking) - TARGET_API_MAC_OS8 Targeting classic Mac OS (9.x and earlier) - - TARGET_RT_LITTLE_ENDIAN Little-endian byte order - TARGET_RT_BIG_ENDIAN Big-endian byte order + TARGET_RT_LITTLE_ENDIAN Little-endian byte order + TARGET_RT_BIG_ENDIAN Big-endian byte order */ #if macintosh -/* Classic Mac OS. Header is part of Universal Interfaces & Carbon. */ +// Classic Mac OS. Header is part of Universal Interfaces & Carbon. #include #elif __APPLE__ -/* Newer apple systems, including macOS >= 10. Header is in /usr/include, or - within /usr/include inside the SDK. */ +// Newer apple systems, including macOS >= 10. Header is in /usr/include, or +// within /usr/include inside the SDK. #include #else @@ -51,9 +47,9 @@ Target information #endif -/*============================================================================== -Basic types -==============================================================================*/ +// ============================================================================= +// Basic types +// ============================================================================= #if TARGET_API_MAC_OS8 @@ -61,7 +57,7 @@ Basic types #else -/* Include for NULL */ +// Include for NULL. #include #include @@ -85,6 +81,8 @@ typedef uint16_t UInt16; typedef int16_t SInt16; typedef uint32_t UInt32; typedef int32_t SInt32; +typedef uint64_t UInt64; +typedef int64_t SInt64; typedef char *Ptr; typedef Ptr *Handle; @@ -92,28 +90,35 @@ typedef long Size; #endif -/*============================================================================== -Error codes and error reporting -==============================================================================*/ +// ============================================================================= +// Error codes and error reporting +// ============================================================================= -/* Error codes. */ +// Error codes. typedef enum { - /* No error. */ + // No error (success). Equal to 0. kErrorOK, - /* Memory allocation failed. */ + // Memory allocation failed. kErrorNoMemory, - /* Invaild table data. */ + // Invaild table data. kErrorBadData, - /* Too many files in one directory. */ + // Too many files in one directory. kErrorDirectoryTooLarge } ErrorCode; -/*============================================================================== -Memory allocation -==============================================================================*/ +// ============================================================================= +// Memory allocation +// ============================================================================= + +/* + These functions are used to work with memory from code that runs on both + classic Mac OS systems and newer systems. Memory can be tight on very old + Mac systems, and to make the most of it, we only relocatable blocks of + memory (handles) whenever possible. +*/ #if TARGET_API_MAC_OS8 @@ -121,23 +126,23 @@ Memory allocation #else -/* Allocate a relocatable block of memory. */ +// Allocate a relocatable block of memory. Handle NewHandle(Size byteSize); -/* Free a relocatable block of memory. */ +// Free a relocatable block of memory. void DisposeHandle(Handle h); #endif -/* Resize a relocatable block of memory. Return true on success. */ +/// Resize a relocatable block of memory. Return true on success. Boolean ResizeHandle(Handle h, Size newSize); -/* Fill memory with zeroes. */ +// Fill memory with zeroes. void MemClear(void *ptr, Size size); -/*============================================================================== -Assertions -==============================================================================*/ +// ============================================================================= +// Assertions +// ============================================================================= #if NDEBUG #define assert(x) ((void)0) diff --git a/lib/test.h b/lib/test.h index ea191c7..e56028d 100644 --- a/lib/test.h +++ b/lib/test.h @@ -3,27 +3,27 @@ // Mozilla Public License, version 2.0. See LICENSE.txt for details. #ifndef LIB_TEST_H #define LIB_TEST_H -/* test.h - unit testing definitions. */ +// test.h - unit testing definitions. #include "lib/defs.h" -/* The number of test failures. */ +// The number of test failures. extern int gFailCount; -/* Set the name of the current test. */ +// Set the name of the current test. void SetTestName(const char *name); -/* Set the name of the current test. */ +// Set the name of the current test. void SetTestNamef(const char *fmt, ...) __attribute__((format(printf, 1, 2))); -/* Fail the current test. */ +// Fail the current test. void Failf(const char *msg, ...) __attribute__((format(printf, 1, 2))); -/* Return the description of an error code. Fatal error if the error code is - invalid. */ +// Return the description of an error code. Fatal error if the error code is +// invalid. const char *ErrorDescriptionOrDie(ErrorCode err); -/* Print information about completed tests and return the status code. */ +// Print information about completed tests and return the status code. int TestsDone(void); #endif diff --git a/lib/toolbox.c b/lib/toolbox.c index 456ab9f..62e3403 100644 --- a/lib/toolbox.c +++ b/lib/toolbox.c @@ -1,11 +1,8 @@ // 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. -/* toolbox.c - replacement functions for Mac OS toolbox functions - This is used to run conversion tests on non-Mac OS systems to make - development easier. These are not intended to make it possible to port the - converter to non-Mac OS systems. */ +// toolbox.c - replacement functions for Mac OS toolbox functions #include "lib/defs.h" #include "lib/util.h" diff --git a/lib/util.h b/lib/util.h index f65a586..6ba0a1a 100644 --- a/lib/util.h +++ b/lib/util.h @@ -5,12 +5,12 @@ #define LIB_UTIL_H #include "lib/defs.h" -/* Print an error message and exit. */ +// Print an error message and exit. void Fatalf(const char *msg, ...) __attribute__((noreturn, format(printf, 1, 2))); -/* Return a basic description of the given error code, or NULL if the error code - is unknown. */ +// Return a basic description of the given error code, or NULL if the error code +// is unknown. const char *ErrorDescription(ErrorCode err); #endif