#!/usr/bin/tclsh # # \brief Extract subtree from device-tree source # \author Norman Feske # \date 2021-05-17 # ## # Return true if command-line switch was specified # proc get_cmd_switch { arg_name } { global argv return [expr [lsearch $argv $arg_name] >= 0] } ## # Return command-line argument value # # If a argument name is specified multiple times, a # list of argument values is returned. # proc get_cmd_arg { arg_name default_value } { global argv # find argument name in argv list set arg_idx_list [lsearch -all $argv $arg_name] if {[llength $arg_idx_list] == 0} { return $default_value } set result {} foreach arg_idx $arg_idx_list { set next_idx [expr $arg_idx + 1] # stop if argv ends with the argument name if {$next_idx >= [llength $argv]} continue # return list element following the argument name lappend result [lindex $argv $next_idx] } # if argument occurred only once, return its value if {[llength $result] == 1} { return [lindex $result 0] } # if argument occurred multiple times, contain list of arguments return $result } ################################################# ## Read input and fill internal representation ## ################################################# ## # Find location of 'parse' # # We expect to find 'parse' in the same directory as we are located. The # question is: Where are we? ## proc parse_file { } { global argv0 set path $argv0 if {[file type $path] == "link"} { set path [file readlink $path] } set parse_file "[file dirname $path]/parse" if {![file exists $parse_file]} { puts stderr "Error: Could not find 'parse' in '$path'." exit -1 } return $parse_file } set input_source [lindex $argv end] if {[catch { set tokens [exec [parse_file] $input_source] }]} { foreach line { "" "Extract subtree from device-tree source" "\n usage: extract \[options\] " "" "Supported options are:" "" " --nodes Print list of DTS nodes" " --labels Print list of labels with their DTS paths" " --references Print referenced labels for each DTS node" " --dot-graph Generate dot file for graphviz" " --select