Linux under C Programming: The low-level terminal programming example

Source: Internet
Author: User
Tags printf linux

The terminal processing of Linux systems is a very large system that needs to deal with many different types of devices and requirements. The content includes: modem, terminal emulation, pseudo terminal and so on.

The way the Linux system handles the terminal is to communicate with the system and run the program through a serial interface connected to the console. Because more and more manufacturers are involved in the production of terminals, and each manufacturer for their own terminal design their own command set, so there needs to be a way to the terminal access to the general processing. The Linux system uses a capability database terminfo to describe the capabilities of each terminal and the methods by which these functions are invoked.

In some cases, the programmer wants to be able to provide terminal driver functionality for certain devices that are not terminals, and a pseudo terminal is required. Pseudo-Terminals provide a way for programmers to pretend to be a real terminal and to interact well with the system.

The function of the following program is to query and print some capabilities of the current terminal

#include <stdlib.h> #include <stdio.h> #include <term.h> #include <curses.h>     
    #define NUMCAPS 3 int main () {int J;     
    int retval = 0;     
    char * BUF;     
    Char *boolcaps[numcaps] = {"AM", "BCE", "km"};     
    Char *numcaps[numcaps] = {"Cols", "lines", "colors"};     
         
    Char *strcaps[numcaps] = {"cup", "Flash", "hpa"};     
    if (Setupterm (Null,fileno (stdin), NULL)!= OK) {perror ("setupterm ()");     
    Exit (Exit_failure);     
    for (j = 0;j<numcaps;++j) {retval = Tigetflag (Boolcaps[j]);     
    if (retval = = FALSE) printf ("%s unsuported\n", Boolcaps[j]);     
         
    else printf ("%s suported\n", Boolcaps[j]);     
    for (j = 0;j<numcaps;++j) {retval = Tigetnum (Numcaps[j]);     
    if (retval = ERR) printf ("%s unspported\n", Numcaps[j]); else printf ("%s is%d\ n ", numcaps[j],retval);     
    for (j = 0;j<numcaps;++j) {buf = Tigetstr (Strcaps[j]);     
    if (buf = NULL) printf ("%s unspported\n", Strcaps[j]);     
         
    else printf ("%s is%d\n", strcaps[j],buf[0]); }     
         
}

Note: You must manually connect LIBCURSES.A when compiling this program, which is compiled in GCC test.c-o test-lcurses

View a full set of articles: Http://www.bianceng.cn/Programming/C/201212/34807.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.