shithub: riscv

ref: 9c0d74e03620811e9a5c0a697a849f9c3551e9bf
dir: /sys/src/9/xen/cppx/

View raw version
#!/bin/rc
awk '
function qq(s) {
	gsub("\"", "£", s)
	return "\"@" s "\""
}

/^#include/	{ next
}
/^#define.*\\$/ {
	save[n++] = $0
	print qq($0 "\\")
	next
}
(n > 0) && /\\$/ {
	save[n++] = $0
	print qq($0 "\\")
	next
}
(n > 0)  {
	save[n++] = $0
	print qq($0)
	for (i = 0; i < n; i++) print save[i]
	n = 0
	next
}
/^# *((define)|(error)).*[^\\]*$/ {
	print qq($0)
	print
	next
}
/^# *undef.*[^\\]*$/ {
	print
	print qq($0)
	next
}
	{ print
}
' $* |
cpp -P |
sed -e 's/£/"/g' -e 's/^"@(.*\\)\\"$/\1/' -e 's/^"@(.*)"$/\1/'