11.1Schristos#	$NetBSD: dmesg,v 1.1 2020/04/14 13:58:11 christos Exp $
21.1Schristos
31.1Schristosdefine dmesg
41.1Schristos	set $mbp = msgbufp
51.1Schristos	set $bufdata = &$mbp->msg_bufc[0]
61.1Schristos	set $print = $mbp->msg_bufs
71.1Schristos	set $newl = 0
81.1Schristos	set $skip = 0
91.1Schristos	set $i = -1 
101.1Schristos	set $p = $bufdata + $mbp->msg_bufx - 1
111.1Schristos
121.1Schristos	while ($i < $mbp->msg_bufs)
131.1Schristos		set $i = $i + 1
141.1Schristos		set $p = $p + 1
151.1Schristos		if ($p == $bufdata + $mbp->msg_bufs)
161.1Schristos			set $p = $bufdata
171.1Schristos		end
181.1Schristos		if ($i < $mbp->msg_bufs - $print)
191.1Schristos			loop_continue
201.1Schristos		end
211.1Schristos		set $c = $p[0]
221.1Schristos		# Skip syslog sequences
231.1Schristos		if ($skip)
241.1Schristos			if ($c == '>')
251.1Schristos				set $newl = 0
261.1Schristos				set $skip = 0
271.1Schristos			end
281.1Schristos			loop_continue
291.1Schristos		end
301.1Schristos		if ($newl && $c == '<')
311.1Schristos			set $skip = 1
321.1Schristos			loop_continue
331.1Schristos		end
341.1Schristos		if ($c == '\0')
351.1Schristos			loop_continue
361.1Schristos		end
371.1Schristos		set $newl = $c == '\n'
381.1Schristos		printf "%c", $c
391.1Schristos	end
401.1Schristos	if (!$newl)
411.1Schristos		printf "\n"
421.1Schristos	end
431.1Schristosend
441.1Schristos
451.1Schristosdocument dmesg
461.1Schristosprint the message buffer
471.1Schristosend
48