diff options
Diffstat (limited to 'src/vmware_common.c')
-rw-r--r-- | src/vmware_common.c | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/src/vmware_common.c b/src/vmware_common.c new file mode 100644 index 0000000..6ef7ca6 --- /dev/null +++ b/src/vmware_common.c | |||
@@ -0,0 +1,163 @@ | |||
1 | /* | ||
2 | * Copyright 2011 VMWare, Inc. | ||
3 | * All Rights Reserved. | ||
4 | * | ||
5 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
6 | * copy of this software and associated documentation files (the | ||
7 | * "Software"), to deal in the Software without restriction, including | ||
8 | * without limitation the rights to use, copy, modify, merge, publish, | ||
9 | * distribute, sub license, and/or sell copies of the Software, and to | ||
10 | * permit persons to whom the Software is furnished to do so, subject to | ||
11 | * the following conditions: | ||
12 | * | ||
13 | * The above copyright notice and this permission notice (including the | ||
14 | * next paragraph) shall be included in all copies or substantial portions | ||
15 | * of the Software. | ||
16 | * | ||
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. | ||
20 | * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR | ||
21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
24 | * | ||
25 | * Author: Unknown at vmware | ||
26 | */ | ||
27 | #ifdef HAVE_CONFIG_H | ||
28 | #include "config.h" | ||
29 | #endif | ||
30 | |||
31 | #include <xf86.h> | ||
32 | #include "vmware_common.h" | ||
33 | |||
34 | #ifndef HAVE_XORG_SERVER_1_5_0 | ||
35 | #include <xf86_ansic.h> | ||
36 | #include <xf86_libc.h> | ||
37 | #endif | ||
38 | |||
39 | static int | ||
40 | VMWAREParseTopologyElement(ScrnInfoPtr pScrn, | ||
41 | unsigned int output, | ||
42 | const char *elementName, | ||
43 | const char *element, | ||
44 | const char *expectedTerminators, | ||
45 | Bool needTerminator, | ||
46 | unsigned int *outValue) | ||
47 | { | ||
48 | char buf[10] = {0, }; | ||
49 | size_t i = 0; | ||
50 | int retVal = -1; | ||
51 | const char *str = element; | ||
52 | |||
53 | for (i = 0; str[i] >= '0' && str[i] <= '9'; i++); | ||
54 | if (i == 0) { | ||
55 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Output %u: unable to parse %s.\n", | ||
56 | output, elementName); | ||
57 | goto exit; | ||
58 | } | ||
59 | |||
60 | strncpy(buf, str, i); | ||
61 | *outValue = atoi(buf); | ||
62 | |||
63 | if (*outValue > (unsigned short)-1) { | ||
64 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Output %u: %s must be less than %hu.\n", | ||
65 | output, elementName, (unsigned short)-1); | ||
66 | goto exit; | ||
67 | } | ||
68 | |||
69 | str += i; | ||
70 | |||
71 | if (needTerminator || str[0] != '\0') { | ||
72 | Bool unexpected = TRUE; | ||
73 | |||
74 | for (i = 0; i < strlen(expectedTerminators); i++) { | ||
75 | if (str[0] == expectedTerminators[i]) { | ||
76 | unexpected = FALSE; | ||
77 | } | ||
78 | } | ||
79 | |||
80 | if (unexpected) { | ||
81 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, | ||
82 | "Output %u: unexpected character '%c' after %s.\n", | ||
83 | output, str[0], elementName); | ||
84 | goto exit; | ||
85 | } else { | ||
86 | str++; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | retVal = str - element; | ||
91 | |||
92 | exit: | ||
93 | return retVal; | ||
94 | } | ||
95 | |||
96 | xXineramaScreenInfo * | ||
97 | VMWAREParseTopologyString(ScrnInfoPtr pScrn, | ||
98 | const char *topology, | ||
99 | unsigned int *retNumOutputs, | ||
100 | const char info[]) | ||
101 | { | ||
102 | xXineramaScreenInfo *extents = NULL; | ||
103 | unsigned int numOutputs = 0; | ||
104 | const char *str = topology; | ||
105 | |||
106 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Parsing %s topology: Starting...\n", | ||
107 | info); | ||
108 | |||
109 | do { | ||
110 | unsigned int x, y, width, height; | ||
111 | int i; | ||
112 | |||
113 | i = VMWAREParseTopologyElement(pScrn, numOutputs, "width", str, "xX", TRUE, &width); | ||
114 | if (i == -1) { | ||
115 | goto error; | ||
116 | } | ||
117 | str += i; | ||
118 | |||
119 | i = VMWAREParseTopologyElement(pScrn, numOutputs, "height", str, "+", TRUE, &height); | ||
120 | if (i == -1) { | ||
121 | goto error; | ||
122 | } | ||
123 | str += i; | ||
124 | |||
125 | i= VMWAREParseTopologyElement(pScrn, numOutputs, "X offset", str, "+", TRUE, &x); | ||
126 | if (i == -1) { | ||
127 | goto error; | ||
128 | } | ||
129 | str += i; | ||
130 | |||
131 | i = VMWAREParseTopologyElement(pScrn, numOutputs, "Y offset", str, ";", FALSE, &y); | ||
132 | if (i == -1) { | ||
133 | goto error; | ||
134 | } | ||
135 | str += i; | ||
136 | |||
137 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Output %u: %ux%u+%u+%u\n", | ||
138 | numOutputs, width, height, x, y); | ||
139 | |||
140 | numOutputs++; | ||
141 | extents = realloc(extents, numOutputs * sizeof (xXineramaScreenInfo)); | ||
142 | extents[numOutputs - 1].x_org = x; | ||
143 | extents[numOutputs - 1].y_org = y; | ||
144 | extents[numOutputs - 1].width = width; | ||
145 | extents[numOutputs - 1].height = height; | ||
146 | } while (*str != 0); | ||
147 | |||
148 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Parsing %s topology: Succeeded.\n", | ||
149 | info); | ||
150 | goto exit; | ||
151 | |||
152 | error: | ||
153 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Parsing %s topology: Failed.\n", | ||
154 | info); | ||
155 | |||
156 | free(extents); | ||
157 | extents = NULL; | ||
158 | numOutputs = 0; | ||
159 | |||
160 | exit: | ||
161 | *retNumOutputs = numOutputs; | ||
162 | return extents; | ||
163 | } | ||