diff options
author | Freya Murphy <freya@freyacat.org> | 2023-11-10 19:44:48 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2023-11-10 19:44:48 -0500 |
commit | 8b7fe69ca362bf7f78fee7207ddd10d8697ae02a (patch) | |
tree | e9c38ea4589360bafd434603feb6bcd95629556b /bin/config.awk | |
download | freyanet-8b7fe69ca362bf7f78fee7207ddd10d8697ae02a.tar.gz freyanet-8b7fe69ca362bf7f78fee7207ddd10d8697ae02a.tar.bz2 freyanet-8b7fe69ca362bf7f78fee7207ddd10d8697ae02a.zip |
things
Diffstat (limited to 'bin/config.awk')
-rwxr-xr-x | bin/config.awk | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/bin/config.awk b/bin/config.awk new file mode 100755 index 0000000..f4833ae --- /dev/null +++ b/bin/config.awk @@ -0,0 +1,35 @@ +#!/run/current-system/profile/bin/awk -f + +BEGIN { + FS = "[ ]"; # use a single space as field separator and don't trim input + ind = 0; # indentation level + last = ARGC - 3; # last argument index + exitcode = 1; # whether anything has been matched + if(last < 0) { # there should be at least one argument after the filename + exit 1; + } + ARGC = 2; # don't read ARGV[2] and onward as files +} + +END { + exit exitcode; +} + +$0 != "" { # exit when the indentation block is exited + for(i = 0; i < ind; i++) { + if(! sub(/^\t/, "")) { + exit exitcode; + } + } +} + +# if on the last argument, interpret it as a key and print the value +ind == last && $1 == ARGV[ind + 2] { + exitcode = 0; + print substr($0, length($1) + 2); +} +# if not on the last argument, find the string exactly and increment indentation +ind != last && $0 == ARGV[ind + 2] { + ind++; +} + |