From a04983a91a70c909c83a7373274d1000ea5b7819 Mon Sep 17 00:00:00 2001 From: Rafael Marçalo Date: Mon, 24 Oct 2022 14:34:21 +0100 Subject: Remake to tongues --- Makefile | 8 ++++---- README.md | 10 ++++------ ouija.c | 38 -------------------------------------- session.c | 2 +- tongues.c | 38 ++++++++++++++++++++++++++++++++++++++ utils.c | 9 ++++----- 6 files changed, 51 insertions(+), 54 deletions(-) delete mode 100644 ouija.c create mode 100644 tongues.c diff --git a/Makefile b/Makefile index 744a229..4cf502d 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ build: clean - cc -o ouija ouija.c session.c utils.c + cc -o trt tongues.c session.c utils.c clean: - rm -rf ouija + rm -rf trt install: build mkdir -p /usr/local/bin - cp -f ouija /usr/local/bin + cp -f trt /usr/local/bin chmod 755 /usr/local/bin uninstall: - rm -rf /usr/local/bin/ouija + rm -rf /usr/local/bin/trt diff --git a/README.md b/README.md index 2ecc931..da3d632 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,9 @@ -# Ouija Board -Just a ouija board based on time and question randomness +# Timer Random Tongues +Tongues 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 @@ -20,8 +18,8 @@ Since TRT was written in HolyC and this random word generator is written in C I ### Run If you already have a `dictionary.dict` file in your path, just run: -`ouija` +`trt` If you have the file saved in another folder, just type: -`ouija /path/to/dictionary` \ No newline at end of file +`trt /path/to/dictionary` diff --git a/ouija.c b/ouija.c deleted file mode 100644 index 5b90cdf..0000000 --- a/ouija.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "session.h" -#include "utils.h" -#include -#include - -int -main (int argc, char **argv) -{ - - FILE *dictionary = NULL; - - switch (argc) - { - case 1: - if (checkIfFileExists ("dictionary.dict") == 0) - { - dictionary = fopen ("dictionary.dict", "r"); - } - break; - case 2: - if (checkIfFileExists (argv[1]) == 0) - { - dictionary = fopen (argv[1], "r"); - } - } - - if (dictionary != NULL) - { - startSession (dictionary); - fclose (dictionary); - } - else - { - printf ("No Dictionary Found\n"); - } - - return 0; -} diff --git a/session.c b/session.c index 2991469..d847c99 100644 --- a/session.c +++ b/session.c @@ -13,11 +13,11 @@ startSession (FILE *dictionary) char reload = '\0'; printf ("WELCOME\n" + "Type something to get an answer\n" "Type GOODBYE to exit\n\n"); while (strcmp (question, "GOODBYE\n") != 0) { - printf ("Enter a question: "); fgets (question, MAX_LINE, stdin); if (strcmp (question, "GOODBYE\n") != 0) diff --git a/tongues.c b/tongues.c new file mode 100644 index 0000000..5b90cdf --- /dev/null +++ b/tongues.c @@ -0,0 +1,38 @@ +#include "session.h" +#include "utils.h" +#include +#include + +int +main (int argc, char **argv) +{ + + FILE *dictionary = NULL; + + switch (argc) + { + case 1: + if (checkIfFileExists ("dictionary.dict") == 0) + { + dictionary = fopen ("dictionary.dict", "r"); + } + break; + case 2: + if (checkIfFileExists (argv[1]) == 0) + { + dictionary = fopen (argv[1], "r"); + } + } + + if (dictionary != NULL) + { + startSession (dictionary); + fclose (dictionary); + } + else + { + printf ("No Dictionary Found\n"); + } + + return 0; +} diff --git a/utils.c b/utils.c index 057f6ef..8ef5567 100644 --- a/utils.c +++ b/utils.c @@ -59,9 +59,8 @@ getLine (FILE *dictionary, int lineNumber) int getRandomNumber (int min, int max, char *question) { - struct timespec s; - clock_gettime (CLOCK_REALTIME, &s); - srand (s.tv_nsec * numerize (question)); - - return ((rand () % (max - min + 1)) + min); + struct timeval randtime; + gettimeofday(&randtime,NULL); + srand(((randtime.tv_sec * 100) + time(NULL)) + ((randtime.tv_usec / 100) - time(NULL))); + return ((rand() % (max - min + 1)) + 1); } -- cgit v1.2.3