diff options
author | Lou Berger <lberger@labn.net> | 2018-03-28 16:30:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-28 16:30:54 +0200 |
commit | 615e608d76bd3e1acf1769c914142210ac88e3f7 (patch) | |
tree | 1159398cc86aa18901a73480303fb52e09b1f9cc /tools | |
parent | Merge pull request #1928 from pguibert6WIND/flowspec_get_vrf_from_rt (diff) | |
parent | *: use C99 standard fixed-width integer types (diff) | |
download | frr-615e608d76bd3e1acf1769c914142210ac88e3f7.tar.xz frr-615e608d76bd3e1acf1769c914142210ac88e3f7.zip |
Merge pull request #1854 from qlyoung/integer-standards-compliance
*: use C99 standard fixed-width integer types
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/checkpatch.pl | 13 | ||||
-rwxr-xr-x | tools/convert-fixedwidth.sh | 44 |
2 files changed, 57 insertions, 0 deletions
diff --git a/tools/checkpatch.pl b/tools/checkpatch.pl index a85d811c9..e66be1875 100755 --- a/tools/checkpatch.pl +++ b/tools/checkpatch.pl @@ -6357,6 +6357,19 @@ sub process { "unknown module license " . $extracted_string . "\n" . $herecurr); } } + +# check for usage of nonstandard fixed-width integral types + if ($line =~ /u_int8_t/ || + $line =~ /u_int32_t/ || + $line =~ /u_int16_t/ || + $line =~ /u_int64_t/ || + $line =~ /[^a-z_]u_char[^a-z_]/ || + $line =~ /[^a-z_]u_short[^a-z_]/ || + $line =~ /[^a-z_]u_int[^a-z_]/ || + $line =~ /[^a-z_]u_long[^a-z_]/) { + ERROR("NONSTANDARD_INTEGRAL_TYPES", + "Please, no nonstandard integer types in new code.\n" . $herecurr) + } } # If we have no input at all, then there is nothing to report on diff --git a/tools/convert-fixedwidth.sh b/tools/convert-fixedwidth.sh new file mode 100755 index 000000000..bb6011edd --- /dev/null +++ b/tools/convert-fixedwidth.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# This script converts nonstandard fixed-width integer types found in FRR to +# C99 standard types. +USAGE="./$(basename "$0")" +USAGE+=$' <src-path> -- convert nonstandard fixed-width integer types found in FRR to C99 standard types\n' +USAGE+=$'<src-path> - a directory containing C source, or a C source file\n' +if [ $# -eq 0 ]; then + printf "%s" "$USAGE" + exit 1 +fi + +FRRTREE=$1 + +if [[ -d $FRRTREE ]]; then + SOURCES=$(find $FRRTREE -type f -name '*.[ch]') +elif [[ -f $FRRTREE ]]; then + SOURCES="$FRRTREE" + SOURCES+=$'\n' +else + printf "%s" "$USAGE" + exit 1 +fi + +printf "%s" "$SOURCES" | while read line ; do + printf "Processing $line " + sed -i -e 's/u_int\([0-9]\{1,3\}\)_t/uint\1_t/g' $line + printf "." + sed -i -e 's/\([^a-z_]\)u_char\([^a-z_]\|$\)/\1uint8_t\2/g' $line + printf "." + sed -i -e 's/\([^a-z_]\)u_short\([^a-z_]\|$\)/\1unsigned short\2/g' $line + printf "." + sed -i -e 's/\([^a-z_]\)u_int\([^a-z_]\|$\)/\1unsigned int\2/g' $line + printf "." + sed -i -e 's/\([^a-z_]\)u_long\([^a-z_]\|$\)/\1unsigned long\2/g' $line + printf "." + sed -i -e 's/^u_char /uint8_t /g' $line + printf "." + sed -i -e 's/^u_short /unsigned short /g' $line + printf "." + sed -i -e 's/^u_int /unsigned int /g' $line + printf "." + sed -i -e 's/^u_long /unsigned long /g' $line + printf ".\n" +done |