1#!/usr/bin/env perl 2#*************************************************************************** 3# _ _ ____ _ 4# Project ___| | | | _ \| | 5# / __| | | | |_) | | 6# | (__| |_| | _ <| |___ 7# \___|\___/|_| \_\_____| 8# 9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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# Yeah, I know, probably 1000 other persons already wrote a script like 27# this, but I'll tell ya: 28 29# THEY DON'T FIT ME :-) 30 31# Get readme file as parameter: 32 33if($ARGV[0] eq "-c") { 34 $c=1; 35 shift @ARGV; 36} 37 38push @out, " _ _ ____ _\n"; 39push @out, " Project ___| | | | _ \\| |\n"; 40push @out, " / __| | | | |_) | |\n"; 41push @out, " | (__| |_| | _ <| |___\n"; 42push @out, " \\___|\\___/|_| \\_\\_____|\n"; 43 44my $olen=0; 45while (<STDIN>) { 46 my $line = $_; 47 48 # this should be removed: 49 $line =~ s/(.|_)//g; 50 51 # remove trailing CR from line. msysgit checks out files as line+CRLF 52 $line =~ s/\r$//; 53 54 if($line =~ /^([ \t]*\n|curl)/i) { 55 # cut off headers and empty lines 56 $wline++; # count number of cut off lines 57 next; 58 } 59 60 my $text = $line; 61 $text =~ s/^\s+//g; # cut off preceding... 62 $text =~ s/\s+$//g; # and trailing whitespaces 63 64 $tlen = length($text); 65 66 if($wline && ($olen == $tlen)) { 67 # if the previous line with contents was exactly as long as 68 # this line, then we ignore the newlines! 69 70 # We do this magic because a header may abort a paragraph at 71 # any line, but we don't want that to be noticed in the output 72 # here 73 $wline=0; 74 } 75 $olen = $tlen; 76 77 if($wline) { 78 # we only make one empty line max 79 $wline = 0; 80 push @out, "\n"; 81 } 82 push @out, $line; 83} 84push @out, "\n"; # just an extra newline 85 86print <<HEAD 87/* 88 * NEVER EVER edit this manually, fix the mkhelp.pl script instead! 89 */ 90#ifdef USE_MANUAL 91#include "tool_hugehelp.h" 92HEAD 93 ; 94if($c) { 95 # If compression requested, check that the Gzip module is available 96 # or else disable compression 97 $c = eval 98 { 99 require IO::Compress::Gzip; 100 IO::Compress::Gzip->import(); 101 1; 102 }; 103 print STDERR "Warning: compression requested but Gzip is not available\n" if (!$c) 104} 105 106if($c) 107{ 108 my $content = join("", @out); 109 my $gzippedContent; 110 IO::Compress::Gzip::gzip( 111 \$content, \$gzippedContent, Level => 9, TextFlag => 1, Time=>0) or die "gzip failed:"; 112 $gzip = length($content); 113 $gzipped = length($gzippedContent); 114 115 print <<HEAD 116#include <zlib.h> 117#include "memdebug.h" /* keep this as LAST include */ 118static const unsigned char hugehelpgz[] = { 119 /* This mumbo-jumbo is the huge help text compressed with gzip. 120 Thanks to this operation, the size of this data shrank from $gzip 121 to $gzipped bytes. You can disable the use of compressed help 122 texts by NOT passing -c to the mkhelp.pl tool. */ 123HEAD 124; 125 126 my $c=0; 127 print " "; 128 for(split(//, $gzippedContent)) { 129 my $num=ord($_); 130 printf(" 0x%02x,", 0+$num); 131 if(!(++$c % 12)) { 132 print "\n "; 133 } 134 } 135 print "\n};\n"; 136 137 print <<EOF 138#define BUF_SIZE 0x10000 139static voidpf zalloc_func(voidpf opaque, unsigned int items, unsigned int size) 140{ 141 (void) opaque; 142 /* not a typo, keep it calloc() */ 143 return (voidpf) calloc(items, size); 144} 145static void zfree_func(voidpf opaque, voidpf ptr) 146{ 147 (void) opaque; 148 free(ptr); 149} 150/* Decompress and send to stdout a gzip-compressed buffer */ 151void hugehelp(void) 152{ 153 unsigned char* buf; 154 int status,headerlen; 155 z_stream z; 156 157 /* Make sure no gzip options are set */ 158 if (hugehelpgz[3] & 0xfe) 159 return; 160 161 headerlen = 10; 162 memset(&z, 0, sizeof(z_stream)); 163 z.zalloc = (alloc_func)zalloc_func; 164 z.zfree = (free_func)zfree_func; 165 z.avail_in = (unsigned int)(sizeof(hugehelpgz) - headerlen); 166 z.next_in = (unsigned char *)hugehelpgz + headerlen; 167 168 if (inflateInit2(&z, -MAX_WBITS) != Z_OK) 169 return; 170 171 buf = malloc(BUF_SIZE); 172 if (buf) { 173 while(1) { 174 z.avail_out = BUF_SIZE; 175 z.next_out = buf; 176 status = inflate(&z, Z_SYNC_FLUSH); 177 if (status == Z_OK || status == Z_STREAM_END) { 178 fwrite(buf, BUF_SIZE - z.avail_out, 1, stdout); 179 if (status == Z_STREAM_END) 180 break; 181 } 182 else 183 break; /* Error */ 184 } 185 free(buf); 186 } 187 inflateEnd(&z); 188} 189EOF 190 ; 191foot(); 192exit; 193} 194else { 195 print <<HEAD 196void hugehelp(void) 197{ 198 fputs( 199HEAD 200 ; 201} 202 203$outsize=0; 204for(@out) { 205 chop; 206 207 $new = $_; 208 209 $outsize += length($new)+1; # one for the newline 210 211 $new =~ s/\\/\\\\/g; 212 $new =~ s/\"/\\\"/g; 213 214 # gcc 2.96 claims ISO C89 only is required to support 509 letter strings 215 if($outsize > 500) { 216 # terminate and make another fputs() call here 217 print ", stdout);\n fputs(\n"; 218 $outsize=length($new)+1; 219 } 220 printf("\"%s\\n\"\n", $new); 221 222} 223 224print ", stdout) ;\n}\n"; 225 226foot(); 227 228sub foot { 229 print <<FOOT 230#endif /* USE_MANUAL */ 231FOOT 232 ; 233} 234