From d46a2402b6a451f51a34aeb1216d42dd73d1421f Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 5 Jan 2026 15:55:38 +0100 Subject: [PATCH] Beautify code with uncrustify --- cmdline/check.c | 6 ++---- cmdline/io.h | 6 +++--- cmdline/main.c | 1 + cmdline/metrotest.c | 2 +- cmdline/murmur3.c | 6 +++--- cmdline/snapraid.c | 18 +++++++++--------- cmdline/spooky2test.c | 1 + cmdline/state.c | 10 +++++----- cmdline/support.c | 4 ++-- cmdline/unix.c | 12 ++++++------ makeuncrustify.sh | 3 +++ 11 files changed, 36 insertions(+), 33 deletions(-) create mode 100755 makeuncrustify.sh diff --git a/cmdline/check.c b/cmdline/check.c index e7458447..5c155d0e 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -1087,8 +1087,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } else { /* open the file only for reading */ if (!file_flag_has(file, FILE_IS_MISSING)) - ret = handle_open(&handle[j], file, state->file_mode, - log_error, state->opt.expected_missing ? log_expected : 0); + ret = handle_open(&handle[j], file, state->file_mode, log_error, state->opt.expected_missing ? log_expected : 0); else ret = -1; /* if the file is missing, we cannot open it */ if (ret == -1) { @@ -1162,8 +1161,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } /* read from the file */ - read_size = handle_read(&handle[j], file_pos, buffer[j], state->block_size, - log_error, state->opt.expected_missing ? log_expected : 0); + read_size = handle_read(&handle[j], file_pos, buffer[j], state->block_size, log_error, state->opt.expected_missing ? log_expected : 0); if (read_size == -1) { /* save the failed block for the check/fix */ failed[failed_count].is_bad = 1; /* it's bad because we cannot read it */ diff --git a/cmdline/io.h b/cmdline/io.h index c9cd816d..66af2614 100644 --- a/cmdline/io.h +++ b/cmdline/io.h @@ -138,7 +138,7 @@ struct snapraid_worker { * * # Initialize the process * io_start(&io, blockstart, blockmax, block_enabled); - * + * * for_each_block { * # Now read starts * # Get the current block to process and the vector of data buffers to use @@ -149,7 +149,7 @@ struct snapraid_worker { * # that the previous "blockcur" position is now available and the * # buffers can be used to read a new look-ahead position. * unsigned blockcur = io_read_next(&io, &buffer); - * + * * for_each_disk { * # Read a disk into buffer[diskcur] * # diskcur is the disk processed, and it may came in random order @@ -159,7 +159,7 @@ struct snapraid_worker { * # the read is not yet done. * # The reader thread will set the condition when ready. * struct snapraid_task* task = io_data_read(&io, &diskcur, waiting_map, &waiting_mac); - * + * * # compute the hash * ... * } diff --git a/cmdline/main.c b/cmdline/main.c index 8b999fcb..076e1b79 100644 --- a/cmdline/main.c +++ b/cmdline/main.c @@ -439,3 +439,4 @@ int main(int argc, char* argv[]) return ret; } #endif + diff --git a/cmdline/metrotest.c b/cmdline/metrotest.c index 512bb8d9..874d8f20 100644 --- a/cmdline/metrotest.c +++ b/cmdline/metrotest.c @@ -1,4 +1,4 @@ -/* +/* * Metro test vector from https://github.com/jandrewrogers/MetroHash/blob/master/src/metrohash128.cpp */ { "012345678901234567890123456789012345678901234567890123456789012", 63, { 0xc7, 0x7c, 0xe2, 0xbf, 0xa4, 0xed, 0x9f, 0x9b, 0x05, 0x48, 0xb2, 0xac, 0x50, 0x74, 0xa2, 0x97 }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }, diff --git a/cmdline/murmur3.c b/cmdline/murmur3.c index 71b61da8..eb12609a 100644 --- a/cmdline/murmur3.c +++ b/cmdline/murmur3.c @@ -140,19 +140,19 @@ void MurmurHash3_x86_128(const void* data, size_t size, const uint8_t* seed, voi case 14 : k4 ^= (uint32_t)tail[13] << 8; /* fallthrough */ case 13 : k4 ^= (uint32_t)tail[12] << 0; /* fallthrough */ k4 *= c4; k4 = util_rotl32(k4, 18); k4 *= c1; h4 ^= k4; - /* fallthrough */ + /* fallthrough */ case 12 : k3 ^= (uint32_t)tail[11] << 24; /* fallthrough */ case 11 : k3 ^= (uint32_t)tail[10] << 16; /* fallthrough */ case 10 : k3 ^= (uint32_t)tail[ 9] << 8; /* fallthrough */ case 9 : k3 ^= (uint32_t)tail[ 8] << 0; /* fallthrough */ k3 *= c3; k3 = util_rotl32(k3, 17); k3 *= c4; h3 ^= k3; - /* fallthrough */ + /* fallthrough */ case 8 : k2 ^= (uint32_t)tail[ 7] << 24; /* fallthrough */ case 7 : k2 ^= (uint32_t)tail[ 6] << 16; /* fallthrough */ case 6 : k2 ^= (uint32_t)tail[ 5] << 8; /* fallthrough */ case 5 : k2 ^= (uint32_t)tail[ 4] << 0; /* fallthrough */ k2 *= c2; k2 = util_rotl32(k2, 16); k2 *= c3; h2 ^= k2; - /* fallthrough */ + /* fallthrough */ case 4 : k1 ^= (uint32_t)tail[ 3] << 24; /* fallthrough */ case 3 : k1 ^= (uint32_t)tail[ 2] << 16; /* fallthrough */ case 2 : k1 ^= (uint32_t)tail[ 1] << 8; /* fallthrough */ diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index ac55decb..1ed26d4b 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -109,14 +109,14 @@ void test(int argc, char* argv[]) assert(strcmp(strtrim(strcpy(buffer, " trim trim \n\r")), "trim trim") == 0); assert(strcmp(strlwr(strcpy(buffer, " LoWer\n\r")), " lower\n\r") == 0); - assert(worddigitstr("longneedlestring","needle") == 0); - assert(worddigitstr("longneedlestring","") == 0); - assert(worddigitstr("long needle string","needle") != 0); - assert(worddigitstr("long1needle2string","needle") != 0); - assert(worddigitstr("long\rneedle3string","needle") != 0); - assert(worddigitstr("long1needle","needle") != 0); - assert(worddigitstr("needle2string","needle") != 0); - assert(worddigitstr("needle","needle") != 0); + assert(worddigitstr("longneedlestring", "needle") == 0); + assert(worddigitstr("longneedlestring", "") == 0); + assert(worddigitstr("long needle string", "needle") != 0); + assert(worddigitstr("long1needle2string", "needle") != 0); + assert(worddigitstr("long\rneedle3string", "needle") != 0); + assert(worddigitstr("long1needle", "needle") != 0); + assert(worddigitstr("needle2string", "needle") != 0); + assert(worddigitstr("needle", "needle") != 0); assert(strcmp(esc_tag("simple", buffer), "simple") == 0); assert(strcmp(esc_tag("line1\nline2", buffer), "line1\\nline2") == 0); @@ -1537,7 +1537,7 @@ int snapraid_main(int argc, char* argv[]) exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } - /* fallthrough */ + /* fallthrough */ case OPERATION_SPINUP : case OPERATION_SPINDOWN : if (!tommy_list_empty(&filterlist_file)) { diff --git a/cmdline/spooky2test.c b/cmdline/spooky2test.c index 1ef7fb2c..e3ac5ba7 100644 --- a/cmdline/spooky2test.c +++ b/cmdline/spooky2test.c @@ -261,3 +261,4 @@ { "\x12\x75\x7c\xa3\xe7\x74\x65\x23\x81\x28\xf1\x5b\x1f\x2d\x8b\x6f\x44\xe0\xcd\x2d\xd8\xdb\x77\x16\x6c\x0b\x7b\x0d\x9b\x70\x34\x9b\x8c\x71\xb7\xdd\x93\xda\x42\x0b\xf7\x73\xd2\xa5\xce\x3e\xd1\x3c\x05\x4c\xeb\xda\x7c\x3c\x01\x0f\x4e\x51\x37\x99\x2e\x2f\x28\xaf\xed\x32\x39\xea\x18\x6b\x0b\xd0\xbd\x39\x0a\xff\x4e\x7f\x22\xf3\x9f\x87\x92\x74\x0a\x73\xd8\x9f\xb2\x5b\xcc\x8e\xe4\x08\xc9\xa7\x99\x4c\x06\x7e\x18\xfc\x02\x68\xb8\x8c\x1e\x9d\xc3\x45\x44\x08\x77\x25\xc5\xaf\x26\x53\x41\xba\x7d\x3d\xbf\x22\xe1\x50\xdd\xf7\xf5\x53\x21\x4d\x38\x61\x6d\xc4\xcc\x81\x91\xb3\x51\xe3\xfb\xf1\xf0\xba\x89\x3f\x74\xb0\x7f\x55\x92\x0a\x94\x88\x49\x5a\x27\x14\x64\xdb\x8f\x0c\x1d\x6c\x90\xdb\xdc\x2c\xe9\x76\x1d\xae\x09\x20\x6f\xd9\xe2\xd9\x98\x5f\xd7\x64\xd6\xd8\xcf\xf4\x40\x7a\x6b\x72\x4b\x77\x54\x6d\x69\xf4\xad\x9f\xcc\xa1\xa8\x18\x49\xf9\x34\x0a\x57\x18\xd4\x30\x36\x34\x8b\xdb\x2c\xb9\xf4\x9a\xea\x05\x6e\x85\x0e\xbd\x73\x26\xc2\xca\x0a\x05\x81\xf4\x53\xcf\xfa\x19\x40\x22\x0d\x09\x63\xf8\xf2\x01\xe1\xad\x79\xc3\x86\xae\x6b\x4e", 254, { 0x23, 0xe9, 0x88, 0x6a, 0xc2, 0x8c, 0x64, 0x59, 0xdb, 0xa2, 0xe7, 0x84, 0x10, 0x37, 0x53, 0xd0 }, { 0x5d, 0x79, 0x66, 0xa7, 0x73, 0x27, 0x02, 0x2f, 0x6a, 0xa1, 0x9e, 0xc1, 0x14, 0x8c, 0x9e, 0x43 } }, { "\xf3\xc0\x10\x3f\xf2\xea\xca\xc4\xea\x01\xdf\x39\x6d\xce\x54\x61\xef\xdd\xf4\x42\x92\xe5\x70\x9d\x1c\xcf\xa0\x08\x0a\x65\xe8\xaa\xbe\x98\xb6\x93\xd3\x6d\x27\xb5\x91\x86\xc9\x83\x7c\x49\x7b\x25\x07\xaf\x71\x55\x66\xab\x54\xd9\x81\x34\x86\x9d\x04\xf1\x83\x6c\x93\x80\x63\x4b\x1b\x64\x7b\x72\x44\x89\x24\xe8\x02\x74\x93\xba\x4b\x0b\xe7\xd7\xe3\xfe\x42\x8b\x53\xd1\x0e\x96\xf8\x88\x61\xe9\x37\xee\x7b\xfc\xce\x81\x6c\xce\x46\xfd\xd3\x7a\x84\x83\xc1\x73\x7f\x66\xbb\x5c\x0c\x93\xde\x86\xd6\x9a\x1d\x07\x69\x5d\xa6\x73\x6d\x54\x64\x3a\xef\x7a\x9d\x9e\xdb\xd7\xba\x4f\x86\xab\x27\xa4\x68\x34\x51\x78\xe7\x1c\xcc\x9f\x4e\x83\x97\x04\xdc\xa4\x77\x61\xf9\x26\x7f\x99\x84\x01\xb1\xb5\x47\x0b\xbf\x79\x8c\x1f\xea\xa2\xc9\xe8\x0c\xbf\x76\x4f\xb1\xa9\xff\x7f\x5f\xa1\xd5\x91\xf6\x04\xa0\xd9\x32\xad\x8f\xcc\x4e\xe7\xcf\x8c\xc3\x0d\x19\x12\x2f\xc1\x66\xf7\x50\xc5\xbe\xdf\x2f\x79\x2e\x83\x59\xf1\xd8\x59\x48\xb2\x24\xe1\xe1\x0a\x15\x8e\x17\x09\xb6\x50\xad\x1f\xb3\xba\x18\x54\x03\xd5\x82\x1e\xc3\x80\xeb\xe2\x1f\x82\x6a\x0a\x69\x2e\x92", 255, { 0xe8, 0x99, 0x39, 0xbb, 0x59, 0x6c, 0x74, 0x74, 0x67, 0x04, 0x26, 0x4c, 0xd3, 0xaf, 0x38, 0x31 }, { 0x5d, 0x79, 0x66, 0xa7, 0x73, 0x27, 0x02, 0x2f, 0x6a, 0xa1, 0x9e, 0xc1, 0x14, 0x8c, 0x9e, 0x43 } }, { "\xbf\x4b\xb1\xf0\x43\x19\xfc\xb0\xee\x40\x48\x5f\xc3\xdc\x4a\xca\xaf\x65\xf5\x06\x5d\x88\xe7\x89\xb8\x14\x71\x76\xfe\x0b\x46\xf6\x7e\xd9\xbf\xc1\xee\xa1\xc8\xbd\x6b\xb2\x6b\xbd\x0d\x18\xf7\x6a\x26\x4f\xcc\x3f\x18\x13\xc6\xae\xd0\x53\x44\x60\xe3\x43\xd4\x9a\x43\x91\x7c\xbb\x9d\xaf\xa7\xe1\x53\x4f\xab\xac\x11\xed\xf3\x1a\x0e\x85\xce\x92\xe1\x66\xd3\xfc\xfd\x1f\xee\x0d\xcb\x95\x0c\xa0\x63\x36\x5f\x40\xe6\x48\x4e\xc2\x7a\x5b\xfd\x0f\xe3\xdd\x74\x00\xbb\xcc\x6e\x62\x4e\x86\xc0\x18\x14\xbc\x64\x60\xcb\x85\x22\x2e\x31\x8f\xda\xb4\x5b\x70\x70\x03\xb5\x1a\x54\xcb\x97\x6d\xac\x3e\x7f\xe7\x21\x13\xf1\x77\x43\xa7\xe8\x6f\x9a\x3e\xf7\x97\x4a\x66\x01\x5d\x62\x7c\x91\x2a\xc1\x48\xd7\xd1\xa5\xc4\x40\x21\xd1\xfa\xb1\x9a\x5b\x0b\x5f\x3c\x0f\x4b\x4d\x7a\x83\x8a\x63\x4e\xb9\x6e\x28\x66\x6a\xfc\x1d\x7c\xf5\x35\xb5\xc3\xe4\xdd\xf4\x7d\x16\x57\xa2\xa9\x8f\xab\x2c\xda\xd9\xaa\x18\x23\x14\x29\x23\x2f\xa1\x69\xf9\x6d\x67\x97\x91\x68\xc0\x6e\x22\x34\x04\xfa\xc5\x04\xb0\x78\xa8\xd9\x32\x5a\xec\x55\x53\x66\x1d\xae\x41\xfe\x4b\xbe\x38\x7a", 256, { 0xf9, 0xd0, 0x4d, 0xbb, 0xc9, 0x3f, 0xc3, 0xa4, 0x73, 0xd0, 0xd2, 0x2a, 0xb4, 0x79, 0x0a, 0xcb }, { 0x5d, 0x79, 0x66, 0xa7, 0x73, 0x27, 0x02, 0x2f, 0x6a, 0xa1, 0x9e, 0xc1, 0x14, 0x8c, 0x9e, 0x43 } }, + diff --git a/cmdline/state.c b/cmdline/state.c index 36e1e206..cbdad12a 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -732,7 +732,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (stat(device, &st) == 0) { dev = st.st_dev; - + /* read the uuid, if unsupported use an empty one */ if (devuuid(dev, split_map[s], uuid, sizeof(uuid)) != 0) { *uuid = 0; @@ -2972,7 +2972,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S state->parity[v_level].split_map[s].size = v_size; /* log the info read from the content file */ - if (s == 0) + if (s == 0) pathcpy(parity_name, sizeof(parity_name), lev_config_name(v_level)); else pathprint(parity_name, sizeof(parity_name), "%s/%u", lev_config_name(v_level), s); @@ -4492,10 +4492,10 @@ static struct snapraid_thermal* state_thermal_find(struct snapraid_state* state, for (i = tommy_list_head(&state->thermallist); i != 0; i = i->next) { struct snapraid_thermal* thermal = i->data; if (strcmp(thermal->name, name) == 0) { - if (found == 0 - /* if multiple matches, return the one with highest temperature */ + if (found == 0 + /* if multiple matches, return the one with highest temperature */ || found->latest_temperature < thermal->latest_temperature - /* or, if the temperature is equal, the one with the higher r_squared */ + /* or, if the temperature is equal, the one with the higher r_squared */ || (found->latest_temperature == thermal->latest_temperature && found->params.r_squared < thermal->params.r_squared) ) { found = thermal; diff --git a/cmdline/support.c b/cmdline/support.c index 417da372..8dd1603b 100644 --- a/cmdline/support.c +++ b/cmdline/support.c @@ -632,7 +632,7 @@ const char* esc_shell_multi(const char** str_map, unsigned str_max, char* buffer ss.str = str_map[0]; ss.map = str_map; ss.max = str_max; - + c = ssget(&ss); while (c) { switch (c) { @@ -761,7 +761,7 @@ char* strlwr(char* str) *s = tolower((unsigned char)*s); ++s; } - + return str; } diff --git a/cmdline/unix.c b/cmdline/unix.c index f7cd906e..7449c145 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -131,7 +131,7 @@ static int sysread(const char* path, char* buf, size_t buf_size) #endif /** - * Read a file from sys. + * Read a file from sys. * Trim spaces. * Always put an ending 0. * Do not report error on reading. @@ -1204,7 +1204,7 @@ static int devsmart(dev_t device, const char* name, const char* smartctl, uint64 FILE* f; int ret; const char* x; - + x = find_smartctl(); if (!x) { /* LCOV_EXCL_START */ @@ -1357,7 +1357,7 @@ static void devattr(dev_t device, uint64_t* info, char* serial, char* vendor, ch char buf[512]; int ret; char* attr; - + (void)vendor; /* the vendor file typically contains "ATA" */ if (info[INFO_SIZE] == SMART_UNASSIGNED) { @@ -1427,7 +1427,7 @@ static int devprobe(dev_t device, const char* name, const char* smartctl, int* p FILE* f; int ret; const char* x; - + x = find_smartctl(); if (!x) { /* LCOV_EXCL_START */ @@ -1496,7 +1496,7 @@ static int devprobe(dev_t device, const char* name, const char* smartctl, int* p } else { log_tag("attr:%s:%s:power:active\n", file, name); *power = POWER_ACTIVE; - + /* store the return smartctl return value */ smart[SMART_FLAGS] = WEXITSTATUS(ret); } @@ -1516,7 +1516,7 @@ static int devdown(dev_t device, const char* name, const char* smartctl) FILE* f; int ret; const char* x; - + x = find_smartctl(); if (!x) { /* LCOV_EXCL_START */ diff --git a/makeuncrustify.sh b/makeuncrustify.sh new file mode 100755 index 00000000..5b3e502b --- /dev/null +++ b/makeuncrustify.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +uncrustify -c uncrustify.cfg --replace cmdline/*.c cmdline/*.h