mawk/filter

This commit is contained in:
Marc Beninca 2025-07-13 18:56:54 +02:00
parent cc4c0e967e
commit b0abc4db45
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -1,3 +1,11 @@
function alias_function(alias, name) {
print alias "() { " name " \"${@}\"; }"
}
function alias_variable(alias, name) {
print alias "() { echo \"${" name "}\"; }"
}
function append(line) { function append(line) {
if (doc) { if (doc) {
doc = doc "\n" doc = doc "\n"
@ -5,12 +13,20 @@ function append(line) {
doc = doc line doc = doc line
} }
function alias_function(alias, target) { function extract(string, type) {
print alias "() { " target " \"${@}\"; }" if (type == "alias") {
} split(string, array, "#=")
return trim(array[2])
function alias_variable(alias, target) { } else if (type == "command") {
print alias "() { echo \"${" target "}\"; }" split(string, array, "#/")
return trim(array[2])
} else if (type == "function") {
split(string, array, "()")
return trim(array[1])
} else if ((type == "constant") || (type == "variable")) {
split(string, array, "=")
return trim(array[1])
}
} }
function output(name, type) { function output(name, type) {
@ -26,6 +42,13 @@ function reset() {
} }
} }
function trim(string) {
text = string
sub("^[\t ]*", "", text)
sub("[\t ]*$", "", text)
return text
}
BEGIN { BEGIN {
RE_ANY = "(.*)" RE_ANY = "(.*)"
RE_BEGIN = "^" RE_BEGIN = "^"
@ -63,8 +86,8 @@ BEGIN {
{ {
if (action == "filter") { if (action == "filter") {
if (match($0, re[target], m)) { if (match($0, re[target])) {
unique[m[1]] = "" unique[extract($0, target)] = ""
} }
} else if (action == "tasks") { } else if (action == "tasks") {
if (match($0, RE_MODULE, m)) { if (match($0, RE_MODULE, m)) {