Beispiel #1
0
static int
read_stdin(void) {
	char buf[MAX_LINE_LEN],
		 retbuf[MAX_LINE_LEN];
	ssize_t n, n_off=0;

	if(!(n = read(STDIN_FILENO, buf, sizeof buf))) {
		if(!dzen.ispersistent) {
			dzen.running = False;
			return -1;
		}
		else
			return -2;
	}
	else {
		while((n_off = chomp(buf, retbuf, n_off, n))) {
			if(!dzen.slave_win.ishmenu
					&& dzen.tsupdate
					&& dzen.slave_win.max_lines
					&& ((dzen.cur_line == 0) || !(dzen.cur_line % (dzen.slave_win.max_lines+1))))
				drawheader(retbuf);
			else if(!dzen.slave_win.ishmenu
					&& !dzen.tsupdate
					&& ((dzen.cur_line == 0) || !dzen.slave_win.max_lines))
				drawheader(retbuf);
			else
				drawbody(retbuf);
			dzen.cur_line++;
		}
	}
	return 0;
}
Beispiel #2
0
//TODO (PM) The check for `ispersistent' is outside the logical scope of this
// function
static int
read_stdin(void) {
	char buf[MAX_LINE_LEN],
		 retbuf[MAX_LINE_LEN];
	ssize_t n, n_off=0;

	n = read(STDIN_FILENO, buf, sizeof buf);
	if(n == 0) {	// If 0 bits are read
		if(!dzen.ispersistent) {	// And dzen is not persistent
			dzen.running = False;	// Stop running
			//TODO (PM) The value of `running' will never be checked since the
			// event loop returns if this function returns -1
			return -1;
		}
		else
			return -2;	// Is persistent
	}
	else if (n > 0) {
		while((n_off = chomp(buf, retbuf, n_off, n))) {
			if(!dzen.slave_win.ishmenu
					&& dzen.tsupdate
					&& dzen.slave_win.max_lines
					&& ((dzen.cur_line == 0) || !(dzen.cur_line % (dzen.slave_win.max_lines+1))))
				drawheader(retbuf);
			else if(!dzen.slave_win.ishmenu
					&& !dzen.tsupdate
					&& ((dzen.cur_line == 0) || !dzen.slave_win.max_lines))
				drawheader(retbuf);
			else
				drawbody(retbuf);
			dzen.cur_line++;
		}
	}
	else {
		perror("read");	//TODO (PM) Consolidate error handling
		exit(EXIT_FAILURE);
	}
	return 0;
}
Beispiel #3
0
void display(void)//绘图函数
{
	glClear(GL_COLOR_BUFFER_BIT);//使用清除颜色来清除指定的缓冲区
	glLoadIdentity();//设置当前矩阵为单位矩阵
	gluLookAt(xTranslation+30, yTranslation,  zTranslation, xTranslation, yTranslation, zTranslation, 0.0, 1.0, 0.0);//第一组数据就是脑袋的位置,第二组数据就是眼睛看的物体的位置,第三组就是头顶朝向的方向
	glRotatef(xRotation, 1.0, 0.0, 0.0);//xRotation为旋转角度,此处初始化为0
	glRotatef(yRotation, 0.0, 1.0, 0.0);
	//画shoulderr和elbowerr右手臂
	glPushMatrix();
	glColor3f(0.0f, 0.0f, 1.0f);//蓝色
	//glColor3f(1.0f, 0.0f, 0.0f);   //红色
	glTranslatef(-2.0, 3.0, 0.0);
	drawbody(armupr, armdownr);
	glPopMatrix();
	//画shoulderl和elbowl左手臂
	glPushMatrix();
	glTranslatef(2.0, 3.0, 0.0);
	drawbody(armupl, armdownl);
	glPopMatrix();
	//画上半身
	glPushMatrix();
	glTranslatef(0.0, 0.0, 0.0);
	glScalef(3, 5, 2);
	glutWireCube(1.0);
	glPopMatrix();
	//画大小脑
	glPushMatrix();
	glTranslatef(0.0, 2.75, 0.0);
	glScalef(1.0, 0.5, 1.0);
	glutWireCube(1.0);//画一个立方体(小脑),大小为一个单位,系数表示大小
	glScalef(1.0, 2.0, 1.0);
	glTranslatef(0.0, 0.25 + 0.75, 0.0);
	glScalef(1.5, 1.5, 1.5);
	glutWireCube(1.0);//画大脑
	glPopMatrix();
	//画两条腿
	glPushMatrix();
	glTranslatef(-(0.6 + 0.1), -(2.5 + 1), 0.0);
	glPushMatrix();
	glTranslatef(0.0, 1.0, 0.0);
	glRotatef((GLfloat)blegr, 1.0, 0.0, 0.0);//右大腿可旋转
	glTranslatef(0.0, -1.0, 0.0);
	glPushMatrix();
	glScalef(1.2, 2.0, 1.2);
	glutWireCube(1.0);//右大腿大小设置为一个单位的立方体大小
	glPopMatrix();
	glTranslatef(0.0, -1.0, 0.0);
	glRotatef((GLfloat)slegr, 1.0, 0.0, 0.0);//右小腿可旋转
	glTranslatef(0.0, -1.25, 0.0);
	glPushMatrix();
	glScalef(1.0, 2.5, 1.0);
	glutWireCube(1.0);//画右小腿
	glPopMatrix();
	glTranslatef(0.0, -1.25, 0.0);
	glTranslatef(0.0, -0.25, 0.75 - 0.5);
	glScalef(1.2, 0.5, 1.5);
	glutWireCube(1.0);//画右脚底
	glPopMatrix();
	glPopMatrix();
	glPushMatrix();
	glTranslatef(0.6 + 0.1, -(2.5 + 1), 0.0);
	glPushMatrix();
	glTranslatef(0.0, 1.0, 0.0);
	glRotatef((GLfloat)blegl, 1.0, 0.0, 0.0);//左大腿可旋转
	glTranslatef(0.0, -1.0, 0.0);
	glPushMatrix();
	glScalef(1.2, 2.0, 1.2);
	glutWireCube(1.0);//画左大腿
	glPopMatrix();
	glTranslatef(0.0, -1.0, 0.0);
	glRotatef((GLfloat)slegl, 1.0, 0.0, 0.0);//左小腿可旋转
	glTranslatef(0.0, -1.25, 0.0);
	glPushMatrix();
	glScalef(1.0, 2.5, 1.0);
	glutWireCube(1.0);//画左小腿
	glPopMatrix();
	glTranslatef(0.0, -1.25, 0.0);
	glTranslatef(0.0, -0.25, 0.75 - 0.5);
	glScalef(1.2, 0.5, 1.5);
	glutWireCube(1.0);//画左脚底
	glPopMatrix();
	glPopMatrix();
	glutSwapBuffers();//交换缓冲区

}