library/src/terminal/BP-LinuxTerminal.cc
P_BP_LINUX_TERMINAL_INFO BP_CreateTerminalInformationByFDLinux(int fd)
{
	// attempt to create space for the terminal information
	P_BP_LINUX_TERMINAL_INFO terminal_info = (P_BP_LINUX_TERMINAL_INFO) bpcalloc(sizeof(BP_LINUX_TERMINAL_INFO), 1);
	if(!terminal_info)
		return NULL;



	// create a new linkl for allocations
	terminal_info->tq = BP_CreateLinkL("terminfo", BP_FALSE);

	// set this if we've determined that the file descriptor is a tty
	if(isatty(fd))
		terminal_info->file_descriptor_is_tty = BP_TRUE;

	// get the tty name
	char *tty_name = ttyname(fd);
	if(tty_name)
		terminal_info->tty_name = tq_strndup(terminal_info->tq, tty_name, 1024, BPLN);

	// set file descriptor as fd
	terminal_info->file_descriptor = fd;

	// set the info flag to true
	if((fd == 0) || (fd == 1) || (fd==2))
		terminal_info->is_current_terminal = BP_TRUE;

	// attempt to get terminal information via ioctl
	ioctl(fd, TIOCGWINSZ, &terminal_info->w);

	// attempt to get termios information, set flag if we got the info ok
	if(tcgetattr(fd, &terminal_info->termios_info) == 0)
		terminal_info->termios_retrieved_successfully = BP_TRUE;

	// return the terminal information
	return terminal_info;

}
// All terminal information requests fall back to this.
All terminal information requests fall back to this.
All terminal information requests fall back to this .
P_BP_LINUX_TERMINAL_INFO BP_CreateTerminalInformationByFDLinux(int fd)
{
	P_BP_LINUX_TERMINAL_INFO terminal_info = (P_BP_LINUX_TERMINAL_INFO) bpcalloc(sizeof(BP_LINUX_TERMINAL_INFO), 1);
	if(!terminal_info)
		return NULL;
	terminal_info->tq = BP_CreateLinkL("terminfo", BP_FALSE);
	if(isatty(fd))
		terminal_info->file_descriptor_is_tty = BP_TRUE;
	char *tty_name = ttyname(fd);
	if(tty_name)
		terminal_info->tty_name = tq_strndup(terminal_info->tq, tty_name, 1024, BPLN);
	terminal_info->file_descriptor = fd;
	if((fd == 0) || (fd == 1) || (fd==2))
		terminal_info->is_current_terminal = BP_TRUE;
	ioctl(fd, TIOCGWINSZ, &terminal_info->w);
	if(tcgetattr(fd, &terminal_info->termios_info) == 0)
		terminal_info->termios_retrieved_successfully = BP_TRUE;
	return terminal_info;
}
P_BP_LINUX_TERMINAL_INFO BP_CreateTerminalInformationByFDLinux ( int fd ) { P_BP_LINUX_TERMINAL_INFO terminal_info = ( P_BP_LINUX_TERMINAL_INFO ) bpcalloc ( sizeof ( BP_LINUX_TERMINAL_INFO ) , 1 ) ; if ( ! terminal_info ) return NULL ; terminal_info -> tq = BP_CreateLinkL ( " " , BP_FALSE ) ; if ( isatty ( fd ) ) terminal_info -> file_descriptor_is_tty = BP_TRUE ; char * tty_name = ttyname ( fd ) ; if ( tty_name ) terminal_info -> tty_name = tq_strndup ( terminal_info -> tq , tty_name , 1024 , BPLN ) ; terminal_info -> file_descriptor = fd ; if ( ( fd == 0 ) || ( fd == 1 ) || ( fd == 2 ) ) terminal_info -> is_current_terminal = BP_TRUE ; ioctl ( fd , TIOCGWINSZ , & terminal_info -> w ) ; if ( tcgetattr ( fd , & terminal_info -> termios_info ) == 0 ) terminal_info -> termios_retrieved_successfully = BP_TRUE ; return terminal_info ; }
All terminal information requests fall back to this.
All terminal information requests fall back to this .
// attempt to create space for the terminal information // create a new linkl for allocations // set this if we've determined that the file descriptor is a tty // get the tty name // set file descriptor as fd // set the info flag to true // attempt to get terminal information via ioctl // attempt to get termios information, set flag if we got the info ok // return the terminal information