diff options
| -rw-r--r-- | .clang-format | 45 | ||||
| -rw-r--r-- | .clang-tidy | 19 | ||||
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | compile_flags.txt | 4 | ||||
| -rw-r--r-- | config.mk | 2 | ||||
| -rw-r--r-- | makefile | 24 | ||||
| -rw-r--r-- | src/simple.c | 77 |
7 files changed, 173 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..21efcac --- /dev/null +++ b/.clang-format | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | --- | ||
| 2 | AccessModifierOffset: -4 | ||
| 3 | AlignConsecutiveAssignments: 'true' | ||
| 4 | AlignConsecutiveDeclarations: 'true' | ||
| 5 | AlignEscapedNewlines: Left | ||
| 6 | AlignTrailingComments: 'true' | ||
| 7 | AlwaysBreakAfterReturnType: TopLevelDefinitions | ||
| 8 | BreakBeforeBraces: Stroustrup | ||
| 9 | BreakConstructorInitializers: BeforeComma | ||
| 10 | BreakInheritanceList: BeforeComma | ||
| 11 | ColumnLimit: '0' | ||
| 12 | CompactNamespaces: 'false' | ||
| 13 | Cpp11BracedListStyle: 'false' | ||
| 14 | FixNamespaceComments: 'true' | ||
| 15 | IncludeBlocks: Regroup | ||
| 16 | IncludeCategories: | ||
| 17 | - Regex: '^.*(precomp|pch|stdafx)' | ||
| 18 | Priority: -1 | ||
| 19 | - Regex: '^<.*>' | ||
| 20 | Priority: 1 | ||
| 21 | - Regex: '^".*"' | ||
| 22 | Priority: 2 | ||
| 23 | - Regex: '.*' | ||
| 24 | Priority: 3 | ||
| 25 | IndentCaseLabels: 'false' | ||
| 26 | IndentPPDirectives: AfterHash | ||
| 27 | IndentWidth: '4' | ||
| 28 | IndentWrappedFunctionNames: 'false' | ||
| 29 | KeepEmptyLinesAtTheStartOfBlocks: 'false' | ||
| 30 | PointerAlignment: Right | ||
| 31 | SortIncludes: 'true' | ||
| 32 | SpaceAfterCStyleCast: 'true' | ||
| 33 | SpaceAfterTemplateKeyword: 'false' | ||
| 34 | SpaceBeforeAssignmentOperators: 'true' | ||
| 35 | SpaceBeforeParens: ControlStatements | ||
| 36 | SpaceBeforeRangeBasedForLoopColon: 'false' | ||
| 37 | SpaceInEmptyParentheses: 'false' | ||
| 38 | SpacesInAngles: 'false' | ||
| 39 | SpacesInCStyleCastParentheses: 'false' | ||
| 40 | SpacesInConditionalStatement: 'true' | ||
| 41 | SpacesInParentheses: 'false' | ||
| 42 | Standard: Auto | ||
| 43 | TabWidth: '4' | ||
| 44 | UseTab: ForIndentation | ||
| 45 | ... | ||
diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..0bceb5b --- /dev/null +++ b/.clang-tidy | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | --- | ||
| 2 | Checks: "*, | ||
| 3 | -abseil-*, | ||
| 4 | -altera-*, | ||
| 5 | -android-*, | ||
| 6 | -fuchsia-*, | ||
| 7 | -google-*, | ||
| 8 | -llvm*, | ||
| 9 | -modernize-use-trailing-return-type, | ||
| 10 | -zircon-*, | ||
| 11 | -readability-else-after-return, | ||
| 12 | -readability-static-accessed-through-instance, | ||
| 13 | -readability-avoid-const-params-in-decls, | ||
| 14 | -cppcoreguidelines-non-private-member-variables-in-classes, | ||
| 15 | -misc-non-private-member-variables-in-classes, | ||
| 16 | " | ||
| 17 | WarningsAsErrors: '' | ||
| 18 | HeaderFilterRegex: '' | ||
| 19 | FormatStyle: none | ||
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd42ee3 --- /dev/null +++ b/.gitignore | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | bin/ | ||
| 2 | obj/ | ||
diff --git a/compile_flags.txt b/compile_flags.txt new file mode 100644 index 0000000..d87afcf --- /dev/null +++ b/compile_flags.txt | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | -Wall | ||
| 2 | -Werror | ||
| 3 | -pedantic | ||
| 4 | -std=c99 | ||
diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..bf800da --- /dev/null +++ b/config.mk | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | CFLAGS=-Wall -Werror -pedantic -std=c99 | ||
| 2 | LDFLAGS=-lz | ||
diff --git a/makefile b/makefile new file mode 100644 index 0000000..4ce05bc --- /dev/null +++ b/makefile | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | include config.mk | ||
| 2 | |||
| 3 | SIMPLE=bin/simple | ||
| 4 | SIMPLE_OBJ_FILES=obj/simple.o | ||
| 5 | |||
| 6 | release: $(SIMPLE) | ||
| 7 | release: CFLAGS+=-DNDEBUG -O2 | ||
| 8 | |||
| 9 | debug: $(SIMPLE) | ||
| 10 | debug: CFLAGS+=-g | ||
| 11 | |||
| 12 | $(SIMPLE): $(SIMPLE_OBJ_FILES) | bin | ||
| 13 | cc $(LDFLAGS) $^ -o $@ | ||
| 14 | |||
| 15 | obj/%.o: src/%.c | obj | ||
| 16 | cc $(CFLAGS) -c $< -o $@ | ||
| 17 | |||
| 18 | bin obj: | ||
| 19 | mkdir -p $@ | ||
| 20 | |||
| 21 | clean: | ||
| 22 | rm -rf bin obj | ||
| 23 | |||
| 24 | .PHONY: release debug clean | ||
diff --git a/src/simple.c b/src/simple.c new file mode 100644 index 0000000..5209841 --- /dev/null +++ b/src/simple.c | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | // Standard C | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | |||
| 5 | // System | ||
| 6 | #include <unistd.h> | ||
| 7 | |||
| 8 | // zlib | ||
| 9 | #include <zlib.h> | ||
| 10 | |||
| 11 | static void | ||
| 12 | usage(void) | ||
| 13 | { | ||
| 14 | (void) fprintf(stderr, "compress [-d] infile outfile\n"); | ||
| 15 | exit(EXIT_FAILURE); | ||
| 16 | } | ||
| 17 | |||
| 18 | int | ||
| 19 | main(int argc, char *argv[]) | ||
| 20 | { | ||
| 21 | // int compress = 1; | ||
| 22 | int level = 5; | ||
| 23 | |||
| 24 | int opt = 0; | ||
| 25 | while ( (opt = getopt(argc, argv, "dl")) != -1 ) { | ||
| 26 | switch ( opt ) { | ||
| 27 | case 'd': | ||
| 28 | // compress = 0; // decompress | ||
| 29 | break; | ||
| 30 | |||
| 31 | case 'l': | ||
| 32 | level = 9; | ||
| 33 | break; | ||
| 34 | |||
| 35 | case '?': | ||
| 36 | default: | ||
| 37 | usage(); | ||
| 38 | break; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | argc -= optind; | ||
| 42 | argv += optind; | ||
| 43 | |||
| 44 | if ( argc != 2 ) { | ||
| 45 | usage(); | ||
| 46 | } | ||
| 47 | |||
| 48 | FILE *in_file = fopen(argv[0], "rb"); | ||
| 49 | FILE *out_file = fopen(argv[1], "wb"); | ||
| 50 | |||
| 51 | (void) fseek(in_file, 0, SEEK_END); | ||
| 52 | unsigned long insize = ftell(in_file); // max 2GB... | ||
| 53 | (void) fseek(in_file, 0, SEEK_SET); | ||
| 54 | |||
| 55 | unsigned char *indata = malloc(insize); | ||
| 56 | (void) fread(indata, 1, insize, in_file); | ||
| 57 | |||
| 58 | unsigned long outsize = compressBound(insize); | ||
| 59 | unsigned char *outdata = malloc(outsize); | ||
| 60 | |||
| 61 | int res = compress2(outdata, &outsize, indata, insize, level); | ||
| 62 | |||
| 63 | if ( res == Z_OK ) { | ||
| 64 | (void) fwrite(outdata, 1, outsize, out_file); | ||
| 65 | } | ||
| 66 | else { | ||
| 67 | printf("Error: %d\n", res); | ||
| 68 | } | ||
| 69 | |||
| 70 | free(outdata); | ||
| 71 | free(indata); | ||
| 72 | |||
| 73 | (void) fclose(out_file); | ||
| 74 | (void) fclose(in_file); | ||
| 75 | |||
| 76 | return EXIT_SUCCESS; | ||
| 77 | } | ||
