summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorepoch <epoch@thebackupbox.net>2022-10-01 03:48:42 -0500
committerepoch <epoch@thebackupbox.net>2022-10-01 03:48:42 -0500
commit35fecc62409ee86ec45ae64a392e152e3e190384 (patch)
treeea7bae6fb9a884382ee1fb5d8061d34a51a8378b
parent8d981a07f9d3d73cdd0a823a675277dc8526e166 (diff)
downloaduritools-35fecc62409ee86ec45ae64a392e152e3e190384.tar.gz
uritools-35fecc62409ee86ec45ae64a392e152e3e190384.zip
added uri-absolution. from geminiclient, but will be useful here too :)
-rw-r--r--Makefile4
-rwxr-xr-xuri-absolution25
2 files changed, 28 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 6c9dbef..64caa52 100644
--- a/Makefile
+++ b/Makefile
@@ -38,6 +38,7 @@ install: all
install -t $(PREFIX)/bin uriunescape
install -t $(PREFIX)/bin uriescape
install -t $(PREFIX)/bin urilaunch
+ install -t $(PREFIX)/bin uri-aboslution
install -t $(PREFIX)/bin search
install -t $(PREFIX)/bin getsrv
install -t $(PREFIX)/bin urititle
@@ -53,4 +54,5 @@ install: all
install -t $(PREFIX)/bin rfc-search
install -t $(PREFIX)/bin urilist
install -t $(PREFIX)/bin rfc-list
- chgrp shorten $(PREFIX)/bin/shorten && chmod g+s $(PREFIX)/bin/shorten
+ install -t $(PREFIX)/bin man-list
+ chgrp shorten $(PREFIX)/bin/shorten && chmod g+s $(PREFIX)/bin/shorten || true #ignore this error
diff --git a/uri-absolution b/uri-absolution
new file mode 100755
index 0000000..a1eb6c1
--- /dev/null
+++ b/uri-absolution
@@ -0,0 +1,25 @@
+#!/bin/sh
+base_uri="$1"
+domain="$(printf "%s\n" "$base_uri" | uricut -d)"
+scheme="$(printf "%s\n" "$base_uri" | uricut -s)"
+path="$(printf "%s\n" "$base_uri" | uricut -p)"
+most_of_path="$(printf "%s\n" "$base_uri" | uricut -p | rev | cut -d/ -f2- | rev)"
+
+### this is the verbose version for debugging.
+### to enable debug mode, uncomment this, and comment out the next sed.
+#sed \
+#'s|^<[ \t]*\([A-Za-z][A-Za-z+.-]*:[^ \t]*\)>|(absolute) \1|g;t
+#s|^<[ \t]*\(#[^ \t]*\)>|(fragmentid_relative) '"${base_uri}"'\1|g;t
+#s|^<[ \t]*\(?[^ \t]*\)>|(querystring_relative) '"$scheme"'://'"$domain""$path"'\1|g;t
+#s|^<[ \t]*\(//[^ \t]*\)>|(scheme_relative) '"$scheme"':\1|g;t
+#s|^<[ \t]*\(/[^ \t]*\)>|(absolute_path) '"$scheme"'://'"$domain"'\1|g;t
+#s|^<[ \t]*\([^ \t]*\)>|(same-dir path relative) '"$scheme"'://'"$domain""$most_of_path"'/\1|g'
+
+sed -u \
+'s|^<[ \t]*\([A-Za-z][A-Za-z+.-]*:[^ \t]*\)>|\1|g;t
+s|^<[ \t]*\(#[^ \t]*\)>|'"${base_uri}"'\1|g;t
+s|^<[ \t]*\(?[^ \t]*\)>|'"$scheme"'://'"$domain""$path"'\1|g;t
+s|^<[ \t]*\(//[^ \t]*\)>|'"$scheme"':\1|g;t
+s|^<[ \t]*\(/[^ \t]*\)>|'"$scheme"'://'"$domain"'\1|g;t
+s|^<[ \t]*\([^ \t]*\)>|'"$scheme"'://'"$domain""$most_of_path"'/\1|g;t
+s|^<[ \t]*\(.*\)>|<\1> UNHANDLED|g'