-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunsource
More file actions
executable file
·26 lines (23 loc) · 857 Bytes
/
unsource
File metadata and controls
executable file
·26 lines (23 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env tclkit8.6
#
# unsource <file>
#
# unsource is a command line program to remove "source" statements by replacing them
# with the contents of the sourced file. The program is used to create a single file
# that contains all the code related to a program, library or module. Sometimes a
# source statement is used to read in parameters or data from the runtime environment.
# When this is the case the source statement can be annotated with "Not UnSourced" as
# a comment on the same line and the source statement will be left in the output.
#
proc K { x y } { set x }
proc unsource { file } {
foreach line [split [K [read [set fp [open $file]]] [close $fp]] \n] {
if { [regexp {[ \t]*source ([^ ]*)} $line -> file] \
&& ![regexp {Not UnSourced} $line]} {
unsource $file
} else {
puts $line
}
}
}
unsource $argv