]> git.proxmox.com Git - mirror_frr.git/blame - tools/convert-fixedwidth.sh
bgpd: fix large route-distinguisher's format
[mirror_frr.git] / tools / convert-fixedwidth.sh
CommitLineData
28ac5a03
QY
1#!/bin/bash
2# This script converts nonstandard fixed-width integer types found in FRR to
3# C99 standard types.
4USAGE="./$(basename "$0")"
5USAGE+=$' <src-path> -- convert nonstandard fixed-width integer types found in FRR to C99 standard types\n'
6USAGE+=$'<src-path> - a directory containing C source, or a C source file\n'
7if [ $# -eq 0 ]; then
8 printf "%s" "$USAGE"
9 exit 1
10fi
11
12FRRTREE=$1
13
14if [[ -d $FRRTREE ]]; then
15 SOURCES=$(find $FRRTREE -type f -name '*.[ch]')
16elif [[ -f $FRRTREE ]]; then
17 SOURCES="$FRRTREE"
18 SOURCES+=$'\n'
19else
20 printf "%s" "$USAGE"
21 exit 1
22fi
23
24printf "%s" "$SOURCES" | while read line ; do
25 printf "Processing $line "
26 sed -i -e 's/u_int\([0-9]\{1,3\}\)_t/uint\1_t/g' $line
27 printf "."
28 sed -i -e 's/\([^a-z_]\)u_char\([^a-z_]\|$\)/\1uint8_t\2/g' $line
29 printf "."
30 sed -i -e 's/\([^a-z_]\)u_short\([^a-z_]\|$\)/\1unsigned short\2/g' $line
31 printf "."
32 sed -i -e 's/\([^a-z_]\)u_int\([^a-z_]\|$\)/\1unsigned int\2/g' $line
33 printf "."
34 sed -i -e 's/\([^a-z_]\)u_long\([^a-z_]\|$\)/\1unsigned long\2/g' $line
35 printf "."
36 sed -i -e 's/^u_char /uint8_t /g' $line
37 printf "."
38 sed -i -e 's/^u_short /unsigned short /g' $line
39 printf "."
40 sed -i -e 's/^u_int /unsigned int /g' $line
41 printf "."
42 sed -i -e 's/^u_long /unsigned long /g' $line
43 printf ".\n"
44done