From 2654b709ab6a673a3f52f781947d6fc2e0606a1c Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Sun, 26 Jul 2020 20:37:46 -0500 Subject: [PATCH] Initial commit --- .gitignore | 3 + importer/importer.pro | 7 + importer/main.c | 115 + puzzles.txt | 14206 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 14331 insertions(+) create mode 100644 .gitignore create mode 100644 importer/importer.pro create mode 100644 importer/main.c create mode 100644 puzzles.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e1508f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build-* +*.dat +*~ diff --git a/importer/importer.pro b/importer/importer.pro new file mode 100644 index 0000000..8b6e209 --- /dev/null +++ b/importer/importer.pro @@ -0,0 +1,7 @@ +TEMPLATE = app +CONFIG += console +CONFIG -= app_bundle +CONFIG -= qt + +SOURCES += \ + main.c diff --git a/importer/main.c b/importer/main.c new file mode 100644 index 0000000..fa650ed --- /dev/null +++ b/importer/main.c @@ -0,0 +1,115 @@ +#include +#include +#include + + +#define MAX_WIDTH 20 +#define MAX_HEIGHT 12 +#define MAX_LINE 8192 + + +int isLegal(char c) { + int x; + char legal[] = { "_# .$@+*" }; + + if (c == '-') c = ' '; + + for (x=0; x<(int)strlen(legal); x++) { + if (legal[x] == c) { + return x + 1; + } + } + return 0; +} + + +int main(int argc, char *argv[]) { + + char puzzle[MAX_WIDTH][MAX_WIDTH]; + char line[MAX_LINE]; // Ooo! Look! Potential buffer overflow! + char height; + unsigned char width; + int16_t x; + int16_t y; + int16_t count = 0; + int32_t bytes = 0; + FILE *in; + FILE *out; + + if (argc != 3) { + printf("%s: [letslogic.txt] [puzzles.dat]\n", argv[0]); + return 1; + } + + in = fopen(argv[1], "rt"); + if (!in) { + printf("Unable to read %s\n", argv[1]); + return 2; + } + + out = fopen(argv[2], "wb"); + if (!out) { + fclose(in); + printf("Unable to write %s\n", argv[2]); + return 2; + } + + // Skip two bytes at the front of the file to later write the puzzle count into. + fputc(0, out); + fputc(0, out); + bytes = 2; + + count = 0; + height = -1; + width = 0; + + while (fgets(line, MAX_LINE, in)) { + // Is there anything on this line? + if (strlen(line) > 0) { + // Is this a puzzle line? + if (isLegal(line[0]) > 0) { + // Got it. Read this line. + if (width < strlen(line)) width = strlen(line); + height++; + for (x=0; x= 0) { + // Yep! Output it! + if ((width & 1) == 1) { + // Width must be even - fill new column with zeros. + for (y=0; y