/* ScummVM - Graphic Adventure Engine * * ScummVM is the legal property of its developers, whose names * are too numerous to list here. Please refer to the COPYRIGHT * file distributed with this source distribution. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #include "engines/glk/glulxe/glulxe.h" namespace Glk { namespace Glulxe { enum serop { serop_KeyIndirect = 0x01, serop_ZeroKeyTerminates = 0x02, serop_ReturnIndex = 0x04 }; uint Glulxe::linear_search(uint key, uint keysize, uint start, uint structsize, uint numstructs, uint keyoffset, uint options) { unsigned char keybuf[4]; uint count; uint ix; int retindex = ((options & serop_ReturnIndex) != 0); int zeroterm = ((options & serop_ZeroKeyTerminates) != 0); fetchkey(keybuf, key, keysize, options); for (count=0; count byte2) cmp = 1; } } else { for (ix=0; (!cmp) && ix byte2) cmp = 1; } } if (!cmp) { if (retindex) return val; else return addr; } if (cmp < 0) { bot = val+1; } else { top = val; } } if (retindex) return (uint)-1; else return 0; } uint Glulxe::linked_search(uint key, uint keysize, uint start, uint keyoffset, uint nextoffset, uint options) { unsigned char keybuf[4]; uint ix; uint val; int zeroterm = ((options & serop_ZeroKeyTerminates) != 0); fetchkey(keybuf, key, keysize, options); while (start != 0) { int match = true; if (keysize <= 4) { for (ix=0; match && ix