lz4

Форк
0
/
datagencli.c 
155 строк · 5.3 Кб
1
/*
2
    datagencli.c
3
    compressible data command line generator
4
    Copyright (C) Yann Collet 2012-2020
5

6
    GPL v2 License
7

8
    This program is free software; you can redistribute it and/or modify
9
    it under the terms of the GNU General Public License as published by
10
    the Free Software Foundation; either version 2 of the License, or
11
    (at your option) any later version.
12

13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

18
    You should have received a copy of the GNU General Public License along
19
    with this program; if not, write to the Free Software Foundation, Inc.,
20
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21

22
    You can contact the author at :
23
   - LZ4 source repository : https://github.com/lz4/lz4
24
   - Public forum : https://groups.google.com/forum/#!forum/lz4c
25
*/
26

27

28
/**************************************
29
*  Includes
30
**************************************/
31
#include "util.h"      /* U32 */
32
#include <stdio.h>     /* fprintf, stderr */
33
#include "datagen.h"   /* RDG_generate */
34
#include "loremOut.h"  /* LOREM_genOut */
35
#include "lz4.h"       /* LZ4_VERSION_STRING */
36

37

38
/**************************************
39
*  Compiler specific
40
**************************************/
41
#ifdef _MSC_VER    /* Visual Studio */
42
# pragma warning(disable : 4127)    /* disable: C4127: conditional expression is constant */
43
# define strtoull  _strtoui64  /* https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strtoui64-wcstoui64-strtoui64-l-wcstoui64-l */
44
#endif
45

46

47
/**************************************
48
*  Constants
49
**************************************/
50
#define KB *(1 <<10)
51
#define MB *(1 <<20)
52
#define GB *(1U<<30)
53

54
#define SIZE_DEFAULT (64 KB)
55
#define SEED_DEFAULT 0
56
#define COMPRESSIBILITY_NOT_SET 9999
57

58

59
/**************************************
60
*  Macros
61
**************************************/
62
#define DISPLAY(...)         fprintf(stderr, __VA_ARGS__)
63
#define DISPLAYLEVEL(l, ...) do { if (displayLevel>=(l)) DISPLAY(__VA_ARGS__); } while (0)
64
static unsigned displayLevel = 2;
65

66

67
/*********************************************************
68
*  Command line
69
*********************************************************/
70
static int usage(char* programName)
71
{
72
    DISPLAY( "Compressible data generator\n");
73
    DISPLAY( "Usage :\n");
74
    DISPLAY( "      %s [size] [args]\n", programName);
75
    DISPLAY( "\n");
76
    DISPLAY( "Arguments :\n");
77
    DISPLAY( " -g#    : generate # data (default:%i)\n", SIZE_DEFAULT);
78
    DISPLAY( " -s#    : Select seed (default:%i)\n", SEED_DEFAULT);
79
    DISPLAY( " -P#    : Select compressibility in %% (range [0-100])\n");
80
    DISPLAY( " -h     : display help and exit\n");
81
    DISPLAY( "Special values :\n");
82
    DISPLAY( " -P0    : generate incompressible noise\n");
83
    DISPLAY( " -P100  : generate sparse files\n");
84
    return 0;
85
}
86

87

88
int main(int argc, char** argv)
89
{
90
    int argNb;
91
    unsigned long long proba = COMPRESSIBILITY_NOT_SET;
92
    double litProba = 0.0;
93
    U64 size = SIZE_DEFAULT;
94
    unsigned seed = SEED_DEFAULT;
95
    char* programName;
96

97
    /* Check command line */
98
    programName = argv[0];
99
    for(argNb=1; argNb<argc; argNb++) {
100
        char* argument = argv[argNb];
101

102
        if(!argument) continue;   /* Protection if argument empty */
103

104
        /* Handle commands. Aggregated commands are allowed */
105
        if (*argument=='-') {
106
            argument++;
107
            while (*argument!=0) {
108
                switch(*argument) {
109
                case 'h':
110
                    return usage(programName);
111
                case 'g':
112
                    argument++;
113
                    size = strtoull(argument, &argument, 10);
114
                    if (*argument=='K') { size <<= 10; argument++; }
115
                    if (*argument=='M') { size <<= 20; argument++; }
116
                    if (*argument=='G') { size <<= 30; argument++; }
117
                    if (*argument=='B') { argument++; }
118
                    break;
119
                case 's':
120
                    argument++;
121
                    seed = (unsigned)strtoul(argument, &argument, 10);
122
                    break;
123
                case 'P':
124
                    argument++;
125
                    proba = strtoull(argument, &argument, 10);
126
                    break;
127
                case 'L':   /* hidden argument : Literal distribution probability */
128
                    argument++;
129
                    litProba = (double) strtoull(argument, &argument, 10);
130
                    if (litProba>100.) litProba=100.;
131
                    litProba /= 100.;
132
                    break;
133
                case 'v':
134
                    displayLevel = 4;
135
                    argument++;
136
                    break;
137
                default:
138
                    return usage(programName);
139
                }
140
            }
141
        }  /* if (*argument=='-') */
142
    }  /* for(argNb=1; argNb<argc; argNb++) */
143

144
    DISPLAYLEVEL(4, "Data Generator %s \n", LZ4_VERSION_STRING);
145
    DISPLAYLEVEL(3, "Seed = %u \n", seed);
146
    if (proba != COMPRESSIBILITY_NOT_SET) {
147
        DISPLAYLEVEL(3, "Compressibility : %i%%\n", (int)proba);
148
        RDG_genOut(size, (double)proba / 100., litProba, seed);
149
    } else {
150
        LOREM_genOut(size, seed);
151
    }
152
    DISPLAYLEVEL(1, "\n");
153

154
    return 0;
155
}
156

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.