]> git.proxmox.com Git - mirror_frr.git/blob - tools/convert-fixedwidth.sh
staticd: Do not ready prefix for printing till it's decoded
[mirror_frr.git] / tools / convert-fixedwidth.sh
1 #!/bin/bash
2 # This script converts nonstandard fixed-width integer types found in FRR to
3 # C99 standard types.
4 USAGE="./$(basename "$0")"
5 USAGE+=$' <src-path> -- convert nonstandard fixed-width integer types found in FRR to C99 standard types\n'
6 USAGE+=$'<src-path> - a directory containing C source, or a C source file\n'
7 if [ $# -eq 0 ]; then
8 printf "%s" "$USAGE"
9 exit 1
10 fi
11
12 FRRTREE=$1
13
14 if [[ -d $FRRTREE ]]; then
15 SOURCES=$(find $FRRTREE -type f -name '*.[ch]')
16 elif [[ -f $FRRTREE ]]; then
17 SOURCES="$FRRTREE"
18 SOURCES+=$'\n'
19 else
20 printf "%s" "$USAGE"
21 exit 1
22 fi
23
24 printf "%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"
44 done