Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/src/mkhelp.pl
2645 views
1
#!/usr/bin/env perl
2
#***************************************************************************
3
# _ _ ____ _
4
# Project ___| | | | _ \| |
5
# / __| | | | |_) | |
6
# | (__| |_| | _ <| |___
7
# \___|\___/|_| \_\_____|
8
#
9
# Copyright (C) Daniel Stenberg, <[email protected]>, et al.
10
#
11
# This software is licensed as described in the file COPYING, which
12
# you should have received as part of this distribution. The terms
13
# are also available at https://curl.se/docs/copyright.html.
14
#
15
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
# copies of the Software, and permit persons to whom the Software is
17
# furnished to do so, under the terms of the COPYING file.
18
#
19
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
# KIND, either express or implied.
21
#
22
# SPDX-License-Identifier: curl
23
#
24
###########################################################################
25
26
use strict;
27
use warnings;
28
29
my $c = 0;
30
if(@ARGV && $ARGV[0] eq "-c") {
31
$c = 1;
32
shift @ARGV;
33
}
34
35
my @out;
36
37
push @out, " _ _ ____ _\n";
38
push @out, " ___| | | | _ \\| |\n";
39
push @out, " / __| | | | |_) | |\n";
40
push @out, " | (__| |_| | _ <| |___\n";
41
push @out, " \\___|\\___/|_| \\_\\_____|\n";
42
43
while(<STDIN>) {
44
my $line = $_;
45
push @out, $line;
46
}
47
48
print <<HEAD
49
/*
50
* NEVER EVER edit this manually, fix the mkhelp.pl script instead!
51
*/
52
#include "tool_hugehelp.h"
53
#ifdef USE_MANUAL
54
#include "tool_help.h"
55
56
HEAD
57
;
58
if($c) {
59
# If compression requested, check that the Gzip module is available
60
# or else disable compression
61
$c = eval
62
{
63
require IO::Compress::Gzip;
64
IO::Compress::Gzip->import();
65
1;
66
};
67
print STDERR "Warning: compression requested but Gzip is not available\n" if(!$c)
68
}
69
70
if($c)
71
{
72
my $content = join("", @out);
73
my $gzippedContent;
74
IO::Compress::Gzip::gzip(
75
\$content, \$gzippedContent, Level => 9, TextFlag => 1, Time=>0) or die "gzip failed:";
76
my $gzip = length($content);
77
my $gzipped = length($gzippedContent);
78
79
print <<HEAD
80
#include <zlib.h>
81
#include <memdebug.h> /* keep this as LAST include */
82
static const unsigned char hugehelpgz[] = {
83
/* This mumbo-jumbo is the huge help text compressed with gzip.
84
Thanks to this operation, the size of this data shrank from $gzip
85
to $gzipped bytes. You can disable the use of compressed help
86
texts by NOT passing -c to the mkhelp.pl tool. */
87
HEAD
88
;
89
90
my $c=0;
91
for(split(//, $gzippedContent)) {
92
my $num=ord($_);
93
if(!($c % 12)) {
94
print " ";
95
}
96
printf(" 0x%02x,", 0+$num);
97
if(!(++$c % 12)) {
98
print "\n";
99
}
100
}
101
print "\n};\n";
102
103
print <<EOF
104
#define BUF_SIZE 0x10000
105
static voidpf zalloc_func(voidpf opaque, unsigned int items, unsigned int size)
106
{
107
(void)opaque;
108
/* not a typo, keep it calloc() */
109
return (voidpf) calloc(items, size);
110
}
111
static void zfree_func(voidpf opaque, voidpf ptr)
112
{
113
(void)opaque;
114
free(ptr);
115
}
116
117
#define HEADERLEN 10
118
119
/* Decompress and send to stdout a gzip-compressed buffer */
120
void hugehelp(void)
121
{
122
unsigned char *buf;
123
int status;
124
z_stream z;
125
126
/* Make sure no gzip options are set */
127
if(hugehelpgz[3] & 0xfe)
128
return;
129
130
memset(&z, 0, sizeof(z_stream));
131
z.zalloc = (alloc_func)zalloc_func;
132
z.zfree = (free_func)zfree_func;
133
z.avail_in = (uInt)(sizeof(hugehelpgz) - HEADERLEN);
134
z.next_in = (z_const Bytef *)hugehelpgz + HEADERLEN;
135
136
if(inflateInit2(&z, -MAX_WBITS) != Z_OK)
137
return;
138
139
buf = malloc(BUF_SIZE);
140
if(buf) {
141
while(1) {
142
z.avail_out = BUF_SIZE;
143
z.next_out = buf;
144
status = inflate(&z, Z_SYNC_FLUSH);
145
if(status == Z_OK || status == Z_STREAM_END) {
146
fwrite(buf, BUF_SIZE - z.avail_out, 1, stdout);
147
if(status == Z_STREAM_END)
148
break;
149
}
150
else
151
break; /* error */
152
}
153
free(buf);
154
}
155
inflateEnd(&z);
156
}
157
/* Show the help text for the 'arg' curl argument on stdout */
158
void showhelp(const char *trigger, const char *arg, const char *endarg)
159
{
160
unsigned char *buf;
161
int status;
162
z_stream z;
163
struct scan_ctx ctx;
164
inithelpscan(&ctx, trigger, arg, endarg);
165
166
/* Make sure no gzip options are set */
167
if(hugehelpgz[3] & 0xfe)
168
return;
169
170
memset(&z, 0, sizeof(z_stream));
171
z.zalloc = (alloc_func)zalloc_func;
172
z.zfree = (free_func)zfree_func;
173
z.avail_in = (uInt)(sizeof(hugehelpgz) - HEADERLEN);
174
z.next_in = (z_const Bytef *)hugehelpgz + HEADERLEN;
175
176
if(inflateInit2(&z, -MAX_WBITS) != Z_OK)
177
return;
178
179
buf = malloc(BUF_SIZE);
180
if(buf) {
181
while(1) {
182
z.avail_out = BUF_SIZE;
183
z.next_out = buf;
184
status = inflate(&z, Z_SYNC_FLUSH);
185
if(status == Z_OK || status == Z_STREAM_END) {
186
size_t len = BUF_SIZE - z.avail_out;
187
if(!helpscan(buf, len, &ctx))
188
break;
189
if(status == Z_STREAM_END)
190
break;
191
}
192
else
193
break; /* error */
194
}
195
free(buf);
196
}
197
inflateEnd(&z);
198
}
199
EOF
200
;
201
foot();
202
exit;
203
}
204
else {
205
print <<HEAD
206
static const char * const curlman[] = {
207
HEAD
208
;
209
}
210
211
my $blank;
212
for my $n (@out) {
213
chomp $n;
214
$n =~ s/\\/\\\\/g;
215
$n =~ s/\"/\\\"/g;
216
$n =~ s/\t/\\t/g;
217
218
if(!$n) {
219
$blank++;
220
}
221
else {
222
$n =~ s/ /\\t/g;
223
printf(" \"%s%s\",\n", $blank?"\\n":"", $n);
224
$blank = 0;
225
}
226
}
227
228
print <<ENDLINE
229
NULL
230
};
231
void hugehelp(void)
232
{
233
int i = 0;
234
while(curlman[i])
235
puts(curlman[i++]);
236
}
237
238
/* Show the help text for the 'arg' curl argument on stdout */
239
void showhelp(const char *trigger, const char *arg, const char *endarg)
240
{
241
int i = 0;
242
struct scan_ctx ctx;
243
inithelpscan(&ctx, trigger, arg, endarg);
244
while(curlman[i]) {
245
size_t len = strlen(curlman[i]);
246
if(!helpscan((const unsigned char *)curlman[i], len, &ctx) ||
247
!helpscan((const unsigned char *)"\\n", 1, &ctx))
248
break;
249
i++;
250
}
251
}
252
ENDLINE
253
;
254
255
foot();
256
257
sub foot {
258
print <<FOOT
259
#endif /* USE_MANUAL */
260
FOOT
261
;
262
}
263
264