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
|
--- xsys2/parse.c.orig 2005-04-17 21:01:24.000000000 +0100
+++ xsys2/parse.c 2005-04-17 21:09:07.000000000 +0100
@@ -150,19 +150,83 @@
int xs_parse_video(char *vid_card)
{
- char *pos = NULL;
- FILE *pipe = popen(LSPCI" | grep VGA | cut -d\" \" -f5-", "r");
- if(pipe == NULL)
- return 1;
- while(fgets(vid_card, 1024, pipe) != NULL)
+ char buffer[1024], pcibus[42], vendor[7], device[7], vendorname[128] = "", devicename[128] = "", *position;
+ int buscount = 0;
+
+ while ( buscount <= 8 )
{
- if((pos = strchr(vid_card, '\n')) != NULL)
- *pos = '\0';
+ buscount++;
+ snprintf(pcibus, 42, "/sys/bus/pci/devices/0000:0%d:00.0/class", buscount);
+ FILE *fp = fopen(pcibus, "r");
+ if(fp != NULL) {
+ if(fgets(buffer, 1024, fp) != NULL)
+ if(strncmp("0x03", buffer, 4) == 0)
+ break;
+ fclose(fp);
+ }
+ }
+
+ if (buscount == 9) {
+ strncpy(vid_card,"No AGP card found",42);
+ return 1;
}
- if(pos == NULL) return 2;
- pclose(pipe);
+ snprintf(pcibus, 42, "/sys/bus/pci/devices/0000:0%d:00.0/device", buscount);
+ FILE *fp = fopen(pcibus, "r");
+ if(fp != NULL) {
+ if(fgets(buffer, 1024, fp) != NULL)
+ if(strstr(buffer, "0x") != NULL) {
+ position = strstr(buffer, "0x");
+ position += 2;
+ strcpy(device, position);
+ position = strstr(device, "\n");
+ *(position) = '\0';
+ }
+ fclose(fp);
+ }
+
+ snprintf(pcibus, 42, "/sys/bus/pci/devices/0000:0%d:00.0/vendor", buscount);
+ FILE *fp2 = fopen(pcibus, "r");
+ if(fp2 != NULL) {
+ if(fgets(buffer, 1024, fp) != NULL)
+ if(strstr(buffer, "0x") != NULL) {
+ position = strstr(buffer, "0x");
+ position += 2;
+ strcpy(vendor, position);
+ position = strstr(vendor, "\n");
+ *(position) = '\0';
+ }
+ fclose(fp2);
+ }
+
+ FILE *fp3 = fopen("/usr/share/misc/pci.ids", "r");
+ if(fp3 == NULL) {
+ snprintf(vid_card, 42, "Found AGP card %s:%s", vendor, device);
+ return 0;
+ }
+ while(fgets(buffer, 1024, fp3) != NULL) {
+ if (!isspace(buffer[0]) && strstr(buffer, vendor) != NULL) {
+ position = strstr(buffer, vendor);
+ position += 6;
+ strncpy(vendorname, position, 128);
+ position = strstr(vendorname, "\n");
+ *(position) = '\0';
+ break;
+ }
+ }
+ while(fgets(buffer, 1024, fp3) != NULL) {
+ if(strstr(buffer, device) != NULL) {
+ position = strstr(buffer, device);
+ position += 6;
+ strncpy(devicename, position, 128);
+ position = strstr(devicename, "\n");
+ *(position) = '\0';
+ break;
+ }
+ }
+ fclose(fp3);
+ snprintf(vid_card, 256, "%s %s", vendorname, devicename);
return 0;
}
@@ -389,4 +453,3 @@
}
return 0;
}
-
--- xsys2/Makefile.orig 2005-04-17 21:01:27.000000000 +0100
+++ xsys2/Makefile 2005-04-17 21:01:31.000000000 +0100
@@ -1,7 +1,3 @@
-#### SET THIS VALUE TO THE LOCATION OF 'lspci' ####
-LSPCI = /sbin/lspci
-
-
#### SHOULD NOT NEED TO EDIT BELOW THIS LINE ####
VER_MAJOR = 1
VER_MINOR = 9
@@ -9,7 +5,7 @@
CC = gcc
CFLAGS += -O2 -Wall -fPIC
CFLAGS += -DVER_MINOR=$(VER_MINOR) -DVER_MAJOR=$(VER_MAJOR) -DVER_PATCH=$(VER_PATCH) \
- -DVER_STRING=\"$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH)\" -DLSPCI=\"$(LSPCI)\"
+ -DVER_STRING=\"$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH)\"
LDFLAGS = $(CFLAGS) -shared
LIBRARY = xsys-$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).so
OBJECTS = xsys.o parse.o
|