1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
#!/usr/bin/env perl
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
# SPDX-License-Identifier: curl
#
###########################################################################
#
# This script grew out of help from Przemyslaw Iskra and Balint Szilakszi
# a late evening in the #curl IRC channel.
#
use strict;
use warnings;
my $curl = shift @ARGV;
my $opt = shift @ARGV;
my $output = shift @ARGV;
my $txt = shift @ARGV;
my $longopt;
my $shortopt;
if($opt =~ /^--/) {
$longopt = $opt;
}
else {
$shortopt = $opt;
}
# first run the help command
system("$curl -h $opt > $output");
my @curlout;
open(O, "<$output");
push @curlout, <O>;
close(O);
# figure out the short+long option combo using -h all*/
open(C, "$curl -h all|");
if($shortopt) {
while(<C>) {
if(/^ +$opt, ([^ ]*)/) {
$longopt = $1;
last;
}
}
}
else {
while(<C>) {
my $f = $_;
if(/ $opt /) {
if($f =~ /^ *(-(.)), $longopt/) {
$shortopt = $1;
}
last;
}
}
}
close(C);
my $fullopt;
if($shortopt) {
$fullopt = "$shortopt, $longopt";
}
else {
$fullopt = $longopt;
}
open(R, "<$txt");
my $show = 0;
my @txtout;
while(<R>) {
if(/^ $fullopt/) {
$show = 1;
}
elsif(/^ -/ && $show) {
last;
}
if($show) {
push @txtout, $_;
}
}
close(R);
my $error = 0;
if(scalar(@curlout) != scalar(@txtout)) {
printf "curl -h $opt is %d lines, $txt says %d lines\n",
scalar(@curlout), scalar(@txtout);
$error++;
}
else {
# same size, compare line by line
for my $i (0 .. $#curlout) {
# trim CRLF from the data
$curlout[$i] =~ s/[\r\n]//g;
$txtout[$i] =~ s/[\r\n]//g;
if($curlout[$i] ne $txtout[$i]) {
printf "Line %d\n", $i;
printf "-h : %s (%d bytes)\n", $curlout[$i],
length($curlout[$i]);
printf "file : %s (%d bytes)\n", $txtout[$i],
length($txtout[$i]);
if(length($curlout[$i]) == length($txtout[$i])) {
my $l = length($curlout[$i]);
for my $c (0 .. $l) {
my $o = substr($curlout[$i], $c, 1);
my $t = substr($txtout[$i], $c, 1);
if($o ne $t) {
print "-h col %d: %02x\n", $c, ord($o);
print "file col %d: %02x\n", $c, ord($t);
}
}
}
$error++;
}
}
}
exit $error;
|