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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/* This file is part of the Project Athena Zephyr Notification System.
* It is one of the source files comprising zwgc, the Zephyr WindowGram
* client.
*
* Created by: Marc Horowitz <marc@athena.mit.edu>
*
* $Source$
* $Author$
*
* Copyright (c) 1989 by the Massachusetts Institute of Technology.
* For copying and distribution information, see the file
* "mit-copyright.h".
*/
#if (!defined(lint) && !defined(SABER))
static char rcsid_display_c[] = "$Header$";
#endif
#include <zephyr/mit-copyright.h>
/****************************************************************************/
/* */
/* "Bus" module for plug in output driver modules: */
/* */
/****************************************************************************/
#include <sysdep.h>
#include "new_memory.h"
#include "new_string.h"
#include "variables.h"
#include "display.h"
/*
* driver_table - <<<>>>
*/
extern void tty_driver();
extern void plain_driver();
extern void raw_driver();
extern int tty_driver_init();
#ifndef X_DISPLAY_MISSING
extern int X_driver_init();
extern void X_driver();
#endif
static struct driver_info {
string driver_name;
void (*driver)();
int (*driver_init)();
void (*driver_reset)();
} driver_table[] = {
#ifndef X_DISPLAY_MISSING
{"X", X_driver, X_driver_init, X_driver_reset},
#endif
{"tty", tty_driver, tty_driver_init, NULL},
{"plain", plain_driver, NULL, NULL},
{"raw", raw_driver, NULL, NULL},
{NULL, NULL, NULL, NULL}
};
/*
* <<<>>>
*/
struct driver_info *get_driver_info(driver_name)
string driver_name;
{
struct driver_info *d;
for (d=driver_table; d->driver_name; d++)
if (string_Eq(d->driver_name, driver_name) && d->driver)
return(d);
return(NULL);
}
/*
* void init_display(int *pargc; char **argv)
* Effects: <<<>>>
*/
void display_init(pargc, argv)
int *pargc;
char **argv;
{
char **new, **current;
struct driver_info *d;
string first_working_driver = "";
string default_driver = "";
/*
* Process argument list handling "-disable <driver>" and
* "-default <driver>" arguments:
*/
for (new=current=argv+1; *current; current++) {
if (string_Eq(*current, "-disable")) {
current++; *pargc -= 2;
if (!*current)
usage();
if (d = get_driver_info(*current))
d->driver = NULL;
} else if (string_Eq(*current, "-default")) {
current++; *pargc -= 2;
if (!*current)
usage();
default_driver = *current;
} else
*(new++) = *current;
}
*new = *current;
/*
* Initialize all non-disabled drivers. If a driver reports an error,
* disable that driver. Set default_driver if not already set
* by the -default argument to the first non-disabled driver.
*/
for (d = driver_table; d->driver_name; d++) {
if (!d->driver)
continue;
if (d->driver_init && d->driver_init(pargc, argv)) {
d->driver = NULL;
continue;
}
if (!*first_working_driver)
first_working_driver = d->driver_name;
}
if (!get_driver_info(default_driver))
default_driver = first_working_driver;
var_set_variable("output_driver", default_driver);
}
void display_reset()
{
for (d = driver_table; d->driver_name; d++)
if (d->driver) d->driver_reset();
}
|