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

📄 ckuusx.c

📁 linux终端仿真程序
💻 C
📖 第 1 页 / 共 5 页
字号:
	    return(0);	}    }    if (!s1) s1="(NULL)";    if (!s2) s2="(NULL)";#ifdef COMMENT/*  This should work, but it doesn't.  So instead we'll cope with overflow via sprintf formats.  N.B.: UNFORTUNATELY, this means we have to put constants in the  sprintf formats.*/    if (!f || (f & 6)) {		/* String argument(s) included? */	x = (int) strlen(s1) + (int) strlen(s2) + 18;	if (x > dbufl) {		/* Longer than buffer? */	    if (dbptr)			/* Yes, free previous buffer */	      free(dbptr);	    dbptr = (char *) malloc(x + 2); /* Allocate a new one */	    if (!dbptr) {		zsoutl(ZDFILE,"DEBUG: Memory allocation failure");		zclose(ZDFILE);		deblog = 0;		return(0);	    } else {		dbufl = x;		sprintf(dbptr,"DEBUG: Buffer expanded to %d\n", x + 18);		zsoutl(ZDFILE,dbptr);	    }	}    }#endif /* COMMENT */#ifdef COMMENT/* The aforementioned sprintf() formats were like this: */	if (n > 31 && n < 127)	  sprintf(sp,"%.100s%.2000s:%c\n",s1,s2,(CHAR) n);	else if (n < 32 || n == 127)	  sprintf(sp,"%.100s%.2000s:^%c\n",s1,s2,(CHAR) ((n+64) & 0x7F));	else if (n > 127 && n < 160)	  sprintf(sp,"%.100s%.2000s:~^%c\n",s1,s2,(CHAR)((n-64) & 0x7F));	else if (n > 159 && n < 256)	  sprintf(sp,"%.100s%.2000s:~%c\n",s1,s2,(CHAR) (n & 0x7F));	else sprintf(sp,"%.100s%.2000s:%ld\n",s1,s2,n);/*  But, naturally, it turns out these are not portable either, so now  we do the stupidest possible thing.*/#endif /* COMMENT */    if ((int) strlen(s1) > 100) s1 = "(string too long)";    if ((int) strlen(s2) + 101 >= DBUFL) s2 = "(string too long)";    sp = dbptr;    switch (f) {		/* Write log record according to format. */      case F000:		/* 0 = print both strings, and n as a char. */	if (n > 31 && n < 127)	  sprintf(sp,"%s%s:%c\n",s1,s2,(CHAR) n);	else if (n < 32 || n == 127)	  sprintf(sp,"%s%s:^%c\n",s1,s2,(CHAR) ((n+64) & 0x7F));	else if (n > 127 && n < 160)	  sprintf(sp,"%s%s:~^%c\n",s1,s2,(CHAR)((n-64) & 0x7F));	else if (n > 159 && n < 256)	  sprintf(sp,"%s%s:~%c\n",s1,s2,(CHAR) (n & 0x7F));	else sprintf(sp,"%s%s:%ld\n",s1,s2,n);	if (zsout(ZDFILE,dbptr) < 0) deblog = 0;	break;      case F001:			/* 1, "=n" */	sprintf(sp,"=%ld\n",n);	if (zsout(ZDFILE,dbptr) < 0) deblog = 0;	break;      case F010:			/* 2, "[s2]" */	sprintf(sp,"[%s]\n",s2);	if (zsout(ZDFILE,"") < 0) deblog = 0;	break;      case F011:			/* 3, "[s2]=n" */	sprintf(sp,"[%s]=%ld\n",s2,n);	if (zsout(ZDFILE,dbptr) < 0) deblog = 0;	break;      case F100:			/* 4, "s1" */	if (zsoutl(ZDFILE,s1) < 0) deblog = 0;	break;      case F101:			/* 5, "s1=n" */	sprintf(sp,"%s=%ld\n",s1,n);	if (zsout(ZDFILE,dbptr) < 0) deblog = 0;	break;      case F110:			/* 6, "s1[s2]" */	sprintf(sp,"%s[%s]\n",s1,s2);	if (zsout(ZDFILE,dbptr) < 0) deblog = 0;	break;      case F111:			/* 7, "s1[s2]=n" */	sprintf(sp,"%s[%s]=%ld\n",s1,s2,n);	if (zsout(ZDFILE,dbptr) < 0) deblog = 0;	break;      default:	sprintf(sp,"\n?Invalid format for debug() - %d\n",f);	if (zsout(ZDFILE,dbptr) < 0) deblog = 0;    }    return(0);}#endif /* DEBUG */#ifdef CK_CURSES/*  F X D I N I T  --  File Xfer Display Initialization  */VOIDfxdinit() {#ifndef COHERENT#ifndef OS2#ifdef VMS#ifdef __DECC_PROTOTYP(int tgetent,(char *, char *));#endif /* __DECC */#endif /* VMS */    char *s;    int x;#ifdef DYNAMIC        if (!trmbuf) {/*  Allocate tgetent() buffer.  Make it big -- some termcaps are pretty huge,  and tgetent() doesn't do any range checking.*/	trmbuf = (char *)malloc(8192);	if (!trmbuf) {	    fdispla = XYFD_S;	    return;	}    }#endif /* DYNAMIC */    debug(F101,"fxdinit fdispla","",fdispla);    if (fdispla == XYFD_C) {	s = getenv("TERM");	if (!s) s = "";	if (*s) {	    x = tgetent(trmbuf,s);	    debug(F111,"fxdinit tgetent",s,x);	} else {	    x = 0;	    debug(F100,"fxdinit TERM null - no tgetent","",0);	}	if (x < 1) {	    printf("Warning: terminal type unknown: \"%s\"\n",s);	    printf("Fullscreen file transfer display disabled.\n");	    fdispla = XYFD_S;	}    }#endif /* OS2 */#endif /* COHERENT */}/*  There are three different ways to do fullscreen on VMS.  1. Use the real curses library, VAXCCURSE.  2. Use do-it-yourself code.  3. Use the Screen Manager, SMG$.  Method 1 doesn't work quite right; you can't call endwin(), so once you've  started curses mode, you can never leave.  Method 2 doesn't optimize the screen, and so much more time is spent in  screen writes.  This actually causes file transfers to fail because the  tty device input buffer can be overrun while the screen is being updated,  especially on a slow MicroVAX that has small typeahead buffers.  In the following #ifdef block, #define one of them and #undef the other 2.  So now let's try method 3...*/#ifdef VMS#define CK_SMG				/* Screen Manager */#undef MYCURSES				/* Do-it-yourself */#undef VMSCURSE				/* VAXCCURSE library */#endif /* VMS */#ifdef MYCURSES#ifdef CK_WREFRESH#undef CK_WREFRESH#endif /* CK_WREFRESH */#endif /* MYCURSES *//*  S C R E E N C  --  Screen display function, uses curses  *//* Idea for curses display contributed by Chris Pratt of APV Baker, UK *//* Avoid conficts with curses.h */#ifdef QNX/* Same as ckcasc.h, but in a different radix... */#ifdef ESC#undef ESC#endif /* ESC */#endif /* QNX */#ifndef MYCURSES#undef VOID				/* This was defined in ckcdeb.h */#endif /* MYCURSES */#undef BS				/* These were defined in ckcasc.h */#undef CR#undef NL#undef SO#undef US#undef SP				/* Used in ncurses */#define CHR_SP 32			/* Use this instead */#ifdef VMS				/* VMS fullscreen display */#ifdef MYCURSES				/* Do-it-yourself method */extern int isvt52;			/* From CKVTIO.C */#define printw printf#else#ifdef VMSCURSE				/* VMS curses library VAXCCURSE */#include <curses.h> /* Note: Screen manager doesn't need a header file */#endif /* VMSCURSE */#endif /* MYCURSES */#else					/* Not VMS */#ifdef MYCURSES				/* Do-it-yourself method */#define isvt52 0			/* Used by OS/2, VT-100/ANSI always */#define printw printf#else#include <curses.h>			/* So use real curses */#endif /* MYCURSES */#endif /* VMS */#ifdef CK_SMG/*  Long section for Screen Manager starts here...  By William Bader.*/#include "ckvvms.h"#ifdef OLD_VMS#include <smgdef.h>                     /* use this on VAX C 2.4 *//* #include <smgmsg.h> */#else#include <smg$routines.h>		/* Martin Zinser */#endif /* OLD_VMS */extern unsigned int vms_status;	    /* Used for system service return status */static long smg_pasteboard_id = -1;	/* pasteboard identifier */static long smg_display_id = -1;	/* display identifier */static int smg_open = 0;		/* flag if smg current open */#ifdef COMMENT#define	clrtoeol()	SMG$ERASE_LINE(&smg_display_id, 0, 0)#define clear()		SMG$ERASE_DISPLAY(&smg_display_id, 0, 0, 0, 0)#define	touchwin(scr)	SMG$REPAINT_SCREEN(&smg_pasteboard_id)#else#define	clrtoeol()	smg$erase_line(&smg_display_id, 0, 0)#define clear()		smg$erase_display(&smg_display_id, 0, 0, 0, 0)#define	touchwin(scr)	smg$repaint_screen(&smg_pasteboard_id)#endif /* COMMENT */#define clearok(curscr,ok)		/* Let wrefresh() do the work */#define wrefresh(cursrc) touchwin(scr)static voidmove(row, col) int row, col; {    /* Change from 0-based for curses to 1-based for SMG */    ++row; ++col;#ifdef COMMENT				/* Martin Zinser */    CHECK_ERR("move: smg$set_cursor_abs",	      SMG$SET_CURSOR_ABS(&smg_display_id, &row, &col));#else    CHECK_ERR("move: smg$set_cursor_abs",	      smg$set_cursor_abs(&smg_display_id, &row, &col));#endif /* COMMENT */}static voidrefresh() {#ifdef COMMENT				/* Martin Zinser */    CHECK_ERR("refresh: smg$end_pasteboard_update",	      SMG$END_PASTEBOARD_UPDATE(&smg_pasteboard_id));    CHECK_ERR("refresh: smg$begin_pasteboard_update",	      SMG$BEGIN_PASTEBOARD_UPDATE(&smg_pasteboard_id));#else    CHECK_ERR("refresh: smg$end_pasteboard_update",	      smg$end_pasteboard_update(&smg_pasteboard_id));    CHECK_ERR("refresh: smg$begin_pasteboard_update",	      smg$begin_pasteboard_update(&smg_pasteboard_id));#endif /* COMMENT */}#ifdef VMS_V40#define	OLD_VMS#endif /* VMS_V40 */#ifdef VMS_V42#define	OLD_VMS#endif /* VMS_V42 */#ifdef VMS_V44#define	OLD_VMS#endif /* VMS_V44 */static intinitscr() {    int rows = 24, cols = 80;    int row = 1, col = 1;    if (smg_pasteboard_id == -1) { /* Open the screen */#ifdef OLD_VMS			   /* Note: Routine calls lowercased 9/96 */	CHECK_ERR("initscr: smg$create_pasteboard",		  smg$create_pasteboard(&smg_pasteboard_id, 0, 0, 0, 0));#else	/* For VMS V5, not tested */	CHECK_ERR("initscr: smg$create_pasteboard",		  smg$create_pasteboard(&smg_pasteboard_id, 0, 0, 0, 0, 0));#endif /* OLD_VMS */    }    if (smg_display_id == -1) {		/* Create a display window */#ifdef COMMENT				/* Martin Zinser */	CHECK_ERR("initscr: smg$create_virtual_display",		  SMG$CREATE_VIRTUAL_DISPLAY(&rows, &cols, &smg_display_id,					     0, 0, 0));	/* Connect the display window to the screen */	CHECK_ERR("initscr: smg$paste_virtual_display",		  SMG$PASTE_VIRTUAL_DISPLAY(&smg_display_id,&smg_pasteboard_id,					    &row,&col));#else	CHECK_ERR("initscr: smg$create_virtual_display",		  smg$create_virtual_display(&rows, &cols, &smg_display_id,					     0, 0, 0));	/* Connect the display window to the screen */	CHECK_ERR("initscr: smg$paste_virtual_display",		  smg$paste_virtual_display(&smg_display_id,&smg_pasteboard_id,					    &row,&col));#endif /* COMMENT */    }    if (!smg_open) {			/* Start a batch update */	smg_open = 1;#ifdef COMMENT	CHECK_ERR("initscr: smg$begin_pasteboard_update",		  SMG$BEGIN_PASTEBOARD_UPDATE(&smg_pasteboard_id));#else	CHECK_ERR("initscr: smg$begin_pasteboard_update",		  smg$begin_pasteboard_update(&smg_pasteboard_id));#endif /* COMMENT */    }    return(1);}static voidendwin() {    if (!smg_open)      return;    smg_open = 0;#ifdef COMMENT    CHECK_ERR("endwin: smg$end_pasteboard_update",	      SMG$END_PASTEBOARD_UPDATE(&smg_pasteboard_id));#else    CHECK_ERR("endwin: smg$end_pasteboard_update",	      smg$end_pasteboard_update(&smg_pasteboard_id));#endif /* COMMENT */    move(22, 0);#ifdef COMMENT/*  These calls clear the screen.  (convert routine calls to lowercase - Martin Zinser)*/    CHECK_ERR("endwin: smg$delete_virtual_display",	      SMG$DELETE_VIRTUAL_DISPLAY(&smg_display_id));    smg_display_id = -1;    CHECK_ERR("endwin: smg$delete_pasteboard",	      SMG$DELETE_PASTEBOARD(&smg_pasteboard_id, 0));    smg_pasteboard_id = -1;#endif /* COMMENT */}static void printw(str, a1, a2, a3, a4, a5, a6, a7, a8)char *str;long a1, a2, a3, a4, a5, a6, a7, a8;/* printw */ {    char buf[255];#ifdef COMMENT				/* Martin Zinser */    $DESCRIPTOR(text_dsc, buf);#else    $DESCRIPTOR(text_dsc, 0);    text_dsc.dsc$a_pointer=buf;#endif /* COMMENT */    text_dsc.dsc$w_length = sprintf(buf, str, a1, a2, a3, a4, a5, a6, a7, a8);#ifdef COMMENT				/* Martin Zinser */    CHECK_ERR("printw: smg$put_chars",	      SMG$PUT_CHARS(&smg_display_id, &text_dsc, 0, 0, 0, 0, 0));#else    CHECK_ERR("printw: smg$put_chars",	      smg$put_chars(&smg_display_id, &text_dsc, 0, 0, 0, 0, 0));#endif /* COMMENT */}#endif /* CK_SMG */#ifdef MYCURSES/*  Do-it-yourself curses implementation for VMS, OS/2 and other ANSI/VT-100's.  Supports only the VT52 and VT1xx (and later VT2xx/3xx/4xx) terminals.  By Terry Kennedy, St Peters College.   First, some stuff we can just ignore:*/inttouchwin(x) int x; {    return(0);}intinitscr() {    return(0);}intrefresh() {    return(0);}intendwin() {    return(0);}/* * Now, some stuff we need to do: */_PROTOTYP( int move, (int, int) );#ifndef OS2intmove(row, col) int row, col; {    if (isvt52)      printf("\033Y%c%c", row + 037, col + 037);    else      printf("\033[%d;%dH", row + 1, col + 1);}intclear() {    move(1,1);    if (isvt52)      printf("\033J");    else      printf("\033[J");}intclrtoeol() {    if (isvt52)      printf("\033K");    else      printf("\033[K");}#else /* OS2 *//* Windows NT and Windows 95 do not provide ANSI emulation *//* Therefore we might as well not use it for OS/2 either   */extern int cmd_rows, cmd_cols;extern unsigned char colorcmd;intmove(row, col) int row, col; {#ifndef ONETERMUPD    SetCurPos(row, col);#endif /* ONETERMUPD */    lgotoxy( VCMD, col+1, row+1);    VscrnIsDirty(VCMD);    return(0);}intclear() {    viocell cell;    move(0,0);#ifdef ONETERMUPD    if (VscrnGetBufferSize(VCMD) > 0) {        VscrnScroll(VCMD, UPWARD, 0,                     VscrnGetHeight(VCMD)-(1),                    VscrnGetHeight(VCMD)-(0), TRUE, CHR_SP);        cleartermscreen(VCMD);    }#else    cell.c = ' ';    cell.a = colorcmd;    WrtNCell(cell, cmd_rows * cmd_cols

⌨️ 快捷键说明

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