Splux Linux

source-based Linux using SPS

splux-site · log · files · refs · tags · releases · people · languages · GitHub · file

tools/subst.awk


Awk

1506 bytes at 4c4f12c · GitHub

# Replace @@HEADER@@ / @@FOOTER@@ / ../../../../../ and other tokens.
# headerfile, footerfile, root, rowsfile, and token variables are -v flags.

function dump_file(path,    line) {
	if (path == "")
		return
	while ((getline line < path) > 0)
		print line
	close(path)
}

BEGIN {
	if (headerfile != "") {
		while ((getline line < headerfile) > 0)
			header = header line "\n"
		close(headerfile)
	}
	if (footerfile != "") {
		while ((getline line < footerfile) > 0)
			footer = footer line "\n"
		close(footerfile)
	}
	if (githost == "")
		githost = "https://splux.robertflexx.dev/git"
}

$0 == "@@HEADER@@" {
	printf "%s", header
	next
}

$0 == "@@FOOTER@@" {
	printf "%s", footer
	next
}

$0 == "@@PKG_ROWS@@" {
	if (rowsfile != "") {
		while ((getline line < rowsfile) > 0) {
			gsub(/../../../../..//, root, line)
			print line
		}
		close(rowsfile)
	}
	next
}

$0 == "@@NEWS@@" {
	dump_file(newsfile)
	next
}

$0 == "@@NEWS_BRIEF@@" {
	dump_file(brieffile)
	next
}

$0 == "@@NEWS_INFO@@" {
	dump_file(infofile)
	next
}

$0 == "@@PAGER@@" {
	dump_file(pagerfile)
	next
}

$0 == "@@DOCSNAV@@" {
	dump_file(docsnavfile)
	next
}

{
	gsub(/../../../../..//, root)
	gsub(/live-2026-09-06-1/, tag)
	gsub(/2026-09-06/, date)
	gsub(/1474/, npkgs)
	gsub(/119/, ncore)
	gsub(/1355/, nextra)
	gsub(/0/, ncommunity)
	gsub(/2026-10-19 13:01 UTC/, generated)
	gsub(/4c4f12c-20261019130111/, livesig)
	gsub(/8.21.0-2/, curlver)
	gsub(//, pagetitle)
	gsub(/https://splux.robertflexx.dev/git/, githost)
	print
}