X-Git-Url: https://git.ladys.computer/Shushe/blobdiff_plain/03f9773767ae7811289561abe5162e8b04578991..b96a5ac986977275066876a3383966f1f4e24d30:/GNUmakefile

diff --git a/GNUmakefile b/GNUmakefile
index 4f1fb5b..8417d13 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -215,19 +215,22 @@ override silent := $(if $(VERBOSE),,@)
 # (callable) Escape special characters for use in sed regular expressions.
 override sedesc = $(subst /,[/],$(subst $$,\$$,$(subst *,\*,$(subst .,\.,$(subst [,\[,$(subst ^,\^,$(subst \,\\,$1)))))))
 
+# The command to use for percent‐decoding.
+override perdeccmd := $(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‐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");cmd="$(XARGS) $(PRINTF) \"%04o\"";printf "%s","\\";printf "%s",$$0|cmd;close(cmd)}' | $(XARGS) -0 $(PRINTF) '%b'))
+override perdec = $(shell $(PRINTF) '%s\0450A' $(foreach encoded,$1,$(call quote,$(encoded))) | $(perdeccmd))
 
 # (callable) Percent‐encode the given strings.
 #
 # This singly‐encodes u·r·i characters and doubly‐encodes other characters, then calls `perdec´ to decode back to a single encoding.
 # The encoding assumes the input is a “u·r·i component”; e·g that the resulting string should only contain `pchar´ (but can contain any `sub-delim´).
-override perenc = $(foreach unencoded,$1,$(call perdec,$(shell $(PRINTF) '%s' $(call quote,$(unencoded)) | $(OD) -t x1 | $(SED) 's/^[0-9]*//;s/2[146-9A-Ea-e]/%&/g;s/3[0-9AaBbDd]/%&/g;s/40/%&/g;s/[46][1-9A-Fa-f]/%&/g;s/[57][0-9Aa]/%&/g;s/5[Ff]/%&/g;s/7[Ee]/%&/g;s/[ ][0-9A-Fa-f]\{2\}/%25&/g' | $(TR) -d ' \n' | $(TR) 'abcdef' 'ABCDEF')))
+#
+# It is assumed that the given strings do not contain newlines.
+override perenc = $(shell $(PRINTF) '%s\n' $(foreach unencoded,$1,$(call quote,$(unencoded))) | $(OD) -t x1 | $(SED) 's/^[0-9]*//;s/0[Aa]/%&/g;s/2[146-9A-Ea-e]/%&/g;s/3[0-9AaBbDd]/%&/g;s/40/%&/g;s/[46][1-9A-Fa-f]/%&/g;s/[57][0-9Aa]/%&/g;s/5[Ff]/%&/g;s/7[Ee]/%&/g;s/[ ][0-9A-Fa-f]\{2\}/%25&/g' | $(TR) -d ' \n' | $(TR) 'abcdef' 'ABCDEF' | $(perdeccmd))
 
 # (callable) Percent‐encode each component in the given paths.
-#
-# ☡ This will remove leading and trailing slashes.
-override pathenc = $(foreach path,$1,$(subst $(space),/,$(call perenc,$(subst /, ,$(path)))))
+override pathenc = $(subst %2F,/,$(call perenc,$1))
 
 # (overridable) Collect all of the applicable includes from the includes directory.
 sourceincludes := $(shell $(FIND) $(foreach dir,$(INCLUDEDIR),$(call quote,$(dir))) '(' $(FINDRULES) ')' -a -type f)
@@ -451,7 +454,7 @@ $(BUILDDIR)/magic.mgc : $(call magicfile,$(MAGIC))
 $(BUILDDIR)/parser.catalog : $(PARSERS)
 	@$(ECHO) "Generating catalog of parsers…"
 	$(silent)$(XMLCATALOG) --create --noout $(call quote,$@)
-	$(foreach parser,$(PARSERS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call id,$(parser),parser)) $(call quote,file:///$(call pathenc,$(abspath $(parser)))) --noout $(call quote,$@)$(newline))
+	$(foreach parser,$(PARSERS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call id,$(parser),parser)) $(call quote,file://$(call pathenc,$(abspath $(parser)))) --noout $(call quote,$@)$(newline))
 $(BUILDDIR)/parser.xslt: $(BUILDDIR)/parser.catalog $(THISDIR)/lib/catalog2parser.xslt
 	@$(ECHO) "Generating main parser…"
 	$(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2parser.xslt) $(call quote,$<)
@@ -471,7 +474,7 @@ $(call parsed,$(sourcefiles) $(sourceincludes)) : % : $$(call unparsed,$$@) $(ty
 $(BUILDDIR)/catalog : $(sourcefiles) $(sourceincludes) $(typeupdates)
 	@$(ECHO) "Generating catalog of parsed files…"
 	$(silent)$(XMLCATALOG) --create --noout $(call quote,$@)
-	$(foreach source,$(sourcefiles) $(sourceincludes),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call localuri,$(source))) $(call quote,file:///$(call pathenc,$(abspath $(call parsed,$(source))))#$(if $(filter $(source),$(assetfiles)),asset,xml)) --noout $(call quote,$@)$(newline))
+	$(foreach source,$(sourcefiles) $(sourceincludes),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call localuri,$(source))) $(call quote,file://$(call pathenc,$(abspath $(call parsed,$(source))))#$(if $(filter $(source),$(assetfiles)),asset,xml)) --noout $(call quote,$@)$(newline))
 
 # Build a list of dependencies for each parsed file.
 $(BUILDDIR)/dependencies : $(BUILDDIR)/catalog $(call parsed,$(plaintextfiles) $(xmlfiles)) $(THISDIR)/lib/catalog2dependencies.xslt
@@ -490,7 +493,7 @@ $(BUILDDIR)/destinations : $(BUILDDIR)/catalog $(call parsed,$(filter-out $(asse
 $(BUILDDIR)/transform.catalog : $(TRANSFORMS)
 	@$(ECHO) "Generating catalog of transforms…"
 	$(silent)$(XMLCATALOG) --create --noout $(call quote,$@)
-	$(foreach transform,$(TRANSFORMS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call id,$(transform),transform)) $(call quote,file:///$(call pathenc,$(abspath $(transform)))) --noout $(call quote,$@)$(newline))
+	$(foreach transform,$(TRANSFORMS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call id,$(transform),transform)) $(call quote,file://$(call pathenc,$(abspath $(transform)))) --noout $(call quote,$@)$(newline))
 $(BUILDDIR)/transform.xslt : $(BUILDDIR)/transform.catalog $(THISDIR)/lib/catalog2transform.xslt
 	@$(ECHO) "Generating main transform…"
 	$(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2transform.xslt) $(call quote,$<)