From dd96385d7cc9c067eff76a5f7825483342af16e9 Mon Sep 17 00:00:00 2001 From: Dietrich Epp Date: Sun, 10 Apr 2022 03:51:59 -0400 Subject: [PATCH] Style: Use trailing commas for enums The trailing comma is supported in MPW and GCC. It fixes the formatting issue with clang-format and makes cleaner diffs, so trailing commas have been added to enums and clang-format has been run over the sources. --- .clang-format | 1 - convert/convert.h | 12 +++--------- convert/convert_1r.c | 3 +-- convert/convert_test.c | 5 ++--- lib/defs.h | 8 +++----- lib/test.h | 2 +- sync/meta.h | 13 +++++-------- sync/tree.c | 3 +-- sync/tree.h | 3 +-- sync/tree_test.c | 5 ++--- 10 files changed, 19 insertions(+), 36 deletions(-) diff --git a/.clang-format b/.clang-format index f6ccaf5..16ac2e7 100644 --- a/.clang-format +++ b/.clang-format @@ -4,7 +4,6 @@ AccessModifierOffset: -4 AllowShortFunctionsOnASingleLine: Inline AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false -AllowShortEnumsOnASingleLine: false DerivePointerAlignment: false IncludeBlocks: Preserve IncludeCategories: diff --git a/convert/convert.h b/convert/convert.h index 8513edd..45e9c69 100644 --- a/convert/convert.h +++ b/convert/convert.h @@ -4,8 +4,7 @@ #include "lib/defs.h" -enum -{ +enum { /* Constants for CR and LF. Note that we should not use '\n' or '\r' anywhere, because these character constants may have unexpected values on certain old Mac OS compilers, depending on the compiler settings. In @@ -17,8 +16,7 @@ enum kCharSubstitute = 63 }; -typedef enum -{ +typedef enum { /* Don't translite line breaks. */ kLineBreakKeep, @@ -33,11 +31,7 @@ typedef enum } LineBreakConversion; /* Directions that the converter runs in. */ -typedef enum -{ - kToUTF8, - kFromUTF8 -} ConvertDirection; +typedef enum { kToUTF8, kFromUTF8 } ConvertDirection; /* Get the character map used for the given Mac OS script and region codes. Return -1 if no known character map exists. */ diff --git a/convert/convert_1r.c b/convert/convert_1r.c index 34404eb..449ba51 100644 --- a/convert/convert_1r.c +++ b/convert/convert_1r.c @@ -2,8 +2,7 @@ #include "convert/convert.h" #include "lib/defs.h" -enum -{ +enum { /* Maximum length of encoded character. */ kMaxEncodedLength = 8, diff --git a/convert/convert_test.c b/convert/convert_test.c index 18434a3..8538ee8 100644 --- a/convert/convert_test.c +++ b/convert/convert_test.c @@ -7,10 +7,9 @@ #include #include -enum -{ +enum { kInitialBufSize = 4 * 1024, - kConvertBufferSize = 1024 + kConvertBufferSize = 1024, }; static UInt8 *gBuffer[3]; diff --git a/lib/defs.h b/lib/defs.h index 257a949..cfd72d6 100644 --- a/lib/defs.h +++ b/lib/defs.h @@ -69,10 +69,9 @@ Basic types #if __bool_true_false_are_defined typedef bool Boolean; #else -enum -{ +enum { false, - true + true, }; typedef unsigned char Boolean; #endif @@ -95,8 +94,7 @@ Error codes and error reporting ==============================================================================*/ /* Error codes. */ -typedef enum -{ +typedef enum { /* No error. */ kErrorOK, diff --git a/lib/test.h b/lib/test.h index 1949309..186f93f 100644 --- a/lib/test.h +++ b/lib/test.h @@ -21,6 +21,6 @@ void Failf(const char *msg, ...) __attribute__((format(printf, 1, 2))); const char *ErrorDescriptionOrDie(ErrorCode err); /* Print information about completed tests and return the status code. */ -int TestsDone(void ); +int TestsDone(void); #endif diff --git a/sync/meta.h b/sync/meta.h index 7edca2f..7e89212 100644 --- a/sync/meta.h +++ b/sync/meta.h @@ -15,21 +15,18 @@ struct Timestamp { }; #endif -typedef enum -{ +typedef enum { kTypeNotExist, kTypeFile, - kTypeDirectory + kTypeDirectory, } FileType; -enum -{ +enum { kLocal, - kRemote + kRemote, }; -enum -{ +enum { /* Maximum length of a filename. This is a Mac OS limitation. */ kFilenameLength = 31, diff --git a/sync/tree.c b/sync/tree.c index e919dac..3effed8 100644 --- a/sync/tree.c +++ b/sync/tree.c @@ -22,8 +22,7 @@ static int CompareFilename(const FileName *x, const FileName *y) return 0; } -enum -{ +enum { /* Maximum height of a file tree. diff --git a/sync/tree.h b/sync/tree.h index 08566bb..ea25f46 100644 --- a/sync/tree.h +++ b/sync/tree.h @@ -7,8 +7,7 @@ /* A reference to a file node by 1-based index, or 0 for none. */ typedef int FileRef; -typedef enum -{ +typedef enum { kNodeBlack, kNodeRed, } NodeColor; diff --git a/sync/tree_test.c b/sync/tree_test.c index bcdbee9..7685956 100644 --- a/sync/tree_test.c +++ b/sync/tree_test.c @@ -8,9 +8,8 @@ #include #include -enum -{ - kFileCount = 200 +enum { + kFileCount = 200, }; static UInt32 Random(UInt32 state)