| 1 |
# cmp replacement program for PC where the error messages aren't |
| 2 |
# exactly the same, and neither are e+NNN exponents. |
| 3 |
# should run even on old awk |
| 4 |
# |
| 5 |
# Copyright (C) 2011-2015, 2019, 2024 the Free Software Foundation, Inc. |
| 6 |
# |
| 7 |
# This file is part of GAWK, the GNU implementation of the |
| 8 |
# AWK Programming Language. |
| 9 |
# |
| 10 |
# GAWK is free software; you can redistribute it and/or modify |
| 11 |
# it under the terms of the GNU General Public License as published by |
| 12 |
# the Free Software Foundation; either version 3 of the License, or |
| 13 |
# (at your option) any later version. |
| 14 |
# |
| 15 |
# GAWK is distributed in the hope that it will be useful, |
| 16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
# GNU General Public License for more details. |
| 19 |
# |
| 20 |
# You should have received a copy of the GNU General Public License |
| 21 |
# along with this program; if not, write to the Free Software |
| 22 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 23 |
|
| 24 |
{ |
| 25 |
if (FNR == NR) |
| 26 |
file = 0 |
| 27 |
else |
| 28 |
file = 1 |
| 29 |
gsub(/\r/, "", $0) |
| 30 |
lines[file, FNR] = $0 |
| 31 |
} |
| 32 |
|
| 33 |
END { |
| 34 |
if (NR/2 != FNR) { |
| 35 |
printf("testoutcmp: warning: files are not of equal length!\n") > "/dev/stderr" |
| 36 |
exit 1 |
| 37 |
} |
| 38 |
|
| 39 |
status = 0; |
| 40 |
for (i = 1; i <= FNR; i++) { |
| 41 |
good = lines[0, i] |
| 42 |
actual = lines[1, i] |
| 43 |
if (good == actual) |
| 44 |
continue |
| 45 |
|
| 46 |
l = length(good) |
| 47 |
if (substr(good, l, 1) == ")") |
| 48 |
l-- |
| 49 |
if (substr(good, 1, l) == substr(actual, 1, l)) |
| 50 |
continue |
| 51 |
|
| 52 |
# For exponents |
| 53 |
actual1 = gensub(/([ <]?)([-+]?[0-9.][0-9.]?+[eE][-+])0([0-9][0-9])/, " \\1\\2\\3", "g", actual) |
| 54 |
if (good == actual1) |
| 55 |
continue |
| 56 |
actual1 = gensub(/([-+]?0)([0-9.]+[eE][-+])0([0-9][0-9])/, "\\10\\2\\3", "g", actual) |
| 57 |
if (good == actual1) |
| 58 |
continue |
| 59 |
actual1 = gensub(/( ?)([-+]?)([1-9.][0-9.]?+[eE][-+])0([0-9][0-9])/, "\\1\\20\\3\\4", "g", actual) |
| 60 |
if (good == actual1) |
| 61 |
continue |
| 62 |
actual1 = gensub(/([-+]?[0-9.]+[eE][-+])0([0-9][0-9])/, "\\1\\2 ", "g", actual) |
| 63 |
if (good == actual1) |
| 64 |
continue |
| 65 |
actual1 = gensub(/([-+]?[0-9.]+[eE][-+])0([0-9][0-9])/, "\\1\\2", "g", actual) |
| 66 |
if (good == actual1) |
| 67 |
continue |
| 68 |
# For NaN and Inf |
| 69 |
actual1 = gensub(/([< \t])([-+])nan/, "\\1\\2NAN", "g", actual) |
| 70 |
if (good == actual1) |
| 71 |
continue |
| 72 |
actual1 = gensub(/([< \t])([-+])inf/, "\\1\\2INF", "g", actual) |
| 73 |
if (good == actual1) |
| 74 |
continue |
| 75 |
# For exit test |
| 76 |
actual1 = gensub(/([01]) nul/, "\\1 null", "g", actual) |
| 77 |
if (good == actual1) |
| 78 |
continue |
| 79 |
else { |
| 80 |
printf("-%s\n", good) > "/dev/stderr" |
| 81 |
printf("+%s\n", actual) > "/dev/stderr" |
| 82 |
status = 1 |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
exit status |
| 87 |
} |