File: finddisp.c

package info (click to toggle)
magic 7.5.220-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 17,860 kB
file content (123 lines) | stat: -rw-r--r-- 4,342 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * finddisplay.c -
 *
 *     ********************************************************************* 
 *     * Copyright (C) 1985, 1990 Regents of the University of California. * 
 *     * Permission to use, copy, modify, and distribute this              * 
 *     * software and its documentation for any purpose and without        * 
 *     * fee is hereby granted, provided that the above copyright          * 
 *     * notice appear in all copies.  The University of California        * 
 *     * makes no representations about the suitability of this            * 
 *     * software for any purpose.  It is provided "as is" without         * 
 *     * express or implied warranty.  Export of this software outside     * 
 *     * of the United States of America may require an export license.    * 
 *     *********************************************************************
 *
 * This file contains a single routine that will find the correct
 * graphics display to use from the current terminal and return
 * parameters for the display, such as its type and the location
 * of the tablet port.  It is used as part of the Caesar design
 * system.
 */

#ifndef lint
static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-7.5/utils/finddisp.c,v 1.1.1.1 2006/04/10 22:03:14 tim Exp $";
#endif  /* not lint */

#include <stdio.h>
#include <string.h>

#include "utils/magic.h"
#include "utils/utils.h"

/* Import from library routines: */

extern char *ttyname();


/*
 * ----------------------------------------------------------------------------
 *	FindDisplay --
 *
 * 	This procedure locates information about the color display
 *	to use from a given terminal (determined by tty or the name
 *	of the standard input file) by looking in the file passed.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The parameters pDisplayPort, pTabletPort, pDisType, and
 *	pMonType all point to strings that are modified.  *pDisplayPort
 *	is filled with the name of the port that connects to the graphics
 *	display.  *pTabletPort is filled in with the name of the port to be
 *	used to receive characters from the tablet.  *pDisType is filled
 *	in with the name of the type of display ("OGL", etc.), and
 *	*pMonType is filled in with the name of the monitor type attached
 *	to the display (used to select color maps).
 *
 *	If the file is not found or if there is not a suitable line then
 *	nothing is modified.
 *
 * File format:
 *	Each line in the displays file contains up to five strings
 *	which are, in order, the name of a text terminal, the name
 *	of the corresponding graphics display port, the monitor type
 *	attached to that display, the name of the display type, and
 *	the name of the tablet port to use for that display.  The
 *	tablet port can be omitted, in which case the display port
 *	is used.
 * ----------------------------------------------------------------------------
 */

void
FindDisplay(tty, file, path, pDisplayPort, pTabletPort, pDisType, pMonType)
    char *tty;			/* Terminal for which display info is desired.
				 * If NULL, used device on stdin.
				 */
    char *file;			/* Name of file in which to find info. */
    char *path;			/* Path to use for lookup. */
    char **pDisplayPort;	/* Will be filled in with the name of the
				 * port for the graphics display.
				 */
    char **pTabletPort;		/* Will be filled in with the name of the 
				 * tablet. */
    char **pDisType;		/* Will be filled in with the display type. */
    char **pMonType;		/* Will be filled in with the monitor type. */

{
    int i;
    char line[100], name1[100];
    static char name2[100], mon[100], dType[100], tabletPort[100];
    FILE *f;

    if (tty == NULL) tty = ttyname(fileno(stdin));
    if (tty == NULL) return;
    f = PaOpen(file, "r", (char *) NULL, path, (char *) NULL, (char **) NULL);
    if (f == NULL) return;
    while (1)
    {
	if (fgets(line, 99, f) == NULL)
	{
	    (void) fclose(f);
	    return;
	}
	i = sscanf(line, "%99s %99s %99s %99s %99s", name1, name2,
	    mon, dType, tabletPort);
	if (i < 4)
	{
	    (void) fclose(f);
	    return;
	}
	if (strcmp(name1, tty) == 0)
	{
	    (void) fclose(f);
	    *pDisplayPort = name2;
	    *pMonType = mon;
	    *pDisType = dType;
	    if (i >= 5) *pTabletPort = tabletPort;
	    else *pTabletPort = name2;
	    return;
	}
    }
}