#ifdef EMBED_THEME␊ |
static int getEmbeddedImageIndexByName(const char *name)␊ |
{␊ |
int i;␊ |
␉for (i = 0; i < sizeof(embeddedImages) / sizeof(embeddedImages[0]); i++)␊ |
␉int upperLimit = sizeof(embeddedImages) / sizeof(embeddedImages[0]) - 1;␊ |
␉int lowerLimit = 0;␊ |
␉int compareIndex = (upperLimit - lowerLimit + 1) >> 1; // Midpoint␊ |
␉int result;␊ |
␉␊ |
␉// NOTE: This algorithm assumes that the embeddedImages is sorted.␊ |
␉// This is currently done using the make file. If the array is every ␊ |
␉// manualy generated, this *will* fail to work properly.␊ |
␉while((result = strcmp(name, embeddedImages[compareIndex].name)) != 0)␊ |
␉{␊ |
␉ if (strcmp(name, embeddedImages[i].name) == 0)␊ |
␉ return i; // found the name␊ |
␊ |
␉␉if(result > 0)␉// We need to search a HIGHER index␊ |
␉␉{␊ |
␉␉␉if(compareIndex != upperLimit - 1)␊ |
␉␉␉{␊ |
␉␉␉␉lowerLimit = compareIndex;␊ |
␉␉␉}␊ |
␉␉␉else␊ |
␉␉␉{␊ |
␉␉␉␉return -1;␊ |
␉␉␉}␊ |
␊ |
␉␉}␊ |
␉␉else //if(result < 0) // We Need to search a LOWER index␊ |
␉␉{␊ |
␉␉␉if(compareIndex != lowerLimit + 1)␊ |
␉␉␉{␊ |
␉␉␉␉upperLimit = compareIndex;␊ |
␉␉␉}␊ |
␉␉␉else␊ |
␉␉␉{␊ |
␉␉␉␉return -1;␊ |
␉␉␉}␊ |
␉␉}␊ |
␉␉compareIndex = (upperLimit + lowerLimit + 1) >> 1;␉// Midpoint␊ |
␉}␊ |
␉return -1;␊ |
␉␊ |
␉return compareIndex;␊ |
}␊ |
#endif␊ |
␊ |