예제 #1
0
파일: io.c 프로젝트: pocket7878/sam
void
initio(void){
    extern int exfd;

    einit(Emouse|Ekeyboard);
    estart(Ehost, 0, 0, false);
    if (exfd >= 0)
        estart(Eextern, exfd, 8192, true);
}
예제 #2
0
파일: unix.c 프로젝트: floren/sam
void
extstart(void)
{
#ifndef	NOFIFO
	char	*disp;
	char	*user;
	int	fd;
	int	flags;

	user = getuser();
	disp = getenv("DISPLAY");

	if (disp) {
		exname = (char *)alloc(4 + 6 + strlen(user) + 1 + strlen(disp) + 1);
		sprint(exname, "/tmp/.sam.%s.%s", user, disp);
	} else { 
		exname = (char *)alloc(4 + 6 + strlen(user) + 1);
		sprint(exname, "/tmp/.sam.%s", user);
	}

	/* Make the named pipe.  Multiple sams with the same user/display share the same pipe */
	if (mkfifo(exname, 0600) == -1) {
		struct stat	statb;
		extern int	errno;

		if (errno != EEXIST || stat(exname, &statb) == -1)
			return;

		if (!S_ISFIFO(statb.st_mode)) {
			removeextern();
			if (mkfifo(exname, 0600) == -1)
				return;
		}
	}

	fd = open(exname, O_RDONLY | O_NONBLOCK);
	if (fd == -1) {
		removeextern();
		return;
	}

	/*
	 * Turn off no-delay and provide ourselves as a lingering
	 * writer so as not to get end of file on read.
         */ 
	flags = fcntl(fd, F_GETFL, 0);
	if (flags == -1 || fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) == -1
			|| open(exname, O_WRONLY) == -1) {
		(void)close(fd);
		removeextern();
		return;
	}

	estart(Eextern, fd, 8192);
	atexit(removeextern);
#endif
}
예제 #3
0
파일: event.c 프로젝트: grobe0ba/plan9front
void
ebegin(int Ehost)
{

	atexit(edie);

	einit(Emouse|Ekeyboard);

	outfd = start_host();
	if( estart(Ehost, outfd, BUFSIZ) != Ehost) {
		exits("event init error");
	}
}
예제 #4
0
파일: event.c 프로젝트: grobe0ba/plan9front
void
einit(ulong keys)
{
	int ctl, fd;
	char buf[256];

	parentpid = getpid();
	if(pipe(epipe) < 0)
		drawerror(display, "events: einit pipe");
	atexit(ekill);
	atnotify(enote, 1);
	snprint(buf, sizeof buf, "%s/mouse", display->devdir);
	mousefd = open(buf, ORDWR|OCEXEC);
	if(mousefd < 0)
		drawerror(display, "einit: can't open mouse\n");
	snprint(buf, sizeof buf, "%s/cursor", display->devdir);
	cursorfd = open(buf, ORDWR|OCEXEC);
	if(cursorfd < 0)
		drawerror(display, "einit: can't open cursor\n");
	if(keys&Ekeyboard){
		snprint(buf, sizeof buf, "%s/cons", display->devdir);
		fd = open(buf, OREAD);
		if(fd < 0)
			drawerror(display, "events: can't open console");
		snprint(buf, sizeof buf, "%s/consctl", display->devdir);
		ctl = open("/dev/consctl", OWRITE|OCEXEC);
		if(ctl < 0)
			drawerror(display, "events: can't open consctl");
		write(ctl, "rawon", 5);
		for(Skeyboard=0; Ekeyboard & ~(1<<Skeyboard); Skeyboard++)
			;
		ekeyslave(fd);
	}
	if(keys&Emouse){
		estart(Emouse, mousefd, 1+4*12);
		for(Smouse=0; Emouse & ~(1<<Smouse); Smouse++)
			;
	}
}
예제 #5
0
void CPrint::OnPaint() 
{
	if(m_bRepaintPreview){
		CWnd* item = GetDlgItem(IDC_PREVIEW_FRAME);
		CRect prerect;
		item->GetWindowRect(prerect);
		ScreenToClient(prerect);
		
		int obase = m_Calculator->m_base;
		m_Calculator->m_base = 10;
		
		UpdateData();
		CDC print_dc;
		print_dc.Attach(m_PrintDlg.GetPrinterDC());         // Attach a printer DC
		
		CPaintDC dc(this); // device context for painting
		CPoint ul(prerect.left + 10, prerect.top + 19);
		CRect print_rect(0,0, print_dc.GetDeviceCaps(HORZRES), print_dc.GetDeviceCaps(VERTRES));
		CRect window_rect(0,0,prerect.Width() - 20, prerect.Height() - 25);
		double scale_factor;
		
		TRACE("print_rect.Width=%d print_rect.Height=%d\n", print_rect.Width(), print_rect.Height());
		
		if((double(print_rect.Width())/double(print_rect.Height())) >
			(double(window_rect.Width())/double(window_rect.Height())))
			scale_factor = double(window_rect.Width()) / double(print_rect.Width());
		else
			scale_factor = double(window_rect.Height()) / double(print_rect.Height());
		
		CPoint start;
		start.x = ul.x + (double(window_rect.Width() - (print_rect.Width() * scale_factor)) / 2.0);
		start.y = ul.y + (double(window_rect.Height() - (print_rect.Height() * scale_factor)) / 2.0);
		
		//////////// DRAW PAPER
		CBrush brush(RGB(255,255,255)), *pOldBrush;
		pOldBrush = dc.SelectObject(&brush);
		CPen penBlack;
		penBlack.CreatePen(PS_SOLID, 0, RGB(0,0,0));
		CPen* pOldPen = dc.SelectObject(&penBlack);
		
		dc.Rectangle(start.x - 3, start.y - 3, 
			start.x + (print_rect.Width() * scale_factor) + 3, 
			start.y + (print_rect.Height() * scale_factor) + 3);
		dc.SelectObject(pOldPen);
		//////////// END DRAW PAPER
		
		//////////// Calculate width and height
		long double w, h;
		
		if(m_iPageSize == 1){
			double scale;
			if((double(print_rect.Width()) / double(m_graph_width)) > 
				(double(print_rect.Height()) / double(m_graph_height)))
				scale = (double(print_rect.Height()) / 2.0) / double(m_graph_height);
			else
				scale = (double(print_rect.Width()) / 2.0) / double(m_graph_width);
			
			h = (double(m_graph_height)/double(print_dc.GetDeviceCaps(LOGPIXELSY))) * scale;
			w = (double(m_graph_width)/double(print_dc.GetDeviceCaps(LOGPIXELSX))) * scale;
		}
		else if(m_iPageSize == 0){
			w = double(print_rect.Width()) / double(print_dc.GetDeviceCaps(LOGPIXELSX));
			h = double(print_rect.Height()) / double(print_dc.GetDeviceCaps(LOGPIXELSY));
		}
		else{
			m_Calculator->StringToDecimal(m_sWidth, 10, w);
			m_Calculator->StringToDecimal(m_sHeight, 10, h);
			w = m_Calculator->abs(w);
			h = m_Calculator->abs(h);
			// convert width
			if(m_sWUnits == "cm")
				w *= 0.39370078740157;
			// convert height
			if(m_sHUnits == "cm")
				h *= 0.39370078740157;
		}
		
		// I now have desired width and height in inches
		CPoint gstart(start.x, start.y);
		
		double max_h((double(print_rect.Height()) / double(print_dc.GetDeviceCaps(LOGPIXELSY))));
		double max_w((double(print_rect.Width()) / double(print_dc.GetDeviceCaps(LOGPIXELSX))));
		
		// resize max height based on printing options
		if(m_bTitleOn){
			max_h -= (0.25 + 0.125);
			gstart.y += ((0.25 + 0.125) * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor);
		}
		if(m_bEquations)
			max_h -= (1.5 + 0.125);
		
		// error check for desired size too large too large
		if(w > (max_w + 0.0001)){
			w = max_w;
			m_Calculator->DecimalToString(m_sWidth, w);
			if(m_iPageSize == 2)
				SetDimensionsW(w);
		}
		if(h > (max_h + 0.0001)){
			h = max_h;
			m_Calculator->DecimalToString(m_sHeight, h);
			if(m_iPageSize == 2)
				SetDimensionsH(h);
		}
		
		// now convert inches into device units (ie device pixels)
		w *= print_dc.GetDeviceCaps(LOGPIXELSX) * scale_factor;			// scale w for window
		h *= print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor;			// scale h for window
		//////////// END Calculate width and height
		
		//////////// Draw Graph Rectangle
		CBrush gray(RGB(128,128,128));
		dc.SelectObject(&gray);
		
		if(m_bCenter){
			gstart.x += ((print_rect.Width() * scale_factor) / 2.0) - (w / 2.0);
			
			double th(h);
			if(m_bTitleOn)
				th += ((0.25 + 0.125) * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor);
			if(m_bEquations)
				th += ((1.5 + 0.125) * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor);
			
			gstart.y += (double(print_rect.Height() * scale_factor) / 2.0) - (double(th) / 2.0);
		}
		dc.Rectangle(gstart.x, 
			gstart.y, 
			gstart.x + w, 
			gstart.y + h);
		//////////// END Draw Graph Rectangle
		
		if(m_bEquations){
			//////////// Draw Equations List
			CPoint estart(gstart.x, gstart.y + h +(0.125 * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor));
			CPoint eend(gstart.x + w, gstart.y + h + (1.625 * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor));
			
			int ew(w);
			
			if(ew < (5 * print_dc.GetDeviceCaps(LOGPIXELSX) * scale_factor)) // check for min eqs list size
				ew = (5 * print_dc.GetDeviceCaps(LOGPIXELSX) * scale_factor);
			
			if(ew > (max_w * print_dc.GetDeviceCaps(LOGPIXELSX) * scale_factor))
				ew = max_w;
			if((eend.y - estart.y) > (max_h * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor))
				eend.y = estart.y + max_h;
			
			estart.x = (gstart.x + (double(w) / 2.0)) - (double(ew) / 2.0);
			if(estart.x < start.x)
				estart.x = start.x;
			
			eend.x = estart.x + ew;
			
			dc.SelectObject(&brush);
			dc.Rectangle(estart.x, estart.y, eend.x, eend.y);
			//////////// END Draw Equations List
		}
		
		if(m_bTitleOn){
			//////////// Draw Title Rectangle
			dc.SelectObject(&brush);
			dc.Rectangle(start.x, 
				start.y, 
				start.x + (print_rect.Width() * scale_factor), 
				start.y + (0.25 * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor));
			//////////// END Draw Title Rectangle
		}
		
		dc.SelectObject(pOldBrush);
		print_dc.Detach();
		UpdateData(true);
		
		m_Calculator->m_base = obase;
	}
	
}