4 * Everything down to the end of the next two functions is copied from the X sources.
9 Copyright 1985, 1986, 1987,1998 The Open Group
11 Permission to use, copy, modify, distribute, and sell this software and its
12 documentation for any purpose is hereby granted without fee, provided that
13 the above copyright notice appear in all copies and that both that
14 copyright notice and this permission notice appear in supporting
17 The above copyright notice and this permission notice shall be included
18 in all copies or substantial portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 OTHER DEALINGS IN THE SOFTWARE.
28 Except as contained in this notice, the name of The Open Group shall
29 not be used in advertising or otherwise to promote the sale, use or
30 other dealings in this Software without prior written authorization
35 #include "xparsegeometry_repl.h"
38 * XParseGeometry parses strings of the form
39 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
40 * width, height, xoffset, and yoffset are unsigned integers.
41 * Example: "=80x24+300-49"
42 * The equal sign is optional.
43 * It returns a bitmask that indicates which of the four values
44 * were actually found in the string. For each value found,
45 * the corresponding argument is updated; for each value
46 * not found, the corresponding argument is left unchanged.
50 ReadInteger(char *string, char **NextString)
52 register int Result = 0;
57 else if (*string == '-')
62 for (; (*string >= '0') && (*string <= '9'); string++)
64 Result = (Result * 10) + (*string - '0');
77 unsigned int *width, /* RETURN */
78 unsigned int *height) /* RETURN */
81 register char *strind;
82 unsigned int tempWidth = 0, tempHeight = 0;
83 int tempX = 0, tempY = 0;
86 if ( (string == NULL) || (*string == '\0'))
89 string++; /* ignore possible '=' at beg of geometry spec */
91 strind = (char *)string;
92 if (*strind != '+' && *strind != '-' && *strind != 'x') {
93 tempWidth = ReadInteger(strind, &nextCharacter);
94 if (strind == nextCharacter)
96 strind = nextCharacter;
100 if (*strind == 'x' || *strind == 'X') {
102 tempHeight = ReadInteger(strind, &nextCharacter);
103 if (strind == nextCharacter)
105 strind = nextCharacter;
109 if ((*strind == '+') || (*strind == '-')) {
110 if (*strind == '-') {
112 tempX = -ReadInteger(strind, &nextCharacter);
113 if (strind == nextCharacter)
115 strind = nextCharacter;
121 tempX = ReadInteger(strind, &nextCharacter);
122 if (strind == nextCharacter)
124 strind = nextCharacter;
127 if ((*strind == '+') || (*strind == '-')) {
128 if (*strind == '-') {
130 tempY = -ReadInteger(strind, &nextCharacter);
131 if (strind == nextCharacter)
133 strind = nextCharacter;
139 tempY = ReadInteger(strind, &nextCharacter);
140 if (strind == nextCharacter)
142 strind = nextCharacter;
148 /* If strind isn't at the end of the string the it's an invalid
149 geometry specification. */
151 if (*strind != '\0') return 0;
157 if (mask & WidthValue)
159 if (mask & HeightValue)
160 *height = tempHeight;