|
|
1.1 ! root 1: #include "copyright.h" ! 2: ! 3: /* Copyright Massachusetts Institute of Technology 1985, 1986, 1987 */ ! 4: /* $Header: XParseGeom.c,v 11.10 87/09/11 08:05:25 toddb Exp $ */ ! 5: ! 6: #include "Xlibint.h" ! 7: #include "Xutil.h" ! 8: ! 9: /* ! 10: *Returns pointer to first char ins search which is also in what, else NULL. ! 11: */ ! 12: static char *strscan (search, what) ! 13: char *search, *what; ! 14: { ! 15: int i, len = strlen (what); ! 16: char c; ! 17: ! 18: while ((c = *(search++)) != NULL) ! 19: for (i = 0; i < len; i++) ! 20: if (c == what [i]) ! 21: return (--search); ! 22: return (NULL); ! 23: } ! 24: ! 25: /* ! 26: * XParseGeometry parses strings of the form ! 27: * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where ! 28: * width, height, xoffset, and yoffset are unsigned integers. ! 29: * Example: "=80x24+300-49" ! 30: * The equal sign is optional. ! 31: * It returns a bitmask that indicates which of the four values ! 32: * were actually found in the string. For each value found, ! 33: * the corresponding argument is updated; for each value ! 34: * not found, the corresponding argument is left unchanged. ! 35: */ ! 36: ! 37: int ! 38: ReadInteger(string, NextString) ! 39: char *string, **NextString; ! 40: { ! 41: int Result = 0; ! 42: ! 43: *NextString = string; ! 44: for (; (**NextString >= '0') && (**NextString <= '9'); (*NextString)++) ! 45: { ! 46: Result = (Result * 10) + (**NextString - '0'); ! 47: } ! 48: return (Result); ! 49: } ! 50: ! 51: int XParseGeometry (string, x, y, width, height) ! 52: char *string; ! 53: int *x, *y; ! 54: unsigned int *width, *height; /* RETURN */ ! 55: { ! 56: int mask = NoValue; ! 57: register char *strind; ! 58: unsigned int tempWidth, tempHeight; ! 59: int tempX, tempY; ! 60: char *nextCharacter; ! 61: ! 62: if ( (string == NULL) || (*string == '\0')) return(mask); ! 63: if (*string == '=') ! 64: string++; /* ignore possible '=' at beg of geometry spec */ ! 65: ! 66: strind = string; ! 67: if (*strind != '+' && *strind != '-' && *strind != 'x') { ! 68: tempWidth = ReadInteger(strind, &nextCharacter); ! 69: if (strind == nextCharacter) ! 70: return (0); ! 71: strind = nextCharacter; ! 72: mask |= WidthValue; ! 73: } ! 74: ! 75: if (*strind == 'x') { ! 76: strind++; ! 77: tempHeight = ReadInteger(strind, &nextCharacter); ! 78: if (strind == nextCharacter) ! 79: return (0); ! 80: strind = nextCharacter; ! 81: mask |= HeightValue; ! 82: } ! 83: ! 84: if (strind == strscan (strind, "+-")) { ! 85: if (*strind == '-') { ! 86: strind++; ! 87: tempX = -ReadInteger(strind, &nextCharacter); ! 88: if (strind == nextCharacter) ! 89: return (0); ! 90: strind = nextCharacter; ! 91: mask |= XNegative; ! 92: ! 93: } ! 94: else ! 95: { strind++; ! 96: tempX = ReadInteger(strind, &nextCharacter); ! 97: if (strind == nextCharacter) ! 98: return(0); ! 99: strind = nextCharacter; ! 100: } ! 101: mask |= XValue; ! 102: if (strind == strscan (strind, "+-")) { ! 103: if (*strind == '-') { ! 104: strind++; ! 105: tempY = -ReadInteger(strind, &nextCharacter); ! 106: if (strind == nextCharacter) ! 107: return(0); ! 108: strind = nextCharacter; ! 109: mask |= YNegative; ! 110: ! 111: } ! 112: else ! 113: { ! 114: strind++; ! 115: tempY = ReadInteger(strind, &nextCharacter); ! 116: if (strind == nextCharacter) ! 117: return(0); ! 118: strind = nextCharacter; ! 119: } ! 120: mask |= YValue; ! 121: } ! 122: } ! 123: ! 124: /* If strind isn't at the end of the string the it's an invalid ! 125: geometry specification. */ ! 126: ! 127: if (*strind != '\0') return (0); ! 128: ! 129: if (mask & XValue) ! 130: *x = tempX; ! 131: if (mask & YValue) ! 132: *y = tempY; ! 133: if (mask & WidthValue) ! 134: *width = tempWidth; ! 135: if (mask & HeightValue) ! 136: *height = tempHeight; ! 137: return (mask); ! 138: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.