コード例 #1
0
ファイル: pipe.c プロジェクト: GanShun/akaros
static long piperead(struct chan *c, void *va, long n, int64_t ignored)
{
	Pipe *p;

	p = c->aux;

	switch (NETTYPE(c->qid.path)) {
		case Qdir:
			return devdirread(c, va, n, p->pipedir, ARRAY_SIZE(pipedir),
							  pipegen);
		case Qdata0:
			if (c->flag & O_NONBLOCK)
				return qread_nonblock(p->q[0], va, n);
			else
				return qread(p->q[0], va, n);
		case Qdata1:
			if (c->flag & O_NONBLOCK)
				return qread_nonblock(p->q[1], va, n);
			else
				return qread(p->q[1], va, n);
		default:
			panic("piperead");
	}
	return -1;	/* not reached */
}
コード例 #2
0
  int readOneImpl() {
    int i;
    std::deque<unsigned char> cmp;
    for (i=0; i<m_nextMark.length(); ++i) {
      int c = qread();
      if (c>=0) {
        cmp.push_front(c);
        if (c==m_nextMark[i]) {
	  // MB_DPRINTLN("MM> %s", m_nextMark.substr(0, i).c_str());
          continue;
	}
      }
      else {

        // EOF
        if (cmp.size()<=0)
          break;
      }

      unsigned char ret = cmp.back();
      cmp.pop_back();
      std::deque<unsigned char>::const_iterator iter = cmp.begin();
      std::deque<unsigned char>::const_iterator iend = cmp.end();
      for (; iter!=iend; ++iter)
        unread(*iter);
      return ret;

    }

    m_bReady = false;
    return -1;
  }
コード例 #3
0
ファイル: linux_file.c プロジェクト: husthl/qos
static bool test_all(void){
    test( linux_file_vfs_open() );

    // write
    int fid = qopen( "./a.txt", O_RDWR | O_CREAT | O_TRUNC, NULL );
    test( 0 != fid );
    test( 5 == qwrite( fid, "12345", 5 ) );
    {
        struct qstat buf;
        test( qfstat( fid, &buf ) );
        test( 5 == buf.size );
    }
    test( qclose( fid ) );
    fid = 0;

    // read
    fid = qopen( "./a.txt", O_RDONLY, NULL );
    test( 0 != fid );
    {
        struct qstat buf;
        test( qfstat( fid, &buf ) );
        test( 5 == buf.size );
    }
    char buf[100];
    memset( buf, 0, sizeof( buf ) );
    test( 5 == qread( fid, buf, sizeof(buf) ) );
    test( 0 == memcmp( buf, "12345", 5 ) );
    test( qclose( fid ) );
    fid = 0;

    return true;
}
コード例 #4
0
ファイル: regress.c プロジェクト: GanShun/akaros
static long
regressread(struct chan *c, void *va, long n, int64_t off)
{
	uint64_t w, *bp;
	char *a, *ea;
	uintptr_t offset = off;
	uint64_t pc;
	int snp_ret, ret = 0;

	switch((int)c->qid.path){
	case Monitordirqid:
		n = devdirread(c, va, n, regresstab, ARRAY_SIZE(regresstab), devgen);
		break;

	case Monitorctlqid:
		n = readstr(off, va, n, ctlcommands);
		break;

	case Monitordataqid:
		if (regress.monitor) {
			printd("monitordataqid: regress.monitor %p len %p\n", regress.monitor, qlen(kprof.monitor));
			if (qlen(regress.monitor) > 0)
				n = qread(regress.monitor, va, n);
			else
				n = 0;
		} else
			error(EFAIL, "no monitor queue");
		break;
	default:
		n = 0;
		break;
	}
	return n;
}
コード例 #5
0
ファイル: asteroids.c プロジェクト: 8l/swieros
void event_loop(void)
{
  int e,w,x,y;
  for (;;) {
    while (qtest()) {
      e = qread(&w, &x, &y);
      switch (e) {
      case KEY:
         key(x);
         break;
               
      case REDRAW:
      case SHAPE:
        break;
        
      case WINSHUT:
      case HANGUP:
        return; 
      }
    }
    idle();
    draw();
    swapbuffers();
  }
}
コード例 #6
0
ファイル: netif.c プロジェクト: alfongj/akaros
long
netifread(struct netif *nif, struct chan *c, void *a, long n, uint32_t offset)
{
	int i, j;
	struct netfile *f;
	char *p;

	if (c->qid.type & QTDIR)
		return devdirread(c, a, n, (struct dirtab *)nif, 0, netifgen);

	switch (NETTYPE(c->qid.path)) {
		case Ndataqid:
			f = nif->f[NETID(c->qid.path)];
			return qread(f->in, a, n);
		case Nctlqid:
			return readnum(offset, a, n, NETID(c->qid.path), NUMSIZE);
		case Nstatqid:
			p = kzmalloc(READSTR, 0);
			if (p == NULL)
				return 0;
			j = snprintf(p, READSTR, "in: %d\n", nif->inpackets);
			j += snprintf(p + j, READSTR - j, "link: %d\n", nif->link);
			j += snprintf(p + j, READSTR - j, "out: %d\n", nif->outpackets);
			j += snprintf(p + j, READSTR - j, "crc errs: %d\n", nif->crcs);
			j += snprintf(p + j, READSTR - j, "overflows: %d\n",
						  nif->overflows);
			j += snprintf(p + j, READSTR - j, "soft overflows: %d\n",
						  nif->soverflows);
			j += snprintf(p + j, READSTR - j, "framing errs: %d\n",
						  nif->frames);
			j += snprintf(p + j, READSTR - j, "buffer errs: %d\n", nif->buffs);
			j += snprintf(p + j, READSTR - j, "output errs: %d\n", nif->oerrs);
			j += snprintf(p + j, READSTR - j, "prom: %d\n", nif->prom);
			j += snprintf(p + j, READSTR - j, "mbps: %d\n", nif->mbps);
			j += snprintf(p + j, READSTR - j, "addr: ");
			for (i = 0; i < nif->alen; i++)
				j += snprintf(p + j, READSTR - j, "%02.2x", nif->addr[i]);
			snprintf(p + j, READSTR - j, "\n");
			n = readstr(offset, a, n, p);
			kfree(p);
			return n;
		case Naddrqid:
			p = kzmalloc(READSTR, 0);
			if (p == NULL)
				return 0;
			j = 0;
			for (i = 0; i < nif->alen; i++)
				j += snprintf(p + j, READSTR - j, "%02.2x", nif->addr[i]);
			n = readstr(offset, a, n, p);
			kfree(p);
			return n;
		case Ntypeqid:
			f = nif->f[NETID(c->qid.path)];
			return readnum(offset, a, n, f->type, NUMSIZE);
		case Nifstatqid:
			return 0;
	}
	error(Ebadarg);
	return -1;	/* not reached */
}
コード例 #7
0
ファイル: matplot.c プロジェクト: B-Rich/tcoffee
/* display_mat: displays a Row x Col matrix Mat in the window Gid,
 * using a simple colour-coded representation (blue for Lowval, red for
 * Upval etc.) The window may be resized, moved or iconified.
 * The window is closed when <Esc> is pressed.
 */
void display_mat(long Gid, double **Mat, unsigned int Row, unsigned int Col, 
		    double Lowval, double Upval)
{
    Device Dev;
    short Val;
    
    plot_mat(Gid, Mat, Row, Col, Lowval, Upval);
    while(1)
    {
	do  /* read the event queue until empty */
	{
	    Dev=qread(&Val);
	    switch(Dev)
	    {
		case REDRAW:	/* redraw if necessary */
		case REDRAWICONIC:
		case WINFREEZE:
		case WINTHAW:
		    plot_mat(Gid, Mat, Row, Col, Lowval, Upval);
		break;
		
		case ESCKEY:	/* both close up shop */
		case WINQUIT:
		    winclose(Gid); return;
		break;
		
		default: break;
	    }
	} while (qtest());
    }	    /* while(1) */
}
コード例 #8
0
ファイル: glwidget.c プロジェクト: pgramage/gaspware
int update_widgets(short val) {
    gl_slider *sl = firstslider;
    gl_button *bt = firstbutton;
    Int16 x, y;
    int flag = FALSE, sliderchange = FALSE;

#ifdef DEBUG
    printf("update_widgets called with val = %d\n", (int)val);
    if (qtest()) {
	int dev; 
	dev = qread(&x);
	printf("update_widgets: qtest() for x is true. dev = %d, val = %d\n",
	       dev, (int)x);
    } else {
	x = getvaluator(MOUSEX);
	printf("update_widgets: qtest() for x is FALSE!. x = %d\n", (int)x);
    }
    if (qtest()) {
	int dev; 
	dev = qread(&y);
	printf("update_widgets: qtest() for y is true. dev = %d, val = %d\n",
	       dev, (int)y);
    } else {
	y = getvaluator(MOUSEY);
	printf("update_widgets: qtest() for y is FALSE!. y = %d\n", (int)y);
    }
#else
    if (qtest()) qread(&x); else x = getvaluator(MOUSEX);
    if (qtest()) qread(&y); else y = getvaluator(MOUSEY);
#endif
    if (val == 0) return(FALSE);
       
    while (sl != NULL && !flag) {
	switch (updateslider(x, y, sl)) {
	  case -1:    sliderchange = TRUE; break;
	  case FALSE: flag = FALSE;        break;
	  default:    flag = TRUE;         break;
	}
	sl = sl->nextp;
    }

    while (bt != NULL && !flag) {
	flag = updatebutton(x, y, bt);
	bt = bt->nextp;
    }
    return(flag||sliderchange);
}
コード例 #9
0
ファイル: poly.c プロジェクト: Milkyway-at-home/nemo
/*
 * drawpoly
 *
 *	draw some polygons
 */
void
drawpoly()
{
	float	vec[3];
	short	val;

	color(YELLOW);

	/*
	 * Draw a polygon using poly, parray is our array of
	 * points and 4 is the number of points in it.
	 */
	poly(4L, parray);

	color(GREEN);

	/*
	 * Draw a 5 sided figure by using bgnpolygon, v3d, and endpolygon
	 */
	polymode(PYM_LINE);
	bgnpolygon();
		vec[0] = 0.0;
		vec[1] = 0.0;
		vec[2] = 0.0;
		v3f(vec);
		vec[0] = 3.0;
		vec[1] = 0.0;
		vec[2] = 0.0;
		v3f(vec);
		vec[0] = 3.0;
		vec[1] = 4.0;
		vec[2] = 0.0;
		v3f(vec);
		vec[0] = -1.0;
		vec[1] = 5.0;
		vec[2] = 0.0;
		v3f(vec);
		vec[0] = -2.0;
		vec[1] = 2.0;
		vec[2] = 0.0;
		v3f(vec);
	endpolygon();

	color(MAGENTA);

	/*
	 * draw a sector representing a 1/4 circle
	 */
	arc(1.5, -7.0, 3.0, 0, 900);

	move2(1.5, -7.0);
	draw2(1.5, -4.0);

	move2(1.5, -7.0);
	draw2(4.5, -7.0);

	qread(&val);
}
コード例 #10
0
ファイル: devpipe.c プロジェクト: Shamar/harvey
static int32_t
piperead(Chan *c, void *va, int32_t n, int64_t m)
{
	Pipe *p;

	p = c->aux;

	switch(PIPETYPE(c->qid.path)){
	case Qdir:
		return devdirread(c, va, n, pipedir, NPIPEDIR, pipegen);
	case Qdata0:
		return qread(p->q[0], va, n);
	case Qdata1:
		return qread(p->q[1], va, n);
	default:
		panic("piperead");
	}
	return -1;	/* not reached */
}
コード例 #11
0
ファイル: devpipe.c プロジェクト: Nurb432/plan9front
static long
piperead(Chan *c, void *va, long n, vlong)
{
	Pipe *p;

	p = c->aux;

	switch(NETTYPE(c->qid.path)){
	case Qdir:
		return devdirread(c, va, n, pipedir, NPIPEDIR, pipegen);
	case Qdata0:
		return qread(p->q[0], va, n);
	case Qdata1:
		return qread(p->q[1], va, n);
	default:
		panic("piperead");
	}
	return -1;	/* not reached */
}
コード例 #12
0
ファイル: devarch.c プロジェクト: dancrossnyc/harvey
static int32_t
consoleread(Chan* c, void *vbuf, int32_t len, int64_t off64)
{
	int amt;
	if (!keybq) {
		keybq = qopen(32, 0, 0, 0);
		if (!keybq)
			panic("keyboard queue alloc failed");
	}
	amt = qread(keybq, vbuf, len);
	return amt;
}
コード例 #13
0
ファイル: qtestc.c プロジェクト: alpheios-project/morpheus
main()
{
    int   nitems;
    char  cline[MAXLINE];
    char  qchar, *malloc();
    Queue *qcreate();

    queue = qcreate( CHAR, 5 );
    printf("ready\n");
    while ( gets(cline) != NULL )  {
        if ( !strcmp( cline, "remove" ))  {
            if ( qremove( &qchar, queue ) == FAILURE )  {
                printf("queue empty\n");
                continue;
            }
            else  {
                printf("%c\n", qchar);
            }
        }
        else if ( !strcmp( cline, "read" ))  {
            if ( qread( &qchar, queue ) == FAILURE )  {
                printf("queue exhausted\n");
                continue;
            }
            else  {
                printf("%c\n", qchar);
            }
        }
        else if ( !strcmp( cline, "reset" ))  {
            qreset( queue );
        }
        else if ( !strcmp( cline, "clear" ))  {
            qclear( queue );
        }
        else if ( !strncmp( cline, "delete ", 7 ))  {
            if ( sscanf( cline, "delete %d", &nitems ) != 1 )  {
                printf("What?\n");
                continue;
            }
            if ( qdelete( nitems, queue ) == FAILURE )
                printf("too many items\n");
        }
        else  {
            qchar = cline[0];
            if ( qadd( &qchar, queue ) == FAILURE )
                printf("queue full\n");
        }
    }

    while ( qremove( &qchar, queue ) == SUCCESS )
        printf("%c\n");
    printf("queue empty\n");
}
コード例 #14
0
ファイル: devcmd.c プロジェクト: 8l/inferno
static long
cmdread(Chan *ch, void *a, long n, vlong offset)
{
	Conv *c;
	char *p, *cmds;
	int fd;

	USED(offset);

	p = a;
	switch(TYPE(ch->qid)) {
	default:
		error(Eperm);
	case Qcmd:
	case Qtopdir:
	case Qconvdir:
		return devdirread(ch, a, n, 0, 0, cmdgen);
	case Qctl:
		sprint(up->genbuf, "%ld", CONV(ch->qid));
		return readstr(offset, p, n, up->genbuf);
	case Qstatus:
		c = cmd.conv[CONV(ch->qid)];
		cmds = "";
		if(c->cmd != nil)
			cmds = c->cmd->f[1];
		snprint(up->genbuf, sizeof(up->genbuf), "cmd/%d %d %s %q %q\n",
			c->x, c->inuse, c->state, c->dir, cmds);
		return readstr(offset, p, n, up->genbuf);
	case Qdata:
	case Qstderr:
		fd = 1;
		if(TYPE(ch->qid) == Qstderr)
			fd = 2;
		c = cmd.conv[CONV(ch->qid)];
		qlock(&c->l);
		if(c->fd[fd] == -1){
			qunlock(&c->l);
			return 0;
		}
		qunlock(&c->l);
		osenter();
		n = read(c->fd[fd], a, n);
		osleave();
		if(n < 0)
			oserror();
		return n;
	case Qwait:
		c = cmd.conv[CONV(ch->qid)];
		return qread(c->waitq, a, n);
	}
}
コード例 #15
0
ファイル: Sensor.cpp プロジェクト: RGrant92/Klampt
void JointPositionSensor::Simulate(ControlledRobotSimulator* robot)
{
  robot->oderobot->GetConfig(q);
  if(!qvariance.empty()) {
    //cout<<"q: "<<qvariance<<endl;
    for(int i=0;i<q.n;i++)
      q(i) += RandGaussian()*Sqrt(qvariance(i));
  }
  if(!qresolution.empty()) {
    //cout<<"q: "<<qresolution<<endl;
    for(int i=0;i<q.n;i++) {
      if(qresolution(i) > 0) {
	q(i) = round(q(i)/qresolution(i))*qresolution(i);
      }
    }
  }
  if(!indices.empty()) {
    //only read a subset
    Vector qread(indices.size(),Zero);
    for(size_t i=0;i<indices.size();i++)
      qread(i) = q(indices[i]);
    swap(qread,q);
  }
}
コード例 #16
0
ファイル: devtk.c プロジェクト: 8l/inferno
static long
tkread(Chan* c, void* a, long n, vlong offset)
{
	USED(offset);
	switch((ulong)c->qid.path){
	case Qdir:
		return devdirread(c, a, n, tkdirtab, nelem(tkdirtab), devgen);
	case Qtkevents:
		return qread(tkevents.eq, a, n);
	default:
		n=0;
		break;
	}
	return n;
}
コード例 #17
0
ファイル: devcons.c プロジェクト: AndreasBriese/node9
/* runs on new char in kbd queue */
void readline(uv_async_t* key_wake)
{
    char ch;

    if(qread(kbdq, &ch, 1) == 0) {
         print("null char\n");
    }
    else {
        lsend = 0;
        if(ch == 0){
            /* flush output on rawoff -> rawon */
            if(kbd.x > 0)
                lsend = !qcanread(kbdq);
        }else if(kbd.raw){
            kbd.line[kbd.x++] = ch;
            lsend = !qcanread(kbdq);
        }else{
            switch(ch){
            case '\b':
                if(kbd.x)
                    kbd.x--;
                break;
            case 0x15:
                kbd.x = 0;
                break;
            case 0x04:
                lsend = 1;
                break;
            case '\n':
                lsend = 1;
            default:
                kbd.line[kbd.x++] = ch;
                break;
            }
        }
        if(lsend || kbd.x == sizeof kbd.line){
            uv_mutex_lock(&line_lock);
            qwrite(lineq, kbd.line, kbd.x);
            // signal the queue consumer
            uv_cond_signal(&line_ready);
            uv_mutex_unlock(&line_lock);
            
            kbd.x = 0;
        }
    }
}
コード例 #18
0
ファイル: devloopback.c プロジェクト: Nurb432/plan9front
static long
loopbackread(Chan *c, void *va, long n, vlong offset)
{
	Loop *lb;
	Link *link;
	char *buf;
	long rv;

	lb = c->aux;
	switch(TYPE(c->qid.path)){
	default:
		error(Eperm);
		return -1;	/* not reached */
	case Qtopdir:
	case Qloopdir:
	case Qportdir:
		return devdirread(c, va, n, nil, 0, loopbackgen);
	case Qdata:
		return qread(lb->link[ID(c->qid.path)].iq, va, n);
	case Qstatus:
		link = &lb->link[ID(c->qid.path)];
		buf = smalloc(Statelen);
		rv = snprint(buf, Statelen, "delay %lld %ld\n", link->delay0ns, link->delaynns);
		rv += snprint(buf+rv, Statelen-rv, "limit %ld\n", link->limit);
		rv += snprint(buf+rv, Statelen-rv, "indrop %d\n", link->indrop);
		snprint(buf+rv, Statelen-rv, "droprate %ld\n", link->droprate);
		rv = readstr(offset, va, n, buf);
		free(buf);
		break;
	case Qstats:
		link = &lb->link[ID(c->qid.path)];
		buf = smalloc(Statelen);
		rv = snprint(buf, Statelen, "packets: %ld\n", link->packets);
		rv += snprint(buf+rv, Statelen-rv, "bytes: %ld\n", link->bytes);
		rv += snprint(buf+rv, Statelen-rv, "dropped: %ld\n", link->drops);
		snprint(buf+rv, Statelen-rv, "soft overflows: %ld\n", link->soverflows);
		rv = readstr(offset, va, n, buf);
		free(buf);
		break;
	}
	return rv;
}
コード例 #19
0
ファイル: vbackup.c プロジェクト: 00001/plan9port
void
cmpproc(void *dummy)
{
	uchar *data;
	Block *db;
	u32int bno, bsize;
	uchar score[VtScoreSize];
	uchar score1[VtScoreSize];

	USED(dummy);

	if(incremental)
		vtfilelock(vscores, VtOREAD);
	bsize = fsys->blocksize;
	while((db = qread(qcmp, &bno)) != nil){
		data = db->data;
		sha1(data, vtzerotruncate(VtDataType, data, bsize), score, nil);
		if(incremental){
			if(vtfileblockscore(vscores, bno, score1) < 0)
				sysfatal("cmpproc vtfileblockscore %d: %r", bno);
		}else{
			if(Bseek(&bscores, (vlong)bno*VtScoreSize, 0) < 0)
				sysfatal("cmpproc Bseek: %r");
			if(Bread(&bscores, score1, VtScoreSize) != VtScoreSize)
				sysfatal("cmpproc Bread: %r");
		}
		if(memcmp(score, score1, VtScoreSize) != 0){
			nchange++;
			if(verbose)
				print("# block %ud: old %V new %V\n", bno, score1, score);
			qwrite(qventi, db, bno);
		}else
			blockput(db);
	}
	qclose(qventi);
	if(incremental)
		vtfileunlock(vscores);
	if(statustime)
		print("# %T cmp proc exiting\n");
	runlock(&endlk);
}
コード例 #20
0
ファイル: vbackup.c プロジェクト: 00001/plan9port
void
ventiproc(void *dummy)
{
	int i;
	Block *db;
	u32int bno;
	u64int bsize;

	USED(dummy);

	proccreate(vtsendproc, z, STACK);
	proccreate(vtrecvproc, z, STACK);

	writechan = chancreate(sizeof(WriteReq), 0);
	for(i=0; i<nwritethread; i++)
		threadcreate(writethread, nil, STACK);
	vtcachesetwrite(zcache, myvtwrite);

	bsize = fsys->blocksize;
	vtfilelock(vfile, -1);
	while((db = qread(qventi, &bno)) != nil){
		if(nop){
			blockput(db);
			continue;
		}
		if(vtfilewrite(vfile, db->data, bsize, bno*bsize) != bsize)
			sysfatal("ventiproc vtfilewrite: %r");
		if(vtfileflushbefore(vfile, (bno+1)*bsize) < 0)
			sysfatal("ventiproc vtfileflushbefore: %r");
		blockput(db);
	}
	vtfileunlock(vfile);
	vtcachesetwrite(zcache, nil);
	for(i=0; i<nwritethread; i++)
		send(writechan, nil);
	chanfree(writechan);
	if(statustime)
		print("# %T venti proc exiting - nsend %d nrecv %d\n", nsend, nrecv);
	runlock(&endlk);
}
コード例 #21
0
ファイル: devuart.c プロジェクト: 8l/inferno
static long
uartread(Chan *c, void *buf, long n, vlong offset)
{
	Uart *p;

	if(c->qid.type & QTDIR){
		setlength(-1);
		return devdirread(c, buf, n, uartdir, ndir, devgen);
	}

	p = uart[NETID(c->qid.path)];
	switch(NETTYPE(c->qid.path)){
	case Ndataqid:
		return qread(p->iq, buf, n);
	case Nctlqid:
		return readnum(offset, buf, n, NETID(c->qid.path), NUMSIZE);
	case Nstatqid:
		return uartstatus(c, p, buf, n, offset);
	}

	return 0;
}
コード例 #22
0
ファイル: devuart.c プロジェクト: dancrossnyc/harvey
static int32_t
uartread(Chan *c, void *buf, int32_t n, int64_t off)
{
	Uart *p;
	uint32_t offset = off;

	if(c->qid.type & QTDIR){
		uartsetlength(-1);
		return devdirread(c, buf, n, uartdir, uartndir, devgen);
	}

	p = uart[UARTID(c->qid.path)];
	switch(UARTTYPE(c->qid.path)){
	case Qdata:
		return qread(p->iq, buf, n);
	case Qctl:
		return readnum(offset, buf, n, UARTID(c->qid.path), NUMSIZE);
	case Qstat:
		return (*p->phys->status)(p, buf, n, offset);
	}

	return 0;
}
コード例 #23
0
ファイル: poly.c プロジェクト: Milkyway-at-home/nemo
/*
 * drawpolyf
 *
 *	draw some filled polygons
 */
void
drawpolyf()
{
	short	val;

	color(YELLOW);

	polymode(PYM_FILL);

	/*
	 * Draw a polygon using poly, parray is our array of
	 * points and 4 is the number of points in it.
	 */
	polf(4L, parray);

	color(GREEN);

	/*
	 * Draw a filled 5 sided figure by using pmv, pdr and pclos.
	 */
	pmv(0.0, 0.0, 0.0);
		pdr(3.0, 0.0, 0.0);
		pdr(3.0, 4.0, 0.0);
		pdr(-1.0, 5.0, 0.0);
		pdr(-2.0, 2.0, 0.0);
	pclos();

	color(MAGENTA);

	/*
	 * draw a filled sector representing a 1/4 circle
	 */
	arcf(1.5, -7.0, 3.0, 0, 900);

	qread(&val);
}
コード例 #24
0
ファイル: devcons.c プロジェクト: 8l/inferno
static long
consread(Chan *c, void *buf, long n, vlong offset)
{
	int l;
	Osenv *o;
	int ch, eol, i;
	char *p, tmp[128];
	char *cbuf = buf;

	if(n <= 0)
		return n;
	o = up->env;
	switch((ulong)c->qid.path){
	case Qdir:
		return devdirread(c, buf, n, consdir, nelem(consdir), devgen);
	case Qsysctl:
		return readstr(offset, buf, n, VERSION);
	case Qcons:
	case Qkeyboard:
		qlock(&kbd);
		if(waserror()) {
			qunlock(&kbd);
			nexterror();
		}
		if(kbd.raw || kbd.kbdr) {
			if(qcanread(lineq))
				n = qread(lineq, buf, n);
			else {
				/* read as much as possible */
				do {
					i = qread(kbdq, cbuf, n);
					cbuf += i;
					n -= i;
				} while(n>0 && qcanread(kbdq));
				n = cbuf - (char*)buf;
			}
		} else {
			while(!qcanread(lineq)) {
				qread(kbdq, &kbd.line[kbd.x], 1);
				ch = kbd.line[kbd.x];
				eol = 0;
				switch(ch){
				case '\b':
					if(kbd.x)
						kbd.x--;
					break;
				case 0x15:
					kbd.x = 0;
					break;
				case '\n':
				case 0x04:
					eol = 1;
				default:
					kbd.line[kbd.x++] = ch;
					break;
				}
				if(kbd.x == sizeof(kbd.line) || eol) {
					if(ch == 0x04)
						kbd.x--;
					qwrite(lineq, kbd.line, kbd.x);
					kbd.x = 0;
				}
			}
			n = qread(lineq, buf, n);
		}
		qunlock(&kbd);
		poperror();
		return n;

	case Qscancode:
		if(offset == 0)
			return readstr(0, buf, n, kscanid);
		else
			return qread(kscanq, buf, n);

	case Qtime:
		snprint(tmp, sizeof(tmp), "%.lld", (vlong)mseconds()*1000);
		return readstr(offset, buf, n, tmp);

	case Qhostowner:
		return readstr(offset, buf, n, eve);

	case Quser:
		return readstr(offset, buf, n, o->user);

	case Qjit:
		snprint(tmp, sizeof(tmp), "%d", cflag);
		return readstr(offset, buf, n, tmp);

	case Qnull:
		return 0;

	case Qmsec:
		return readnum(offset, buf, n, TK2MS(MACHP(0)->ticks), NUMSIZE);

	case Qsysname:
		if(sysname == nil)
			return 0;
		return readstr(offset, buf, n, sysname);

	case Qnotquiterandom:
		genrandom(buf, n);
		return n;

	case Qrandom:
		return randomread(buf, n);

	case Qmemory:
		return poolread(buf, n, offset);

	case Qdrivers:
		p = malloc(READSTR);
		if(p == nil)
			error(Enomem);
		l = 0;
		for(i = 0; devtab[i] != nil; i++)
			l += snprint(p+l, READSTR-l, "#%C %s\n", devtab[i]->dc,  devtab[i]->name);
		if(waserror()){
			free(p);
			nexterror();
		}
		n = readstr(offset, buf, n, p);
		free(p);
		poperror();
		return n;

	case Qklog:
		return qread(klogq, buf, n);

	case Qkprint:
		rlock(&kprintq);
		if(waserror()){
			runlock(&kprintq);
			nexterror();
		}
		n = qread(kprintq.q, buf, n);
		poperror();
		runlock(&kprintq);
		return n;

	default:
		print("consread %llud\n", c->qid.path);
		error(Egreg);
	}
	return -1;		/* never reached */
}
コード例 #25
0
ファイル: circtxt.c プロジェクト: Milkyway-at-home/nemo
/*
 * display all the hershey fonts and demonstrate textang
 */
main()
{
	char	buf[50];
	char	*str1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
	char	*str2 = "abcdefghijklmnopqrstuvwxyz" ;
	char	*str3 = "1234567890+-=!@#$%^&*(){}[]" ;
	char	*str4 = "<>,./?~`\\|_BONK,blark" ;
	int	i;
	short	val;

	vinit("mswin");
	winopen("circtxt");

	hleftjustify(1);

	unqdevice(INPUTCHANGE);
	qdevice(KEYBD);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;

	color(BLACK);
	clear();

	ortho2(-14.0, 14.0, -14.0, 14.0);	/* define the world space */

	for(i = 0; i < 22; i++) {

		/*
		 * textang is used to specify the orientation of text. As
		 * we want the title to come out straight we make sure it is
		 * zero each time we go through this loop.
		 */
		htextang(0.0);

		/*
		 * do the title
		 */
		color(YELLOW);
		hfont("futura.m");
		sprintf(buf, "This is hershey font %s", fonts[i]);
		hboxtext(-11.0, 12.0, 20.0, 1.0, buf);

		/*
		 * draw a box around the title
		 */
		rect(-11.0, 12.0, 9.0, 13.0);

		color(GREEN);

		hfont(fonts[i]);		/* grab a font from the table */

		htextsize(1.5, 1.5);		/* show the outer ring */
		ShowCircularText(11.0, str1);

		htextsize(1.3, 1.3);		/* show the second ring */
		ShowCircularText(8.5, str2);

		htextsize(1.1, 1.1);		/* show the third ring */
		ShowCircularText(7.0, str3);

		htextsize(0.9, 0.9);		/* show the inside ring */
		ShowCircularText(5.0, str4);

		if (qread(&val)) {
			if (val == 'q') {
				gexit();
				exit(0);
			}
		}

		color(BLACK);
		clear();
	}

	gexit();
}
コード例 #26
0
ファイル: glwidget.c プロジェクト: pgramage/gaspware
static int updatebutton(int x, int y, gl_button *bt) {
    Int32 xo, yo;
    Int16 xx, yy;
    Int32  oriwin = winget();
    int oldstate;

#ifdef DEBUG
    printf("updatebutton: button with label %s - ", bt->label);
#endif
    
    winset(bt->win);
    locate_button(bt);
    
    getorigin(&xo, &yo);
    x -= xo;
    y -= yo;
    if (x < bt->scx0 || y > bt->scy0 ||
	x > bt->scx1 ||	y < bt->scy1) {
	winset(oriwin);
	bt->changed = FALSE;
#ifdef DEBUG
	printf("x = %d y = %d, btscx0 = %d btscx1 = %d btscy0 = %d btscy1 = %d\n",
	       x, y, bt->scx0,  bt->scx1, bt->scy0,  bt->scy1);
	puts("click not inside - return(FALSE)");
#endif
	return(FALSE);
    }
    oldstate = *(bt->state);
    *(bt->state) = (bt->type == BUTTON)?TRUE:!oldstate;
    drawbutton(bt);
    
    while (qread(&xx) != LEFTMOUSE); /* wait for LEFTMOUSE release */

    if (qtest()) qread(&xx); else {
	xx = getvaluator(MOUSEX);      
	fprintf(stderr, 
		"updatebutton: This should not happen, tie() seems to fail.\n");
    }
    if (qtest()) qread(&yy); else {
	yy = getvaluator(MOUSEY);
	fprintf(stderr, 
		"updatebutton: This should not happen, tie() seems to fail.\n");
    }
    getorigin(&xo, &yo);
    x = xx - xo;
    y = yy - yo;

    if (!(bt->changed = !(
			  x < bt->scx0 || y > bt->scy0 ||
			  x > bt->scx1 || y < bt->scy1
			  )
	  )) *(bt->state) = oldstate;

    if (bt->type == BUTTON) {
	*(bt->state) = FALSE;
	usleep(50000);
    }
    drawbutton(bt);
    if (oriwin != bt->win) winset(oriwin);

    if (bt->callback != NULL && bt->changed) {
	bt->callback(bt, *(bt->state));
    }
#ifdef DEBUG
    printf("return(%s)\n", bt->changed?"true":"false");
#endif
    return(bt->changed);
}
コード例 #27
0
ファイル: devcons.c プロジェクト: Mekapaedia/inferno-rpi
static long
consread(Chan *c, void *va, long n, vlong offset)
{
	int send;
	char buf[64], ch;

	if(c->qid.type & QTDIR)
		return devdirread(c, va, n, contab, nelem(contab), devgen);

	switch((ulong)c->qid.path) {
	default:
		error(Egreg);

	case Qsysctl:
		return readstr(offset, va, n, VERSION);

	case Qsysname:
		if(ossysname == nil)
			return 0;
		return readstr(offset, va, n, ossysname);

	case Qrandom:
		return randomread(va, n);

	case Qnotquiterandom:
		genrandom(va, n);
		return n;

	case Qhostowner:
		return readstr(offset, va, n, eve);

	case Qhoststdin:
		return read(0, va, n);	/* should be pread */

	case Quser:
		return readstr(offset, va, n, up->env->user);

	case Qjit:
		snprint(buf, sizeof(buf), "%d", cflag);
		return readstr(offset, va, n, buf);

	case Qtime:
		snprint(buf, sizeof(buf), "%.lld", timeoffset + osusectime());
		return readstr(offset, va, n, buf);

	case Qdrivers:
		return devtabread(c, va, n, offset);

	case Qmemory:
		return poolread(va, n, offset);

	case Qnull:
		return 0;

	case Qmsec:
		return readnum(offset, va, n, osmillisec(), NUMSIZE);

	case Qcons:
		qlock(&kbd.q);
		if(waserror()){
			qunlock(&kbd.q);
			nexterror();
		}

		if(dflag)
			error(Enonexist);

		while(!qcanread(lineq)) {
			if(qread(kbdq, &ch, 1) == 0)
				continue;
			send = 0;
			if(ch == 0){
				/* flush output on rawoff -> rawon */
				if(kbd.x > 0)
					send = !qcanread(kbdq);
			}else if(kbd.raw){
				kbd.line[kbd.x++] = ch;
				send = !qcanread(kbdq);
			}else{
				switch(ch){
				case '\b':
					if(kbd.x)
						kbd.x--;
					break;
				case 0x15:
					kbd.x = 0;
					break;
				case 0x04:
					send = 1;
					break;
				case '\n':
					send = 1;
				default:
					kbd.line[kbd.x++] = ch;
					break;
				}
			}
			if(send || kbd.x == sizeof kbd.line){
				qwrite(lineq, kbd.line, kbd.x);
				kbd.x = 0;
			}
		}
		n = qread(lineq, va, n);
		qunlock(&kbd.q);
		poperror();
		return n;

	case Qscancode:
		if(offset == 0)
			return readstr(0, va, n, gkscanid);
		return qread(gkscanq, va, n);

	case Qkeyboard:
		return qread(gkbdq, va, n);

	case Qkprint:
		rlock(&kprintq.l);
		if(waserror()){
			runlock(&kprintq.l);
			nexterror();
		}
		n = qread(kprintq.q, va, n);
		poperror();
		runlock(&kprintq.l);
		return n;
	}
}
コード例 #28
0
ファイル: glwidget.c プロジェクト: pgramage/gaspware
static int updateslider(int x, int y, gl_slider *sl) {
    Int32 xo, yo;
    Int16 xx, yy;
    double orival;
    Int32  oriwin = winget();
    int dev;
    
    orival = sl->value;
    update_slider_value(sl);
    winset(sl->win);

    getorigin(&xo, &yo);
    x -= xo;
    y -= yo;

#ifdef DEBUG
    printf("updateslider: slider label %s - ", sl->buf);
#endif    
    locate_slider(sl);
    
    if (x < sl->scx0 || y > sl->scy0 ||
	x > sl->scx1 + sl->sc_thick  ||	y < sl->scy1) {
	winset(oriwin);
	if (orival != sl->value) {
	    /* This is used when the click is not for this slider, but
	       update_slider_value() has changed the value... */
	    if (sl->callback != NULL) sl->callback(sl, sl->value);
#ifdef DEBUG
	    puts("return(-1)");
#endif
	    return(-1);
	} else {
#ifdef DEBUG
	    puts("return(FALSE)");
#endif
	    return(FALSE);
	}
    }
	
    while (qtest() == 0 || (dev = qread(&xx)) != LEFTMOUSE) {
	/* getorigin(&xo, &yo); */
	setslider(getvaluator(MOUSEX) - xo, sl);
	usleep(100000);
    } 
#ifdef DEBUG
    printf("updateslider: got an event, dev = %d val = %d\n", dev, (int)xx);
    if (qtest()) {
	int dev; 
	dev = qread(&xx);
	printf("updateslider: qtest() for x is true. dev = %d, val = %d\n",
	       dev, (int)xx);
    } else {
	xx = getvaluator(MOUSEX);
	printf("updateslider: qtest() for x is FALSE!. x = %d\n", (int)xx);
    }
    if (qtest()) {
	int dev; 
	dev = qread(&yy);
	printf("updateslider: qtest() for y is true. dev = %d, val = %d\n",
	       dev, (int)yy);
    } else {
	yy = getvaluator(MOUSEY);
	printf("updateslider: qtest() for y is FALSE!. y = %d\n", (int)yy);
    }
    setslider((int)(xx-xo), sl);
#else
    if (qtest()) qread(&xx);
    if (qtest()) {
	qread(&yy);
	setslider((int)(xx-xo), sl);
    } else 
      fprintf(stderr, 
	      "updateslider: This should not happen, tie() seems to fail.\n");
#endif
    winset(oriwin);
    if (sl->value != orival) {
	if (sl->callback != NULL) sl->callback(sl, sl->value);
	return(TRUE);
#ifdef DEBUG
	puts("return(TRUE)");
#endif
    } else {
#ifdef DEBUG
	puts("return(FALSE)");
#endif
	return(FALSE);
    }
}
コード例 #29
0
ファイル: netif.c プロジェクト: Requaos/harvey
int32_t
netifread(Netif *nif, Chan *c, void *a, int32_t n, int64_t off)
{
	Proc *up = externup();
	int i, j;
	Netfile *f;
	char *p;
	int32_t offset;

	if(c->qid.type & QTDIR)
		return devdirread(c, a, n, (Dirtab*)nif, 0, netifgen);

	offset = off;
	switch(NETTYPE(c->qid.path)){
	case Ndataqid:
		f = nif->f[NETID(c->qid.path)];
		return qread(f->iq, a, n);
	case Nctlqid:
		return readnum(offset, a, n, NETID(c->qid.path), NUMSIZE);
	case Nstatqid:
		p = malloc(READSTR);
		if(p == nil)
			error(Enomem);
		j = snprint(p, READSTR, "in: %llu\n", nif->inpackets);
		j += snprint(p+j, READSTR-j, "link: %d\n", nif->link);
		j += snprint(p+j, READSTR-j, "out: %llu\n", nif->outpackets);
		j += snprint(p+j, READSTR-j, "crc errs: %llu\n", nif->crcs);
		j += snprint(p+j, READSTR-j, "overflows: %llu\n", nif->overflows);
		j += snprint(p+j, READSTR-j, "soft overflows: %llu\n", nif->soverflows);
		j += snprint(p+j, READSTR-j, "framing errs: %llu\n", nif->frames);
		j += snprint(p+j, READSTR-j, "buffer errs: %llu\n", nif->buffs);
		j += snprint(p+j, READSTR-j, "output errs: %llu\n", nif->oerrs);
		j += snprint(p+j, READSTR-j, "prom: %d\n", nif->prom);
		j += snprint(p+j, READSTR-j, "mbps: %d\n", nif->mbps);
		j += snprint(p+j, READSTR-j, "addr: ");
		for(i = 0; i < nif->alen; i++)
			j += snprint(p+j, READSTR-j, "%2.2x", nif->addr[i]);
		snprint(p+j, READSTR-j, "\n");
		n = readstr(offset, a, n, p);
		free(p);
		return n;
	case Naddrqid:
		p = malloc(READSTR);
		j = 0;
		for(i = 0; i < nif->alen; i++)
			j += snprint(p+j, READSTR-j, "%2.2x", nif->addr[i]);
		n = readstr(offset, a, n, p);
		free(p);
		return n;
	case Ntypeqid:
		f = nif->f[NETID(c->qid.path)];
		return readnum(offset, a, n, f->type, NUMSIZE);
	case Nifstatqid:
		return 0;
	case Nmtuqid:
		snprint(up->genbuf, sizeof up->genbuf, "%11.u %11.u %11.u\n", nif->minmtu, nif->mtu, nif->maxmtu);
		return readstr(offset, a, n, up->genbuf);
	}
	error(Ebadarg);
	return -1;	/* not reached */
}
コード例 #30
0
ファイル: devip.c プロジェクト: 99years/plan9
static long
ipread(Chan *ch, void *a, long n, vlong off)
{
	Conv *c;
	Proto *x;
	char *buf, *p;
	long rv;
	Fs *f;
	ulong offset = off;

	f = ipfs[ch->dev];

	p = a;
	switch(TYPE(ch->qid)) {
	default:
		error(Eperm);
	case Qtopdir:
	case Qprotodir:
	case Qconvdir:
		return devdirread(ch, a, n, 0, 0, ipgen);
	case Qarp:
		return arpread(f->arp, a, offset, n);
 	case Qbootp:
 		return bootpread(a, offset, n);
 	case Qndb:
		return readstr(offset, a, n, f->ndb);
	case Qiproute:
		return routeread(f, a, offset, n);
	case Qipselftab:
		return ipselftabread(f, a, offset, n);
	case Qlog:
		return netlogread(f, a, offset, n);
	case Qctl:
		buf = smalloc(16);
		snprint(buf, 16, "%lud", CONV(ch->qid));
		rv = readstr(offset, p, n, buf);
		free(buf);
		return rv;
	case Qremote:
		buf = smalloc(Statelen);
		x = f->p[PROTO(ch->qid)];
		c = x->conv[CONV(ch->qid)];
		if(x->remote == nil) {
			snprint(buf, Statelen, "%I!%d\n", c->raddr, c->rport);
		} else {
			(*x->remote)(c, buf, Statelen-2);
		}
		rv = readstr(offset, p, n, buf);
		free(buf);
		return rv;
	case Qlocal:
		buf = smalloc(Statelen);
		x = f->p[PROTO(ch->qid)];
		c = x->conv[CONV(ch->qid)];
		if(x->local == nil) {
			snprint(buf, Statelen, "%I!%d\n", c->laddr, c->lport);
		} else {
			(*x->local)(c, buf, Statelen-2);
		}
		rv = readstr(offset, p, n, buf);
		free(buf);
		return rv;
	case Qstatus:
		buf = smalloc(Statelen);
		x = f->p[PROTO(ch->qid)];
		c = x->conv[CONV(ch->qid)];
		(*x->state)(c, buf, Statelen-2);
		rv = readstr(offset, p, n, buf);
		free(buf);
		return rv;
	case Qdata:
		c = f->p[PROTO(ch->qid)]->conv[CONV(ch->qid)];
		return qread(c->rq, a, n);
	case Qerr:
		c = f->p[PROTO(ch->qid)]->conv[CONV(ch->qid)];
		return qread(c->eq, a, n);
	case Qsnoop:
		c = f->p[PROTO(ch->qid)]->conv[CONV(ch->qid)];
		return qread(c->sq, a, n);
	case Qstats:
		x = f->p[PROTO(ch->qid)];
		if(x->stats == nil)
			error("stats not implemented");
		buf = smalloc(Statelen);
		(*x->stats)(x, buf, Statelen);
		rv = readstr(offset, p, n, buf);
		free(buf);
		return rv;
	}
}