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# This script grew out of help from Przemyslaw Iskra and Balint Szilakszi 27# a late evening in the #curl IRC channel. 28# 29 30use strict; 31use warnings; 32 33my $curl = shift @ARGV; 34my $opt = shift @ARGV; 35my $output = shift @ARGV; 36my $txt = shift @ARGV; 37 38my $longopt; 39my $shortopt; 40if($opt =~ /^--/) { 41 $longopt = $opt; 42} 43else { 44 $shortopt = $opt; 45} 46 47# first run the help command 48system("$curl -h $opt > $output"); 49my @curlout; 50open(O, "<$output"); 51push @curlout, <O>; 52close(O); 53 54# figure out the short+long option combo using -h all*/ 55open(C, "$curl -h all|"); 56if($shortopt) { 57 while(<C>) { 58 if(/^ +$opt, ([^ ]*)/) { 59 $longopt = $1; 60 last; 61 } 62 } 63} 64else { 65 while(<C>) { 66 my $f = $_; 67 if(/ $opt /) { 68 if($f =~ /^ *(-(.)), $longopt/) { 69 $shortopt = $1; 70 } 71 last; 72 } 73 } 74} 75close(C); 76 77my $fullopt; 78if($shortopt) { 79 $fullopt = "$shortopt, $longopt"; 80} 81else { 82 $fullopt = $longopt; 83} 84 85open(R, "<$txt"); 86my $show = 0; 87my @txtout; 88while(<R>) { 89 if(/^ $fullopt/) { 90 $show = 1; 91 } 92 elsif(/^ -/ && $show) { 93 last; 94 } 95 if($show) { 96 push @txtout, $_; 97 } 98} 99close(R); 100 101my $error; 102if(scalar(@curlout) != scalar(@txtout)) { 103 printf "curl -h $opt is %d lines, $txt says %d lines\n", 104 scalar(@curlout), scalar(@txtout); 105 $error++; 106} 107else { 108 # same size, compare line by line 109 for my $i (0 .. $#curlout) { 110 # trim CRLF from the data 111 $curlout[$i] =~ s/[\r\n]//g; 112 $txtout[$i] =~ s/[\r\n]//g; 113 if($curlout[$i] ne $txtout[$i]) { 114 printf "Line %d\n", $i; 115 printf "-h : %s (%d bytes)\n", $curlout[$i], 116 length($curlout[$i]); 117 printf "file : %s (%d bytes)\n", $txtout[$i], 118 length($txtout[$i]); 119 120 if(length($curlout[$i]) == length($txtout[$i])) { 121 my $l = length($curlout[$i]); 122 for my $c (0 .. $l) { 123 my $o = substr($curlout[$i], $c, 1); 124 my $t = substr($txtout[$i], $c, 1); 125 if($o ne $t) { 126 print "-h col %d: %02x\n", $c, ord($o); 127 print "file col %d: %02x\n", $c, ord($t); 128 } 129 } 130 } 131 $error++; 132 } 133 } 134} 135exit $error; 136