]> Lady’s Gitweb - Shushe/commitdiff
Make percent‐decoding awk script portable
authorLady <redacted>
Fri, 2 Feb 2024 04:09:47 +0000 (23:09 -0500)
committerLady <redacted>
Sat, 3 Feb 2024 22:24:22 +0000 (17:24 -0500)
This script depended on `printf` having the same behaviour within `awk`
and on the commandline. This doesn’t appear to be true in G·N·U Awk.
Instead, pipe into the shell version from within the Awk script.

GNUmakefile

index 1bdc8b76fde13491b92c3c5399b9d27e313a2337..4979bfbc8b11c4001505fe8598560423e7556eca 100644 (file)
@@ -202,7 +202,7 @@ override silent := $(if $(VERBOSE),,@)
 override sedesc = $(subst /,[/],$(subst $$,\$$,$(subst *,\*,$(subst .,\.,$(subst [,\[,$(subst ^,\^,$(subst \,\\,$1)))))))
 
 # (callable) Percent‐decode the given strings.
-override perdec = $(foreach encoded,$1,$(shell $(PRINTF) '%s\n' $(call quote,$(encoded)) | $(SED) 's/|/%7C/g;s/[\]/%5C/g;s/%[0-9A-Fa-f]\{2\}/|&|/g' | $(TR) '|' '\n' | $(SED) '/^%[0-9A-Fa-f]\{2\}$$/!s/%/|%25|/' | $(TR) '|' '\n' | $(AWK) '$$0!~/%/{printf("%s",$$0)}/%/{sub("%","0x");printf("\\%04o",$$0)}' | $(XARGS) -0 $(PRINTF) '%b'))
+override perdec = $(foreach encoded,$1,$(shell $(PRINTF) '%s\n' $(call quote,$(encoded)) | $(SED) 's/|/%7C/g;s/[\]/%5C/g;s/%[0-9A-Fa-f]\{2\}/|&|/g' | $(TR) '|' '\n' | $(SED) '/^%[0-9A-Fa-f]\{2\}$$/!s/%/|%25|/' | $(TR) '|' '\n' | $(AWK) '$$0!~/%/{printf "%s",$$0}/%/{sub("%","0x");cmd="$(XARGS) $(PRINTF) \"%04o\"";printf "%s","\\";printf "%s",$$0|cmd;close(cmd)}' | $(XARGS) -0 $(PRINTF) '%b'))
 
 # (callable) Percent‐encode the given strings.
 #
This page took 0.024037 seconds and 4 git commands to generate.