9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] watch
@ 2005-04-19  9:07 Steve Simon
  0 siblings, 0 replies; only message in thread
From: Steve Simon @ 2005-04-19  9:07 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 48 bytes --]

watch and wrapper that I use attached.

-Steve

[-- Attachment #2: revu --]
[-- Type: text/plain, Size: 104 bytes --]

#!/bin/rc

cmd=`{doctype $*}
while(){
	$cmd | proof &
	watch $* > /dev/null && slay proof | rc
}

[-- Attachment #3: watch.c --]
[-- Type: text/plain, Size: 825 bytes --]

/* watch.c - await first file is modified, then cat all files */
#include <u.h>
#include <libc.h>

void
main(int argc, char *argv[])
{
	char buf[4096];
	int fd, i, n;
	Dir *ods, *ds;

	if (argc != 2){
		fprint(2, "usage: await <file>\n");
		exits("usage");
	}

	if ((ods = dirstat(argv[1])) == nil)
		sysfatal("%s - cannot stat\n", argv[1]);
	while(1){
		sleep(1);
		if ((ds = dirstat(argv[1])) == nil)
			sysfatal("%s cannot stat %r\n", argv[1]);
		
		if (ds->mtime > ods->mtime)
			break;
		free(ds);
	}

	for (i = 1; i < argc; i++){
		if ((fd = open(argv[i], OREAD)) == -1)
			fprint(2, "%s cannot open - %r\n", argv[i]);
		while((n = read(fd, buf, sizeof(buf))) > 0)
			if (write(1, buf, n) != n)
				sysfatal("%s write failed - %r\n", argv[i]);
		close(fd);
	}

	exits(0);
}




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-04-19  9:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-19  9:07 [9fans] watch Steve Simon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).