From ea56cdb5a8557ad4e8ff6f00db09102a3d002e0a Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Tue, 31 Dec 2024 17:14:23 -0800 Subject: [PATCH 1/2] Added formatting checks for C/C++ and python code --- .bazelci/config.yaml | 1 - .clang-format | 4 + .github/workflows/formatting.yaml | 34 ++++ .gitignore | 3 + examples/cmake_android/cpp/native-lib.cpp | 11 +- examples/cmake_android/hello_lib-example.cpp | 8 +- .../example/android/bazel/MainActivity.java | 3 +- examples/cmake_android/zlib-example.cpp | 34 ++-- examples/cmake_crosstool/hello.cc | 4 +- .../cmake_crosstool/static/hello_client.c | 7 +- .../static/hello_client_version123.c | 7 +- examples/cmake_crosstool/static/src/hello.c | 4 +- examples/cmake_defines/lib_a/lib_a.cpp | 12 +- .../cmake_hello_world_lib/binary/src/hello.c | 4 +- .../cmake_hello_world_lib/binary/src/main.c | 7 +- .../shared/hello_client.c | 7 +- .../cmake_hello_world_lib/shared/src/hello.c | 4 +- .../static/hello_client.c | 7 +- .../static/hello_client_version123.c | 7 +- .../cmake_hello_world_lib/static/src/hello.c | 4 +- examples/cmake_synthetic/liba/src/liba.cpp | 4 +- examples/cmake_synthetic/liba/src/liba.h | 1 + examples/cmake_synthetic/libb/src/libb.cpp | 4 +- examples/cmake_synthetic/libb/src/libb.h | 2 + examples/cmake_synthetic/libc/src/libc.cpp | 2 +- examples/cmake_synthetic/libc/src/libc.h | 2 + examples/cmake_synthetic/test_libb.cpp | 17 +- .../libb/src/libb.cpp | 4 +- .../libb/src/libb.h | 2 + .../cmake_with_bazel_transitive/test_libb.cpp | 17 +- examples/cmake_with_data/lib_a/src/lib_a.cpp | 11 +- examples/cmake_with_data/lib_b/src/lib_b.cpp | 5 +- .../tests/test_cmake_with_data.cpp | 10 +- .../tests/test_cmake_with_shared_lib.cpp | 9 +- examples/cmake_with_target/src/lib.cpp | 5 +- .../source_root/src/liba.cpp | 4 +- .../cmake_working_dir/source_root/src/liba.h | 1 + examples/cmake_working_dir/test_liba.cpp | 17 +- .../simple_lib/include/simple.h | 2 +- .../simple_lib/src/simple.c | 4 +- .../testSimple.c | 4 +- .../builtWithBazel.c | 4 +- .../builtWithBazel.h | 2 +- .../simple_lib/include/simple.h | 2 +- .../simple_lib/src/simple.c | 8 +- .../testSimple.c | 7 +- examples/make_simple/code/liba.cpp | 12 +- examples/make_simple/code/liba.h | 1 + examples/make_simple/test_libb.cpp | 28 +-- examples/ninja_simple/code/liba.cpp | 4 +- examples/ninja_simple/code/liba.h | 1 + examples/ninja_simple/test_libb.cpp | 10 +- examples/third_party/cares/c-ares-test.cpp | 20 +- examples/third_party/curl/curl_test.cc | 9 +- .../third_party/gperftools/malloc_test.cc | 5 +- .../libpng/libpng_usage_example.cpp | 173 +++++++++--------- examples/third_party/openssl/openssl_test.cc | 28 ++- examples/third_party/zlib/zlib-example.cpp | 34 ++-- 58 files changed, 315 insertions(+), 332 deletions(-) create mode 100644 .clang-format create mode 100644 .github/workflows/formatting.yaml diff --git a/.bazelci/config.yaml b/.bazelci/config.yaml index cf6e9a556..691fbc464 100644 --- a/.bazelci/config.yaml +++ b/.bazelci/config.yaml @@ -252,6 +252,5 @@ tasks: test_targets: *min_supported_targets buildifier: - version: "6.1.0" # keep this argument in sync with .pre-commit-config.yaml warnings: "all" diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..5aa4a34f3 --- /dev/null +++ b/.clang-format @@ -0,0 +1,4 @@ +--- +BasedOnStyle: Google +IndentWidth: 4 +... diff --git a/.github/workflows/formatting.yaml b/.github/workflows/formatting.yaml new file mode 100644 index 000000000..0a12cc696 --- /dev/null +++ b/.github/workflows/formatting.yaml @@ -0,0 +1,34 @@ +name: Formatting + +on: + push: + branches: + - main + pull_request: + types: + - opened + - synchronize + +jobs: + code-format-checks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: DoozyX/clang-format-lint-action@v0.14 + with: + source: '.' + extensions: 'h,c,cc,cpp,proto,java' + clangFormatVersion: 14 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.11 + - name: Install dependencies + run: | + pip install 'black==24.10.0' 'isort==5.13.2' + - name: Run black + run: | + python -m black --check --diff ./ + - name: Run isort + run: | + python -m isort --profile=black --check-only ./ diff --git a/.gitignore b/.gitignore index 4b2f4842e..ba46b0ff5 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,9 @@ # CMake cmake-build-*/ +# Python +/*venv/ + # Mongo Explorer plugin .idea/**/mongoSettings.xml diff --git a/examples/cmake_android/cpp/native-lib.cpp b/examples/cmake_android/cpp/native-lib.cpp index b28dfc6ca..8964d6000 100644 --- a/examples/cmake_android/cpp/native-lib.cpp +++ b/examples/cmake_android/cpp/native-lib.cpp @@ -1,13 +1,12 @@ #include + #include -extern "C" -JNIEXPORT jstring +extern "C" JNIEXPORT jstring -JNICALL -Java_com_example_android_bazel_MainActivity_stringFromJNI( - JNIEnv *env, - jobject /* this */) { + JNICALL + Java_com_example_android_bazel_MainActivity_stringFromJNI( + JNIEnv *env, jobject /* this */) { std::string hello = "Hello from C++"; return env->NewStringUTF(hello.c_str()); } diff --git a/examples/cmake_android/hello_lib-example.cpp b/examples/cmake_android/hello_lib-example.cpp index 2b1956ece..3b6900dd7 100644 --- a/examples/cmake_android/hello_lib-example.cpp +++ b/examples/cmake_android/hello_lib-example.cpp @@ -1,8 +1,8 @@ #include + #include "hello.h" -int main(int argc, char* argv[]) -{ - hello_func(); - return 0; +int main(int argc, char* argv[]) { + hello_func(); + return 0; } diff --git a/examples/cmake_android/java/com/example/android/bazel/MainActivity.java b/examples/cmake_android/java/com/example/android/bazel/MainActivity.java index 48bad31f2..9e3a4d94e 100644 --- a/examples/cmake_android/java/com/example/android/bazel/MainActivity.java +++ b/examples/cmake_android/java/com/example/android/bazel/MainActivity.java @@ -1,11 +1,10 @@ package examples.cmake_android.java.com.example.android.bazel; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; import android.widget.TextView; public class MainActivity extends AppCompatActivity { - static { System.loadLibrary("app"); } diff --git a/examples/cmake_android/zlib-example.cpp b/examples/cmake_android/zlib-example.cpp index bef3d2ac7..b1ad1361f 100644 --- a/examples/cmake_android/zlib-example.cpp +++ b/examples/cmake_android/zlib-example.cpp @@ -1,13 +1,14 @@ // Copied from https://gist.github.com/arq5x/5315739 for test purposes +#include #include #include // for strlen -#include + #include "zlib.h" -// adapted from: http://stackoverflow.com/questions/7540259/deflate-and-inflate-zlib-h-in-c -int main(int argc, char* argv[]) -{ +// adapted from: +// http://stackoverflow.com/questions/7540259/deflate-and-inflate-zlib-h-in-c +int main(int argc, char *argv[]) { // original string len = 36 char a[50] = "Hello Hello Hello Hello Hello Hello!"; @@ -17,11 +18,9 @@ int main(int argc, char* argv[]) // placeholder for the UNcompressed (inflated) version of "b" char c[50]; - printf("Uncompressed size is: %lu\n", strlen(a)); printf("Uncompressed string is: %s\n", a); - printf("\n----------\n\n"); // STEP 1. @@ -33,10 +32,11 @@ int main(int argc, char* argv[]) defstream.zfree = Z_NULL; defstream.opaque = Z_NULL; // setup "a" as the input and "b" as the compressed output - defstream.avail_in = (uInt)strlen(a)+1; // size of input, string + terminator - defstream.next_in = (Bytef *)a; // input char array - defstream.avail_out = (uInt)sizeof(b); // size of output - defstream.next_out = (Bytef *)b; // output char array + defstream.avail_in = + (uInt)strlen(a) + 1; // size of input, string + terminator + defstream.next_in = (Bytef *)a; // input char array + defstream.avail_out = (uInt)sizeof(b); // size of output + defstream.next_out = (Bytef *)b; // output char array // the actual compression work. deflateInit(&defstream, Z_BEST_COMPRESSION); @@ -47,10 +47,8 @@ int main(int argc, char* argv[]) printf("Compressed size is: %lu\n", strlen(b)); printf("Compressed string is: %s\n", b); - printf("\n----------\n\n"); - // STEP 2. // inflate b into c // zlib struct @@ -59,10 +57,11 @@ int main(int argc, char* argv[]) infstream.zfree = Z_NULL; infstream.opaque = Z_NULL; // setup "b" as the input and "c" as the compressed output - infstream.avail_in = (uInt)((char*)defstream.next_out - b); // size of input - infstream.next_in = (Bytef *)b; // input char array - infstream.avail_out = (uInt)sizeof(c); // size of output - infstream.next_out = (Bytef *)c; // output char array + infstream.avail_in = + (uInt)((char *)defstream.next_out - b); // size of input + infstream.next_in = (Bytef *)b; // input char array + infstream.avail_out = (uInt)sizeof(c); // size of output + infstream.next_out = (Bytef *)c; // output char array // the actual DE-compression work. inflateInit(&infstream); @@ -72,9 +71,8 @@ int main(int argc, char* argv[]) printf("Uncompressed size is: %lu\n", strlen(c)); printf("Uncompressed string is: %s\n", c); - // make sure uncompressed is exactly equal to original. - assert(strcmp(a,c)==0); + assert(strcmp(a, c) == 0); return 0; } diff --git a/examples/cmake_crosstool/hello.cc b/examples/cmake_crosstool/hello.cc index b41be6d19..7647e7884 100644 --- a/examples/cmake_crosstool/hello.cc +++ b/examples/cmake_crosstool/hello.cc @@ -18,6 +18,6 @@ #include int main(int argc, char* argv[]) { - std::cout << "Hello! sqrt(time) = " << std::sqrt(time(NULL)) << std::endl; - return EXIT_SUCCESS; + std::cout << "Hello! sqrt(time) = " << std::sqrt(time(NULL)) << std::endl; + return EXIT_SUCCESS; } diff --git a/examples/cmake_crosstool/static/hello_client.c b/examples/cmake_crosstool/static/hello_client.c index a6bfc670d..5def9da62 100644 --- a/examples/cmake_crosstool/static/hello_client.c +++ b/examples/cmake_crosstool/static/hello_client.c @@ -1,7 +1,6 @@ #include "hello.h" -int main(int argc, char* argv[]) -{ - hello_func(); - return 0; +int main(int argc, char* argv[]) { + hello_func(); + return 0; } diff --git a/examples/cmake_crosstool/static/hello_client_version123.c b/examples/cmake_crosstool/static/hello_client_version123.c index bab7781b0..d13ffd349 100644 --- a/examples/cmake_crosstool/static/hello_client_version123.c +++ b/examples/cmake_crosstool/static/hello_client_version123.c @@ -1,7 +1,6 @@ #include "version123/hello.h" -int main(int argc, char* argv[]) -{ - hello_func(); - return 0; +int main(int argc, char* argv[]) { + hello_func(); + return 0; } diff --git a/examples/cmake_crosstool/static/src/hello.c b/examples/cmake_crosstool/static/src/hello.c index 9e6007dc7..de1ddcefb 100644 --- a/examples/cmake_crosstool/static/src/hello.c +++ b/examples/cmake_crosstool/static/src/hello.c @@ -1,7 +1,7 @@ #include "hello.h" void hello_func(void) { - printf("Hello World!\n"); + printf("Hello World!\n"); - return; + return; } diff --git a/examples/cmake_defines/lib_a/lib_a.cpp b/examples/cmake_defines/lib_a/lib_a.cpp index 89ea243e5..0a8dc662c 100644 --- a/examples/cmake_defines/lib_a/lib_a.cpp +++ b/examples/cmake_defines/lib_a/lib_a.cpp @@ -6,14 +6,10 @@ #define STR(x) #x #pragma message "The value of __TIME__: " XSTR(__TIME__) -#define STATIC_ASSERT( condition, name )\ - typedef char assert_failed_ ## name [ (condition) ? 1 : -1 ]; +#define STATIC_ASSERT(condition, name) \ + typedef char assert_failed_##name[(condition) ? 1 : -1]; -void foo() { -STATIC_ASSERT(__TIME__ == "redacted", time_must_be_redacted); -} +void foo() { STATIC_ASSERT(__TIME__ == "redacted", time_must_be_redacted); } // Should return "redacted" -const char *getBuildTime(void) { - return __TIME__; -} +const char *getBuildTime(void) { return __TIME__; } diff --git a/examples/cmake_hello_world_lib/binary/src/hello.c b/examples/cmake_hello_world_lib/binary/src/hello.c index f5a0f535f..7074b5fed 100644 --- a/examples/cmake_hello_world_lib/binary/src/hello.c +++ b/examples/cmake_hello_world_lib/binary/src/hello.c @@ -1,5 +1,3 @@ #include "hello.h" -void hello_func(char* name) { - printf("Hello, %s!", name); -} +void hello_func(char* name) { printf("Hello, %s!", name); } diff --git a/examples/cmake_hello_world_lib/binary/src/main.c b/examples/cmake_hello_world_lib/binary/src/main.c index 4c2359857..2803c2ef8 100644 --- a/examples/cmake_hello_world_lib/binary/src/main.c +++ b/examples/cmake_hello_world_lib/binary/src/main.c @@ -1,7 +1,6 @@ #include "hello.h" -int main(int argc, char* argv[]) -{ - hello_func(argv[1]); - return 0; +int main(int argc, char* argv[]) { + hello_func(argv[1]); + return 0; } diff --git a/examples/cmake_hello_world_lib/shared/hello_client.c b/examples/cmake_hello_world_lib/shared/hello_client.c index a6bfc670d..5def9da62 100644 --- a/examples/cmake_hello_world_lib/shared/hello_client.c +++ b/examples/cmake_hello_world_lib/shared/hello_client.c @@ -1,7 +1,6 @@ #include "hello.h" -int main(int argc, char* argv[]) -{ - hello_func(); - return 0; +int main(int argc, char* argv[]) { + hello_func(); + return 0; } diff --git a/examples/cmake_hello_world_lib/shared/src/hello.c b/examples/cmake_hello_world_lib/shared/src/hello.c index 9e6007dc7..de1ddcefb 100644 --- a/examples/cmake_hello_world_lib/shared/src/hello.c +++ b/examples/cmake_hello_world_lib/shared/src/hello.c @@ -1,7 +1,7 @@ #include "hello.h" void hello_func(void) { - printf("Hello World!\n"); + printf("Hello World!\n"); - return; + return; } diff --git a/examples/cmake_hello_world_lib/static/hello_client.c b/examples/cmake_hello_world_lib/static/hello_client.c index a6bfc670d..5def9da62 100644 --- a/examples/cmake_hello_world_lib/static/hello_client.c +++ b/examples/cmake_hello_world_lib/static/hello_client.c @@ -1,7 +1,6 @@ #include "hello.h" -int main(int argc, char* argv[]) -{ - hello_func(); - return 0; +int main(int argc, char* argv[]) { + hello_func(); + return 0; } diff --git a/examples/cmake_hello_world_lib/static/hello_client_version123.c b/examples/cmake_hello_world_lib/static/hello_client_version123.c index bab7781b0..d13ffd349 100644 --- a/examples/cmake_hello_world_lib/static/hello_client_version123.c +++ b/examples/cmake_hello_world_lib/static/hello_client_version123.c @@ -1,7 +1,6 @@ #include "version123/hello.h" -int main(int argc, char* argv[]) -{ - hello_func(); - return 0; +int main(int argc, char* argv[]) { + hello_func(); + return 0; } diff --git a/examples/cmake_hello_world_lib/static/src/hello.c b/examples/cmake_hello_world_lib/static/src/hello.c index 9e6007dc7..de1ddcefb 100644 --- a/examples/cmake_hello_world_lib/static/src/hello.c +++ b/examples/cmake_hello_world_lib/static/src/hello.c @@ -1,7 +1,7 @@ #include "hello.h" void hello_func(void) { - printf("Hello World!\n"); + printf("Hello World!\n"); - return; + return; } diff --git a/examples/cmake_synthetic/liba/src/liba.cpp b/examples/cmake_synthetic/liba/src/liba.cpp index 6dfcbdbc9..061f48810 100644 --- a/examples/cmake_synthetic/liba/src/liba.cpp +++ b/examples/cmake_synthetic/liba/src/liba.cpp @@ -1,5 +1,3 @@ #include "liba.h" -std::string hello_liba(void) { - return "Hello from LIBA!"; -} +std::string hello_liba(void) { return "Hello from LIBA!"; } diff --git a/examples/cmake_synthetic/liba/src/liba.h b/examples/cmake_synthetic/liba/src/liba.h index 610c2e6fa..58c231398 100644 --- a/examples/cmake_synthetic/liba/src/liba.h +++ b/examples/cmake_synthetic/liba/src/liba.h @@ -2,6 +2,7 @@ #define LIBA_H_ (1) #include + #include std::string hello_liba(void); diff --git a/examples/cmake_synthetic/libb/src/libb.cpp b/examples/cmake_synthetic/libb/src/libb.cpp index e5bc67fd9..c1cd05363 100644 --- a/examples/cmake_synthetic/libb/src/libb.cpp +++ b/examples/cmake_synthetic/libb/src/libb.cpp @@ -1,5 +1,3 @@ #include "libb.h" -std::string hello_libb(void) { - return hello_liba() + " Hello from LIBB!"; -} +std::string hello_libb(void) { return hello_liba() + " Hello from LIBB!"; } diff --git a/examples/cmake_synthetic/libb/src/libb.h b/examples/cmake_synthetic/libb/src/libb.h index 50aa4c66e..a67701816 100644 --- a/examples/cmake_synthetic/libb/src/libb.h +++ b/examples/cmake_synthetic/libb/src/libb.h @@ -2,7 +2,9 @@ #define LIBB_H_ (1) #include + #include + #include "liba.h" std::string hello_libb(void); diff --git a/examples/cmake_synthetic/libc/src/libc.cpp b/examples/cmake_synthetic/libc/src/libc.cpp index dde57f9da..d102a08b4 100644 --- a/examples/cmake_synthetic/libc/src/libc.cpp +++ b/examples/cmake_synthetic/libc/src/libc.cpp @@ -1,5 +1,5 @@ #include "libc.h" std::string hello_libc(void) { - return hello_liba() + " " + hello_libb() + " Hello from LIBC!"; + return hello_liba() + " " + hello_libb() + " Hello from LIBC!"; } diff --git a/examples/cmake_synthetic/libc/src/libc.h b/examples/cmake_synthetic/libc/src/libc.h index 4e8468f52..17f2f9221 100644 --- a/examples/cmake_synthetic/libc/src/libc.h +++ b/examples/cmake_synthetic/libc/src/libc.h @@ -2,7 +2,9 @@ #define LIBC_H_ (1) #include + #include + #include "liba.h" #include "libb.h" diff --git a/examples/cmake_synthetic/test_libb.cpp b/examples/cmake_synthetic/test_libb.cpp index 79edb38f7..b3bd8f273 100644 --- a/examples/cmake_synthetic/test_libb.cpp +++ b/examples/cmake_synthetic/test_libb.cpp @@ -1,14 +1,13 @@ -#include "libb.h" - #include #include #include -int main(int argc, char* argv[]) -{ - std:: string result = hello_libb(); - if (result != "Hello from LIBA! Hello from LIBB!") { - throw std::runtime_error("Wrong result: " + result); - } - std::cout << "Everything's fine!"; +#include "libb.h" + +int main(int argc, char* argv[]) { + std::string result = hello_libb(); + if (result != "Hello from LIBA! Hello from LIBB!") { + throw std::runtime_error("Wrong result: " + result); + } + std::cout << "Everything's fine!"; } diff --git a/examples/cmake_with_bazel_transitive/libb/src/libb.cpp b/examples/cmake_with_bazel_transitive/libb/src/libb.cpp index e5bc67fd9..c1cd05363 100644 --- a/examples/cmake_with_bazel_transitive/libb/src/libb.cpp +++ b/examples/cmake_with_bazel_transitive/libb/src/libb.cpp @@ -1,5 +1,3 @@ #include "libb.h" -std::string hello_libb(void) { - return hello_liba() + " Hello from LIBB!"; -} +std::string hello_libb(void) { return hello_liba() + " Hello from LIBB!"; } diff --git a/examples/cmake_with_bazel_transitive/libb/src/libb.h b/examples/cmake_with_bazel_transitive/libb/src/libb.h index 50aa4c66e..a67701816 100644 --- a/examples/cmake_with_bazel_transitive/libb/src/libb.h +++ b/examples/cmake_with_bazel_transitive/libb/src/libb.h @@ -2,7 +2,9 @@ #define LIBB_H_ (1) #include + #include + #include "liba.h" std::string hello_libb(void); diff --git a/examples/cmake_with_bazel_transitive/test_libb.cpp b/examples/cmake_with_bazel_transitive/test_libb.cpp index 79edb38f7..b3bd8f273 100644 --- a/examples/cmake_with_bazel_transitive/test_libb.cpp +++ b/examples/cmake_with_bazel_transitive/test_libb.cpp @@ -1,14 +1,13 @@ -#include "libb.h" - #include #include #include -int main(int argc, char* argv[]) -{ - std:: string result = hello_libb(); - if (result != "Hello from LIBA! Hello from LIBB!") { - throw std::runtime_error("Wrong result: " + result); - } - std::cout << "Everything's fine!"; +#include "libb.h" + +int main(int argc, char* argv[]) { + std::string result = hello_libb(); + if (result != "Hello from LIBA! Hello from LIBB!") { + throw std::runtime_error("Wrong result: " + result); + } + std::cout << "Everything's fine!"; } diff --git a/examples/cmake_with_data/lib_a/src/lib_a.cpp b/examples/cmake_with_data/lib_a/src/lib_a.cpp index 2ab53b35e..11d65fbb0 100644 --- a/examples/cmake_with_data/lib_a/src/lib_a.cpp +++ b/examples/cmake_with_data/lib_a/src/lib_a.cpp @@ -5,19 +5,16 @@ #include #include -std::string hello_data(std::string path) -{ +std::string hello_data(std::string path) { // Open the file std::ifstream data_file(path.c_str()); - if (!data_file.good()) - { + if (!data_file.good()) { throw std::runtime_error("Could not open: " + path); } // Read it's contents to a string - std::string data_str( - (std::istreambuf_iterator(data_file)), - (std::istreambuf_iterator())); + std::string data_str((std::istreambuf_iterator(data_file)), + (std::istreambuf_iterator())); // Close the file data_file.close(); diff --git a/examples/cmake_with_data/lib_b/src/lib_b.cpp b/examples/cmake_with_data/lib_b/src/lib_b.cpp index 70462a97b..0ef5b944e 100644 --- a/examples/cmake_with_data/lib_b/src/lib_b.cpp +++ b/examples/cmake_with_data/lib_b/src/lib_b.cpp @@ -1,6 +1,3 @@ #include "lib_b.h" -std::string hello_data(std::string path) -{ - return std::string("Hello world!"); -} +std::string hello_data(std::string path) { return std::string("Hello world!"); } diff --git a/examples/cmake_with_data/tests/test_cmake_with_data.cpp b/examples/cmake_with_data/tests/test_cmake_with_data.cpp index ac4febec1..018a8ceed 100644 --- a/examples/cmake_with_data/tests/test_cmake_with_data.cpp +++ b/examples/cmake_with_data/tests/test_cmake_with_data.cpp @@ -1,18 +1,16 @@ -#include "lib_a.h" - #include #include #include -int main(int argc, char* argv[]) -{ +#include "lib_a.h" + +int main(int argc, char* argv[]) { #ifdef _WIN32 std::string result = hello_data(".\\cmake_with_data\\cmake_with_data.txt"); #else std::string result = hello_data("./cmake_with_data/cmake_with_data.txt"); #endif - if (result != "Hallo welt!") - { + if (result != "Hallo welt!") { throw std::runtime_error("Wrong result: " + result); } std::cout << "Everything's fine!"; diff --git a/examples/cmake_with_data/tests/test_cmake_with_shared_lib.cpp b/examples/cmake_with_data/tests/test_cmake_with_shared_lib.cpp index 0c218b31d..3cc933594 100644 --- a/examples/cmake_with_data/tests/test_cmake_with_shared_lib.cpp +++ b/examples/cmake_with_data/tests/test_cmake_with_shared_lib.cpp @@ -3,19 +3,16 @@ #include #include -void test_opening_file(std::string path) -{ +void test_opening_file(std::string path) { std::ifstream data_file(path); - if (!data_file.good()) - { + if (!data_file.good()) { throw std::runtime_error("Could not open file: " + path); } data_file.close(); } -int main(int argc, char* argv[]) -{ +int main(int argc, char* argv[]) { // Make sure the expectd shared library is available #ifdef _WIN32 test_opening_file(".\\cmake_with_data\\lib_b\\lib_b.dll"); diff --git a/examples/cmake_with_target/src/lib.cpp b/examples/cmake_with_target/src/lib.cpp index c967c7ae2..024c68c8d 100644 --- a/examples/cmake_with_target/src/lib.cpp +++ b/examples/cmake_with_target/src/lib.cpp @@ -10,7 +10,4 @@ #error This error intentionally prevents this library from compiling #endif -void hello_world() -{ - std::cout << "Hello world!" << std::endl; -} +void hello_world() { std::cout << "Hello world!" << std::endl; } diff --git a/examples/cmake_working_dir/source_root/src/liba.cpp b/examples/cmake_working_dir/source_root/src/liba.cpp index 773d903b0..061f48810 100644 --- a/examples/cmake_working_dir/source_root/src/liba.cpp +++ b/examples/cmake_working_dir/source_root/src/liba.cpp @@ -1,5 +1,3 @@ #include "liba.h" -std::string hello_liba(void) { - return "Hello from LIBA!"; -} +std::string hello_liba(void) { return "Hello from LIBA!"; } diff --git a/examples/cmake_working_dir/source_root/src/liba.h b/examples/cmake_working_dir/source_root/src/liba.h index 610c2e6fa..58c231398 100644 --- a/examples/cmake_working_dir/source_root/src/liba.h +++ b/examples/cmake_working_dir/source_root/src/liba.h @@ -2,6 +2,7 @@ #define LIBA_H_ (1) #include + #include std::string hello_liba(void); diff --git a/examples/cmake_working_dir/test_liba.cpp b/examples/cmake_working_dir/test_liba.cpp index 38dd79e6a..7a6b3b2e1 100644 --- a/examples/cmake_working_dir/test_liba.cpp +++ b/examples/cmake_working_dir/test_liba.cpp @@ -1,14 +1,13 @@ -#include "liba.h" - #include #include #include -int main(int argc, char* argv[]) -{ - std:: string result = hello_liba(); - if (result != "Hello from LIBA!") { - throw std::runtime_error("Wrong result: " + result); - } - std::cout << "Everything's fine!"; +#include "liba.h" + +int main(int argc, char* argv[]) { + std::string result = hello_liba(); + if (result != "Hello from LIBA!") { + throw std::runtime_error("Wrong result: " + result); + } + std::cout << "Everything's fine!"; } diff --git a/examples/configure_modify_input_source/simple_lib/include/simple.h b/examples/configure_modify_input_source/simple_lib/include/simple.h index 9caccba58..aee4446c1 100644 --- a/examples/configure_modify_input_source/simple_lib/include/simple.h +++ b/examples/configure_modify_input_source/simple_lib/include/simple.h @@ -3,4 +3,4 @@ int simpleFun(void); -#endif // SIMPLE_H_ +#endif // SIMPLE_H_ diff --git a/examples/configure_modify_input_source/simple_lib/src/simple.c b/examples/configure_modify_input_source/simple_lib/src/simple.c index dbec161a8..1d76ffd64 100644 --- a/examples/configure_modify_input_source/simple_lib/src/simple.c +++ b/examples/configure_modify_input_source/simple_lib/src/simple.c @@ -1,5 +1,3 @@ #include "simple.h" -int simpleFun(void) { - return 42; -} +int simpleFun(void) { return 42; } diff --git a/examples/configure_modify_input_source/testSimple.c b/examples/configure_modify_input_source/testSimple.c index 507b20a17..c11c9352f 100644 --- a/examples/configure_modify_input_source/testSimple.c +++ b/examples/configure_modify_input_source/testSimple.c @@ -1,5 +1,3 @@ #include "simple.h" -int main(int argc, char **argv) { - return simpleFun(); -} +int main(int argc, char **argv) { return simpleFun(); } diff --git a/examples/configure_with_bazel_transitive/builtWithBazel.c b/examples/configure_with_bazel_transitive/builtWithBazel.c index 0f1fc9dbe..d5feac23a 100644 --- a/examples/configure_with_bazel_transitive/builtWithBazel.c +++ b/examples/configure_with_bazel_transitive/builtWithBazel.c @@ -1,5 +1,3 @@ #include "builtWithBazel.h" -char* bazelSays(void) { - return "It's me, Bazel!"; -} +char* bazelSays(void) { return "It's me, Bazel!"; } diff --git a/examples/configure_with_bazel_transitive/builtWithBazel.h b/examples/configure_with_bazel_transitive/builtWithBazel.h index 831557c2a..df5ebcaf2 100644 --- a/examples/configure_with_bazel_transitive/builtWithBazel.h +++ b/examples/configure_with_bazel_transitive/builtWithBazel.h @@ -3,4 +3,4 @@ char* bazelSays(void); -#endif // BUILT_WITH_BAZEL_H_ +#endif // BUILT_WITH_BAZEL_H_ diff --git a/examples/configure_with_bazel_transitive/simple_lib/include/simple.h b/examples/configure_with_bazel_transitive/simple_lib/include/simple.h index b2edf4739..85e8f8a57 100644 --- a/examples/configure_with_bazel_transitive/simple_lib/include/simple.h +++ b/examples/configure_with_bazel_transitive/simple_lib/include/simple.h @@ -3,4 +3,4 @@ void simpleFun(void); -#endif // SIMPLE_H_ +#endif // SIMPLE_H_ diff --git a/examples/configure_with_bazel_transitive/simple_lib/src/simple.c b/examples/configure_with_bazel_transitive/simple_lib/src/simple.c index 1d69dda14..4fe0648ea 100644 --- a/examples/configure_with_bazel_transitive/simple_lib/src/simple.c +++ b/examples/configure_with_bazel_transitive/simple_lib/src/simple.c @@ -1,7 +1,7 @@ -#include #include "simple.h" + +#include + #include "builtWithBazel.h" -void simpleFun(void) { - printf("simpleFun: %s", bazelSays()); -} +void simpleFun(void) { printf("simpleFun: %s", bazelSays()); } diff --git a/examples/configure_with_bazel_transitive/testSimple.c b/examples/configure_with_bazel_transitive/testSimple.c index 9bc5a28c6..d47d44677 100644 --- a/examples/configure_with_bazel_transitive/testSimple.c +++ b/examples/configure_with_bazel_transitive/testSimple.c @@ -1,9 +1,10 @@ #include + #include "builtWithBazel.h" #include "simple.h" int main(int argc, char **argv) { - printf("Call bazelSays() directly: %s\n", bazelSays()); - simpleFun(); - return 0; + printf("Call bazelSays() directly: %s\n", bazelSays()); + simpleFun(); + return 0; } diff --git a/examples/make_simple/code/liba.cpp b/examples/make_simple/code/liba.cpp index ab1b3d28e..d76518776 100644 --- a/examples/make_simple/code/liba.cpp +++ b/examples/make_simple/code/liba.cpp @@ -7,13 +7,11 @@ #error "REQUIRED_DEFINE is not defined" #endif -std::string hello_liba(void) { - return "Hello from LIBA!"; -} +std::string hello_liba(void) { return "Hello from LIBA!"; } double hello_math(double a) { - // On Unix, this call requires linking to libm.so. The Bazel toolchain adds - // the required `-lm` linkopt automatically and rules_foreign_cc forwards - // this option to make invocation via the CXXFLAGS variable. - return acos(a); + // On Unix, this call requires linking to libm.so. The Bazel toolchain adds + // the required `-lm` linkopt automatically and rules_foreign_cc forwards + // this option to make invocation via the CXXFLAGS variable. + return acos(a); } diff --git a/examples/make_simple/code/liba.h b/examples/make_simple/code/liba.h index a537dccc7..ad9be90f2 100644 --- a/examples/make_simple/code/liba.h +++ b/examples/make_simple/code/liba.h @@ -2,6 +2,7 @@ #define LIBA_H_ (1) #include + #include std::string hello_liba(void); diff --git a/examples/make_simple/test_libb.cpp b/examples/make_simple/test_libb.cpp index c4e60c5a5..5e5bd3b79 100644 --- a/examples/make_simple/test_libb.cpp +++ b/examples/make_simple/test_libb.cpp @@ -1,18 +1,18 @@ -#include "liba.h" - #include -#include #include +#include + +#include "liba.h" -int main(int argc, char* argv[]) -{ - std::string result = hello_liba(); - if (result != "Hello from LIBA!") { - throw std::runtime_error("Wrong result: " + result); - } - double math_result = hello_math(0.5); - if (math_result < 1.047 || math_result > 1.048) { - throw std::runtime_error("Wrong math_result: " + std::to_string(math_result)); - } - std::cout << "Everything's fine!"; +int main(int argc, char* argv[]) { + std::string result = hello_liba(); + if (result != "Hello from LIBA!") { + throw std::runtime_error("Wrong result: " + result); + } + double math_result = hello_math(0.5); + if (math_result < 1.047 || math_result > 1.048) { + throw std::runtime_error("Wrong math_result: " + + std::to_string(math_result)); + } + std::cout << "Everything's fine!"; } diff --git a/examples/ninja_simple/code/liba.cpp b/examples/ninja_simple/code/liba.cpp index 6dfcbdbc9..061f48810 100644 --- a/examples/ninja_simple/code/liba.cpp +++ b/examples/ninja_simple/code/liba.cpp @@ -1,5 +1,3 @@ #include "liba.h" -std::string hello_liba(void) { - return "Hello from LIBA!"; -} +std::string hello_liba(void) { return "Hello from LIBA!"; } diff --git a/examples/ninja_simple/code/liba.h b/examples/ninja_simple/code/liba.h index 610c2e6fa..58c231398 100644 --- a/examples/ninja_simple/code/liba.h +++ b/examples/ninja_simple/code/liba.h @@ -2,6 +2,7 @@ #define LIBA_H_ (1) #include + #include std::string hello_liba(void); diff --git a/examples/ninja_simple/test_libb.cpp b/examples/ninja_simple/test_libb.cpp index 3e5dbb806..7a6b3b2e1 100644 --- a/examples/ninja_simple/test_libb.cpp +++ b/examples/ninja_simple/test_libb.cpp @@ -1,14 +1,12 @@ -#include "liba.h" - #include #include #include -int main(int argc, char* argv[]) -{ +#include "liba.h" + +int main(int argc, char* argv[]) { std::string result = hello_liba(); - if (result != "Hello from LIBA!") - { + if (result != "Hello from LIBA!") { throw std::runtime_error("Wrong result: " + result); } std::cout << "Everything's fine!"; diff --git a/examples/third_party/cares/c-ares-test.cpp b/examples/third_party/cares/c-ares-test.cpp index 791890ade..6dc9473c9 100644 --- a/examples/third_party/cares/c-ares-test.cpp +++ b/examples/third_party/cares/c-ares-test.cpp @@ -1,15 +1,15 @@ -#include "ares.h" +#include #include #include -#include -int main(int argc, char* argv[]) -{ - int version = 0; - const char* strVersion = ares_version(&version); - if (strcmp(strVersion, "1.14.0") != 0) { - throw std::runtime_error("Wrong version: " + std::string(strVersion)); - } - std::cout << "C-ares version: " << strVersion; +#include "ares.h" + +int main(int argc, char* argv[]) { + int version = 0; + const char* strVersion = ares_version(&version); + if (strcmp(strVersion, "1.14.0") != 0) { + throw std::runtime_error("Wrong version: " + std::string(strVersion)); + } + std::cout << "C-ares version: " << strVersion; } diff --git a/examples/third_party/curl/curl_test.cc b/examples/third_party/curl/curl_test.cc index 77fde9aac..3875250a6 100644 --- a/examples/third_party/curl/curl_test.cc +++ b/examples/third_party/curl/curl_test.cc @@ -6,12 +6,13 @@ // Use (void) to silent unused warnings. #define assertm(exp, msg) assert(((void)msg, exp)) -int main(int argc, char* argv[]) -{ +int main(int argc, char* argv[]) { curl_version_info_data* data = curl_version_info(CURLVERSION_NOW); - assertm(std::string(data->version) == std::string("7.74.0"), "The version of curl does not match the expected version"); - assertm(std::string(data->ssl_version) == std::string("OpenSSL/1.1.1o"), "The version of openssl does not match the expected version"); + assertm(std::string(data->version) == std::string("7.74.0"), + "The version of curl does not match the expected version"); + assertm(std::string(data->ssl_version) == std::string("OpenSSL/1.1.1o"), + "The version of openssl does not match the expected version"); return 0; } diff --git a/examples/third_party/gperftools/malloc_test.cc b/examples/third_party/gperftools/malloc_test.cc index 5a0f1ebdc..7050032bf 100644 --- a/examples/third_party/gperftools/malloc_test.cc +++ b/examples/third_party/gperftools/malloc_test.cc @@ -1,6 +1,3 @@ #include -int main(int argc, char* argv[]) -{ - std::cout << "Hi there!"; -} +int main(int argc, char* argv[]) { std::cout << "Hi there!"; } diff --git a/examples/third_party/libpng/libpng_usage_example.cpp b/examples/third_party/libpng/libpng_usage_example.cpp index be878696c..5d00935ca 100644 --- a/examples/third_party/libpng/libpng_usage_example.cpp +++ b/examples/third_party/libpng/libpng_usage_example.cpp @@ -16,10 +16,11 @@ * */ -#include #include +#include #define PNG_DEBUG 3 #include + #include int width, height; @@ -28,131 +29,123 @@ png_byte bit_depth; png_bytep *row_pointers; void read_png_file(char *filename) { - FILE *fp = fopen(filename, "rb"); + FILE *fp = fopen(filename, "rb"); - png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if(!png) { - abort(); - } + png_structp png = + png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png) { + abort(); + } - png_infop info = png_create_info_struct(png); - if(!info) { - abort(); - } + png_infop info = png_create_info_struct(png); + if (!info) { + abort(); + } - if(setjmp(png_jmpbuf(png))) { - abort(); - } + if (setjmp(png_jmpbuf(png))) { + abort(); + } - png_init_io(png, fp); + png_init_io(png, fp); - png_read_info(png, info); + png_read_info(png, info); - width = png_get_image_width(png, info); - height = png_get_image_height(png, info); - color_type = png_get_color_type(png, info); - bit_depth = png_get_bit_depth(png, info); + width = png_get_image_width(png, info); + height = png_get_image_height(png, info); + color_type = png_get_color_type(png, info); + bit_depth = png_get_bit_depth(png, info); - // Read any color_type into 8bit depth, RGBA format. - // See http://www.libpng.org/pub/png/libpng-manual.txt + // Read any color_type into 8bit depth, RGBA format. + // See http://www.libpng.org/pub/png/libpng-manual.txt - if(bit_depth == 16) - png_set_strip_16(png); + if (bit_depth == 16) png_set_strip_16(png); - if(color_type == PNG_COLOR_TYPE_PALETTE) - png_set_palette_to_rgb(png); + if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png); - // PNG_COLOR_TYPE_GRAY_ALPHA is always 8 or 16bit depth. - if(color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) - png_set_expand_gray_1_2_4_to_8(png); + // PNG_COLOR_TYPE_GRAY_ALPHA is always 8 or 16bit depth. + if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) + png_set_expand_gray_1_2_4_to_8(png); - if(png_get_valid(png, info, PNG_INFO_tRNS)) - png_set_tRNS_to_alpha(png); + if (png_get_valid(png, info, PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png); - // These color_type don't have an alpha channel then fill it with 0xff. - if(color_type == PNG_COLOR_TYPE_RGB || - color_type == PNG_COLOR_TYPE_GRAY || - color_type == PNG_COLOR_TYPE_PALETTE) - png_set_filler(png, 0xFF, PNG_FILLER_AFTER); + // These color_type don't have an alpha channel then fill it with 0xff. + if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_PALETTE) + png_set_filler(png, 0xFF, PNG_FILLER_AFTER); - if(color_type == PNG_COLOR_TYPE_GRAY || - color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - png_set_gray_to_rgb(png); + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_gray_to_rgb(png); - png_read_update_info(png, info); + png_read_update_info(png, info); - row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * height); - for(int y = 0; y < height; y++) { - row_pointers[y] = (png_byte*)malloc(png_get_rowbytes(png,info)); - } + row_pointers = (png_bytep *)malloc(sizeof(png_bytep) * height); + for (int y = 0; y < height; y++) { + row_pointers[y] = (png_byte *)malloc(png_get_rowbytes(png, info)); + } - png_read_image(png, row_pointers); + png_read_image(png, row_pointers); - fclose(fp); + fclose(fp); } void write_png_file(char *filename) { - FILE *fp = fopen(filename, "wb"); - if(!fp) abort(); + FILE *fp = fopen(filename, "wb"); + if (!fp) abort(); - png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (!png) abort(); + png_structp png = + png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png) abort(); - png_infop info = png_create_info_struct(png); - if (!info) abort(); + png_infop info = png_create_info_struct(png); + if (!info) abort(); - if (setjmp(png_jmpbuf(png))) abort(); + if (setjmp(png_jmpbuf(png))) abort(); - png_init_io(png, fp); + png_init_io(png, fp); - // Output is 8bit depth, RGBA format. - png_set_IHDR( - png, - info, - width, height, - 8, - PNG_COLOR_TYPE_RGBA, - PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, - PNG_FILTER_TYPE_DEFAULT - ); - png_write_info(png, info); + // Output is 8bit depth, RGBA format. + png_set_IHDR(png, info, width, height, 8, PNG_COLOR_TYPE_RGBA, + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, + PNG_FILTER_TYPE_DEFAULT); + png_write_info(png, info); - // To remove the alpha channel for PNG_COLOR_TYPE_RGB format, - // Use png_set_filler(). - //png_set_filler(png, 0, PNG_FILLER_AFTER); + // To remove the alpha channel for PNG_COLOR_TYPE_RGB format, + // Use png_set_filler(). + // png_set_filler(png, 0, PNG_FILLER_AFTER); - png_write_image(png, row_pointers); - png_write_end(png, NULL); + png_write_image(png, row_pointers); + png_write_end(png, NULL); - for(int y = 0; y < height; y++) { - free(row_pointers[y]); - } - free(row_pointers); + for (int y = 0; y < height; y++) { + free(row_pointers[y]); + } + free(row_pointers); - fclose(fp); + fclose(fp); } void process_png_file() { - for(int y = 0; y < height; y++) { - png_bytep row = row_pointers[y]; - for(int x = 0; x < width; x++) { - png_bytep px = &(row[x * 4]); - px[0] = 112; - // Do something awesome for each pixel here... -// printf("%4d, %4d = RGBA(%3d, %3d, %3d, %3d)\n", x, y, px[0], px[1], px[2], px[3]); + for (int y = 0; y < height; y++) { + png_bytep row = row_pointers[y]; + for (int x = 0; x < width; x++) { + png_bytep px = &(row[x * 4]); + px[0] = 112; + // Do something awesome for each pixel here... + // printf("%4d, %4d = RGBA(%3d, %3d, %3d, %3d)\n", x, y, px[0], + // px[1], px[2], px[3]); + } } - } } int main(int argc, char *argv[]) { - if(argc != 3) { - abort(); - } + if (argc != 3) { + abort(); + } - read_png_file(argv[1]); - process_png_file(); - write_png_file(argv[2]); + read_png_file(argv[1]); + process_png_file(); + write_png_file(argv[2]); - return 0; + return 0; } diff --git a/examples/third_party/openssl/openssl_test.cc b/examples/third_party/openssl/openssl_test.cc index 611f7b132..b5fae4ad6 100644 --- a/examples/third_party/openssl/openssl_test.cc +++ b/examples/third_party/openssl/openssl_test.cc @@ -9,28 +9,22 @@ #define assertm(exp, msg) assert(((void)msg, exp)) // From https://stackoverflow.com/a/2262447/7768383 -bool simpleSHA256(const void* input, unsigned long length, unsigned char* md) -{ +bool simpleSHA256(const void* input, unsigned long length, unsigned char* md) { SHA256_CTX context; - if (!SHA256_Init(&context)) - return false; + if (!SHA256_Init(&context)) return false; - if (!SHA256_Update(&context, (unsigned char*)input, length)) - return false; + if (!SHA256_Update(&context, (unsigned char*)input, length)) return false; - if (!SHA256_Final(md, &context)) - return false; + if (!SHA256_Final(md, &context)) return false; return true; } // Convert an byte array into a string -std::string fromByteArray(const unsigned char* data, unsigned long length) -{ +std::string fromByteArray(const unsigned char* data, unsigned long length) { std::stringstream shastr; shastr << std::hex << std::setfill('0'); - for (unsigned long i = 0; i < length; ++i) - { + for (unsigned long i = 0; i < length; ++i) { shastr << std::setw(2) << static_cast(data[i]); } @@ -38,13 +32,15 @@ std::string fromByteArray(const unsigned char* data, unsigned long length) } std::string MESSAGE = "hello world"; -std::string MESSAGE_HASH = "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"; +std::string MESSAGE_HASH = + "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"; -int main(int argc, char* argv[]) -{ +int main(int argc, char* argv[]) { unsigned char md[SHA256_DIGEST_LENGTH] = {}; - assertm(simpleSHA256(static_cast(MESSAGE.data()), MESSAGE.size(), md), "Failed to generate hash"); + assertm(simpleSHA256(static_cast(MESSAGE.data()), + MESSAGE.size(), md), + "Failed to generate hash"); std::string hash = fromByteArray(md, SHA256_DIGEST_LENGTH); assertm(hash == MESSAGE_HASH, "Unexpected message hash"); diff --git a/examples/third_party/zlib/zlib-example.cpp b/examples/third_party/zlib/zlib-example.cpp index bef3d2ac7..b1ad1361f 100644 --- a/examples/third_party/zlib/zlib-example.cpp +++ b/examples/third_party/zlib/zlib-example.cpp @@ -1,13 +1,14 @@ // Copied from https://gist.github.com/arq5x/5315739 for test purposes +#include #include #include // for strlen -#include + #include "zlib.h" -// adapted from: http://stackoverflow.com/questions/7540259/deflate-and-inflate-zlib-h-in-c -int main(int argc, char* argv[]) -{ +// adapted from: +// http://stackoverflow.com/questions/7540259/deflate-and-inflate-zlib-h-in-c +int main(int argc, char *argv[]) { // original string len = 36 char a[50] = "Hello Hello Hello Hello Hello Hello!"; @@ -17,11 +18,9 @@ int main(int argc, char* argv[]) // placeholder for the UNcompressed (inflated) version of "b" char c[50]; - printf("Uncompressed size is: %lu\n", strlen(a)); printf("Uncompressed string is: %s\n", a); - printf("\n----------\n\n"); // STEP 1. @@ -33,10 +32,11 @@ int main(int argc, char* argv[]) defstream.zfree = Z_NULL; defstream.opaque = Z_NULL; // setup "a" as the input and "b" as the compressed output - defstream.avail_in = (uInt)strlen(a)+1; // size of input, string + terminator - defstream.next_in = (Bytef *)a; // input char array - defstream.avail_out = (uInt)sizeof(b); // size of output - defstream.next_out = (Bytef *)b; // output char array + defstream.avail_in = + (uInt)strlen(a) + 1; // size of input, string + terminator + defstream.next_in = (Bytef *)a; // input char array + defstream.avail_out = (uInt)sizeof(b); // size of output + defstream.next_out = (Bytef *)b; // output char array // the actual compression work. deflateInit(&defstream, Z_BEST_COMPRESSION); @@ -47,10 +47,8 @@ int main(int argc, char* argv[]) printf("Compressed size is: %lu\n", strlen(b)); printf("Compressed string is: %s\n", b); - printf("\n----------\n\n"); - // STEP 2. // inflate b into c // zlib struct @@ -59,10 +57,11 @@ int main(int argc, char* argv[]) infstream.zfree = Z_NULL; infstream.opaque = Z_NULL; // setup "b" as the input and "c" as the compressed output - infstream.avail_in = (uInt)((char*)defstream.next_out - b); // size of input - infstream.next_in = (Bytef *)b; // input char array - infstream.avail_out = (uInt)sizeof(c); // size of output - infstream.next_out = (Bytef *)c; // output char array + infstream.avail_in = + (uInt)((char *)defstream.next_out - b); // size of input + infstream.next_in = (Bytef *)b; // input char array + infstream.avail_out = (uInt)sizeof(c); // size of output + infstream.next_out = (Bytef *)c; // output char array // the actual DE-compression work. inflateInit(&infstream); @@ -72,9 +71,8 @@ int main(int argc, char* argv[]) printf("Uncompressed size is: %lu\n", strlen(c)); printf("Uncompressed string is: %s\n", c); - // make sure uncompressed is exactly equal to original. - assert(strcmp(a,c)==0); + assert(strcmp(a, c) == 0); return 0; } From 1930456dffaa2db00d0bb21dd02ac401f9517092 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Wed, 1 Jan 2025 08:47:46 -0800 Subject: [PATCH 2/2] keep in sync --- .bazelci/config.yaml | 1 + .pre-commit-config.yaml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.bazelci/config.yaml b/.bazelci/config.yaml index 691fbc464..3bf609560 100644 --- a/.bazelci/config.yaml +++ b/.bazelci/config.yaml @@ -252,5 +252,6 @@ tasks: test_targets: *min_supported_targets buildifier: + version: "7.3.1" # keep this argument in sync with .pre-commit-config.yaml warnings: "all" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6ad0b37d7..69b9f4df2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: - id: check-yaml - repo: https://github.com/keith/pre-commit-buildifier - rev: 6.1.0.1 + rev: 7.3.1.1 hooks: - id: buildifier args: &args