Skip to content

Commit

Permalink
Format code (#38)
Browse files Browse the repository at this point in the history
* Add format c code in makefile

* Format code
  • Loading branch information
joii2020 authored Jan 9, 2024
1 parent 1863484 commit c17dc11
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{BasedOnStyle: google, IndentWidth: 4, SortIncludes: false}
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ CFLAGS_LIBECC_OPTIMIZED = -I ../ckb-c-stdlib-2023 -I ../ckb-c-stdlib-2023/libc -
CFLAGS_LINK_TO_LIBECC_OPTIMIZED := -fno-builtin -fno-builtin-printf -DWORDSIZE=64 -DWITH_STDLIB -DWITH_CKB -I ${LIBECC_OPTIMIZED_PATH}/src -I ${LIBECC_OPTIMIZED_PATH}/src/external_deps

# docker pull nervos/ckb-riscv-gnu-toolchain:gnu-jammy-20230214
BUILDER_DOCKER := nervos/ckb-riscv-gnu-toolchain@sha256:d3f649ef8079395eb25a21ceaeb15674f47eaa2d8cc23adc8bcdae3d5abce6ec
BUILDER_DOCKER := \
nervos/ckb-riscv-gnu-toolchain@sha256:d3f649ef8079395eb25a21ceaeb15674f47eaa2d8cc23adc8bcdae3d5abce6ec
CLANG_FORMAT_DOCKER := \
kason223/clang-format@sha256:3cce35b0400a7d420ec8504558a02bdfc12fd2d10e40206f140c4545059cd95d

all: build/secp256k1_data_info_20210801.h $(SECP256K1_SRC_20210801) deps/mbedtls/library/libmbedcrypto.a build/auth_libecc build/auth build/always_success

Expand Down Expand Up @@ -87,8 +90,23 @@ build/auth_libecc: c/auth_libecc.c $(LIBECC_OPTIMIZED_FILES)
$(OBJCOPY) --strip-debug --strip-all $@
ls -l $@

ALL_C_SOURCE := c/always_success.c \
c/dump_secp256k1_data_20210801.c \
c/secp256k1_helper_20210801.h \
c/secp256r1.h \
c/ckb_keccak256.h \
c/ckb_auth.h \
c/auth.c \
c/auth_libecc.c \
c/ckb_hex.h \
c/ripple.h

fmt:
clang-format -i -style="{BasedOnStyle: Google, IndentWidth: 4, SortIncludes: false}" c/*.c c/*.h
clang-format -i $(ALL_C_SOURCE)

fmt-via-docker:
docker run -u `id -u`:`id -g` --rm -v `pwd`:/code ${CLANG_FORMAT_DOCKER} bash -c \
"cd code && clang-format -i $(ALL_C_SOURCE)"

clean:
rm -rf build/*.debug
Expand Down
2 changes: 1 addition & 1 deletion c/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ size_t write_varint(uint8_t *dest, size_t n) {
uint8_t *ptr = dest;
/* Make sure that there is one after this */
while (n >= 0x80) {
*ptr = ((uint8_t)(n) & 0x7f) | 0x80;
*ptr = ((uint8_t)(n)&0x7f) | 0x80;
ptr++;
n >>= 7; /* I should be in multiples of 7, this should just get the next
part */
Expand Down
4 changes: 2 additions & 2 deletions c/ckb_keccak256.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ static void sha3_process_block(uint64_t hash[25], const uint64_t *block) {
sha3_permutation(hash);
}

//#define SHA3_FINALIZED 0x80000000
//#define SHA3_FINALIZED 0x8000
// #define SHA3_FINALIZED 0x80000000
// #define SHA3_FINALIZED 0x8000

/**
* Calculate message hash.
Expand Down

0 comments on commit c17dc11

Please sign in to comment.