library/src/terminal/BP-LinuxTerminal.cc
P_BP_LINUX_TERMINAL_INFO BP_CreateTerminalInformationByDeviceFileLinux(char * device_file_name)
{
	// 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;


	// attempt to open the device
	int fd = open(device_file_name, O_RDWR);

	// 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;

	// now close the file descriptor which was opened earlier
	close(fd);

	// return the terminal information
	return terminal_info;

}
// Gets information about the terminal which is currently being used (retrieves data by file name)
Gets information about the terminal which is currently being used (retrieves data by file name)
Gets information about the terminal which is currently being used ( retrieves data by file name )
P_BP_LINUX_TERMINAL_INFO BP_CreateTerminalInformationByDeviceFileLinux(char * device_file_name)
{
	P_BP_LINUX_TERMINAL_INFO terminal_info = (P_BP_LINUX_TERMINAL_INFO) bpcalloc(sizeof(BP_LINUX_TERMINAL_INFO), 1);
	if(!terminal_info)
		return NULL;
	int fd = open(device_file_name, O_RDWR);
	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;
	close(fd);
	return terminal_info;
}
P_BP_LINUX_TERMINAL_INFO BP_CreateTerminalInformationByDeviceFileLinux ( char * device_file_name ) { P_BP_LINUX_TERMINAL_INFO terminal_info = ( P_BP_LINUX_TERMINAL_INFO ) bpcalloc ( sizeof ( BP_LINUX_TERMINAL_INFO ) , 1 ) ; if ( ! terminal_info ) return NULL ; int fd = open ( device_file_name , O_RDWR ) ; 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 ; close ( fd ) ; return terminal_info ; }
Gets information about the terminal which is currently being used (retrieves data by file name)
Gets information about the terminal which is currently being used ( retrieves data by file name )
// attempt to create space for the terminal information // attempt to open the device // 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 // now close the file descriptor which was opened earlier // return the terminal information