diff --git a/tools/find_long_lines b/tools/find_long_lines new file mode 100755 index 000000000..fd4ef13da --- /dev/null +++ b/tools/find_long_lines @@ -0,0 +1,41 @@ +#!/bin/sh +# vim: ft=sh ts=4 sw=4 et +# +# This script, when invoked with a number (representing a line length) +# and a list of filenames, will look for lines longer than the given length +# in each of the listed files. When it finds such a line, it prints +# +# - the name of the file, +# - line number within that file, and +# - the length of that line. +# + +case "$#" in + 0) + echo "usage: find_long_lines limit_length filename1 ..." + exit 1 + ;; + *) + LIMIT_LEN="$1" + export LIMIT_LEN + shift + ;; +esac + +awk " +BEGIN { + limit_len = ${LIMIT_LEN}; + CUR_FILENAME = \"\"; + line_number = 0; + } + { + if (FILENAME != CUR_FILENAME) { + CUR_FILENAME = FILENAME; + line_number = 0; + } + ++line_number; + len = length(\$0); + if (len > limit_len + 0) { + printf \"%s:%d: %d\n\", FILENAME, line_number, len; + } + }" "$@" diff --git a/tools/line_len_stats b/tools/line_len_stats new file mode 100755 index 000000000..2f97ccbb4 --- /dev/null +++ b/tools/line_len_stats @@ -0,0 +1,27 @@ +#!/bin/sh +# vim: ft=sh ts=4 sw=4 et +# +# Generate a histogram of the line lengths in the input, whether that input +# comes from stdin or from a list of filenames on the command line. +# +# Usage: line_len_stats [filename ...] +# + +awk ' +START { + maxlen = 0; + } + { + len = length($0); + count[len] += 1; + if (len > maxlen) { + maxlen = len; + } + } +END { + for (len = 1; len <= maxlen; len++) { + if (count[len] != 0) { + printf "len %4d: %d\n", len, count[len]; + } + } + }' "$@"