9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: john@minster.cs.york.ac.uk john@minster.cs.york.ac.uk
Subject: [9fans] Novice use of libg
Date: Thu, 20 Nov 1997 16:16:33 +0000	[thread overview]
Message-ID: <19971120161633.pT6BxpytXw6bKClbtSEG-H3ZG2mLCJ31i0b9k9761Lg@z> (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);
}





             reply	other threads:[~1997-11-20 16:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-11-20 16:16 john [this message]
1997-11-20 18:04 Tad
1997-11-20 23:17 forsyth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=19971120161633.pT6BxpytXw6bKClbtSEG-H3ZG2mLCJ31i0b9k9761Lg@z \
    --to=john@minster.cs.york.ac.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).