lz4
1/*
2lorem.c - lorem ipsum generator to stdout
3Copyright (C) Yann Collet 2024
4
5GPL v2 License
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License along
18with this program; if not, write to the Free Software Foundation, Inc.,
1951 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21You can contact the author at :
22- LZ4 source repository : https://github.com/lz4/lz4
23- Public forum : https://groups.google.com/forum/#!forum/lz4c
24*/
25
26/* Implementation notes:
27* Generates a stream of Lorem ipsum paragraphs to stdout,
28* up to the requested size, which can be very large (> 4 GB).
29* Note that, beyond 1 paragraph, this generator produces
30* a different content than LOREM_genBuffer (even when using same seed).
31*/
32
33#include "platform.h" /* Compiler options, SET_BINARY_MODE */34#include "loremOut.h"35#include "lorem.h" /* LOREM_genBlock */36#include <stdio.h>37#include <assert.h>38
39
40#define MIN(a, b) ((a) < (b) ? (a) : (b))41#define LOREM_BLOCKSIZE (2 << 10)42void LOREM_genOut(unsigned long long size, unsigned seed)43{
44char buff[LOREM_BLOCKSIZE] = {0};45unsigned long long total = 0;46size_t genBlockSize = (size_t)MIN(size, LOREM_BLOCKSIZE);47
48/* init */49SET_BINARY_MODE(stdout);50
51/* Generate Ipsum text, one paragraph at a time */52while (total < size) {53size_t generated = LOREM_genBlock(buff, genBlockSize, seed++, total == 0, 0);54assert(generated <= genBlockSize);55total += generated;56assert(total <= size);57fwrite(buff, 1, generated, stdout); /* note: should check potential write error */58if (size - total < genBlockSize)59genBlockSize = (size_t)(size - total);60}61assert(total == size);62}
63