From 926c92ef6e2d68d14c47aeb6c043900d71f220a5 Mon Sep 17 00:00:00 2001 From: Marcelo Politzer Date: Mon, 6 Dec 2021 12:38:43 -0300 Subject: [PATCH] Pass ioctl-echo-loop.c through clang-format --- .clang-format | 19 ++++ .../rollup/ioctl-echo-loop/ioctl-echo-loop.c | 91 ++++++++----------- 2 files changed, 58 insertions(+), 52 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..989c84a2 --- /dev/null +++ b/.clang-format @@ -0,0 +1,19 @@ +Language: Cpp +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignOperands: DontAlign +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortFunctionsOnASingleLine: Empty +AlwaysBreakTemplateDeclarations: Yes +BreakInheritanceList: AfterColon +BreakBeforeTernaryOperators: false +BreakConstructorInitializers: AfterColon +ColumnLimit: 120 +ConstructorInitializerAllOnOneLineOrOnePerLine: true +IndentCaseLabels: true +IndentWidth: 4 +SpaceAfterCStyleCast: true +Standard: c++17 diff --git a/linux/rollup/ioctl-echo-loop/ioctl-echo-loop.c b/linux/rollup/ioctl-echo-loop/ioctl-echo-loop.c index 12c7fa79..95ff42ef 100644 --- a/linux/rollup/ioctl-echo-loop/ioctl-echo-loop.c +++ b/linux/rollup/ioctl-echo-loop/ioctl-echo-loop.c @@ -11,15 +11,14 @@ * the License. */ +#include "sys/ioctl.h" +#include +#include #include #include #include #include -#include -#include -#include "sys/ioctl.h" -#include #include #define ROLLUP_DEVICE_NAME "/dev/rollup" @@ -84,7 +83,7 @@ static int finish_request(int fd, struct rollup_finish *finish, bool accept) { int res = 0; memset(finish, 0, sizeof(*finish)); finish->accept_previous_request = accept; - res = ioctl(fd, IOCTL_ROLLUP_FINISH, (unsigned long)finish); + res = ioctl(fd, IOCTL_ROLLUP_FINISH, (unsigned long) finish); if (res != 0) { fprintf(stderr, "IOCTL_ROLLUP_FINISH returned error %d\n", res); } @@ -204,8 +203,7 @@ static int handle_inspect_state_request(int fd, struct parsed_args *args, struct return 0; } -static int handle_request(int fd, struct parsed_args *args, struct rollup_finish *finish, - struct rollup_bytes *bytes) { +static int handle_request(int fd, struct parsed_args *args, struct rollup_finish *finish, struct rollup_bytes *bytes) { switch (finish->next_request_type) { case CARTESI_ROLLUP_ADVANCE_STATE: return handle_advance_state_request(fd, args, finish, bytes); @@ -232,13 +230,13 @@ int main(int argc, char *argv[]) { return fd; } - fprintf(stderr, "Echoing as %d voucher copies, %d notice copies, and %d report copies\n", - args.voucher_count, args.notice_count, args.report_count); + fprintf(stderr, "Echoing as %d voucher copies, %d notice copies, and %d report copies\n", args.voucher_count, + args.notice_count, args.report_count); memset(&bytes, 0, sizeof(bytes)); /* Loop accepting previous request, waiting for next, and handling it */ - for (int i=0 ;; ++i) { + for (int i = 0;; ++i) { struct rollup_finish finish; if (finish_request(fd, &finish, !(i == args.reject)) != 0) { break; @@ -257,52 +255,42 @@ int main(int argc, char *argv[]) { return 0; } -static void print_address(uint8_t *address) -{ - for (int i=0; inext_request_type) { - case CARTESI_ROLLUP_ADVANCE_STATE: - type = "advance"; - break; - case CARTESI_ROLLUP_INSPECT_STATE: - type = "inspect"; - break; + case CARTESI_ROLLUP_ADVANCE_STATE: + type = "advance"; + break; + case CARTESI_ROLLUP_INSPECT_STATE: + type = "inspect"; + break; } - printf( - "finish:\n" - "\taccept: %s\n" - "\ttype: %s\n" - "\tlength: %d\n" - , finish->accept_previous_request? "yes" : "no" - , type - , finish->next_request_payload_length); + printf("finish:\n" + "\taccept: %s\n" + "\ttype: %s\n" + "\tlength: %d\n", + finish->accept_previous_request ? "yes" : "no", type, finish->next_request_payload_length); } -static void show_advance(struct rollup_advance_state *advance) -{ - printf( - "advance:\n" - "\tmsg_sender: "); +static void show_advance(struct rollup_advance_state *advance) { + printf("advance:\n" + "\tmsg_sender: "); print_address(advance->metadata.msg_sender); - printf( - "\tblock_number: %lu\n" - "\ttime_stamp: %lu\n" - "\tepoch_index: %lu\n" - "\tinput_index: %lu\n" - , advance->metadata.block_number - , advance->metadata.time_stamp - , advance->metadata.epoch_index - , advance->metadata.input_index); + printf("\tblock_number: %lu\n" + "\ttime_stamp: %lu\n" + "\tepoch_index: %lu\n" + "\tinput_index: %lu\n", + advance->metadata.block_number, advance->metadata.time_stamp, advance->metadata.epoch_index, + advance->metadata.input_index); } static void show_inspect(struct rollup_inspect_state *inspect) { @@ -326,10 +314,9 @@ static void show_notice(struct rollup_notice *notice) { "\tlength: %lu\n", notice->index, notice->payload.length); } -static void show_report(struct rollup_report *report) -{ - printf( - "report:\n" - "\tlength: %lu\n" - , report->payload.length); + +static void show_report(struct rollup_report *report) { + printf("report:\n" + "\tlength: %lu\n", + report->payload.length); }