Пример #1
0
extern void
disp_open(		/* open the named display driver */
	char	*dname
)
{
	char	buf[sizeof(HDGRID)+512], fd0[8], fd1[8], *cmd[5], *sfn;
	int	i, n, len;

	if (!strcmp(dname, SLAVENAME)) {
		dpd.r = 0;		/* read from stdin */
		dpout = stdout;		/* write to stdout */
		dpd.running = 0; /* we're the slave procees */
	} else {
					/* get full display program name */
#ifdef DEVPATH
		sprintf(buf, "%s/%s%s", DEVPATH, dname, HDSUF);
#else
		sprintf(buf, "dev/%s%s", dname, HDSUF);
#endif
					/* dup stdin and stdout */
		if (readinp)
			sprintf(fd0, "%d", dup(0));
		else
			strcpy(fd0, "-1");
		sprintf(fd1, "%d", dup(1));
					/* start the display process */
		cmd[0] = buf;
		cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0;
		cmd[4] = NULL;
		i = open_process(&dpd, cmd);
		if (i <= 0)
			error(USER, "cannot start display process");
		if ((dpout = fdopen(dpd.w, "w")) == NULL)
			error(SYSTEM, "problem opening display pipe");
					/* close dup'ed stdin and stdout */
		if (readinp)
			close(atoi(fd0));
		close(atoi(fd1));
	}
	dpd.w = -1;		/* causes ignored error in close_process() */
	inp_flags = 0;
				/* check if outside */
	if (vdef(OBSTRUCTIONS) && vbool(OBSTRUCTIONS))
		disp_result(DS_OUTSECT, 0, NULL);
				/* send eye separation if specified */
	if (vdef(EYESEP)) {
		sprintf(buf, "%.9e", vflt(EYESEP));
		disp_result(DS_EYESEP, strlen(buf)+1, buf);
	}
				/* write out hologram grids & octrees */
	for (i = 0; hdlist[i] != NULL; i++) {
		memcpy(buf, (void *)hdlist[i], sizeof(HDGRID));
		len = sizeof(HDGRID);
		n = vdef(GEOMETRY);
		sfn = i<n ? nvalue(GEOMETRY,i) :
				n ? nvalue(GEOMETRY,n-1) : vval(OCTREE);
		strcpy(buf+len, sfn);
		len += strlen(sfn) + 1;
		n = vdef(PORTS);
		sfn = i<n ? nvalue(PORTS,i) : n ? nvalue(PORTS,n-1) : "";
		strcpy(buf+len, sfn);
		len += strlen(sfn) + 1;
		disp_result(DS_ADDHOLO, len, buf);
	}
	disp_flush();
}
Пример #2
0
Graph* Graph::readGraph( QTextStream *s, QGraphicsItem *parent )
{
    Graph *g = new Graph();

    //This regexp matches the definition of a vertex
    QRegExp vdef("\\s*"+uE+"\\s+\\[label=\"(.*)\",pos=\""+qE+"\\s+"+qE+"\"\\]");
    //This regexp matches the definition of an edge
    QRegExp edef("\\s*"+uE+"\\s*--\\s*"+uE+"\\s*\\[weight=\""+qE+"\"\\]" );

    while( !s->atEnd() ) {
        QString curline = s->readLine();
        if( curline.contains(vdef) ) { //Does this line define a vertex?
            //qDebug() << vdef.pattern() << "  MATCHES  " << curline;

            bool ok = false; //pessimists are never dissapointed
            uint id = vdef.cap(1).toUInt(&ok);
            if(!ok) {
                qDebug() << "error: couldn't do toUInt(" << vdef.cap(1);
                continue;
            } else ok = false;

            QString label = vdef.cap(2);

            qreal x = vdef.cap(3).toDouble(&ok);
            if(!ok) {
                qDebug() << "error: couldn't do toDouble(" << vdef.cap(3);
                continue;
            } else ok = false;
            qreal y = vdef.cap(4).toDouble(&ok);
            if(!ok) {
                qDebug() << "error: couldn't do toDouble(" << vdef.cap(4);
                continue;
            }

            qDebug() << "New Vertex with label \"" << label << "\", id"
                     << id << ", and X,Y " << x << "," << y;

            Vertex *v = new Vertex(g,id,label,QPointF(x,y),parent);

        } else if( curline.contains(edef) ) { //Does this line define an edge?
            //qDebug() << edef.pattern() << "  MATCHES  " << curline;
            bool ok = false; //pessimists are never dissapointed

            uint head_id = edef.cap(1).toUInt(&ok);
            if(!ok) {
                qDebug() << "error: couldn't do toUInt(" << edef.cap(1);
                continue;
            } else ok = false;

            uint tail_id = edef.cap(2).toUInt(&ok);
            if(!ok) {
                qDebug() << "error: couldn't do toUInt(" << edef.cap(2);
                continue;
            } else ok = false;

            qreal w = edef.cap(3).toDouble(&ok);
            if(!ok) {
                qDebug() << "error: couldn't do toDouble(" << edef.cap(3);
                continue;
            }

            qDebug()<<"New edge (w="<<w<<") between "<<head_id<<" "<<tail_id;
            if( !g->vertices().contains(head_id) ) {
                qDebug() << "error: id " << head_id << " not found";
                continue;
            } else if( !g->vertices().contains(tail_id) ) {
                qDebug() << "error: id " << tail_id << " not found";
                continue;
            }

            Edge *e = new Edge(g, g->vertices().value(head_id),
                               g->vertices().value(tail_id), w );
        }
    }
    return g;
}