9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Novice use of libg
@ 1997-11-20 18:04 Tad
  0 siblings, 0 replies; 3+ messages in thread
From: Tad @ 1997-11-20 18:04 UTC (permalink / raw)


In message <swordfish.880045065@minster.cs.york.ac.uk>, you said:
;------------------------------- cut here -----------------------
;int
;main(int argc, char **argv) {
;	Mouse mouse;
;	ulong Estdin;
;	bool done = false;
;	progname = argv[0];
;	binit(panic, 0, progname);
;	if ((Estdin = estart((ulong)0, 0, 8192)) == 0)
;		panic("Estdin = estart(0, 0, 8192) fails");
;	einit(Emouse | Estdin);
;	do {
;		struct Event e;
;		ulong key = eread(Emouse | Estdin, &e);
;		if (key == Estdin) {
;fprintf(stderr, "debug: Estdin, e.n %d\n", e.n); fflush(stderr);
;		} else if (key == Emouse) {
;fprintf(stderr, "debug: Emouse, x %d y %d\n", e.mouse.xy.x, e.mouse.xy.y);
;fflush(stderr);
;		} else
;			panic("unexpected event");
;	} while (!done);

I see two problems off the top of my head:
    eread() is only called once.
    done is never set to "true", thus the looping.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [9fans] Novice use of libg
@ 1997-11-20 23:17 forsyth
  0 siblings, 0 replies; 3+ messages in thread
From: forsyth @ 1997-11-20 23:17 UTC (permalink / raw)


>>	if ((Estdin = estart((ulong)0, 0, 8192)) == 0)
>>		panic("Estdin = estart(0, 0, 8192) fails");
>>	einit(Emouse | Estdin);

einit must be called before estart (it initialises the state for
the other event routines).

on Plan 9, you can use
	fprint(2, ...);
to print directly to a file descriptor, instead of
	fprintf(stderr, ...
avoiding an old library and the possible need to fflush.





^ permalink raw reply	[flat|nested] 3+ messages in thread

* [9fans] Novice use of libg
@ 1997-11-20 16:16 john
  0 siblings, 0 replies; 3+ messages in thread
From: john @ 1997-11-20 16:16 UTC (permalink / raw)


I'm an experienced UNIX programmer who should have made more time
over the last several years to get started writing programs for
use with Plan 9. I'm having a little trouble with writing a program
which I hope will sit at the r.h.s. of a two-process pipeline and draw
a graphical representation of some slowly incoming data, and also
allow the user to manipulate the representation with their mouse.
Perhaps some kind person will offer their advice.

I made a start with the tiny sample program below. I'm compiling
it on a 486 with `8c viewer.c' and loading it with `8l viewer.8',
then testing it with `echo hello | 8.out'. I thought I could use
estart() to get me an `Estdin' event key, but I actually see the
fatal error message `8.out events: bad slave assignment'.

I also have libXg from the UNIX sam distribution. What alterations
would I need to (the corrected version of) the program below in order
to run it under (a modern) UNIX? (My guess is that fcntl() with
O_NONBLOCK is part of the answer, but when I try this I see an
infinite number of copies of my message `debug: Estdin, e.n 0'.)

Any other comments, e.g. on style, would be thankfully received.

John A. Murdie
Department of Computer Science
University of York
England
------------------------------- cut here -----------------------
#include <u.h>
#include <libc.h>
#include <libg.h>
#include <stdio.h>

#define bool int
#define false 0
#define true 1

static char	*progname;

void
panic(char *s) {
	fprintf(stderr, "%s: %s\n", progname, s);
	fflush(stderr);
	exits("fatal");
}

void
ereshaped(Rectangle r) {
}

int
main(int argc, char **argv) {
	Mouse mouse;
	ulong Estdin;
	bool done = false;
	progname = argv[0];
	binit(panic, 0, progname);
	if ((Estdin = estart((ulong)0, 0, 8192)) == 0)
		panic("Estdin = estart(0, 0, 8192) fails");
	einit(Emouse | Estdin);
	do {
		struct Event e;
		ulong key = eread(Emouse | Estdin, &e);
		if (key == Estdin) {
fprintf(stderr, "debug: Estdin, e.n %d\n", e.n); fflush(stderr);
		} else if (key == Emouse) {
fprintf(stderr, "debug: Emouse, x %d y %d\n", e.mouse.xy.x, e.mouse.xy.y);
fflush(stderr);
		} else
			panic("unexpected event");
	} while (!done);
	bflush();
	exits(0);
}





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-11-20 23:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-20 18:04 [9fans] Novice use of libg Tad
  -- strict thread matches above, loose matches on Subject: below --
1997-11-20 23:17 forsyth
1997-11-20 16:16 john

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).