[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Groff] poor man's wysiwyg for groff/gv
From: |
Larry McVoy |
Subject: |
[Groff] poor man's wysiwyg for groff/gv |
Date: |
Sun, 16 Dec 2001 23:03:37 -0800 |
I use this a lot, maybe you'll like it. It burns a little cpu but that's
a non issue these days. You run it like
g groff -mgs -s -p -t mypaper.ms
and it redraws any time you touch any of the files included by mypaper.ms
or mypaper.ms itself.
Enjoy.
#!/usr/bin/perl
# Run the command into PS
# Run gv with the -watch option
# go into a loop watching the file and rerun command whenever the file
# has changed.
use POSIX ":sys_wait_h";
$usage = "usage: $0 comand -args -args filename\n";
die $usage unless -f $ARGV[$#ARGV];
$file = $ARGV[$#ARGV];
$cmd = "@ARGV > PS";
$gv = "gv -spartan -antialias PS";
system $cmd;
$pid = fork;
if ($pid == 0) {
exec $gv;
die $gv;
}
$stat{$file} = (stat($file))[9];
open(F, $file);
while (<F>) {
next unless /^\.so\s+(.*)\s*$/;
$stat{$1} = (stat($1))[9];
}
close(F);
while (1) {
select(undef, undef, undef, .2);
$kid = waitpid($pid,&WNOHANG);
exit 0 if (kill(0, $pid) != 1);
$doit = 0;
foreach $f (keys %stat) {
if ($stat{$f} != (stat($f))[9]) {
$stat{$f} = (stat($f))[9];
$doit = 1;
}
}
if ($doit) {
system $cmd;
kill(1, $pid);
}
}
- [Groff] poor man's wysiwyg for groff/gv,
Larry McVoy <=