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

📄 setterm.c

📁 Util-linux 软件包包含许多工具。其中比较重要的是加载、卸载、格式化、分区和管理硬盘驱动器
💻 C
📖 第 1 页 / 共 3 页
字号:
/* setterm.c, set terminal attributes. * * Copyright (C) 1990 Gordon Irlam (gordoni@cs.ua.oz.au).  Conditions of use, * modification, and redistribution are contained in the file COPYRIGHT that * forms part of this distribution. *  * Adaption to Linux by Peter MacDonald. * * Enhancements by Mika Liljeberg (liljeber@cs.Helsinki.FI) * * Beep modifications by Christophe Jolif (cjolif@storm.gatelink.fr.net) * * Sanity increases by Cafeine Addict [sic]. * * Powersave features by todd j. derr <tjd@wordsmith.org> * * Converted to terminfo by Kars de Jong (jongk@cs.utwente.nl) * * 1999-02-22 Arkadiusz Mi秌iewicz <misiek@pld.ORG.PL> * - added Native Language Support * * * Syntax: * * setterm *   [ -term terminal_name ] *   [ -reset ] *   [ -initialize ] *   [ -cursor [on|off] ] *   [ -repeat [on|off] ] *   [ -appcursorkeys [on|off] ] *   [ -linewrap [on|off] ] *   [ -snow [on|off] ] *   [ -softscroll [on|off] ] *   [ -defaults ] *   [ -foreground black|red|green|yellow|blue|magenta|cyan|white|default ] *   [ -background black|red|green|yellow|blue|magenta|cyan|white|default ] *   [ -ulcolor black|grey|red|green|yellow|blue|magenta|cyan|white ] *   [ -ulcolor bright red|green|yellow|blue|magenta|cyan|white ] *   [ -hbcolor black|grey|red|green|yellow|blue|magenta|cyan|white ] *   [ -hbcolor bright red|green|yellow|blue|magenta|cyan|white ] *   [ -inversescreen [on|off] ] *   [ -bold [on|off] ] *   [ -half-bright [on|off] ] *   [ -blink [on|off] ] *   [ -reverse [on|off] ] *   [ -underline [on|off] ] *   [ -store ] *   [ -clear [ all|rest ] ] *   [ -tabs [tab1 tab2 tab3 ... ] ]     (tabn = 1-160) *   [ -clrtabs [ tab1 tab2 tab3 ... ]   (tabn = 1-160) *   [ -regtabs [1-160] ] *   [ -blank [0-60] ] *   [ -dump   [1-NR_CONS ] ] *   [ -append [1-NR_CONS ] ] *   [ -file dumpfilename ] *   [ -standout [attr] ] *   [ -msg [on|off] ] *   [ -msglevel [0-8] ] *   [ -powersave [on|vsync|hsync|powerdown|off] ] *   [ -powerdown [0-60] ] *   [ -blength [0-2000] ] *   [ -bfreq freq ] * * * Semantics: * * Setterm writes to standard output a character string that will * invoke the specified terminal capabilities.  Where possibile * terminfo is consulted to find the string to use.  Some options * however do not correspond to a terminfo capability.  In this case if * the terminal type is "con*", or "linux*" the string that invokes * the specified capabilities on the PC Linux virtual console driver * is output.  Options that are not implemented by the terminal are * ignored. * * The following options are non-obvious. * *   -term can be used to override the TERM environment variable. * *   -reset displays the terminal reset string, which typically resets the *      terminal to its power on state. * *   -initialize displays the terminal initialization string, which typically *      sets the terminal's rendering options, and other attributes to the *      default values. * *   -default sets the terminal's rendering options to the default values. * *   -store stores the terminal's current rendering options as the default *      values.  */#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <ctype.h>#include <unistd.h>#include <termios.h>#include <string.h>#include <fcntl.h>#ifndef NCURSES_CONST#define NCURSES_CONST const	/* define before including term.h */#endif#include <term.h>#if NCH#include <ncurses.h>#else#include <curses.h>#endif#include <sys/param.h>		/* for MAXPATHLEN */#include <sys/ioctl.h>#include <sys/time.h>#include "nls.h"#ifndef TCGETS/* TCGETS is either defined in termios.h, or here: */#include <asm/ioctls.h>#endif#if __GNU_LIBRARY__ < 5#ifndef __alpha__# include <linux/unistd.h>#define __NR_klogctl __NR_syslog_syscall3(int, klogctl, int, type, char*, buf, int, len);#else /* __alpha__ */#define klogctl syslog#endif#endifextern int klogctl(int type, char *buf, int len);/* Constants. *//* General constants. */#ifndef TRUE#define TRUE  1#define FALSE 0#endif/* Keyboard types. */#define PC	 0#define OLIVETTI 1#define DUTCH    2#define EXTENDED 3/* Colors. */#define BLACK   0#define RED     1#define GREEN   2#define YELLOW  3#define BLUE    4#define MAGENTA 5#define CYAN    6#define WHITE   7#define GREY	8#define DEFAULT 9/* Control sequences. */#define ESC "\033"#define DCS "\033P"#define ST  "\033\\"/* Static variables. *//* Option flags.  Set if the option is to be invoked. */int opt_term, opt_reset, opt_initialize, opt_cursor;int opt_linewrap, opt_snow, opt_softscroll, opt_default, opt_foreground;int opt_background, opt_bold, opt_blink, opt_reverse, opt_underline;int opt_store, opt_clear, opt_blank, opt_snap, opt_snapfile, opt_standout;int opt_append, opt_ulcolor, opt_hbcolor, opt_halfbright, opt_repeat;int opt_tabs, opt_clrtabs, opt_regtabs, opt_appcursorkeys, opt_inversescreen;int opt_msg, opt_msglevel, opt_powersave, opt_powerdown;int opt_blength, opt_bfreq;/* Option controls.  The variable names have been contracted to ensure * uniqueness. */char *opt_te_terminal_name;	/* Terminal name. */int opt_cu_on, opt_li_on, opt_sn_on, opt_so_on, opt_bo_on, opt_hb_on, opt_bl_on;int opt_re_on, opt_un_on, opt_rep_on, opt_appck_on, opt_invsc_on;int opt_msg_on;			/* Boolean switches. */int opt_ke_type;		/* Keyboard type. */int opt_fo_color, opt_ba_color;	/* Colors. */int opt_ul_color, opt_hb_color;int opt_cl_all;			/* Clear all or rest. */int opt_bl_min;			/* Blank screen. */int opt_blength_l;int opt_bfreq_f;int opt_sn_num;			/* Snap screen. */int opt_st_attr;int opt_rt_len;			/* regular tab length */int opt_tb_array[161];		/* Array for tab list */int opt_msglevel_num;int opt_ps_mode, opt_pd_min;	/* powersave mode/powerdown time */char opt_sn_name[200] = "screen.dump";static void screendump(int vcnum, FILE *F);/* Command line parsing routines. * * Note that it is an error for a given option to be invoked more than once. */static voidparse_term(int argc, char **argv, int *option, char **opt_term, int *bad_arg) {	/* argc: Number of arguments for this option. */	/* argv: Arguments for this option. */	/* option: Term flag to set. */	/* opt_term: Terminal name to set. */	/* bad_arg: Set to true if an error is detected. *//* Parse a -term specification. */	if (argc != 1 || *option)		*bad_arg = TRUE;	*option = TRUE;	if (argc == 1)		*opt_term = argv[0];}static voidparse_none(int argc, char **argv, int *option, int *bad_arg) {	/* argc: Number of arguments for this option. */	/* argv: Arguments for this option. */	/* option: Term flag to set. */	/* bad_arg: Set to true if an error is detected. *//* Parse a parameterless specification. */	if (argc != 0 || *option)		*bad_arg = TRUE;	*option = TRUE;}static voidparse_switch(int argc, char **argv, int *option, int *opt_on, int *bad_arg) {	/* argc: Number of arguments for this option. */	/* argv: Arguments for this option. */	/* option: Option flag to set. */	/* opt_on: Boolean option switch to set or reset. */	/* bad_arg: Set to true if an error is detected. *//* Parse a boolean (on/off) specification. */	if (argc > 1 || *option)		*bad_arg = TRUE;	*option = TRUE;	if (argc == 1) {		if (strcmp(argv[0], "on") == 0)			*opt_on = TRUE;		else if (strcmp(argv[0], "off") == 0)			*opt_on = FALSE;		else			*bad_arg = TRUE;	} else {		*opt_on = TRUE;	}}static voidpar_color(int argc, char **argv, int *option, int *opt_color, int *bad_arg) {	/* argc: Number of arguments for this option. */	/* argv: Arguments for this option. */	/* option: Color flag to set. */	/* opt_color: Color to set. */	/* bad_arg: Set to true if an error is detected. *//* Parse a -foreground or -background specification. */	if (argc != 1 || *option)		*bad_arg = TRUE;	*option = TRUE;	if (argc == 1) {		if (strcmp(argv[0], "black") == 0)			*opt_color = BLACK;		else if (strcmp(argv[0], "red") == 0)			*opt_color = RED;		else if (strcmp(argv[0], "green") == 0)			*opt_color = GREEN;		else if (strcmp(argv[0], "yellow") == 0)			*opt_color = YELLOW;		else if (strcmp(argv[0], "blue") == 0)			*opt_color = BLUE;		else if (strcmp(argv[0], "magenta") == 0)			*opt_color = MAGENTA;		else if (strcmp(argv[0], "cyan") == 0)			*opt_color = CYAN;		else if (strcmp(argv[0], "white") == 0)			*opt_color = WHITE;		else if (strcmp(argv[0], "default") == 0)			*opt_color = DEFAULT;		else if (isdigit(argv[0][0]))			*opt_color = atoi(argv[0]);		else 			*bad_arg = TRUE;    		if(*opt_color < 0 || *opt_color > 9 || *opt_color == 8)			*bad_arg = TRUE;	}}static voidpar_color2(int argc, char **argv, int *option, int *opt_color, int *bad_arg) {	/* argc: Number of arguments for this option. */	/* argv: Arguments for this option. */	/* option: Color flag to set. */	/* opt_color: Color to set. */	/* bad_arg: Set to true if an error is detected. *//* Parse a -ulcolor or -hbcolor specification. */	if (!argc || argc > 2 || *option)		*bad_arg = TRUE;	*option = TRUE;	*opt_color = 0;	if (argc == 2) {		if (strcmp(argv[0], "bright") == 0)			*opt_color = 8;		else {			*bad_arg = TRUE;			return;		}	}	if (argc) {		if (strcmp(argv[argc-1], "black") == 0) {			if(*opt_color)				*bad_arg = TRUE;			else				*opt_color = BLACK;		} else if (strcmp(argv[argc-1], "grey") == 0) {			if(*opt_color)				*bad_arg = TRUE;			else				*opt_color = GREY;		} else if (strcmp(argv[argc-1], "red") == 0)			*opt_color |= RED;		else if (strcmp(argv[argc-1], "green") == 0)			*opt_color |= GREEN;		else if (strcmp(argv[argc-1], "yellow") == 0)			*opt_color |= YELLOW;		else if (strcmp(argv[argc-1], "blue") == 0)			*opt_color |= BLUE;		else if (strcmp(argv[argc-1], "magenta") == 0)			*opt_color |= MAGENTA;		else if (strcmp(argv[argc-1], "cyan") == 0)			*opt_color |= CYAN;		else if (strcmp(argv[argc-1], "white") == 0)			*opt_color |= WHITE;		else if (isdigit(argv[argc-1][0]))			*opt_color = atoi(argv[argc-1]);		else    			*bad_arg = TRUE;		if(*opt_color < 0 || *opt_color > 15)			*bad_arg = TRUE;	}}static voidparse_clear(int argc, char **argv, int *option, int *opt_all, int *bad_arg) {	/* argc: Number of arguments for this option. */	/* argv: Arguments for this option. */	/* option: Clear flag to set. */	/* opt_all: Clear all switch to set or reset. */	/* bad_arg: Set to true if an error is detected. *//* Parse a -clear specification. */	if (argc > 1 || *option)		*bad_arg = TRUE;	*option = TRUE;	if (argc == 1) {		if (strcmp(argv[0], "all") == 0)			*opt_all = TRUE;		else if (strcmp(argv[0], "rest") == 0)			*opt_all = FALSE;		else			*bad_arg = TRUE;	} else {		*opt_all = TRUE;	}}static voidparse_blank(int argc, char **argv, int *option, int *opt_all, int *bad_arg) {	/* argc: Number of arguments for this option. */	/* argv: Arguments for this option. */	/* option: Clear flag to set. */	/* opt_all: Clear all switch to set or reset. */	/* bad_arg: Set to true if an error is detected. *//* Parse a -blank specification. */	if (argc > 1 || *option)		*bad_arg = TRUE;	*option = TRUE;	if (argc == 1) {		*opt_all = atoi(argv[0]);		if ((*opt_all > 60) || (*opt_all < 0))			*bad_arg = TRUE;	} else {		*opt_all = 0;	}}static voidparse_powersave(int argc, char **argv, int *option, int *opt_mode, int *bad_arg) {	/* argc: Number of arguments for this option. */	/* argv: Arguments for this option. */	/* option: powersave flag to set. */	/* opt_mode: Powersaving mode, defined in vesa_blank.c */	/* bad_arg: Set to true if an error is detected. *//* Parse a -powersave mode specification. */	if (argc > 1 || *option)		*bad_arg = TRUE;	*option = TRUE;	if (argc == 1) {		if (strcmp(argv[0], "on") == 0)			*opt_mode = 1;		else if (strcmp(argv[0], "vsync") == 0)			*opt_mode = 1;

⌨️ 快捷键说明

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