diff options
author | EliteTK <tomasz.kramkowski@gmail.com> | 2014-11-08 18:19:05 +0000 |
---|---|---|
committer | EliteTK <tomasz.kramkowski@gmail.com> | 2014-11-08 18:19:05 +0000 |
commit | b59699746fd3afe2390aadbeaa2249a7b84d5cb8 (patch) | |
tree | 72bb91f50391bf2215f5df3b12493410dfe8b43f | |
parent | 59980aebbaaaee28062f9a10b283561c6cd0f2dd (diff) | |
download | c-stuff-b59699746fd3afe2390aadbeaa2249a7b84d5cb8.tar.gz c-stuff-b59699746fd3afe2390aadbeaa2249a7b84d5cb8.tar.xz c-stuff-b59699746fd3afe2390aadbeaa2249a7b84d5cb8.zip |
Wrote license header prefixing tool and added some new code.
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | LICENSE_HEADER (renamed from gpl_header.c) | 0 | ||||
-rw-r--r-- | casting.c | 34 | ||||
-rw-r--r-- | lskdecode.c | 51 | ||||
-rw-r--r-- | makefile | 2 | ||||
-rwxr-xr-x | prefix_header | 7 |
6 files changed, 95 insertions, 1 deletions
@@ -2,5 +2,7 @@ !*.c !*.h !LICENSE +!LICENSE_HEADER +!prefix_header !README.md !makefile diff --git a/gpl_header.c b/LICENSE_HEADER index f038758..f038758 100644 --- a/gpl_header.c +++ b/LICENSE_HEADER diff --git a/casting.c b/casting.c new file mode 100644 index 0000000..9911112 --- /dev/null +++ b/casting.c @@ -0,0 +1,34 @@ + +/* + * Copyright (C) 2014 Tomasz Kramkowski <tk@the-tk.com> + * + * This program is free software. It is licensed under version 3 of the + * GNU General Public License. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see [http://www.gnu.org/licenses/]. + */ +#include <stdio.h> +#include <stdlib.h> + +#define harray(type, name, x, y) type (*name)[y] = malloc(sizeof(type) * x * y) + +int main(int argc, char **argv) +{ + /*int (*test)[5] = malloc(sizeof(int) * 5 * 10);*/ + harray(int, test, 10, 5); + + for (int i = 0; i < 10; i++) + for (int ii = 0; ii < 5; ii++) { + test[i][ii] = i * ii; + printf("%d, ", i * ii); + } + putchar('\n'); + + for (int i = 0; i < 10 * 5; i++) + printf("%d, ", *(((int *)test) + i)); + putchar('\n'); + + free(test); + return 0; +} diff --git a/lskdecode.c b/lskdecode.c new file mode 100644 index 0000000..96ab023 --- /dev/null +++ b/lskdecode.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2014 Tomasz Kramkowski <tk@the-tk.com> + * + * This program is free software. It is licensed under version 3 of the + * GNU General Public License. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see [http://www.gnu.org/licenses/]. + */ +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> + +int main(int argc, char **argv) +{ + unsigned char subst[4][256]; + unsigned char lastval[] = {249, 20, 174, 199}; + + /* Generate substitution tables. */ + for (int i = 0; i < 256; i++) { + for (int ii = 0; ii < 4; ii++) + subst[ii][i] = lastval[ii]; + + if (i % 8 == 7) lastval[0] -= 13; + else lastval[0] += i & 1 ? 3 : -1; + + if (i % 8 == 7) lastval[1] += 9; + else if ((i + 4) % 8 == 7) lastval[1] -=7; + else lastval[1] += 1; + + if (i % 16 == 15) lastval[2] += 29; + else lastval[2] += i & 1 ? -3 : 1; + + if (i % 8 == 7) lastval[3] += 15; + else lastval[3] -= 1; + } + + /* decode */ + int c; + int pos = argc > 1 ? strtol(argv[1], NULL, 10) : 0; + while ((c = getchar()) != EOF) { + for (int i = 0; i < 256; i++) + if (subst[pos%4][i] == c) { + if (isascii(i)) putchar(i); + break; + } + pos++; + } + + return 0; +} @@ -24,4 +24,4 @@ uninstall : rm "$(DESTDIR)$(PREFIX)$(BINDIR)/$(target)" clean : - find . -mindepth 1 -maxdepth 1 -executable -type f -delete + find . -mindepth 1 -maxdepth 1 -executable -type f ! -name "prefix_header" -delete diff --git a/prefix_header b/prefix_header new file mode 100755 index 0000000..f18305e --- /dev/null +++ b/prefix_header @@ -0,0 +1,7 @@ +#! /usr/bin/env bash + +for file in "$@"; do + echo "Processing $file" + cat "LICENSE_HEADER" "$file" >"${file}.LICENSE_HEADER" + mv "${file}.LICENSE_HEADER" "$file" +done |