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