From: kenkona@twics.co.jp
Newsgroups: fj.unix
Subject: Help on IRIS/GL programming (multiplexing GL devices)
Date: 13 Oct 92 14:42:03 GMT
Organization: TWICS, Tokyo, Japan

IRIS $B$N(J GL $B$N%W%m%0%i%`$K4XO"$7$?OC$7$J$N$G$9$,!"$I$J$?$+!"$o$+$k$+$?(J
$B$$$i$C$7$c$$$^$9$G$7$g$&$+!)(J $BBeM}E9$N$R$H$N$[$&$K$bJ9$$$?$N$G$9$,!"7k(J
$B6I!"!V$h$/$o$+$i$J$$!W$H$$$&$3$H$K$J$C$F$7$^$$$^$7$F!&!&!&(J

$B$d$j$?$$$3$H$O(J GL $B$N(J qdevice() $B$GEPO?$7$F$k%G%P%$%9$HIaDL$N%=%1%C%H$N(J
$B4V$G!"%^%k%A%W%l%C%/%9(J --- $B$I$A$i$+$K(J I/O $B%$%Y%s%H$,5/$3$k$^$GBT$D$H$$(J
$B$&$3$H$J$N$G$9$,!"$3$l$,$J$+$J$+$&$^$/F0$+$:$J$d$s$G$$$^$9!#(J

$B$3$l$O2?$+!"$d$j$+$?$H$$$&$N$,$"$k$N$G$7$g$&$+!)(J

$B$H$j$"$($:!"$3$NJU$N$G!";W$$$D$-$r%F%9%H$9$k$N$K:n$C$?%W%m%0%i%`$,$"$k(J
$B$N$G!"$=$l$b$D$1$F$*$-$^$9!#(J

$B%5%s%W%k!'(J
GL $B$N$[$&$O%U%!%$%k%G%9%/%j%W%?$,$"$k$N$+$I$&$+$h$/$o$+$i$J$$$N$G$9$,!"(J
$B%5%s%W%k!&%W%m%0%i%`$G$D$1$?$h$&$K!"$H$j$"$($:!"%U%!%$%k%G%9%/%j%W%?%F!<(J
$B%V%k$r%9%-%c%s$7$F$_$k$H!"$I$&$b!"$=$l$i$7$$$N$,!"#2$D=P$F$/$k$N$G!"$=(J
$B$l$r(J select() $B$7$F$_$k$H!"$3$l<+BN$O$A$c$s$H(J select() $B$G$-$F$$$k$h$&$K(J
$B;W$$$^$9!#$,!"$3$l$K%=%1%C%H$N%U%!%$%k%G%9%/%j%W%?$,2C$o$k$H!"%=%1%C%H(J
$BB&$K$O%G!<%?$,Mh$F$b$9$0$K$O(J select() $B$,JV$C$F$3$J$/$J$C$F$7$^$&!"$H$$(J
$B$&L/$J!J!)!K8=>]$,$*$-$^$9!#(J--- $B$J$<$J$N$G$7$g$&!)(J

---<cut here>---
: To unbundle, sh this file
echo Makefile
cat >Makefile <<'@@@ Fin de Makefile'
# $Id: Makefile,v 1.1.1.1 1992/10/13 04:20:13 ko Exp $

SHELL = /bin/sh

LIBS= -lgl_s -s

CFLAGS = -g

all: glselect

.c:
	cc $(CFLAGS) $(INCLUDES) -o $@ $< $(LIBS)

@@@ Fin de Makefile
echo glselect.c
cat >glselect.c <<'@@@ Fin de glselect.c'
/*
 * $Id: glselect.c,v 1.2 1992/10/13 04:40:39 ko Exp $
 *
 * glselect
 *
 * GL $B$N(J qdevice() $B$N%$%Y%s%H$H%=%1%C%H!J(Jstdin$B!K$KBP$7$F(J select()
 * $B$7$h$&$H$9$k%W%m%0%i%`!#(J
 *
 * $B<B:]$O!"Av$i$;$k$H(J stdin $BB&$K%G!<%?$,Mh$F$b$9$0$K$O(J select() $B$,(J
 * $BH4$1$F$3$J$$!J!)!K(J
 * 
 * $B!J(Jstdin $B$O!"(J$ rsh `hostname` `pwd`/glselect $B$N$h$&$K$7$F(J
 * $B%=%1%C%H$K3+$$$F$$$k$H2>Dj$7$F$k!K(J
 */

#include <sys/param.h>		/* for NOFILE */
#include <sys/types.h>
#include <sys/stat.h>

#include <gl/gl.h>
#include <gl/device.h>

#include <stdio.h>

char *program;			/* window title (NULL, if not given) */
  
  int drawproc();			/* redraw procedure */
  
  main(argc,argv)
  int argc;
  char **argv;
{
  short val;
  fd_set set0, set;
  int nfds;
  
  setbuf(stdin, NULL);
  setbuf(stdout, NULL);
  setbuf(stderr, NULL);
  
  program = argv[1];
  
  winopen(program);
  
  drawproc();			/* force update */
  
  /* select() $B$N(J fd_set $B$r$D$/$k(J */
  FD_ZERO(&set0);
  FD_SET(0, &set0);		/* look stdin */
  nfds = 1;
  
  /* qdevice() $B$N(J fd $B$rC5$9(J -- $B$"$l$P!"(Jset0 $B$K5-O?!#(J */
  { int fd;
    struct stat s;
    for(fd=3; fd<NOFILE; fd++){
      if((fd!=2) && (fstat(fd,&s) == 0)){ /* fstat() $B$N(J 0 => $B@.8y(J */
	fprintf(stderr, "stat: fd no.%d is in use...\n",  fd);
	FD_SET(fd, &set0);
	nfds = fd + 1;
      }
    }
  }
  
  /* enter our event loop */
  while(1){
    int r;			/* return value of select() */
    set = set0;			/* setup fd_set */
    if((r=select(nfds, &set, (fd_set *) NULL, (fd_set *) NULL, (struct timeval *)NULL)) < 0){
      perror("select");
      exit(1);
    }
    if(FD_ISSET(0, &set)){	/* data on stdin */
      char b[128];
      if(gets(b) != NULL){
	printf("stdin ==> %s\n", b);
      }
      else{
	printf("can't read stdin ??\n");
      }
    }
    if(!(r == 1 && FD_ISSET(0, &set))){	/* data on GL file descriptor */
      switch(qread(&val)){
      case REDRAW:
	fputs("redraw\n", stderr);
	drawproc();
	break;
      default:
	;				/* ignore */
      }
    }
  }
}

/* procedure get called each time canvas is redrawn. */
drawproc()
{
  long x, y;
  reshapeviewport();
  getsize(&x, &y);
  ortho2((Coord) 0, (Coord) x, (Coord) 0, (Coord) y);
  color(WHITE);
  clear();
  color(RED);
  move2i((long) 0, (long) 0);
  draw2i((long) x, (long) y);
}

@@@ Fin de glselect.c
exit 0
---<end of shar file>--
$B$3$J$+(J $B$1$s$8(J ----- Kokubunji-Shi, Tokyo (kenkona@twics.co.jp, 
					  ko@takuan.chi.snet.or.jp)
PHONE: 0423-20-7171 (office)

Newsgroups: fj.unix