summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrafa_99 <rafa99@protonmail.com>2020-12-04 03:31:45 +0000
committerrafa_99 <rafa99@protonmail.com>2020-12-04 03:31:45 +0000
commit7be4deeee60d11e3ae09ddef1147b2a93b183d88 (patch)
treeb566529d788449442b95fe6a2f0ec41e657a7c45
parent650fb220913f79b5016dcfe1e497493619bf6fa2 (diff)
Pushed Working Board
-rw-r--r--Makefile15
-rw-r--r--README.md23
-rw-r--r--images/image.pngbin0 -> 4185545 bytes
-rw-r--r--logo.pngbin0 -> 37120 bytes
-rw-r--r--ouija.c6
-rw-r--r--session.c22
-rw-r--r--utils.c17
-rw-r--r--utils.h3
8 files changed, 70 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index f22e98e..744a229 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,13 @@
build: clean
- gcc -o ouija ouija.c session.c utils.c
-
-debug: clean
- gcc -g -o ouija ouija.c session.c utils.c
+ cc -o ouija ouija.c session.c utils.c
clean:
- rm -rf ouija
+ rm -rf ouija
+
+install: build
+ mkdir -p /usr/local/bin
+ cp -f ouija /usr/local/bin
+ chmod 755 /usr/local/bin
+
+uninstall:
+ rm -rf /usr/local/bin/ouija
diff --git a/README.md b/README.md
index d564471..2f5cdb8 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,25 @@
# Ouija Board
+Just a ouija board based on time and question randomness
+## Inspiration
+Inspired by Terry Davis TempleOS Timer Random Tongues which he used to communicate with God.
+
+Since TRT was written in HolyC and this random word generator is written in C I decided to call it a Ouija Board.
+
+![TempleOS Timer Random Tongues](images/image.png)
+
+## How to Use
+
+### Compile
+#### Portable
+`make`
+
+#### Installable
+`make install`
+
+### Run
+If you already have a `dictionary.dict` file in your path, just run:
+`ouija`
+
+If you have the file saved in another folder, just type:
+`ouija /path/to/dictionary`
diff --git a/images/image.png b/images/image.png
new file mode 100644
index 0000000..34e58e0
--- /dev/null
+++ b/images/image.png
Binary files differ
diff --git a/logo.png b/logo.png
new file mode 100644
index 0000000..8681e3b
--- /dev/null
+++ b/logo.png
Binary files differ
diff --git a/ouija.c b/ouija.c
index 44e6cc9..aab31c5 100644
--- a/ouija.c
+++ b/ouija.c
@@ -1,6 +1,6 @@
-#include "session.h"
#include <stdio.h>
#include <stdlib.h>
+#include "session.h"
int main(int argc, char **argv)
{
@@ -27,6 +27,10 @@ int main(int argc, char **argv)
startSession(dictionary);
fclose(dictionary);
}
+ else
+ {
+ printf("No Dictionary Found\n");
+ }
return 0;
}
diff --git a/session.c b/session.c
index b04958d..205e92f 100644
--- a/session.c
+++ b/session.c
@@ -8,15 +8,25 @@ void startSession(FILE *dictionary)
if ( dictionary != NULL )
{
int totalWords = lineCounter(dictionary);
- char *word;
+ char *word, *question = (char *) calloc(MAX_LINE, sizeof(char));;
char reload = '\0';
- while( reload != 'q' )
+ printf("WELCOME\n"
+ "Type GOODBYE to exit\n\n");
+
+ while( strcmp(question, "GOODBYE\n") != 0 )
{
- word = getLine(dictionary, getRandomNumber(1, totalWords));
- printf("%s", word);
- free(word);
- reload = getchar();
+ printf("Enter a question: ");
+ fgets(question, MAX_LINE, stdin);
+
+ if ( strcmp(question, "GOODBYE\n") != 0 )
+ {
+ word = getLine(dictionary, getRandomNumber(1, totalWords, question));
+ printf("-> %s", word);
+ free(word);
+ }
}
+
+ free(question);
}
}
diff --git a/utils.c b/utils.c
index 49a6069..e349368 100644
--- a/utils.c
+++ b/utils.c
@@ -1,7 +1,8 @@
#include <stdio.h>
-#include <unistd.h>
#include <stdlib.h>
+#include <string.h>
#include <time.h>
+#include <unistd.h>
#include <sys/time.h>
#include "utils.h"
@@ -10,6 +11,16 @@ int checkIfFileExists(char *path)
return access(path, F_OK);
}
+int numerize(char *string)
+{
+ int val = 0;
+ for( int i = 0; i < strlen(string); i++ )
+ {
+ val += string[i];
+ }
+ return val;
+}
+
int lineCounter(FILE *dictionary)
{
int words = 0;
@@ -41,12 +52,12 @@ char* getLine(FILE *dictionary, int lineNumber)
return line;
}
-int getRandomNumber(int min, int max)
+int getRandomNumber(int min, int max, char *question)
{
// Adding Randomize Time Values for Less Chances of Running into Seed Collisions
struct timeval randtime;
gettimeofday(&randtime,NULL);
- srand((randtime.tv_sec * 100 + time(NULL)) + (randtime.tv_usec / 100 - time(NULL)));
+ srand(((randtime.tv_sec * 100) + time(NULL) * numerize(question)) + ((randtime.tv_usec / 100) - time(NULL) * numerize(question)));
return ((rand() % (max - min + 1)) + 1);
}
diff --git a/utils.h b/utils.h
index 0b72df4..6cfbc80 100644
--- a/utils.h
+++ b/utils.h
@@ -3,6 +3,7 @@
#define MAX_LINE 256
int checkIfFileExists(char *path);
+int numerize(char *string);
int lineCounter(FILE *dictionary);
char* getLine(FILE *dictionary, int line);
-int getRandomNumber(int min, int max);
+int getRandomNumber(int min, int max, char *question);