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

📄 captoinfo.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
{    register int i;    if (verbose > 1)	(void) fprintf (trace, "changing value for %s to %d.\n",	    infoname, newvalue);    i = search (boolnames, boolcount, infoname);    if (i != -1)	{	if (verbose > 1)	    (void) fprintf (trace, "value was: %d.\n", boolval[uselevel][i]);	boolval [uselevel] [i] = newvalue;	return;	}    (void) fprintf (stderr, "%s: TERM=%s: the boolean name '%s' was not found!\n",	progname, term_name, infoname);}/*    Replace the value stored for the terminfo number    capability 'infoname' with the newvalue.*/void putnum (infoname, newvalue)register char *infoname;register int newvalue;{    register int i;    if (verbose > 1)	(void) fprintf (trace, "changing value for %s to %d.\n",	    infoname, newvalue);    i = search (numnames, numcount, infoname);    if (i != -1)	{	if (verbose > 1)	    (void) fprintf (trace, "value was: %d.\n",		numval [uselevel] [i]);	numval [uselevel] [i] = newvalue;	return;	}    (void) fprintf (stderr, "%s: TERM=%s: the numeric name '%s' was not found!\n",	progname, term_name, infoname);}/*    replace the value stored for the terminfo string capability 'infoname'    with the newvalue.*/void putstr (infoname, newvalue)register char *infoname, *newvalue;{    register int i;    if (verbose > 1)	{	(void) fprintf (trace, "changing value for %s to ", infoname);	tpr (trace, newvalue);	(void) fprintf (trace, ".\n");	}    i = search (strnames, strcount, infoname);    if (i != -1)	{	if (verbose > 1)	    {	    (void) fprintf (trace, "value was:");	    tpr (trace, strval [uselevel] [i]);	    (void) fprintf (trace, ".\n");	    }	strval [uselevel] [i] = nextstring;	while (*newvalue)	    *nextstring++ = *newvalue++;	*nextstring++ = '\0';	return;	}    (void) fprintf (stderr, "%s: TERM=%s: the string name '%s' was not found!\n",	progname, term_name, infoname);}/*    Add in extra delays if they are not recorded already.    This is done before the padding information has been modified by    changecalculations() below, so the padding information, if there    already, is still at the beginning of the string in termcap format.*/void addpadding (cappadding, infostr)register int cappadding;register char *infostr;{    register char *cap;    char tempbuffer [100];    /* Is there padding to add? */    if (cappadding > 0)	/* Is there a string to add it to? */	if (cap = getinfostr (infostr))	    /* Is there any padding info already? */	    if (ispadchar(*cap))		{		/* Assume that the padding info that is there is correct. */		}	    else		{		/* Add the padding at the end of the present string. */		(void) sprintf(tempbuffer, "%s$<%d>", cap, cappadding);		putstr (infostr, tempbuffer);		}	else	    {	    /* Create a new string that only has the padding. */	    (void) sprintf(tempbuffer, "$<%d>", cappadding);	    putstr (infostr, tempbuffer);	    }}struct    {    char *capname;    char *keyedinfoname;    } ko_map[] =	{	"al",		"kil1",	"bs",		"kbs",		/* special addition */	"bt",		"kcbt",	"cd",		"ked",	"ce",		"kel",	"cl",		"kclr",	"ct",		"ktbc",	"dc",		"kdch1",	"dl",		"kdl1",	"do",		"kcud1",	"ei",		"krmir",	"ho",		"khome",	"ic",		"kich1",	"im",		"kich1",	/* special addition */	"le",		"kcub1",	"ll",		"kll",	"nd",		"kcuf1",	"sf",		"kind",	"sr",		"kri",	"st",		"khts",	"up",		"kcuu1",/*	"",		"kctab",	*//*	"",		"knp",		*//*	"",		"kpp",		*/	0,		0	};/*    Work with the ko string. It is a comma separated list of keys for which    the keyboard has a key by the same name that emits the same sequence.    For example, ko=dc,im,ei means that there are keys called    delete-character, enter-insert-mode and exit-insert-mode on the keyboard,    and they emit the same sequences as specified in the dc, im and ei    capabilities.*/handleko(){    char capname[3];    register char *capstr;    register int i, j, found;    register char *infostr;    if (verbose > 1)	(void) fprintf (trace, "working on termcap ko string.\n");    if (ostrval[uselevel][cap_ko] == NULL)	return;    capname[2] = '\0';    for (i = 0; ostrval[uselevel][cap_ko][i] != '\0'; )	{	/* isolate the termcap name */	capname[0] = ostrval[uselevel][cap_ko][i++];	if (ostrval[uselevel][cap_ko][i] == '\0')	    break;	capname[1] = ostrval[uselevel][cap_ko][i++];	if (ostrval[uselevel][cap_ko][i] == ',')	    i++;	if (verbose > 1)	    {	    (void) fprintf (trace, "key termcap name is '");	    tpr (trace, capname);	    (void) fprintf (trace, "'.\n");	    }	/* match it up into our list */	found = 0;	for (j = 0; !found && ko_map[j].keyedinfoname != NULL; j++)	    {	    if (verbose > 1)		(void) fprintf (trace, "looking at termcap name %s.\n",		    ko_map[j].capname);	    if (capname[0] == ko_map[j].capname[0] &&		capname[1] == ko_map[j].capname[1])		{		/* add the value to our database */		if ((capstr = getcapstr (capname)) != NULL)		    {		    infostr = getinfostr (ko_map[j].keyedinfoname);		    if (infostr == NULL)			{			/* skip any possible padding information */			while (ispadchar(*capstr))			    capstr++;			putstr (ko_map[j].keyedinfoname, capstr);			}		    else			if (strcmp(capstr, infostr) != 0)			    {			    (void) fprintf (stderr,				"%s: TERM=%s: a function key for '%s' was specified with the value ",				progname, term_name, capname);			    tpr (stderr, capstr);			    (void) fprintf (stderr, ", but it already has the value '");			    tpr (stderr, infostr);			    (void) fprintf (stderr, "'.\n");			    }		    }		found = 1;		}	    }	if (!found)	    {	    (void) fprintf (stderr, "%s: TERM=%s: the unknown termcap name '%s' was\n",		progname, term_name, capname);	    (void) fprintf (stderr, "specified in the 'ko' termcap capability.\n");	    }	}}#undef CTRL#define CTRL(x)		((x) & 037)struct    {    char vichar;    char *keyedinfoname;    } ma_map[] =	{	CTRL('J'),	"kcud1",	/* down */	CTRL('N'),	"kcud1",	'j',		"kcud1",	CTRL('P'),	"kcuu1",	/* up */	'k',		"kcuu1",	'h',		"kcub1",	/* left */	CTRL('H'),	"kcub1",	' ',		"kcuf1",	/* right */	'l',		"kcuf1",	'H',		"khome",	/* home */	CTRL('L'),	"kclr",		/* clear */	0,		0	};/*    Work with the ma string. This is a list of pairs of characters.    The first character is the what a function key sends. The second    character is the equivalent vi function that should be done when    it receives that character. Note that only function keys that send    a single character could be defined by this list.*/void prchar (stream, c)register FILE *stream;register int c;{    char xbuf[2];    xbuf[0] = c;    xbuf[1] = '\0';    (void) fprintf (stream, "%s", iexpand (xbuf));}handlema(){    register char vichar;    char cap[2];    register int i, j, found;    register char *infostr;    if (verbose > 1)	(void) fprintf (trace, "working on termcap ma string.\n");    if (ostrval[uselevel][cap_ma] == NULL)	return;    cap[1] = '\0';    for (i = 0; ostrval[uselevel][cap_ma][i] != '\0'; )	{	/* isolate the key's value */	cap[0] = ostrval[uselevel][cap_ma][i++];	if (verbose > 1)	    {	    (void) fprintf (trace, "key value is '");	    tpr (trace, cap);	    (void) fprintf (trace, "'.\n");	    }	if (ostrval[uselevel][cap_ma][i] == '\0')	    break;	/* isolate the vi key name */	vichar = ostrval[uselevel][cap_ma][i++];	if (verbose > 1)	    {	    (void) fprintf (trace, "the vi key is '");	    prchar (trace, vichar);	    (void) fprintf (trace, "'.\n");	    }	/* match up the vi name in our list */	found = 0;	for (j = 0; !found && ma_map[j].keyedinfoname != NULL; j++)	    {	    if (verbose > 1)		{		(void) fprintf (trace, "looking at vi character '");		prchar (trace, ma_map[j].vichar);		(void) fprintf (trace, "'\n");		}	    if (vichar == ma_map[j].vichar)		{		infostr = getinfostr (ma_map[j].keyedinfoname);		if ( infostr == NULL )		    putstr (ma_map[j].keyedinfoname, cap);		else if (strcmp (cap, infostr) != 0)		    {		    (void) fprintf (stderr, "%s: TERM=%s: the vi character '",			progname, term_name);		    prchar (stderr, vichar);		    (void) fprintf (stderr,			"' (info '%s') has the value '",			ma_map[j].keyedinfoname);		    tpr (stderr, infostr);		    (void) fprintf (stderr, "', but 'ma' gives '");		    prchar (stderr, cap[0]);		    (void) fprintf (stderr, "'.\n");		    }		found = 1;		}	    }	if (!found)	    {	    (void) fprintf (stderr, "%s: the unknown vi key '", progname);	    prchar (stderr, vichar);	    (void) fprintf (stderr, "' was\n");	    (void) fprintf (stderr, "specified in the 'ma' termcap capability.\n");	    }	}}/*    Many capabilities were defaulted in termcap which must now be explicitly    given. We'll assume that the defaults are in effect for this terminal.*/void adddefaults (){    register char *cap;    register int sg;    if (verbose > 1)	(void) fprintf (trace, "assigning defaults.\n");    /* cr was assumed to be ^M, unless nc was given, */    /* which meant it could not be done. */    /* Also, xr meant that ^M acted strangely. */    if ( (getinfostr ("cr") == NULL) && !oboolval[uselevel][cap_nc] &&	 !oboolval[uselevel][cap_xr])	if ( (cap = getcapstr ("cr")) == NULL)	    putstr ("cr", "\r");	else	    putstr ("cr", cap);    /* cursor down was assumed to be ^J if not specified by nl */    if (getinfostr ("cud1") == NULL)	if (ostrval[uselevel][cap_nl] != NULL)	    putstr ("cud1", ostrval[uselevel][cap_nl]);	else	    putstr ("cud1", "\n");    /* ind was assumed to be ^J, unless ns was given, */    /* which meant it could not be done. */    if ( (getinfostr ("ind") == NULL) && !oboolval[uselevel][cap_ns] )	if ( ostrval[uselevel][cap_nl] == NULL)	    putstr ("ind", "\n");	else	    putstr ("ind", ostrval[uselevel][cap_nl]);    /* bel was assumed to be ^G */    if (getinfostr ("bel") == NULL)	putstr ("bel", "\07");    /* if bs, then could do backspacing, */    /* with value of bc, default of ^H */    if ( (getinfostr ("cub1") == NULL) && oboolval[uselevel][cap_bs] )	if (ostrval[uselevel][cap_bc] != NULL)	    putstr ("cub1", ostrval[uselevel][cap_bc]);	else	    putstr ("cub1", "\b");    /* default xon to true */    if ( !otgetflag ("xo") )	putbool ("xon", 1);    /* if pt, then hardware tabs are allowed, */    /* with value of ta, default of ^I */    if ( (getinfostr ("ht") == NULL) && oboolval[uselevel][cap_pt] )	if ( (cap = getcapstr ("ta")) == NULL)	    putstr ("ht", "\t");	else	    putstr ("ht", cap);    /* The dX numbers are now stored as padding */    /* in the appropriate terminfo string. */    addpadding (onumval[uselevel][cap_dB], "cub1");    addpadding (onumval[uselevel][cap_dC], "cr");    addpadding (onumval[uselevel][cap_dF], "ff");    addpadding (onumval[uselevel][cap_dN], "cud1");    addpadding (onumval[uselevel][cap_dT], "ht");    /* The ug and sg caps were essentially identical, */    /* so ug almost never got used. We set sg from ug */    /* if it hasn't already been set. */    if (onumval[uselevel][cap_ug] >= 0 && (sg = otgetnum ("sg")) < 0)	putnum ("xmc", onumval[uselevel][cap_ug]);    else if ((onumval[uselevel][cap_ug] >= 0) &&	     (sg >= 0) &&	     (onumval[uselevel][cap_ug] != sg))	(void) fprintf (stderr,	    "%s: TERM=%s: Warning: termcap sg and ug had different values (%d<->%d).\n",	    progname, term_name, sg, onumval[uselevel][cap_ug]);    /* The MT boolean was never really part of termcap, */    /* but we can check for it anyways. */    if (oboolval[uselevel][cap_MT] && !otgetflag ("km"))	putbool ("km", 1);    /* the rs string was renamed r2 (info rs2) */    if ( (ostrval[uselevel][cap_rs] != NULL) &&	 (ostrval[uselevel][cap_rs][0] != NULL) )	putstr ("rs2", ostrval[uselevel][cap_rs]);    handleko();    handlema();}#define caddch(x) *to++ = (x)/*    add the string to the string table*/char *caddstr (to, str)register char *to, *str;{    while (*str)	*to++ = *str++;    return to;}/* If there is no padding info or parmed strings, *//* then we do not need to copy the string. */int needscopying (string)register char *string;{    /* any string at all? */    if (string == NULL)	return 0;    /* any padding info? */    if (ispadchar (*string))	return 1;    /* any parmed info? */    while (*string)	if (*string++ == '%')	    return 1;    return 0;}/*    Certain manipulations of the stack require strange manipulations of the    values that are on the stack. To handle these, we save the values of the    parameters in registers at the very beginning and make the changes in    the registers. We don't want to do this in the general case because of the    potential performance loss.*/int fancycap (string)register char *string;{    register int parmset = 0;    while (*string)	if (*string++ == '%')	    {	    switch (*string)		{		/* These manipulate just the top value on the stack, so we */		/* only have to do something strange if a %r follows. */		case '>': case 'B': case 'D':		    parmset = 1;		    break;		/* If the parm has already been been pushed onto the stack */		/* by %>, then we can not reverse the parms and must get */		/* them from the registers. */		case 'r':		    if (parmset)			return 1;		    break;		/* This manipulates both parameters, so we cannot */		/* just do one and leave the value on the stack */		/* like we can with %>, %B or %D. */		case 'n':

⌨️ 快捷键说明

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