#!/bin/bash ## (c) Denis Kaganovich ## v5 ## grep-pcre required #BUS="pci" BUS="\w+" STR="^(?:static\s+)?(?:const\s+)?struct\s+" fnd(){ local msg="Fixing:" $fix || msg="Need to fix:" grep -Prhl "${STR}${BUS}_device_id\s+" $1 --include="*.c" | while read i ; do local bus=`grep -Prho "${STR}${BUS}_device_id.*\s+" $i` bus="${bus#*struct }" local n="${bus%%[*}" n="${n%%=*}" n="${n##*device_id }" n="${n// }" bus="${bus%%_device_id*}" grep -Pq "^module_init\s*\(" $i || continue grep -q "MODULE_DEVICE_TABLE" $i && continue local ii="${i#$1}" ii="${ii#/}" # case $ii in # */mdio-gpio.c) # echo "BROKEN: $bus: $ii" # continue # ;; # esac bus="${bus%%_*}" local BU case "$bus" in sdio)BU=MMC;; *)BU="${bus^^}";; esac if grep -Prq "^\s*(?:menu)?config\s+$BU(?:\s.*)?$" $1 --include="Kconfig*"; then echo "$msg $BU: ($n) $ii" $fix && sed -i -e 's/^\(module_init.*\)$/\n#ifdef CONFIG_'"$BU"'\nMODULE_DEVICE_TABLE('"$bus, $n"');\n#endif\n\n\1/' $i else echo "$msg $bus: ($n) $ii" $fix && sed -i -e 's/^\(module_init.*\)$/\nMODULE_DEVICE_TABLE('"$bus, $n"');\n\n\1/' $i fi done } p="" fix=false while [[ -n "$*" ]]; do case "$1" in --fix)fix=true;; *)p="$p $1";; esac shift done [[ -z "$p" ]] && echo "$0 [--fix] (grep+pcre required)" && exit 1 fnd $p