aboutsummaryrefslogtreecommitdiff
path: root/src/gendata.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gendata.c')
-rw-r--r--src/gendata.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/gendata.c b/src/gendata.c
new file mode 100644
index 0000000..cb92133
--- /dev/null
+++ b/src/gendata.c
@@ -0,0 +1,49 @@
1#include <stdlib.h>
2#include <stdio.h>
3#include <libgen.h>
4#include <errno.h>
5#include <time.h>
6#include <wchar.h>
7#include <unistd.h>
8#include "config.h"
9
10int
11main (int argc, char *argv[])
12{
13 if (argc != 2) {
14 fprintf (stderr, "Usage: %s {outfile}\n", basename (argv[0]));
15 return EXIT_FAILURE;
16 }
17
18 FILE *stream = fopen (argv[1], "w,ccs="CCS);
19 if (stream == NULL) {
20 perror (NULL);
21 return EXIT_FAILURE;
22 }
23
24 srand (time (NULL));
25 size_t letter_count = 15;
26 for (int i = 0; i < 15; ++i)
27 fputwc (ALPHABET[rand () % wcslen (ALPHABET)], stream);
28 while (letter_count < LETTER_COUNT) {
29 int count = rand () % 15 + 1;
30 size_t letters_left = LETTER_COUNT - letter_count;
31 count = count > letters_left ? letters_left : count;
32 if (rand () % 2) {
33 for (int i = 0; i < count; ++i)
34 fputwc (ALPHABET[rand () % wcslen (ALPHABET)], stream);
35 } else {
36 wchar_t wc = ALPHABET[rand () % wcslen (ALPHABET)];
37 for (int i = 0; i < count; ++i)
38 fputwc (wc, stream);
39 }
40 letter_count += count;
41 }
42
43 if (fclose (stream) == EOF) {
44 perror (NULL);
45 return EXIT_FAILURE;
46 }
47
48 return EXIT_SUCCESS;
49}