From b59699746fd3afe2390aadbeaa2249a7b84d5cb8 Mon Sep 17 00:00:00 2001 From: EliteTK Date: Sat, 8 Nov 2014 18:19:05 +0000 Subject: Wrote license header prefixing tool and added some new code. --- .gitignore | 2 ++ LICENSE_HEADER | 9 +++++++++ casting.c | 34 ++++++++++++++++++++++++++++++++++ gpl_header.c | 9 --------- lskdecode.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ makefile | 2 +- prefix_header | 7 +++++++ 7 files changed, 104 insertions(+), 10 deletions(-) create mode 100644 LICENSE_HEADER create mode 100644 casting.c delete mode 100644 gpl_header.c create mode 100644 lskdecode.c create mode 100755 prefix_header diff --git a/.gitignore b/.gitignore index caabbb7..2d55a54 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,7 @@ !*.c !*.h !LICENSE +!LICENSE_HEADER +!prefix_header !README.md !makefile diff --git a/LICENSE_HEADER b/LICENSE_HEADER new file mode 100644 index 0000000..f038758 --- /dev/null +++ b/LICENSE_HEADER @@ -0,0 +1,9 @@ +/* + * Copyright (C) 2014 Tomasz Kramkowski + * + * 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/]. + */ 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 + * + * 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 +#include + +#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/gpl_header.c b/gpl_header.c deleted file mode 100644 index f038758..0000000 --- a/gpl_header.c +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (C) 2014 Tomasz Kramkowski - * - * 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/]. - */ 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 + * + * 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 +#include +#include + +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; +} diff --git a/makefile b/makefile index 6b7de25..4bffe01 100644 --- a/makefile +++ b/makefile @@ -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 -- cgit v1.2.3-54-g00ecf