Debian Codegraph @

nx-X11/lib/src/ParseGeom.c

raw
1
2 /*
3
4 Copyright 1985, 1986, 1987,1998 The Open Group
5
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
10 documentation.
11
12 The above copyright notice and this permission notice shall be included
13 in all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 OTHER DEALINGS IN THE SOFTWARE.
22
23 Except as contained in this notice, the name of The Open Group shall
24 not be used in advertising or otherwise to promote the sale, use or
25 other dealings in this Software without prior written authorization
26 from The Open Group.
27
28 */
29
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 #include "Xlibint.h"
34 #include "Xutil.h"
35
36 /*
37 * XParseGeometry parses strings of the form
38 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
39 * width, height, xoffset, and yoffset are unsigned integers.
40 * Example: "=80x24+300-49"
41 * The equal sign is optional.
42 * It returns a bitmask that indicates which of the four values
43 * were actually found in the string. For each value found,
44 * the corresponding argument is updated; for each value
45 * not found, the corresponding argument is left unchanged.
46 */
47
48 static int
49 ReadInteger(char *string, char **NextString)
50 {
51 register int Result = 0;
52 int Sign = 1;
53
54 if (*string == '+')
55 string++;
56 else if (*string == '-')
57 {
58 string++;
59 Sign = -1;
60 }
61 for (; (*string >= '0') && (*string <= '9'); string++)
62 {
63 Result = (Result * 10) + (*string - '0');
64 }
65 *NextString = string;
66 if (Sign >= 0)
67 return (Result);
68 else
69 return (-Result);
70 }
71
72 int
73 XParseGeometry (
74 _Xconst char *string,
75 int *x,
76 int *y,
77 unsigned int *width, /* RETURN */
78 unsigned int *height) /* RETURN */
79 {
80 int mask = NoValue;
81 register char *strind;
82 unsigned int tempWidth = 0, tempHeight = 0;
83 int tempX = 0, tempY = 0;
84 char *nextCharacter;
85
86 if ( (string == NULL) || (*string == '\0')) return(mask);
87 if (*string == '=')
88 string++; /* ignore possible '=' at beg of geometry spec */
89
90 strind = (char *)string;
91 if (*strind != '+' && *strind != '-' && *strind != 'x') {
92 tempWidth = ReadInteger(strind, &nextCharacter);
93 if (strind == nextCharacter)
94 return (0);
95 strind = nextCharacter;
96 mask |= WidthValue;
97 }
98
99 if (*strind == 'x' || *strind == 'X') {
100 strind++;
101 tempHeight = ReadInteger(strind, &nextCharacter);
102 if (strind == nextCharacter)
103 return (0);
104 strind = nextCharacter;
105 mask |= HeightValue;
106 }
107
108 if ((*strind == '+') || (*strind == '-')) {
109 if (*strind == '-') {
110 strind++;
111 tempX = -ReadInteger(strind, &nextCharacter);
112 if (strind == nextCharacter)
113 return (0);
114 strind = nextCharacter;
115 mask |= XNegative;
116
117 }
118 else
119 { strind++;
120 tempX = ReadInteger(strind, &nextCharacter);
121 if (strind == nextCharacter)
122 return(0);
123 strind = nextCharacter;
124 }
125 mask |= XValue;
126 if ((*strind == '+') || (*strind == '-')) {
127 if (*strind == '-') {
128 strind++;
129 tempY = -ReadInteger(strind, &nextCharacter);
130 if (strind == nextCharacter)
131 return(0);
132 strind = nextCharacter;
133 mask |= YNegative;
134
135 }
136 else
137 {
138 strind++;
139 tempY = ReadInteger(strind, &nextCharacter);
140 if (strind == nextCharacter)
141 return(0);
142 strind = nextCharacter;
143 }
144 mask |= YValue;
145 }
146 }
147
148 /* If strind isn't at the end of the string the it's an invalid
149 geometry specification. */
150
151 if (*strind != '\0') return (0);
152
153 if (mask & XValue)
154 *x = tempX;
155 if (mask & YValue)
156 *y = tempY;
157 if (mask & WidthValue)
158 *width = tempWidth;
159 if (mask & HeightValue)
160 *height = tempHeight;
161 return (mask);
162 }