2 #***************************************************************************
4 # Project ___| | | | _ \| |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
9 # Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
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.haxx.se/docs/copyright.html.
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.
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
22 ###########################################################################
24 # Yeah, I know, probably 1000 other persons already wrote a script like
25 # this, but I'll tell ya:
27 # THEY DON'T FIT ME :-)
29 # Get readme file as parameter:
31 if($ARGV[0] eq "-c") {
36 my $README = $ARGV[0];
39 print "usage: mkhelp.pl [-c] <README> < manpage\n";
44 push @out, " _ _ ____ _\n";
45 push @out, " Project ___| | | | _ \\| |\n";
46 push @out, " / __| | | | |_) | |\n";
47 push @out, " | (__| |_| | _ <| |___\n";
48 push @out, " \\___|\\___/|_| \\_\\_____|\n";
54 # this should be removed:
55 $line =~ s/(
\b.|_
\b)//g;
57 # remove trailing CR from line. msysgit checks out files as line+CRLF
60 if($line =~ /^([ \t]*\n|curl)/i) {
61 # cut off headers and empty lines
62 $wline++; # count number of cut off lines
67 $text =~ s/^\s+//g; # cut off preceding...
68 $text =~ s/\s+$//g; # and trailing whitespaces
70 $tlen = length($text);
72 if($wline && ($olen == $tlen)) {
73 # if the previous line with contents was exactly as long as
74 # this line, then we ignore the newlines!
76 # We do this magic because a header may abort a paragraph at
77 # any line, but we don't want that to be noticed in the output
84 # we only make one empty line max
90 push @out, "\n"; # just an extra newline
92 open(READ, "<$README") ||
93 die "couldn't read the README infile $README";
98 # remove trailing CR from line. msysgit checks out files as line+CRLF
107 * NEVER EVER edit this manually, fix the mkhelp.pl script instead!
110 #include "tool_hugehelp.h"
114 # If compression requested, check that the Gzip module is available
115 # or else disable compression
118 require IO::Compress::Gzip;
119 IO::Compress::Gzip->import();
122 print STDERR "Warning: compression requested but Gzip is not available\n" if (!$c)
127 my $content = join("", @out);
129 IO::Compress::Gzip::gzip(
130 \$content, \$gzippedContent, Level => 9, TextFlag => 1, Time=>0) or die "gzip failed:";
131 $gzip = length($content);
132 $gzipped = length($gzippedContent);
136 #include "memdebug.h" /* keep this as LAST include */
137 static const unsigned char hugehelpgz[] = {
138 /* This mumbo-jumbo is the huge help text compressed with gzip.
139 Thanks to this operation, the size of this data shrank from $gzip
140 to $gzipped bytes. You can disable the use of compressed help
141 texts by NOT passing -c to the mkhelp.pl tool. */
147 for(split(//, $gzippedContent)) {
149 printf(" 0x%02x,", 0+$num);
157 #define BUF_SIZE 0x10000
158 static voidpf zalloc_func(voidpf opaque, unsigned int items, unsigned int size)
161 /* not a typo, keep it calloc() */
162 return (voidpf) calloc(items, size);
164 static void zfree_func(voidpf opaque, voidpf ptr)
169 /* Decompress and send to stdout a gzip-compressed buffer */
173 int status,headerlen;
176 /* Make sure no gzip options are set */
177 if (hugehelpgz[3] & 0xfe)
181 memset(&z, 0, sizeof(z_stream));
182 z.zalloc = (alloc_func)zalloc_func;
183 z.zfree = (free_func)zfree_func;
184 z.avail_in = (unsigned int)(sizeof(hugehelpgz) - headerlen);
185 z.next_in = (unsigned char *)hugehelpgz + headerlen;
187 if (inflateInit2(&z, -MAX_WBITS) != Z_OK)
190 buf = malloc(BUF_SIZE);
193 z.avail_out = BUF_SIZE;
195 status = inflate(&z, Z_SYNC_FLUSH);
196 if (status == Z_OK || status == Z_STREAM_END) {
197 fwrite(buf, BUF_SIZE - z.avail_out, 1, stdout);
198 if (status == Z_STREAM_END)
228 $outsize += length($new)+1; # one for the newline
233 # gcc 2.96 claims ISO C89 only is required to support 509 letter strings
235 # terminate and make another fputs() call here
236 print ", stdout);\n fputs(\n";
237 $outsize=length($new)+1;
239 printf("\"%s\\n\"\n", $new);
243 print ", stdout) ;\n}\n";
249 #else /* !USE_MANUAL */
250 /* built-in manual is disabled, blank function */
251 #include "tool_hugehelp.h"
252 void hugehelp(void) {}
253 #endif /* USE_MANUAL */