static Status _XkbGeomAlloc( XPointer * old, unsigned short * num, unsigned short * total, int num_new, size_t sz_elem) { if (num_new<1) return Success; if ((*old)==NULL) *num= *total= 0; if ((*num)+num_new<=(*total)) return Success; *total= (*num)+num_new; if ((*old)!=NULL) (*old)= (XPointer)_XkbRealloc((*old),(*total)*sz_elem); else (*old)= (XPointer)_XkbCalloc((*total),sz_elem); if ((*old)==NULL) { *total= *num= 0; return BadAlloc; } if (*num>0) { char *tmp= (char *)(*old); bzero(&tmp[sz_elem*(*num)],(num_new*sz_elem)); } return Success; }
static int InputLineAddChar(InputLine *line,int ch) { if (line->num_line>=line->sz_line) { if (line->line==line->buf) { line->line= (char *)_XkbAlloc(line->sz_line*2); memcpy(line->line,line->buf,line->sz_line); } else { line->line=(char *)_XkbRealloc((char *)line->line,line->sz_line*2); } line->sz_line*= 2; } line->line[line->num_line++]= ch; return ch; }
static Atom _XkbMakeAtom(const char *string, unsigned len, Bool makeit) { register NodePtr *np; unsigned i; int comp; register unsigned int fp = 0; np = &atomRoot; for (i = 0; i < (len + 1) / 2; i++) { fp = fp * 27 + string[i]; fp = fp * 27 + string[len - 1 - i]; } while (*np != (NodePtr) NULL) { if (fp < (*np)->fingerPrint) np = &((*np)->left); else if (fp > (*np)->fingerPrint) np = &((*np)->right); else { /* now start testing the strings */ comp = strncmp(string, (*np)->string, (int) len); if ((comp < 0) || ((comp == 0) && (len < strlen((*np)->string)))) np = &((*np)->left); else if (comp > 0) np = &((*np)->right); else return (*np)->a; } } if (makeit) { register NodePtr nd; nd = (NodePtr) _XkbAlloc(sizeof(NodeRec)); if (!nd) return BAD_RESOURCE; nd->string = (char *) _XkbAlloc(len + 1); if (!nd->string) { _XkbFree(nd); return BAD_RESOURCE; } strncpy(nd->string, string, (int) len); nd->string[len] = 0; if ((lastAtom + 1) >= tableLength) { NodePtr *table; table = (NodePtr *) _XkbRealloc(nodeTable, tableLength * (2 * sizeof(NodePtr))); if (!table) { if (nd->string != string) _XkbFree(nd->string); _XkbFree(nd); return BAD_RESOURCE; } tableLength <<= 1; nodeTable = table; } *np = nd; nd->left = nd->right = (NodePtr) NULL; nd->fingerPrint = fp; nd->a = (++lastAtom); *(nodeTable + lastAtom) = nd; return nd->a; } else return None; }