📄 tprintf.c
字号:
/*************************************************************************** * * * db.* * * open source database kernel * * * * Copyright (c) 2000 Centura Software Corporation. All rights reserved. * * * * Use of this software, whether in source code format, or in executable, * * binary object code form, is governed by the CENTURA OPEN SOURCE LICENSE * * which is fully described in the LICENSE.TXT file, included within this * * distribution of source code files. * * * * Except as provided herein, the contents of this file are subject to the * * Centura Open Source Public License Version 1.0 (the "License"); you may * * not use this file except in compliance with the License. A copy of the * * License will be provided to you by Club ITTIA. * * * * Software distributed under the License is distributed on an "AS IS" * * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * * License for the specific language governing rights and limitations * * under the License. * * * * The Original Code is db.linux version 1.0, released February 29, 2000. * * * * The Initial Developer of the Original Code is Centura Software * * Corporation. Portions created by Centura Software Corporation are * * Copyright (C) 1984-2000 Centura Software Corporation. All Rights * * Reserved. * * * * This file contains modifications to the Original Code made by ITTIA. * * This file may only be used in accordance with the ITTIA DB.* V.2 * * License Agreement which is available at WWW.ITTIA.COM. * * * **************************************************************************//* ------------------------------------------------------------------------- IDA - Terminal Printf Function--------------------------------------------------------------------------*//***************************************************************************NAME tprintf - formatted terminal output conversionSYNOPSIS tprintf(format [, arg]...) char *format;DESCRIPTION tprintf places output on the standard output stream, stdout, just like printf with additional formatting codes to take advantage of the screen control capabilities provided by most CRT terminals. If tprintf is called using only printf formatting codes then it will function precisely like printf. Hence, tprintf can be used instead of printf when only terminal output is to be used. tprintf formatting codes are as follows: @@ - '@' character @I - Insert line @S - Standout mode on @i - Insert character @s - Standout mode off @D - Delete line @c - Clear display screen @d - Delete character @H - Cursor to home @R - Reverse video on @h - Cursor left @r - Reverse video off @j - Cursor down @U - Start underscore @k - Cursor up @u - Stop underscore @l - Cursor right @B - Blink on @E - Erase to end of screen @b - Blink off @e - Erase to end of line @O - Turn cursor character on @o - Turn cursor character off @m - Move cursor (literal) @mrrcc where rr is the row number and cc is the column number both in decimal with a leading zero if necessary. Example: tprintf("@m0324: row 3, column 24"); Note: The row and column numbers begin at zero. Hence @m0000 is the home position for the cursor. @M - Move cursor (variable). This form requires that the rou and column be specified as the next two arguments in the tprinf argument list. Example: row = 3; col = 24; tprintf("@M: row 3, column 24",row,col); SEE ALSO printf(3s)***************************************************************************/#include "db.star.h"#ifdef QNX/*************************** QNX VERSION *****************************/void sscopy( char *, char * );char *tgoto( char *, int, int );/* ********************** LOCAL VARIABLE DECLARATIONS **************** */#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","\033J"}, {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","\033="}, {NULL,NULL}, {"CO",NULL}, {NULL,NULL}, {NULL,NULL},/* 'R' 'S' 'T' 'U' 'V' */ {"rv","\033("}, {"so","\033<"}, {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","\033H\033J"}, {"dc",NULL}, {"ce","\033K"},/* '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","\033="}, {NULL,NULL}, {"CF",NULL},/* 'p' 'q' 'r' 's' 't' */ {NULL,NULL}, {NULL,NULL}, {"re","\033)"}, {"se","\033>"}, {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 *//****************************************************************************/int tprintf( char *format, ... ){ va_list argptr; char fmt[256]; register int i; register char *fin, *fout; register char *sptr; char fcode, *cp; va_start( argptr, format ); fin = format; /* scan format copying characters into 'fmt' until an '@', '%', or '\0' */ while ( *fin ) { 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' ) { row = *(va_arg( argptr, int * )); col = *(va_arg( argptr, int * )); } else { row = 10*(*(fin+1)-'0') + (*(fin+2)-'0'); col = 10*(*(fin+3)-'0') + (*(fin+4)-'0'); fin += 4; } sptr = fout; sscopy(fout, tgoto(scr_table[i].control, col, row)); fout += strlen(sptr); } else { sscopy(fout, scr_table[i].control); fout += strlen(scr_table[i].control); } } fin++; } } if ( *fin == '%' ) { *fout++ = *fin++; while((*fin == '-')||(*fin == '.')||(*fin >= '0'&&*fin <= '9')) *fout++ = *fin++; fcode = *fout++ = *fin++; *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); va_end( argptr ); return 0;}/****************************************************************************/void sscopy(char *s1, char *s2) /* Special string copy function to allow printing '%' */{ while ( *s1++ = *s2 ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -