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

📄 lycurses.c

📁 基于rtos开发的浏览器!
💻 C
📖 第 1 页 / 共 3 页
字号:
PUBLIC void lynx_setup_colors NOARGS{    int n;    for (n = 0; n < 8; n++)	lynx_map_color(n);}#endif /* USE_COLOR_TABLE */#if defined (DJGPP) && !defined (USE_SLANG)/* * Sorry about making a completely new function, * but the real one is messy! WB */PUBLIC void start_curses NOARGS{	 static BOOLEAN first_time = TRUE;	 if(first_time)	 {		  initscr();	  /* start curses */		  first_time = FALSE;		  cbreak();		  keypad(stdscr, TRUE);		  fflush(stdin);		  fflush(stdout);		  if (has_colors()) {		      lynx_has_color = TRUE;		      start_color();		  }		  lynx_init_colors();		  lynx_called_initscr = TRUE; /* Inform pdcurses that we're interested in knowing when mouse    buttons are clicked.  Maybe someday pdcurses will support it. */	 if (LYUseMouse)	      lynx_enable_mouse (1);	 } else sock_init();	 LYCursesON = TRUE;	 clear();	 noecho();}#elsePUBLIC void start_curses NOARGS{#ifdef USE_SLANG    static int slinit;    if (LYCursesON)	return;    if (slinit == 0) {	SLtt_get_terminfo();#ifdef UNIX#if SLANG_VERSION >= 9935	SLang_TT_Read_FD = fileno(stdin);#endif /* SLANG_VERSION >= 9935 */#endif /* UNIX */	/*	 *  Check whether a saved show_color:off override is in effect. - kw	 */	if (LYrcShowColor == SHOW_COLOR_NEVER) {	    SLtt_Use_Ansi_Colors = 0;	}	/*	 *  Check whether we're forcing color on. - FM	 */	if ((LYShowColor > 1) && (Lynx_Color_Flags & SL_LYNX_USE_COLOR))	    SLtt_Use_Ansi_Colors = 1;	/*	 *  Check whether a -nocolor override is in effect. - kw	 */	if (Lynx_Color_Flags & SL_LYNX_OVERRIDE_COLOR)	    SLtt_Use_Ansi_Colors = 0;	/*	 *  Make sure our flags are in register. - FM	 */	if (SLtt_Use_Ansi_Colors == 1) {	    if (LYShowColor != SHOW_COLOR_ALWAYS) {		LYShowColor = SHOW_COLOR_ON;	    }	} else {	    if (LYShowColor != SHOW_COLOR_NEVER) {		LYShowColor = SHOW_COLOR_OFF;	    }	}	size_change(0);	SLtt_add_color_attribute(4, SLTT_ULINE_MASK);	SLtt_add_color_attribute(5, SLTT_ULINE_MASK);	/*	 *  If set, the blink escape sequence will turn on high	 *  intensity background (rxvt and maybe Linux console).	 */	if (LYShowColor && (Lynx_Color_Flags & SL_LYNX_USE_BLINK)) {	    SLtt_Blink_Mode = 1;	} else {	    SLtt_Blink_Mode = 0;	}    }    slinit = 1;    Current_Attr = 0;#ifndef VMS#if SLANG_VERSION > 9929    SLang_init_tty(-1, 0, 1);#else    SLang_init_tty(3, 0, 1);#endif /* SLANG_VERSION > 9929 */#endif /* !VMS */    SLsmg_init_smg();    SLsmg_Display_Eight_Bit = LYlowest_eightbit[current_char_set];    if (SLsmg_Display_Eight_Bit > 191)       SLsmg_Display_Eight_Bit = 191; /* may print ctrl chars otherwise - kw */    scrollok(0,0);    SLsmg_Backspace_Moves = 1;#ifndef VMS#ifndef _WINDOWS   SLtty_set_suspend_state(1);#endif /* !_WINDOWS */#ifdef SIGTSTP    if (!no_suspend)	signal(SIGTSTP, sl_suspend);#endif /* SIGTSTP */    signal(SIGINT, cleanup_sig);#endif /* !VMS */   lynx_enable_mouse (1);#else /* Using curses: */#ifdef VMS    /*     *	If we are VMS then do initsrc() everytime start_curses()     *	is called!     */    initscr();	/* start curses */#else /* Unix: */    static BOOLEAN first_time = TRUE;    if (first_time) {	/*	 *  If we're not VMS then only do initscr() one time,	 *  and one time only!	 */	if (initscr() == NULL) {  /* start curses */	    fprintf(stderr,		"Terminal initialisation failed - unknown terminal type?\n");#ifndef NOSIGHUP	    (void) signal(SIGHUP, SIG_DFL);#endif /* !NOSIGHUP */	    (void) signal(SIGTERM, SIG_DFL);	    (void) signal(SIGINT, SIG_DFL);#ifdef SIGTSTP	    if (no_suspend)		(void) signal(SIGTSTP,SIG_DFL);#endif /* SIGTSTP */	    exit (-1);	}#if defined(SIGWINCH) && defined(NCURSES_VERSION)	size_change(0);#endif /* SIGWINCH */	/*	 * This is a workaround for a bug in SVr4 curses, observed on Solaris	 * 2.4:  if your terminal's alternate-character set contains codes in	 * the range 128-255, they'll be sign-extended in the acs_map[] table,	 * which in turn causes their values to be emitted as 255 (0xff).	 * "Fix" this by forcing the table to 8-bit codes (it has to be	 * anyway).	 */#if defined(ALT_CHAR_SET) && !defined(NCURSES_VERSION)	{	    int n;	    for (n = 0; n < 128; n++)		if (acs_map[n] & 0x80) {		    acs_map[n] &= 0xff;		    acs_map[n] |= A_ALTCHARSET;		}	}#endif#if defined(USE_COLOR_STYLE) || defined(USE_COLOR_TABLE)	if (has_colors()) {	    lynx_has_color = TRUE;	    start_color();#if HAVE_USE_DEFAULT_COLORS	    if (use_default_colors() == OK) {		default_fg = DEFAULT_COLOR;		default_bg = DEFAULT_COLOR;	    }#endif /* HAVE_USE_DEFAULT_COLORS */	}#endif /* USE_COLOR_STYLE || USE_COLOR_TABLE */#ifdef USE_COLOR_STYLE	parse_userstyles();#endif	first_time = FALSE;#if USE_COLOR_TABLE	lynx_init_colors();	lynx_called_initscr = TRUE;#endif /* USE_COLOR_TABLE */    }#endif /* VMS */    /* nonl();	 */ /* seems to slow things down */#ifdef VMS    crmode();    raw();#else#if HAVE_CBREAK    cbreak();#else    crmode();#endif /* HAVE_CBREAK */    signal(SIGINT, cleanup_sig);#endif /* VMS */    noecho();#if HAVE_KEYPAD    keypad(stdscr,TRUE);#endif /* HAVE_KEYPAD */   lynx_enable_mouse (1);    fflush(stdin);    fflush(stdout);    fflush(stderr);#endif /* USE_SLANG */#ifdef _WINDOWS    clear();#endif    LYCursesON = TRUE;}#endif /* defined (DJGPP) && !defined (USE_SLANG) */PUBLIC void lynx_enable_mouse ARGS1(int,state){   if (LYUseMouse == 0)     return;#ifdef USE_SLANG_MOUSE   SLtt_set_mouse_mode (state, 0);   SLtt_flush_output ();#else#ifdef NCURSES_MOUSE_VERSION     /* Inform ncurses that we're interested in knowing when mouse      button 1 is clicked */#ifndef _WINDOWS   if (state)     mousemask(BUTTON1_CLICKED | BUTTON3_CLICKED, NULL);   else     mousemask(0, NULL);#else   if (state) mouse_set(BUTTON1_CLICKED && BUTTON2_CLICKED && BUTTON3_CLICKED);#endif /* !_WINDOWS */#endif /* NCURSES_MOUSE_VERSION */#if defined(DJGPP) && !defined(USE_SLANG)     if (state)       mouse_set(BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED);#endif#endif				       /* NOT USE_SLANG_MOUSE */}PUBLIC void stop_curses NOARGS{    echo();#ifdef DJGPP    sock_exit();#endif#if defined (DOSPATH) && !defined(USE_SLANG)    clrscr();#else    /*     *	Fixed for better dumb terminal support.     *	05-28-94 Lynx 2-3-1 Garrett Arch Blythe     */    if(LYCursesON == TRUE)	{	 lynx_enable_mouse (0);	 endwin();	/* stop curses */    }    fflush(stdout);#endif /* DJGPP */    fflush(stderr);    LYCursesON = FALSE;#if defined(SIGTSTP) && defined(USE_SLANG)#ifndef VMS   if (!no_suspend)       signal(SIGTSTP, SIG_DFL);#endif /* !VMS */#endif /* SIGTSTP && USE_SLANG */#ifndef VMS    signal(SIGINT, SIG_DFL);#endif /* !VMS */}#ifdef VMS/* *  Check terminal type, start curses & setup terminal. */PUBLIC BOOLEAN setup ARGS1(	char *, 	terminal){    int c;    int status;    char *dummy, *cp, term[81];#ifdef USE_SLANG    extern void longname();#endif /* USE_SLANG */    /*     *	If the display was not set by a command line option then     *	see if it is available from the environment.     */    if ((cp = getenv(DISPLAY)) != NULL && *cp != '\0') {	StrAllocCopy(display, cp);    } else {	FREE(display);    }    /*     *	Get terminal type, and convert to lower case.     */    term[0] = '\0';    longname(dummy, term);    if (term[0] == '\0' && (form_get_data || form_post_data)) {	/*	 *  Some yoyo used these under conditions which require	 *  -dump, so force that mode here. - FM	 */	dump_output_immediately = TRUE;	LYcols = 80;	if (keypad_mode == NUMBERS_AS_ARROWS)	    keypad_mode = LINKS_ARE_NUMBERED;	status = mainloop();	(void) signal (SIGHUP, SIG_DFL);	(void) signal (SIGTERM, SIG_DFL);#ifdef SIGTSTP	if (no_suspend)	  (void) signal(SIGTSTP,SIG_DFL);#endif /* SIGTSTP */	exit(status);    }    for (cp = term; *cp != '\0'; cp++)	if (isupper(*cp))	    *cp = TOLOWER(*cp);    printf("Terminal = %s\n", term);    sleep(InfoSecs);    if ((strlen(term) < 5) ||	strncmp(term, "vt", 2) || !isdigit(term[2])) {	printf(	    "You must use a vt100, 200, etc. terminal with this program.\n");	printf("Proceed (n/y)? ");	c = getchar();	if (c != 'y' && c != 'Y') {	    printf("\n");	    return(FALSE);	}	strcpy(term,"vt100");    }    ttopen();    start_curses();    LYlines = LINES;    LYcols = COLS;    if (LYlines <= 0)	LYlines = 24;    if (LYcols <= 0)	LYcols = 80;    return(TRUE);}#else	/* Not VMS: *//* *  Check terminal type, start curses & setup terminal. */PUBLIC BOOLEAN setup ARGS1(	char *, 	terminal){    static char term_putenv[120];    char buffer[120];    char *cp;#if defined(HAVE_SIZECHANGE) && !defined(USE_SLANG) && defined(NOTDEFINED)/* *  Hack to deal with a problem in sysV curses, that screen can't be *  resized to greater than the size used by initscr, which can only *  be called once.  So set environment variables LINES and COLUMNS *  to some suitably large size to force initscr to allocate enough *  space.  Later we get the real window size for setting LYlines *  and LYcols. - AJL & FM * *  Has problems, so we don't use this hack, but the code is here *  if someone wants to play with it some more. - FM */    char *lines_putenv = NULL;    char *cols_putenv = NULL;    if (getenv("LINES") == NULL && getenv("COLUMNS") == NULL) {	StrAllocCopy(lines_putenv, "LINES=120");	(void) putenv(lines_putenv);	StrAllocCopy(cols_putenv, "COLUMNS=240");	(void) putenv(cols_putenv);    }#endif /* HAVE_SIZECHANGE && !USE_SLANG && NOTDEFINED */   /*    *  If the display was not set by a command line option then    *  see if it is available from the environment .    */    if ((cp = getenv(DISPLAY)) != NULL && *cp != '\0') {	StrAllocCopy(display, cp);    } else {	FREE(display);    }    if (terminal != NULL) {	sprintf(term_putenv, "TERM=%s", terminal);	(void) putenv(term_putenv);    }    /*     *	Query the terminal type.     */    if (dumbterm(getenv("TERM"))) {	char *s;	printf("\n\n  Your Terminal type is unknown!\n\n");	printf("  Enter a terminal type: [vt100] ");	*buffer = '\0';	fgets(buffer, sizeof(buffer), stdin);	if ((s = strchr(buffer, '\n')) != NULL)	    *s = '\0';	if (strlen(buffer) == 0)	    strcpy(buffer,"vt100");	sprintf(term_putenv,"TERM=%s", buffer);	putenv(term_putenv);	printf("\nTERMINAL TYPE IS SET TO %s\n",getenv("TERM"));	sleep(MESSAGESECS);    }    start_curses();#if HAVE_TTYTYPE    /*     *	Get terminal type (strip 'dec-' from vms style types).     */    if (strncmp((CONST char*)ttytype, "dec-vt", 6) == 0) {	(void) setterm(ttytype + 4);    }#endif /* HAVE_TTYTYPE */#if defined(HAVE_SIZECHANGE) && !defined(USE_SLANG) && defined(NOTDEFINED)    if (lines_putenv != NULL) {	/*	 *  Use SIGWINCH handler to set the true window size. - AJL && FM	 *	 *  Has problems, so we don't use this hack, but the code is here	 *  if someone wants to play with it some more. - FM	 */	size_change(0);	lines_putenv[6] = '\0';	(void) putenv(lines_putenv);	cols_putenv[8] = '\0';	(void) putenv(cols_putenv);	FREE(lines_putenv);	FREE(cols_putenv);    } else {	LYlines = LINES;	LYcols = COLS;    }#else    LYlines = LINES;    LYcols = COLS;#endif /* HAVE_SIZECHANGE && !USE_SLANG && USE_NOTDEFINED */    if (LYlines <= 0)	LYlines = 24;    if (LYcols <= 0)	LYcols = 80;    return(1);}PRIVATE int dumbterm ARGS1(	char *, 	terminal){    int dumb = FALSE;    /*     *	Began checking for terminal == NULL in case that TERM environment     *	variable is not set.  Thanks to Dick Wesseling (ftu@fi.ruu.nl).     */    if (terminal == NULL ||	!strcasecomp(terminal, "network") ||	!strcasecomp(terminal, "unknown") ||	!strcasecomp(terminal, "dialup")  ||	!strcasecomp(terminal, "dumb")	  ||	!strcasecomp(terminal, "switch")  ||	!strcasecomp(terminal, "ethernet")  )	dumb = TRUE;    return(dumb);}#ifdef FANCY_CURSES#ifndef USE_COLOR_STYLE#if USE_COLOR_TABLEPUBLIC void LYaddWAttr ARGS2(	WINDOW *,	win,	int,		a){    Current_Attr |= a;    LYsetWAttr(win);}PUBLIC void LYaddAttr ARGS1(	int,		a){    LYaddWAttr(stdscr, a);}PUBLIC void LYsubWAttr ARGS2(	WINDOW *,	win,	int,		a){    Current_Attr &= ~a;    LYsetWAttr(win);}PUBLIC void LYsubAttr ARGS1(	int,		a){    LYsubWAttr(stdscr, a);}#endif /* USE_COLOR_TABLE */#endif /* !USE_COLOR_STYLE */#endif /* FANCY_CURSES */#endif /* VMS */PUBLIC void LYstartTargetEmphasis NOARGS{#if defined(FANCY_CURSES) || defined(USE_SLANG)    start_bold();    start_reverse();#endif /* FANCY_CURSES || USE_SLANG */    start_underline();}PUBLIC void LYstopTargetEmphasis NOARGS{    stop_underline();#if defined(FANCY_CURSES) || defined(USE_SLANG)    stop_reverse();    stop_bold();#endif /* FANCY_CURSES || USE_SLANG */}#ifdef VMS/* *	Cut-down termio -- *		Do character-oriented stream input for Jeff. *		Code ripped off from Micro-Emacs 3.7 by Daniel Lawrence. * *		Ever-so-slightly modified by Kathryn Huxtable.	29-Jan-1991. *		Cut down for Lou.  8 Sep 1992. *		Cut down farther for Lou.  19 Apr 1993. *			We don't set PASSALL or PASTHRU since we don't *			want to block CTRL/C, CTRL/Y, CTRL/S or CTRL/Q. *			Simply setting NOECHO and doing timed reads *			is sufficient. *		Further mods by Fote.  29-June-1993 *			ttopen() and ttclose() are now terminal initialization *			 and restoration procedures, called once at startup *			 and at exit, respectively, of the LYNX image. *			ttclose() should be called before an exit from LYNX *			 no matter how the exit is invoked. *			setup(terminal) does the ttopen(). *			cleanup() calls cleanup_files() and ttclose(). *			ttgetc() now handles NOECHO and NOFLITR (instead of *			 setting the terminal itself to NOECHO in ttopen()). *			VMSsignal() added for handling both Ctrl-C *and* Ctrl-Y *			 interrupts, and disabling system response to Ctrl-T. *		Further mods by Fote.  15-Dec-1993 *			Added edit handler in ttopen() which will invoke *			 VMSexit() and behave intelligently on ACCVIO's. *		Further mods by Fote.  29-Dec-1993 *			Simplified ttgetc(). *		Further mods by Fote.  16-Jan-1994 *			Added code in ttopen() which will invoke VMSVersion() *			 to get the version of VMS as VersionVMS for use by *			 by new or modified interrupt or spawning routines.

⌨️ 快捷键说明

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