summaryrefslogtreecommitdiff
path: root/source/ook2bf.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <leo@localhost.localdomain>2016-01-11 20:27:31 -0500
committerLeo Tenenbaum <leo@localhost.localdomain>2016-01-11 20:27:31 -0500
commitc3afbe13e0938ffd21ce0d06dea0f9d6b4b75f69 (patch)
tree46e00ce324711717e0e4b8c455af2be5952fa826 /source/ook2bf.c
Created cOok
Diffstat (limited to 'source/ook2bf.c')
-rw-r--r--source/ook2bf.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/source/ook2bf.c b/source/ook2bf.c
new file mode 100644
index 0000000..dcc8c73
--- /dev/null
+++ b/source/ook2bf.c
@@ -0,0 +1,79 @@
+
+
+
+int isValid(char c)
+{
+ return c == '.' || c == '!' || c == '?';
+}
+
+
+char ook2bfchar(char a, char b)
+{
+ if (a == '.' && b == '?')
+ return '>';
+ if (a == '?' && b == '.')
+ return '<';
+ if (a == '.' && b == '.')
+ return '+';
+ if (a == '!' && b == '!')
+ return '-';
+ if (a == '!' && b == '.')
+ return '.';
+ if (a == '.' && b == '!')
+ return ',';
+ if (a == '!' && b == '?')
+ return '[';
+ if (a == '?' && b == '!')
+ return ']';
+ return '.';
+}
+
+int bfsize(int filesize)
+{
+ int i;
+ int sz = 0;
+ for (i = 3; i < filesize; i+=10)
+ sz++;
+
+ return sz;
+}
+
+int getSize(FILE *fp)
+{
+ fseek(fp, 0L, SEEK_END);
+ int sz = ftell(fp);
+ fseek(fp, 0L, SEEK_SET);
+ return sz;
+}
+
+
+char* ook2bf(char* in_filename)
+{
+
+ FILE* in_file;
+ int filesize;
+ int i;
+
+ in_file = fopen(in_filename, "r");
+
+ filesize = getSize(in_file);
+
+ char ook[filesize];
+ fread(ook, 1, filesize, in_file);
+
+
+
+ fclose(in_file);
+ char* bf = malloc(bfsize(filesize));
+ char c;
+ for (i = 3; (i+5) < filesize; i+=10)
+ {
+ if (!isValid(ook[i]) || !isValid(ook[i+5]))
+ continue;
+ c = ook2bfchar(ook[i], ook[i+5]);
+ bf[(i-3)/10] = c;
+ }
+
+ return bf;
+
+}