mirror of
https://git.lain.church/bake/bake.git
synced 2025-04-20 00:54:10 +00:00
84 lines
1.7 KiB
Awk
Executable File
84 lines
1.7 KiB
Awk
Executable File
#!/bin/sh
|
|
# vim:set ft=awk:
|
|
# Written by Egor, modified for compatibility by Emil.
|
|
# SPDX-License-Identifier: Unlicense
|
|
"exec" "${AWK:-awk}" "-f" "$(basename $0)" "--" "$@" && 0
|
|
function usage() {
|
|
print "awake: usage: awake [-nl] [-s num] filename [args...]"
|
|
exit
|
|
}
|
|
BEGIN {
|
|
RS = "\r?\n"
|
|
FS = "\n"
|
|
select = 1
|
|
for (i = 1; i < ARGC; i++) {
|
|
if (!optsdone && substr(ARGV[i], 1, 1) == "-") {
|
|
if (ARGV[i] == "--") {
|
|
optsdone = 1
|
|
} else {
|
|
for (j = 2; j <= length(ARGV[i]); j++) {
|
|
c = substr(ARGV[i], j, 1)
|
|
if (c == "s") {
|
|
select = substr(ARGV[i], j+1)
|
|
if (!select) {
|
|
ARGV[i] = ""
|
|
select = ARGV[++i]
|
|
}
|
|
if (select !~ /^[0-9]+$/) {
|
|
print "awake: junk -s argument: "select
|
|
usage()
|
|
}
|
|
break
|
|
} else if (c == "n") {
|
|
dryrun = 1
|
|
} else if (c == "l") {
|
|
list = 1
|
|
} else {
|
|
print "awake: unknown option: -"c
|
|
usage()
|
|
}
|
|
}
|
|
}
|
|
ARGV[i] = ""
|
|
} else if (hasfilename) {
|
|
if (extraargs) {
|
|
extraargs = extraargs" "ARGV[i]
|
|
} else {
|
|
extraargs = ARGV[i]
|
|
}
|
|
ARGV[i] = ""
|
|
} else {
|
|
if (index(ARGV[i], "=")) {
|
|
print "awake: bad filename: "ARGV[i]
|
|
usage()
|
|
}
|
|
hasfilename = 1
|
|
shortname = filename = ARGV[i]
|
|
sub(/.*\//, "", shortname)
|
|
sub(/[.][^.]*/, "", shortname)
|
|
}
|
|
}
|
|
if (!hasfilename) {
|
|
usage()
|
|
}
|
|
}
|
|
/@BAKE[ ]/ {
|
|
bakenum++
|
|
sub(/.*@BAKE[ ]/, "")
|
|
sub(/ *@STOP.*/, "")
|
|
if (list) {
|
|
print bakenum": "$0
|
|
} else if (select == bakenum) {
|
|
gsub(/\$@|@FILE/, filename)
|
|
gsub(/\$\*|@SHORT/, shortname)
|
|
gsub(/\$\+|@ARGS/, extraargs)
|
|
gsub(/@RECURS/, ARGV[0])
|
|
print "Awake: " $0
|
|
printf "Output: "
|
|
if (!dryrun) {
|
|
system($0)
|
|
print ""
|
|
}
|
|
}
|
|
}
|