Subject: Re: CVS commit: pkgsrc/sysutils/dmesg2gif
To: Jeremy C. Reed <reed@reedmedia.net>
From: Robert Elz <kre@munnari.OZ.AU>
List: pkgsrc-changes
Date: 10/21/2003 01:43:07
    Date:        Mon, 20 Oct 2003 10:00:57 -0700 (PDT)
    From:        "Jeremy C. Reed" <reed@reedmedia.net>
    Message-ID:  <Pine.LNX.4.43.0310200955190.8732-100000@pilchuck.reedmedia.net>

  | I had a look at this code. It has unsafe tmp file usage.

It doesn't actually need a temp file at all - dot reads stdin, all
that's needed is to pipe the () subshell output into dot.

I just make that change locally, removing all references to the temp
file, and it worked just the same as before.

And even then, that's assuming that Dan Carosone's suggestion (in mail
that never went to the list, but should be appended to PR pkg/23207)
that the script shouldn't just produce the dot input file, and leave it
to the user to pipe the output into dot (at which point the user could use 
dotty, or dot -Tps or ...)

kre

ps: it should also be possible to replace that perl script with sed
I'd think, which would likely be faster (not that that matters), and
definitely one less dependency.   In fact it is easy ... this is what
I ended up with - same output is produced on my system:

#!/bin/sh
# $NetBSD: dmesg2gif,v 1.3 2003/10/20 17:11:43 hubertf Exp $
#
# Copyright (c) 2003 Hubert Feyrer <hubertf@netbsd.org>
#

if [ -t 0 -o -t 1 ]
then
	echo 2>&1 "Usage: cat /var/run/dmesg.boot | $0 | xv -"
	exit 1
fi


(
	echo "digraph dmesg { "
	cat \
	| grep -v ^# \
	| sed	-e 's/^[^ ]* at [^ ]*$/& /' \
		-e '/^[^ ]* at [^ ]* /!d' \
		-e 's/^\([^ ]*\) at \([^ :]*\).*/	\1 -> \2/'
	echo "}"

) | dot -Tgif

Note there's a tab in the RHS of the 's' command in the final sed
command, not that I expect it matters should it get replaced by spaces.