aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2022-11-11 00:24:24 +0200
committerkartofen <mladenovnasko0@gmail.com>2022-11-11 00:24:24 +0200
commit7578a9d04b666cff3f02aa2d2c1b2cce8a3d3939 (patch)
treeaaa7b7a7aae5f893d38e649ff3001206f6c9dd5b /src
parent6516b26acec2abd862a3c1f42886e749e2dfad5c (diff)
add bigger stack fixHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/gen_chain.c6
-rw-r--r--src/main.c45
-rw-r--r--src/markov.h29
3 files changed, 55 insertions, 25 deletions
diff --git a/src/gen_chain.c b/src/gen_chain.c
index 0ad13d1..252debf 100644
--- a/src/gen_chain.c
+++ b/src/gen_chain.c
@@ -1,14 +1,14 @@
#include <stdio.h>
#include <time.h>
+#define WALK_LEN 1000000
+#define SAVE_TO_FILE_ON_WALK "files/in.txt"
#define PRINT_ITEM_FREQUENCY
// #define PRINT_ON_WALK
-#define SAVE_TO_FILE_ON_WALK "files/in.txt"
-#define WALK_LEN 10000
#define ITEM_CAP 3
-int ITEMS = 3;
+int ITEMS = 3;
double chain[ITEM_CAP][ITEM_CAP] = {
{ 0.2, 0.6, 0.2 },
{ 0.3, 0.0, 0.7 },
diff --git a/src/main.c b/src/main.c
index 8b412ca..e6974a0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,33 +1,52 @@
-// ----------------- OPTIONS ----------------- //
-#define FILE_PATH "files/in.txt"
+#define WALK_LEN 200
+// #define FILE_PATH "files/in.txt"
+#define FILE_PATH "files/shakespeare.txt"
// #define FILE_PATH "files/south-park-the-aristocrats.txt"
-#define WALK_LEN 100000
-
-#define PRINT_CHAIN
-#define PRINT_ITEM_FREQUENCY
-// #define PRINT_ON_WALK
-// #define SAVE_TO_FILE_ON_WALK "out.txt"
-// --------------- END OPTIONS --------------- //
+// #define PRINT_CHAIN
+// #define PRINT_ITEM_FREQUENCY
+#define PRINT_ON_WALK
#include <stdio.h>
+#include <stdlib.h>
#include <time.h>
-#define ITEM_CAP 1024
-int ITEMS = 0;
+#define ITEM_CAP 4000
+#include "markov.h"
+int ITEMS = 0;
double chain[ITEM_CAP][ITEM_CAP] = {0};
char item_names[ITEM_CAP][64] = {0};
-#include "markov.h"
+void set_stack();
int main(void)
{
+ set_stack();
+
srand(time(NULL));
generate_chain();
+ take_walk();
#ifdef PRINT_CHAIN
print_chain();
#endif
- take_walk();
return 0;
}
+
+// for stack
+#include <sys/resource.h>
+void set_stack()
+{
+ const rlim_t kStackSize = 64L * 1024L * 1024L; // min stack size = 64 Mb
+ struct rlimit rl;
+ int result;
+
+ if(getrlimit(RLIMIT_STACK, &rl) == 0) {
+ if (rl.rlim_cur < kStackSize) {
+ rl.rlim_cur = kStackSize;
+
+ if((result = setrlimit(RLIMIT_STACK, &rl)) != 0)
+ fprintf(stderr, "setrlimit returned result = %d\n", result);
+ }
+ }
+}
diff --git a/src/markov.h b/src/markov.h
index 1c95775..ca879f3 100644
--- a/src/markov.h
+++ b/src/markov.h
@@ -7,20 +7,28 @@
#include <string.h>
#include <ctype.h>
+#ifndef WALK_LEN
+#define WALK_LEN 0
+#endif
+
+#ifndef FILE_PATH
+#define FILE_PATH ""
+#endif
+
+#ifndef ITEM_CAP
+#define ITEM_CAP 1024
+#endif
+
extern int ITEMS;
extern double chain[][ITEM_CAP];
extern char item_names[][64];
void generate_chain()
{
- char *file_path = NULL;
- #ifdef FILE_PATH
- file_path = FILE_PATH;
- #endif
-
- FILE *fp = fopen(file_path, "r");
+ printf("%s\n", FILE_PATH);
+ FILE *fp = fopen(FILE_PATH, "r");
if(!fp) {
- fprintf(stderr, "ERROR: Could not open file %s\n", file_path);
+ fprintf(stderr, "ERROR: Could not open file %s\n", FILE_PATH);
exit(EXIT_FAILURE);
}
@@ -33,7 +41,8 @@ void generate_chain()
{
if(ch != ' ' && ch != ',' && ch != '"' &&
ch != '\n' && ch != '[' && ch != ']' &&
- ch != '!' && ch != '?' && ch != '.') {
+ ch != '!' && ch != '?' && ch != '.' &&
+ ch != ';' && ch != ':') {
word[strlen(word)] = tolower(ch);
continue;
}
@@ -49,6 +58,7 @@ void generate_chain()
if(item == ITEMS) {
ITEMS++;
+ assert(ITEMS <= ITEM_CAP);
strcpy(item_names[item], word);
}
@@ -60,7 +70,8 @@ void generate_chain()
manage_cur_item:
if(ch == '\n' || ch == '[' || ch == ']' ||
- ch == '!' || ch == '?' || ch == '.')
+ ch == '!' || ch == '?' || ch == '.' ||
+ ch == ';' || ch == ':')
cur_item = -1;
memset(word, 0, sizeof(word));