Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- PLn () { printf '%s\n' "${@}" ; } # PLn
- MkLiteral () { # <string>
- # Make pattern for literal match of <string>
- # in 'grep' or 'sed' regular expressions.
- printf '%s' "${1}" | sed 's/./[&]/g ; s/\^/[.^.]/g'
- } # MkLiteral
- # А "node" is a string of any character, except null,
- # space and newline characters.
- # An "arc" is a pair of "nodes", delimited with one or more spaces.
- # A "list" is sequence of something, delimited with newlines.
- GetArcs () { # <top node> <arc list>
- local Arcs="${2}" Visited=
- DFS () { # <source node>
- # Deep-First Search
- local N="${1}" # nonlocal: Arcs, Visited
- Visited=$( PLn "${N}" "${Visited}" ) N=$( MkLiteral "${N}" )
- N=$( PLn "${Arcs}" | grep "^${N} " ) && PLn "${N}"
- for N in $( PLn "${N}" | sed -n "s/^[^ ]*[ ][ ]*//p" ) ; do
- PLn "${Visited}" | grep -F -x -q "${N}" || DFS "${N}"
- done
- } # DFS
- DFS "${1}"
- } # GetArcs
- PutSortedModules () { # <source module name>
- local M="${1}"
- # It's assumed here that the names of the modules
- # don't contain spaces and newlines.
- GetHolders () {
- local H ; for H in /sys/module/*/holders/* ; do
- PLn "${H}" | sed 's|^/sys/module/|| ; s|/holders/| |'
- done
- } # GetHolders
- { PLn "${M} ${M}" ; GetArcs "${M}" "$( GetHolders )" ; } | tsort | tac
- } # PutSortedModules
- PutSortedModules "${1}"
- exit # lsholders
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement