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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
/*
* Hardware Information, version 0.3.1b
* Copyright (C) 2003 Leandro Pereira <leandro@linuxmag.com.br>
*
* May be modified and/or distributed under the terms of GNU GPL version 2.
*
* Tested only with 2.4.x kernels on ix86.
* USB support needs usbdevfs.
*/
#include "hardinfo.h"
#include "parport.h"
#define srch_def(str,len,var) \
if (!strncmp(buffer, str, len)) { \
walk_until_inclusive(':'); \
parport_dev->var = g_strdup(buf); \
}
ParportDevice *hi_scan_parport(void)
{
FILE *autoprobe;
struct stat st;
gint n=0, i;
ParportDevice *parport_dev, *parport;
parport = NULL;
for (i = 0; i <= 16; i++) {
gchar *file;
gchar buffer[128];
gint port, dma;
file = g_strdup_printf(PARPORT_PROC_BASE "parport%d", i);
if (stat(file, &st)) {
g_free(file);
continue;
}
g_free(file);
file = g_strdup_printf
(PARPORT_PROC_BASE "parport%d/autoprobe", i);
parport_dev = g_new0(ParportDevice, 1);
parport_dev->next = parport;
parport = parport_dev;
n++;
parport_dev->number = i;
autoprobe = fopen(file, "r");
while (autoprobe && fgets(buffer, 128, autoprobe)) {
char *buf;
buf = g_strstrip(buffer);
*(buf + strlen(buf) - 1) = 0;
srch_def("CLASS:", 6, pclass);
srch_def("MODEL:", 6, model);
srch_def("MANUFA", 6, manufacturer);
srch_def("DESCRI", 6, description);
srch_def("COMMAN", 6, cmdset);
}
if(autoprobe) fclose(autoprobe);
g_free(file);
if (parport_dev->model) {
parport_dev->name =
g_strdup_printf("%s %s (lp%d)",
parport_dev->manufacturer,
parport_dev->model, i);
} else {
parport_dev->name =
g_strdup_printf ("Parallel port (lp%d)", i);
}
file = g_strdup_printf
(PARPORT_PROC_BASE "parport%d/base-addr", i);
autoprobe = fopen(file, "r");
if (autoprobe) {
fscanf(autoprobe, "%d", &port);
fclose(autoprobe);
parport_dev->port = port;
}
g_free(file);
file = g_strdup_printf
(PARPORT_PROC_BASE "parport%d/dma", i);
autoprobe = fopen(file, "r");
if (autoprobe) {
fscanf(autoprobe, "%d", &dma);
fclose(autoprobe);
parport_dev->dma = (dma == -1) ? FALSE : TRUE;
}
g_free(file);
file = g_strdup_printf
(PARPORT_PROC_BASE "parport%d/modes", i);
autoprobe = fopen(file, "r");
if (autoprobe) {
gchar modes[64];
fgets(modes, 64, autoprobe);
fclose(autoprobe);
modes[strlen(modes)-1]=0;
parport_dev->modes = g_strdup(modes);
}
if(!parport_dev->modes)
parport_dev->modes = g_strdup(_("N/A"));
g_free(file);
}
return parport;
}
void hi_show_parport_info(MainWindow *mainwindow, ParportDevice *device)
{
gchar *buf;
static struct {
gchar *type, *label, *icon;
} type2icon[] = {
{"PRINTER", "Printer", "lpr.png" },
{"MEDIA", "Multimedia", "media.png" },
{NULL, "Legacy Device", "gen_connector.png"},
};
gint i;
if(!device) return;
if (device->pclass) {
for (i = 0; type2icon[i].type != NULL; ++i)
if(!strcmp(device->pclass, type2icon[i].type))
break;
} else
i = sizeof(type2icon) / sizeof(type2icon[0]) - 1;
buf = g_strdup_printf("%s%s", IMG_PREFIX, type2icon[i].icon);
detail_window_set_icon(mainwindow->det_window, buf);
g_free(buf);
gtk_window_set_title(GTK_WINDOW(mainwindow->det_window->window), _("Parallel Port"));
detail_window_set_dev_name(mainwindow->det_window, device->name);
detail_window_set_dev_type(mainwindow->det_window, type2icon[i].label);
if (device->description)
detail_window_append_info(mainwindow->det_window, _("Description"),
device->description);
if (device->cmdset)
detail_window_append_info(mainwindow->det_window, _("Command set"),
device->cmdset);
detail_window_append_info_int(mainwindow->det_window, _("Base I/O address"),
device->port, TRUE);
detail_window_append_info(mainwindow->det_window, _("Modes"),
device->modes);
detail_window_append_info(mainwindow->det_window, _("Uses DMA"),
device->dma ? _("Yes") : _("No"));
}
|