⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tprintf.c

📁 db.* (pronounced dee-be star) is an advanced, high performance, small footprint embedded database fo
💻 C
📖 第 1 页 / 共 2 页
字号:
        if ( *s2++ == '%' )            *s1++ = '%';    }}/****************************************************************************/char *tgoto(char *st, int c, int r){    static char rcstr[10];    sprintf(rcstr, "\033=%c%c", r +' ', c +' ');        return (rcstr);}#else/****************************** UNIX VERSION ******************************//************************** EXTERNAL FUNCTIONS ****************************/extern int tgetent();extern int tgetflag();extern int tgetnum();extern char *tgetstr();extern char *tgoto();extern int tputs();extern char *fgetlr();/**************************** LOCAL FUNCTIONS *****************************/int scopy(char *, char * );/*************************** LOCAL  VARIABLES *****************************/#define NOCODES 95struct scr_entry{    char *code;    char *control;};struct scr_entry scr_table[] = {/*      ' '          '!'          '"'          '#'          '$'      */    {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL},/*      '%'          '&'          '''          '('          ')'      */    {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL},/*      '*'          '+'          ','          '-'          '.'      */    {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {"GH", "-"}, {NULL, NULL},/*      '/'          '0'          '1'          '2'          '3'      */    {NULL, NULL}, {NULL, NULL}, {"G3", "+"}, {"GU", "+"}, {"G4", "+"},/*      '4'          '5'          '6'          '7'          '8'      */    {"GR", "+"}, {"GM", "+"}, {"GL", "+"}, {NULL, "+"}, {NULL, "+"},/*      '9'          ':'          ';'          '<'          '='      */    {NULL, "+"}, {NULL, NULL}, {NULL, NULL}, {"AL", "<"}, {NULL, NULL},/*      '>'          '?'          '@'          'A'          'B'      */    {"AR", ">"}, {NULL, NULL}, {NULL, "@"}, {NULL, NULL}, {"vs", NULL},/*      'C'          'D'          'E'          'F'          'G'      */    {NULL, NULL}, {"dl", NULL}, {"cd", NULL}, {NULL, NULL}, {NULL, NULL},/*      'H'          'I'          'J'          'K'          'L'      */    {"ho", NULL}, {"al", NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL},/*      'M'          'N'          'O'          'P'          'Q'      */    {"cm", NULL}, {NULL, NULL}, {"CO", NULL}, {NULL, NULL}, {NULL, NULL},/*      'R'          'S'          'T'          'U'          'V'      */    {"so", NULL}, {"us", NULL}, {NULL, NULL}, {"us", NULL}, {NULL, NULL},/*      'W'          'X'          'Y'          'Z'          '['      */    {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL},/*      '\'          ']'          '^'          '_'          '`'      */    {NULL, NULL}, {NULL, NULL}, {"AU", "^"}, {NULL, NULL}, {NULL, NULL},/*      'a'          'b'          'c'          'd'          'e'      */    {NULL, NULL}, {"ve", NULL}, {"cl", NULL}, {"dc", NULL}, {"ce", NULL},/*      'f'          'g'          'h'          'i'          'j'      */    {NULL, NULL}, {NULL, NULL}, {"bc", "\b"}, {"ic", NULL}, {"do", NULL},/*      'k'          'l'          'm'          'n'          'o'      */    {"up", NULL}, {"nd", NULL}, {"cm", NULL}, {NULL, NULL}, {"CF", NULL},/*      'p'          'q'          'r'          's'          't'      */    {NULL, NULL}, {NULL, NULL}, {"se", NULL}, {"ue", NULL}, {NULL, NULL},/*      'u'          'v'          'w'          'x'          'y'      */    {"ue", NULL}, {"AD", "v"}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL},/*      'z'          '{'          '|'          '}'          '~'      */    {NULL, NULL}, {NULL, NULL}, {"GV", "|"}, {NULL, NULL}, {NULL, NULL}};int litmode = 0;                       /* literal interp. mode flag */int ldmode = 0;                        /* line drawing mode flag */static int initialized = 0;            /* non-zero once initerm has been                                        * called *//* ===================================================================    Initialize terminal screen table*/static void initerm(){    char bp[1024];    char sbuf[80];    char *term, *q, *p;    register int i;    term = getenv("TERM");    switch (tgetent(bp, term))    {        case -1:            fprintf(stderr, "unable to open termcap\n");            exit(1);        case 0:            fprintf(stderr, "no termcap entry for terminal %s\n", term);            exit(1);    }    /* Load screen control table */    for (i = 0; i < NOCODES; ++i)    {        p = sbuf;        if (scr_table[i].code)        {            if (q = tgetstr(scr_table[i].code, &p))            {                if ((scr_table[i].control = (char *)malloc(strlen(q) + 1)) == NULL)                {                    fprintf(stderr, "tprintf: no memory for screen tables\n");                    exit(1);                }                for (p = q; (*p >= '0' && *p <= '9'); ++p)                {                    if (*(p + 1) == '*')                    {                        p += 2;                        break;                    }                }                strcpy(scr_table[i].control, p);            }        }    }}/* ===================================================================    Formatted terminal output conversion*/int tprintf(char *format, ...){    va_list argptr;    char fmt[256];    char fcode;    char *cp;    int *ip;    register int i;    register char *fin, *fout;    register char *sptr;    if (!initialized)    {        initerm();        initialized = 1;    }    va_start(argptr, format);    fin = format;    while (*fin)    {        /* scan format copying characters into 'fmt' until an '@', '%', or a         * '\0' is seen. */        fout = fmt;        while ((*fin != '%') && *fin)        {            if (*fin != '@')            {                *fout++ = *fin++;            }            else            {                ++fin;                i = (int) (*fin - ' ');                if (scr_table[i].control)                {                    if (*fin == 'M' || *fin == 'm')                    {                        register int row, col;                        if (*fin == 'M')                        {                    /* variable cursor movement */                            ip = va_arg(argptr, int *);                            row = *ip;                            ip = va_arg(argptr, int *);                            col = *ip;                        }                        else                        {                            row = 10 * (*(fin + 1) - '0') + (*(fin + 2) - '0');                            col = 10 * (*(fin + 3) - '0') + (*(fin + 4) - '0');                            fin += 4;                        }                        sptr = fout;                        scopy(fout, tgoto(scr_table[i].control, col, row));                        fout += strlen(sptr);                    }                    else                    {                        scopy(fout, scr_table[i].control);                        fout += strlen(scr_table[i].control);                    }                }                fin++;            }        }        if (*fin == '%')        {            /* copy % spec into fmt */            *fout++ = *fin++;             /* copy % sign */            while ((*fin == '-') ||                     (*fin == '.') ||                     (*fin >= '0' && *fin <= '9'))                *fout++ = *fin++;          /* copy field spec */            fcode = *fout++ = *fin++;     /* copy format code */            *fout = '\0';            switch (fcode)            {                case 'l':                    fcode = *fout++ = *fin++;                    *fout = '\0';                    if (fcode == 'd')                        printf(fmt, va_arg(argptr, long));                    else                        printf("Unknown format code = l%c\n", fcode);                    break;                case 'd':                    printf(fmt, va_arg(argptr, int));                    break;                case 's':                    printf(fmt, va_arg(argptr, char *));                    break;                case 'c':                    cp = va_arg(argptr, char *);                    printf(fmt, *cp);                    break;                default:                    printf("Unknown format code = %c\n", fcode);            }        }        else if (fout)        {            *fout = '\0';            printf(fmt);        }    }    fflush(stdout);    return 0;}/* ===================================================================    Special string copy function*/int scopy(char *s1, char *s2){    while (*s1++ = *s2)    {        if (*s2++ == '%')            *s1++ = '%';    }    return 0;}#endif /* QNX */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -