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

📄 captoinfo.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
		    return 1;		}	    string++;	    }    return 0;}/*    Change old style of doing calculations to the new stack style.    Note that this will not necessarily produce the most efficient string,    but it will work.*/void changecalculations (){    register int i, currentparm;    register char *from, *to = nextstring;    int ch;    int parmset, parmsaved;    char padding [100], *saveto;    for (i = 0; strnames [i]; i++)	if (needscopying (strval [uselevel] [i]))	    {	    if (verbose)		{		(void) fprintf (trace, "%s needs copying, was:", strnames [i]);		tpr (trace, strval [uselevel] [i]);		(void) fprintf (trace, ".\n");		}	    from = strval [uselevel] [i];	    strval [uselevel] [i] = to;	    currentparm = 1;	    parmset = 0;	    /* Handle padding information. Save it so that it can be */	    /* placed at the end of the string where it should */	    /* have been in the first place. */	    if (ispadchar (*from))		{		saveto = to;		to = padding;		to = caddstr (to, "$<");		while (isdigit (*from) || *from == '.')		    caddch (*from++);		if (*from == '*')		    caddch (*from++);		caddch ('>');		caddch ('\0');		to = saveto;		}	    else		padding [0] = '\0';	    if (fancycap (from))		{		to = caddstr (to, "%p1%Pa%p2%Pb");		parmsaved = 1;		(void) fprintf (stderr,		    "%s: TERM=%s: Warning: the string produced for '%s' may be inefficient.\n",		    progname, term_name, strnames[i]);		(void) fprintf (stderr, "It should be looked at by hand.\n");		}	    else		parmsaved = 0;	    while (ch = *from++)		if (ch != '%')		    caddch (ch);		else		    switch (ch = *from++)			{			case '.':	/* %.  -> %p1%c */			case 'd':	/* %d  -> %p1%d */			case '2':	/* %2  -> %p1%2.2d */			case '3':	/* %3  -> %p1%3.3d */			case '+':	/* %+x -> %p1%'x'%+%c */			case '>':	/* %>xy -> %p1%Pc%?%'x'%>%t%gc%'y'%+ */					/* if current value > x, then add y. */					/* No output. */			case 'B':	/* %B: BCD (16*(x/10))+(x%10) */					/* No output. */					/* (Adds Regent 100) */			case 'D':	/* %D: Reverse coding (x-2*(x%16)) */					/* No output. */					/* (Delta Data) */			    if (!parmset)				if (parmsaved)				    {				    to = caddstr (to, "%g");				    if (currentparm == 1)					caddch ('a');				    else					caddch ('b');				    }				else				    {				    to = caddstr (to, "%p");				    if (currentparm == 1)					caddch ('1');				    else					caddch ('2');				    }			    currentparm = 3 - currentparm;			    parmset = 0;			    switch (ch)				{				case '.':				    to = caddstr (to, "%c");				    break;				case 'd':				    to = caddstr (to, "%d");				    break;				case '2': case '3':#ifdef USG	/* Vr2==USG, Vr3==SYSV. Use %02d for Vr2, %2.2d for Vr3 */				    caddch('%'); caddch ('0');#else				    caddch('%'); caddch (ch); caddch ('.');#endif /* USG vs. SYSV */				    caddch (ch); caddch ('d');				    break;				case '+':				    to = caddstr (to, "%'");				    caddch (*from++);				    to = caddstr (to, "'%+%c");				    break;				case '>':				    to = caddstr (to, "%Pc%?%'");				    caddch (*from++);				    to = caddstr (to, "'%>%t%gc%'");				    caddch (*from++);				    to = caddstr (to, "'%+");				    parmset = 1;				    break;				case 'B':				    to = caddstr (to, "%Pc%gc%{10}%/%{16}%*%gc%{10}%m%+");				    parmset = 1;				    break;				case 'D':				    to = caddstr (to, "%Pc%gc%gc%{16}%m%{2}%*%-");				    parmset = 1;				    break;				}			    break;			/* %r reverses current parameter */			case 'r':			    currentparm = 3 - currentparm;			    break;			/* %n: exclusive-or row AND column */			/* with 0140, 96 decimal, no output */			/* (Datamedia 2500, Exidy Sorceror) */			case 'n':			    to = caddstr (to, "%ga%'`'%^%Pa");			    to = caddstr (to, "%gb%'`'%^%Pb");			    break;			/* assume %x means %x */			/* this includes %i and %% */			default:			    caddch ('%');			    caddch (ch);			}	    to = caddstr (to, padding);	    caddch ('\0');	    if (verbose)		{		(void) fprintf (trace, "and has become:");		tpr (trace, strval [uselevel] [i]);		(void) fprintf (trace, ".\n");		}	    }    nextstring = to;}print_no_use_entry(){    register int i;    pr_heading ("", buflongname);    pr_bheading();    for (i = 0; boolcodes [i]; i++)	if (boolval [0] [i])	    pr_boolean (boolnames[i], (char *)0, (char *)0, 1);    pr_bfooting();    pr_sheading();    for (i = 0; numcodes [i]; i++)	if (numval [0] [i] > -1)	    pr_number(numnames[i], (char *)0, (char *)0, numval[0][i]);    pr_nfooting();    pr_sheading();    for (i = 0; strcodes [i]; i++)	if (strval [0] [i])	    pr_string (strnames[i], (char *)0, (char *)0, strval[0][i]);    pr_sfooting();}print_use_entry (usename)char *usename;{    register int i;    pr_heading ("", buflongname);    pr_bheading();    for (i = 0; boolcodes [i]; i++)	if (boolval [0] [i] && !boolval [1] [i])	    pr_boolean (boolnames[i], (char *)0, (char *)0, 1);	else if (!boolval [0] [i] && boolval [1] [i])	    pr_boolean (boolnames[i], (char *)0, (char *)0, -1);    pr_bfooting();    pr_nheading();    for (i = 0; numcodes [i]; i++)	if ((numval [0] [i] > -1) && (numval [0] [i] != numval [1] [i]))	    pr_number (numnames[i], (char *)0, (char *)0, numval[0][i]);	else if ((numval [0] [i] == -1) && (numval [1] [i] > -1))	    pr_number (numnames[i], (char *)0, (char *)0, -1);    pr_nfooting();    pr_sheading();    for (i = 0; strcodes [i]; i++)	/* print out str[0] if: */	/* str[0] != NULL and str[1] == NULL, or str[0] != str[1] */	if (strval [0] [i] &&	    ((strval[1][i] == NULL) ||	     (strcmp(strval [0] [i],strval [1] [i]) != 0)) )	    pr_string (strnames[i], (char *)0, (char *)0, strval[0][i]);	/* print out @ if str[0] == NULL and str[1] != NULL */	else if (strval [0] [i] == NULL && strval [1] [i] != NULL)	    pr_string (strnames[i], (char *)0, (char *)0, (char *)0);    pr_sfooting();    (void) printf ("\tuse=%s,\n", usename);}captoinfo (){    char usename[512];    char *sterm_name;    if (term_name == NULL)	{	(void) fprintf (stderr, "%s: Null term_name given.\n", progname);	return;	}    if (verbose)	(void) fprintf (trace, "changing cap to info, TERM=%s.\n", term_name);    uselevel = 0;    if (filltables () == 0)	return;    getlongname ();    adddefaults ();    changecalculations ();    if (TLHtcfound != 0)	{	uselevel = 1;	if (verbose)	    (void) fprintf (trace, "use= found, %s uses %s.\n",		term_name, TLHtcname);	(void) strcpy (usename, TLHtcname);	sterm_name = term_name;	term_name = usename;	if (filltables () == 0)	    return;	adddefaults ();	changecalculations ();	term_name = sterm_name;	print_use_entry (usename);	}    else	print_no_use_entry ();}use_etc_termcap (){    if (verbose)	(void) fprintf (trace, "reading from /etc/termcap\n");    term_name = getenv ("TERM");    captoinfo ();}initdirname (){#if defined(SYSV) || defined(USG)  /* handle both Sys Vr2 and Vr3 curses */    (void) getcwd (dirname, BUFSIZ-2);#else    (void) getwd (dirname);#endif /* SYSV || USG */    if (verbose)	(void) fprintf (trace, "current directory name=%s.\n", dirname);    environ = newenviron;}setfilename (capfile)register char *capfile;{    if (capfile [0] == '/')	(void) sprintf (TERMCAP, "TERMCAP=%s", capfile);    else	(void) sprintf (TERMCAP, "TERMCAP=%s/%s", dirname, capfile);    if (verbose)	(void) fprintf (trace, "setting the environment for %s.\n", TERMCAP);}setterm_name (){    if (verbose)	(void) fprintf (trace, "setting the environment for TERM=%s.\n", term_name);    (void) sprintf (TERM, "TERM=%s", term_name);}/* Look at the current line to see if it is a list of names. *//* If it is, return the first name in the list, else NULL. *//* As a side-effect, comment lines and blank lines *//* are copied to standard output. */char *getterm_name (line)register char *line;{    register char *lineptr = line;    if (verbose)	(void) fprintf (trace, "extracting name from '%s'.\n", line);    /* Copy comment lines out. */    if (*line == '#')	{	if (copycomments)	    (void) printf ("%s", line);	}    /* Blank lines get copied too. */    else if (isspace (*line))	{	if (copycomments)	    {	    for ( ; *lineptr ; lineptr++)		if (!isspace(*lineptr))		    break;	    if (*lineptr == '\0')		(void) printf ("\n");	    }	}    else	for ( ; *lineptr ; lineptr++)	    if (*lineptr == '|' || *lineptr == ':')		{		*lineptr = '\0';		if (verbose)		    (void) fprintf (trace, "returning %s.\n", line);		return line;		}    if (verbose)	(void) fprintf (trace, "returning NULL.\n");    return NULL;}use_file (filename)register char *filename;{    register FILE *termfile;    char buffer [BUFSIZ];    if (verbose)	(void) fprintf (trace, "reading from %s.\n", filename);    if ( (termfile = fopen (filename, "r")) == NULL)	{	(void) fprintf (stderr, "%s: cannot open %s for reading.\n",	    progname, filename);	return;	}    copycomments++;    setfilename (filename);    while (fgets (buffer, BUFSIZ, termfile) != NULL)	{	if ((term_name = getterm_name (buffer)) != NULL)	    {	    setterm_name ();	    captoinfo ();	    }	}}/*    Sort a name and code table pair according to the name table.    Use a simple bubble sort for now. Too bad I can't call qsort(3).    At least I only have to do it once for each table.*/sorttable (nametable, codetable)char *nametable [], *codetable [];{    register int i, j;    register char *c;    for (i = 0; nametable [i]; i++)	for (j = 0; j < i; j++)	    if (strcmp (nametable [i], nametable [j]) < 0)		{		c = nametable [i];		nametable [i] = nametable [j];		nametable [j] = c;		c = codetable [i];		codetable [i] = codetable [j];		codetable [j] = c;		}}/*    Initialize and sort the name and code tables. Allocate space for the    value tables.*/inittables (){    register unsigned int i;    for (i = 0; boolnames [i]; i++)	;    boolval[0] = (char *) malloc (i * sizeof (char));    boolval[1] = (char *) malloc (i * sizeof (char));    boolcount = i;    sorttable (boolnames, boolcodes);    for (i = 0; numcodes [i]; i++)	;    numval [0] = (short *) malloc (i * sizeof (short));    numval [1] = (short *) malloc (i * sizeof (short));    numcount = i;    sorttable (numnames, numcodes);    for (i = 0; strcodes [i]; i++)	;    strval [0] = (char **) malloc (i * sizeof (char *));    strval [1] = (char **) malloc (i * sizeof (char *));    strcount = i;    sorttable (strnames, strcodes);}main (argc, argv)int argc;char **argv;{    int c;    char _capbuffer [8192];    char _bp [TBUFSIZE];    char _buflongname [128];    capbuffer = &_capbuffer[0];    bp = &_bp[0];    buflongname = &_buflongname[0];    progname = argv [0];    while ( (c = getopt (argc, argv, "1vVw:")) != EOF)	switch (c)	    {	    case '1':		pr_onecolumn (1);		break;	    case 'w':		pr_width (atoi(optarg));		break;	    case 'v':		verbose++;		break;	    case 'V':		printf("@(#)curses:screen/captoinfo.c	1.6.1.7\n");		fflush(stdout);		exit (0);	    case '?':		(void) fprintf (stderr,		    "usage: %s [-1Vv] [-w width] [filename ...]\n", progname);		(void) fprintf (stderr, "\t-1\tsingle column output\n");		(void) fprintf (stderr, "\t-v\tverbose debugging output\n");		(void) fprintf (stderr, "\t-V\tprint program version\n");		exit (-1);	    }    /* initialize */    pr_init (pr_terminfo);    inittables ();    if (optind >= argc)	use_etc_termcap ();    else	{	initdirname ();	for ( ; optind < argc ; optind++)	    use_file (argv [optind]);	}    return 0;}/* fake out the modules in print.c so we don't have to load in *//* cexpand.c and infotocap.c *//* ARGSUSED */int cpr(stream, string) FILE *stream; char *string; { return 0; }/* ARGSUSED */char *cexpand(string) char *string; { return string; }/* ARGSUSED */char *infotocap(value, err) char *value; int *err; { return value; }

⌨️ 快捷键说明

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