Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/freeglut/src/util/xparsegeometry_repl.c @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 #include <stdlib.h> | |
| 2 | |
| 3 /* | |
| 4 * Everything down to the end of the next two functions is copied from the X sources. | |
| 5 */ | |
| 6 | |
| 7 /* | |
| 8 | |
| 9 Copyright 1985, 1986, 1987,1998 The Open Group | |
| 10 | |
| 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 | |
| 15 documentation. | |
| 16 | |
| 17 The above copyright notice and this permission notice shall be included | |
| 18 in all copies or substantial portions of the Software. | |
| 19 | |
| 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. | |
| 27 | |
| 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 | |
| 31 from The Open Group. | |
| 32 | |
| 33 */ | |
| 34 | |
| 35 #include "xparsegeometry_repl.h" | |
| 36 | |
| 37 /* | |
| 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. | |
| 47 */ | |
| 48 | |
| 49 static int | |
| 50 ReadInteger(char *string, char **NextString) | |
| 51 { | |
| 52 register int Result = 0; | |
| 53 int Sign = 1; | |
| 54 | |
| 55 if (*string == '+') | |
| 56 string++; | |
| 57 else if (*string == '-') | |
| 58 { | |
| 59 string++; | |
| 60 Sign = -1; | |
| 61 } | |
| 62 for (; (*string >= '0') && (*string <= '9'); string++) | |
| 63 { | |
| 64 Result = (Result * 10) + (*string - '0'); | |
| 65 } | |
| 66 *NextString = string; | |
| 67 if (Sign >= 0) | |
| 68 return Result; | |
| 69 else | |
| 70 return -Result; | |
| 71 } | |
| 72 | |
| 73 int XParseGeometry ( | |
| 74 const 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')) | |
| 87 return mask; | |
| 88 if (*string == '=') | |
| 89 string++; /* ignore possible '=' at beg of geometry spec */ | |
| 90 | |
| 91 strind = (char *)string; | |
| 92 if (*strind != '+' && *strind != '-' && *strind != 'x') { | |
| 93 tempWidth = ReadInteger(strind, &nextCharacter); | |
| 94 if (strind == nextCharacter) | |
| 95 return 0; | |
| 96 strind = nextCharacter; | |
| 97 mask |= WidthValue; | |
| 98 } | |
| 99 | |
| 100 if (*strind == 'x' || *strind == 'X') { | |
| 101 strind++; | |
| 102 tempHeight = ReadInteger(strind, &nextCharacter); | |
| 103 if (strind == nextCharacter) | |
| 104 return 0; | |
| 105 strind = nextCharacter; | |
| 106 mask |= HeightValue; | |
| 107 } | |
| 108 | |
| 109 if ((*strind == '+') || (*strind == '-')) { | |
| 110 if (*strind == '-') { | |
| 111 strind++; | |
| 112 tempX = -ReadInteger(strind, &nextCharacter); | |
| 113 if (strind == nextCharacter) | |
| 114 return 0; | |
| 115 strind = nextCharacter; | |
| 116 mask |= XNegative; | |
| 117 } | |
| 118 else | |
| 119 { | |
| 120 strind++; | |
| 121 tempX = ReadInteger(strind, &nextCharacter); | |
| 122 if (strind == nextCharacter) | |
| 123 return 0; | |
| 124 strind = nextCharacter; | |
| 125 } | |
| 126 mask |= XValue; | |
| 127 if ((*strind == '+') || (*strind == '-')) { | |
| 128 if (*strind == '-') { | |
| 129 strind++; | |
| 130 tempY = -ReadInteger(strind, &nextCharacter); | |
| 131 if (strind == nextCharacter) | |
| 132 return 0; | |
| 133 strind = nextCharacter; | |
| 134 mask |= YNegative; | |
| 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 } |
