TYPED_TEST(StringHashTest, HasEqualHashForEqualStrings) { StringHash<TypeParam> hash("abacaba"); EXPECT_EQ(hash.hash(0, 2), hash.hash(4, 6)); EXPECT_EQ(hash.hash(2, 3), hash.hash(4, 5)); }
int hashfile_findrec(int fd,int keyoffset ,int keylen,void *buf) { HashFileHeader hfh; readHashFileHeader(fd,&hfh); int addr = hash(keyoffset,keylen,buf,hfh.total_rec_num); int offset = sizeof(HashFileHeader)+addr*(hfh.reclen+sizeof(CFTag)); if(lseek(fd,offset,SEEK_SET)==-1) return -1; CFTag tag; read(fd,&tag,sizeof(CFTag)); char count =tag.collision; if(count==0) return -1;//not exist recfree: if(tag.free==0) { offset+=hfh.reclen+sizeof(CFTag); if(lseek(fd,offset,SEEK_SET)==-1) return-1; read(fd,&tag,sizeof(CFTag)); goto recfree; } else { char *p=(char*)malloc(hfh.reclen*sizeof(char)); read(fd,p,hfh.reclen); char *p1,*p2; p1=(char*)buf+keyoffset; p2=p+keyoffset; int j=0; while((*p1==*p2)&&(j<keylen)) { p1++; p2++; j++; } if(j==keylen) { free(p); p=NULL; return (offset); } else { if(addr==hash(keyoffset,keylen,p,hfh.total_rec_num)) { count--; if(count==0) { free(p); p=NULL; return -1; } } free(p); p=NULL; offset+=hfh.reclen+sizeof(CFTag); if(lseek(fd,offset,SEEK_SET)==-1) return -1; read(fd,&tag,sizeof(CFTag)); goto recfree; } } }
static void *assoc_maintenance_thread(void *arg) { bool expansion_started = false; while (do_run_maintenance_thread) { int ii = 0; if (!expansion_started) { pthread_mutex_lock(&assoc_expansion_lock); expansion_started = true; } /* Lock the cache, and bulk move multiple buckets to the new * hash table. */ item_lock_global(); mutex_lock(&cache_lock); for (ii = 0; ii < hash_bulk_move && expanding; ++ii) { item *it, *next; int bucket; for (it = old_hashtable[expand_bucket]; NULL != it; it = next) { next = it->h_next; bucket = hash(ITEM_key(it), it->nkey, 0) & hashmask(hashpower); it->h_next = primary_hashtable[bucket]; primary_hashtable[bucket] = it; } old_hashtable[expand_bucket] = NULL; expand_bucket++; if (expand_bucket == hashsize(hashpower - 1)) { expanding = false; free(old_hashtable); STATS_LOCK(); stats.hash_bytes -= hashsize(hashpower - 1) * sizeof(void *); stats.hash_is_expanding = 0; STATS_UNLOCK(); if (settings.verbose > 1) fprintf(stderr, "Hash table expansion done\n"); } } mutex_unlock(&cache_lock); item_unlock_global(); if (!expanding) { if (expansion_started) { pthread_mutex_unlock(&assoc_expansion_lock); expansion_started = false; } /* finished expanding. tell all threads to use fine-grained locks */ switch_item_lock_type(ITEM_LOCK_GRANULAR); slabs_rebalancer_resume(); /* We are done expanding.. just wait for next invocation */ mutex_lock(&cache_lock); started_expanding = false; pthread_cond_wait(&maintenance_cond, &cache_lock); /* Before doing anything, tell threads to use a global lock */ mutex_unlock(&cache_lock); slabs_rebalancer_pause(); switch_item_lock_type(ITEM_LOCK_GLOBAL); mutex_lock(&cache_lock); assoc_expand(); mutex_unlock(&cache_lock); } } if (expansion_started) pthread_mutex_unlock(&assoc_expansion_lock); return NULL; }
/* -------------------------------------------------------------------- */ void Readlog(BOOL revOrder) { int i, grpslot; char dtstr[80]; char flags[11]; char wild=FALSE; char buser=FALSE; char step; grpslot = ERROR; if (mf.mfUser[0]) { getNormStr("user", mf.mfUser, NAMESIZE, ECHO); stripansi(mf.mfUser); if (personexists(mf.mfUser) == ERROR) { if( strpos('?',mf.mfUser) || strpos('*',mf.mfUser) || strpos('[',mf.mfUser)) { wild = TRUE; } else { mPrintf(" \nNo such user!\n "); return; } } else { buser = TRUE; } } outFlag = OUTOK; setio(whichIO, echo, outFlag); if (mf.mfLim && (cfg.readluser || sysop || aide)) { doCR(); getgroup(); if (!mf.mfLim) return; grpslot = groupexists(mf.mfGroup); } else { mf.mfLim = FALSE; } outFlag = OUTOK; setio(whichIO, echo, outFlag); if (!expert) mPrintf(" \n \n <3J0>ump <3N0>ext <3P0>ause <3S0>top"); if (!revOrder) { step = 1; i = 0; } else { step = -1; i = cfg.MAXLOGTAB - 1; } for ( ; ( (i < cfg.MAXLOGTAB) && (outFlag != OUTSKIP) && (i >= 0) ); i += step) { if(mAbort(FALSE)) return; if (logTab[i].ltpwhash != 0 && logTab[i].ltnmhash != 0) { if (buser && (int)hash(mf.mfUser) != logTab[i].ltnmhash) continue; getLog(&lBuf,logTab[i].ltlogSlot); if (buser && strcmpi(mf.mfUser, lBuf.lbname) != SAMESTRING) continue; if(wild && !u_match(deansi(lBuf.lbname), mf.mfUser)) continue; if (mf.mfLim && (lBuf.groups[grpslot] != grpBuf.group[grpslot].groupgen) && (strcmpi(lBuf.lbname, cfg.sysop) != SAMESTRING ) ) continue; /* Show yourself even if unlisted */ if ( (!i && loggedIn) || (lBuf.lbflags.L_INUSE && (aide || !lBuf.lbflags.UNLISTED) ) ) { if (verbose) { strftime(dtstr, 79, (loggedIn) ? logBuf.vdstamp : cfg.vdatestamp, lBuf.calltime); if ((cfg.surnames || cfg.titles) && /* verbose >= 2 */ logBuf.DISPLAYTS) { doCR(); doCR(); if (*lBuf.title) mPrintf(" [%s]", lBuf.title); mPrintf(" 3%s0", lBuf.lbname); if (*lBuf.surname) mPrintf(" [%s]", lBuf.surname); doCR(); mPrintf(" #%lu %s", lBuf.callno, dtstr); } else { doCR(); mPrintf(" 3%-20s0 #%lu %s", lBuf.lbname, lBuf.callno, dtstr); } } else { doCR(); #if 1 if (aide || lBuf.lbflags.NODE) #endif mPrintf(" %-20s",lBuf.lbname); #if 1 else mPrintf(" %s", lBuf.lbname); #endif } if (aide ) /* A>ide T>wit P>erm U>nlist N>etuser S>ysop */ { if (cfg.accounting && verbose) { if (lBuf.lbflags.NOACCOUNT) mPrintf( " %10s", "N/A"); else mPrintf( " %10.2f", lBuf.credits); } strcpy(flags, " "); if ( lBuf.lbflags.AIDE) flags[0] = 'A'; if ( lBuf.lbflags.PROBLEM) flags[1] = 'T'; if ( lBuf.lbflags.PERMANENT) flags[2] = 'P'; if ( lBuf.lbflags.NETUSER) flags[3] = 'N'; if ( lBuf.lbflags.UNLISTED) flags[4] = 'U'; if ( lBuf.lbflags.SYSOP) flags[5] = 'S'; if ( lBuf.lbflags.NOMAIL) flags[6] = 'M'; if ( lBuf.VERIFIED) flags[7] = 'V'; if ( lBuf.DUNGEONED) flags[8] = 'D'; if ( lBuf.MSGAIDE) flags[9] = 'm'; mPrintf(" %s",flags); } if (lBuf.lbflags.NODE) { mPrintf(" (Node) "); } } #ifdef GOODBYE if (verbose) { strftime(dtstr, 79, (loggedIn) ? logBuf.dstamp : cfg.datestamp, lBuf.calltime); if ((cfg.surnames || cfg.titles) && logBuf.DISPLAYTS) { doCR(); mPrintf(" [%s] 3%s0 [%s]", lBuf.title, lBuf.lbname, lBuf.surname); doCR(); mPrintf(" #%lu %s", lBuf.callno, dtstr); } else { doCR(); mPrintf(" 3%-20s0 #%lu %s", lBuf.lbname, lBuf.callno, dtstr); } } else { doCR(); mPrintf(" %-20s",lBuf.lbname); } if (aide ) /* A>ide T>wit P>erm U>nlist N>etuser S>ysop */ { if (cfg.accounting && verbose) { if (lBuf.lbflags.NOACCOUNT) mPrintf( " %10s", "N/A"); else mPrintf( " %10.2f", lBuf.credits); } strcpy(flags, " "); if ( lBuf.lbflags.AIDE) flags[0] = 'A'; if ( lBuf.lbflags.PROBLEM) flags[1] = 'T'; if ( lBuf.lbflags.PERMANENT) flags[2] = 'P'; if ( lBuf.lbflags.NETUSER) flags[3] = 'N'; if ( lBuf.lbflags.UNLISTED) flags[4] = 'U'; if ( lBuf.lbflags.SYSOP) flags[5] = 'S'; if ( lBuf.lbflags.NOMAIL) flags[6] = 'M'; if ( lBuf.VERIFIED) flags[7] = 'V'; if ( lBuf.DUNGEONED) flags[8] = 'D'; if ( lBuf.MSGAIDE) flags[9] = 'm'; mPrintf(" %s",flags); } if (lBuf.lbflags.NODE) { mPrintf(" (Node) "); } if (verbose) doCR(); } #endif } }
void SvgParser::parseElement() { bool hasAttributes = true; int nameLength = 0; while (!atEnd()) { // check is element name ends with end tag // namely do not have child elements and attributes EndTagType endType = isEndTag(false); if (endType != NotEnd) { hasAttributes = false; m_name = QString(str-nameLength, nameLength); if (endType == EndType1) str++; else if (endType == EndType2) { str += 2; m_isPrevElemEnded = true; } break; } // if char is space than node name is ended if (StringWalker::isSpace(str->unicode())) { m_name = QString(str-nameLength, nameLength); // check is element has end char after spaces // and not attributes skipSpaces(); endType = isEndTag(); if (endType != NotEnd) { if (endType == EndType2) m_isPrevElemEnded = true; hasAttributes = false; } break; } nameLength++; str++; } if (!hasAttributes) return; // parse attributes // reserve memory for attributes // 6 - is average attributes count m_attrHash.reserve(6); QChar quote; QString attrName; while (!atEnd()) { nameLength = 0; skipSpaces(); // data between ' ' and '=' is attribute name while (!atEnd() && *str != QL1C('=')) { nameLength++; ++str; } // ignore spaces in attribute name attrName.clear(); uint attrId = hash(str-nameLength, nameLength); if (!isDefaultAttribute(attrId)) attrName = QString(str-nameLength, nameLength); // skip '=' str++; skipSpaces(); if (!atEnd() && (*str == QL1C('\"') || *str == QL1C('\''))) { quote = *str; str++; } // data between quotes is attribute value nameLength = 0; while (!atEnd() && *str != quote) { nameLength++; str++; } // ignore empty attributes if (nameLength > 0) { if ( attrId == AttrId::transform || attrId == AttrId::gradientTransform || attrId == AttrId::patternTransform) { Transform ts(str-nameLength, nameLength); if (ts.isValid()) m_attrHash.insert(AttrId::transform, SvgAttribute(ts)); } else { QString attrValue = QString(str-nameLength, nameLength); if (attrName.isEmpty()) { if (attrId == AttrId::d) m_attrHash.insert(AttrId::d, SvgAttribute(PathSegmentList(), attrValue)); else m_attrHash.insert(attrId, SvgAttribute(attrId, attrValue)); } else { m_attrHash.insert(attrId, SvgAttribute(attrName, attrValue)); } } } // skip quote char str++; skipSpaces(); EndTagType endType = isEndTag(); if (endType != NotEnd) { if (endType == EndType2) m_isPrevElemEnded = true; break; } } }
/* * init script */ static int __init script_init(void) { int i, j, count; script_origin_head_t *script_hdr = __va(SYS_CONFIG_MEMBASE); script_origin_main_key_t *origin_main; script_origin_sub_key_t *origin_sub; script_main_key_t *main_key; script_sub_key_t *sub_key, *tmp_sub, swap_sub; script_item_u *sub_val, *tmp_val, swap_val, *pval_temp; printk("%s enter!\n", __func__); if (!script_hdr) { printk(KERN_ERR "script buffer is NULL!\n"); return -1; } /* alloc memory for main keys */ g_script = SCRIPT_MALLOC(script_hdr->main_cnt * sizeof(script_main_key_t)); if (!g_script) { printk(KERN_ERR "try to alloc memory for main keys!\n"); return -1; } origin_main = &script_hdr->main_key; for (i = 0; i < script_hdr->main_cnt; i++) { main_key = &g_script[i]; /* copy main key name */ strncpy(main_key->name, origin_main[i].name, SCRIPT_NAME_SIZE_MAX); /* calculate hash value */ main_key->hash = hash(main_key->name); /* allock memory for sub-keys */ main_key->subkey = SCRIPT_MALLOC(origin_main[i].sub_cnt * sizeof(script_sub_key_t)); main_key->subkey_val = SCRIPT_MALLOC(origin_main[i].sub_cnt * sizeof(script_item_u)); if (!main_key->subkey || !main_key->subkey_val) { printk(KERN_ERR "try alloc memory for sub keys failed!\n"); goto err_out; } sub_key = main_key->subkey; sub_val = main_key->subkey_val; origin_sub = (script_origin_sub_key_t *)((unsigned int)script_hdr + (origin_main[i].offset << 2)); /* process sub keys */ for (j = 0; j < origin_main[i].sub_cnt; j++) { strncpy(sub_key[j].name, origin_sub[j].name, SCRIPT_NAME_SIZE_MAX); sub_key[j].hash = hash(sub_key[j].name); sub_key[j].type = (script_item_value_type_e)origin_sub[j].pattern.type; sub_key[j].value = &sub_val[j]; if (origin_sub[j].pattern.type == SCIRPT_PARSER_VALUE_TYPE_SINGLE_WORD) { sub_val[j].val = *(int *)((unsigned int)script_hdr + (origin_sub[j].offset << 2)); sub_key[j].type = SCIRPT_ITEM_VALUE_TYPE_INT; } else if (origin_sub[j].pattern.type == SCIRPT_PARSER_VALUE_TYPE_STRING) { sub_val[j].str = SCRIPT_MALLOC((origin_sub[j].pattern.cnt << 2) + 1); memcpy(sub_val[j].str, (char *)((unsigned int)script_hdr + (origin_sub[j].offset << 2)), origin_sub[j].pattern.cnt << 2); sub_key[j].type = SCIRPT_ITEM_VALUE_TYPE_STR; } else if (origin_sub[j].pattern.type == SCIRPT_PARSER_VALUE_TYPE_GPIO_WORD) { script_origin_gpio_t *origin_gpio = (script_origin_gpio_t *)((unsigned int)script_hdr + (origin_sub[j].offset << 2) - 32); u32 gpio_tmp = port_to_index(origin_gpio->port, origin_gpio->port_num); if (GPIO_INDEX_INVALID == gpio_tmp) printk(KERN_ERR "%s:%s->%s gpio cfg invalid, please check sys_config.fex!\n", __func__, main_key->name, sub_key[j].name); sub_val[j].gpio.gpio = gpio_tmp; sub_val[j].gpio.mul_sel = (u32)origin_gpio->mul_sel; sub_val[j].gpio.pull = (u32)origin_gpio->pull; sub_val[j].gpio.drv_level = (u32)origin_gpio->drv_level; sub_val[j].gpio.data = (u32)origin_gpio->data; /* add by cjcheng start {----------------------------------- */ /* flicker led when receive ir signal 2013-04-24 */ sub_val[j].gpio.port = (u32)origin_gpio->port; sub_val[j].gpio.port_num = (u32)origin_gpio->port_num; /* add by cjcheng end -----------------------------------} */ sub_key[j].type = SCIRPT_ITEM_VALUE_TYPE_PIO; } else { sub_key[j].type = SCIRPT_ITEM_VALUE_TYPE_INVALID; } } /* process gpios */ tmp_sub = main_key->subkey; tmp_val = main_key->subkey_val; count = 0; for (j = 0; j < origin_main[i].sub_cnt; j++) { if (sub_key[j].type == SCIRPT_ITEM_VALUE_TYPE_PIO) { /* swap sub key */ swap_sub = *tmp_sub; *tmp_sub = sub_key[j]; sub_key[j] = swap_sub; /* swap sub key value ptr */ pval_temp = tmp_sub->value; tmp_sub->value = sub_key[j].value; sub_key[j].value = pval_temp; /* swap key value */ swap_val = *tmp_val; *tmp_val = main_key->subkey_val[j]; main_key->subkey_val[j] = swap_val; tmp_sub++; tmp_val++; count++; } } /* process sub key link */ for (j = 0; j < origin_main[i].sub_cnt - 1; j++) { main_key->subkey[j].next = &main_key->subkey[j + 1]; } /* set gpio infermation */ main_key->gpio = main_key->subkey_val; main_key->gpio_cnt = count; main_key->next = &g_script[i + 1]; } g_script[script_hdr->main_cnt - 1].next = 0; printk("%s exit!\n", __func__); return 0; err_out: /* script init failed, release resource */ printk(KERN_ERR "init sys_config script failed!\n"); if (g_script) { for (i = 0; i < script_hdr->main_cnt; i++) { main_key = &g_script[i]; if (main_key->subkey_val) { for (j = 0; j < origin_main[i].sub_cnt; j++) { if (main_key->subkey[j].type == SCIRPT_ITEM_VALUE_TYPE_STR) { SCRIPT_FREE(main_key->subkey_val[j].str); } } SCRIPT_FREE(main_key->subkey_val); } if (main_key->subkey) { SCRIPT_FREE(main_key->subkey); } } SCRIPT_FREE(g_script); g_script = 0; } return -1; }
const char * Perfect_Hash::in_word_set (register const char *str, register unsigned int len) { static unsigned char lengthtable[] = { 11, 12, 10, 11, 18, 9, 16, 12, 18, 14, 11, 12, 13, 10, 16, 17, 13, 16, 17, 18, 19, 11, 11, 19, 10, 16, 5, 8, 16, 17, 6, 17, 19, 11, 12, 14, 11, 13, 14, 21, 17, 14, 11, 7, 9, 10, 16, 17, 13, 16, 21, 12, 21, 14, 7, 11, 14, 17, 16 }; static const char * wordlist[] = { "margin-left" /* hash value = 11, index = 0 */, "margin-right" /* hash value = 12, index = 1 */, "margin-top" /* hash value = 15, index = 2 */, "data-format" /* hash value = 16, index = 3 */, "border-right-color" /* hash value = 18, index = 4 */, "direction" /* hash value = 19, index = 5 */, "border-top-width" /* hash value = 21, index = 6 */, "padding-left" /* hash value = 22, index = 7 */, "border-right-width" /* hash value = 23, index = 8 */, "padding-bottom" /* hash value = 24, index = 9 */, "padding-top" /* hash value = 26, index = 10 */, "number-align" /* hash value = 27, index = 11 */, "padding-right" /* hash value = 28, index = 12 */, "can-shrink" /* hash value = 30, index = 13 */, "border-top-color" /* hash value = 31, index = 14 */, "background-repeat" /* hash value = 32, index = 15 */, "margin-bottom" /* hash value = 33, index = 16 */, "background-width" /* hash value = 36, index = 17 */, "background-height" /* hash value = 37, index = 18 */, "border-right-style" /* hash value = 38, index = 19 */, "border-bottom-color" /* hash value = 39, index = 20 */, "text-indent" /* hash value = 41, index = 21 */, "line-height" /* hash value = 43, index = 22 */, "border-bottom-width" /* hash value = 44, index = 23 */, "text-align" /* hash value = 45, index = 24 */, "background-color" /* hash value = 46, index = 25 */, "color" /* hash value = 47, index = 26 */, "overflow" /* hash value = 48, index = 27 */, "text-linethrough" /* hash value = 51, index = 28 */, "border-left-color" /* hash value = 52, index = 29 */, "widows" /* hash value = 56, index = 30 */, "border-left-width" /* hash value = 57, index = 31 */, "border-bottom-style" /* hash value = 59, index = 32 */, "font-weight" /* hash value = 61, index = 33 */, "font-variant" /* hash value = 62, index = 34 */, "text-transform" /* hash value = 64, index = 35 */, "white-space" /* hash value = 66, index = 36 */, "text-overline" /* hash value = 68, index = 37 */, "vertical-align" /* hash value = 69, index = 38 */, "background-position-x" /* hash value = 71, index = 39 */, "border-left-style" /* hash value = 72, index = 40 */, "visible-format" /* hash value = 74, index = 41 */, "master-page" /* hash value = 76, index = 42 */, "orphans" /* hash value = 77, index = 43 */, "font-size" /* hash value = 79, index = 44 */, "font-style" /* hash value = 80, index = 45 */, "border-top-style" /* hash value = 81, index = 46 */, "page-break-before" /* hash value = 82, index = 47 */, "show-if-blank" /* hash value = 83, index = 48 */, "background-image" /* hash value = 86, index = 49 */, "background-position-y" /* hash value = 91, index = 50 */, "word-spacing" /* hash value = 92, index = 51 */, "background-attachment" /* hash value = 96, index = 52 */, "text-underline" /* hash value = 99, index = 53 */, "display" /* hash value = 107, index = 54 */, "font-family" /* hash value = 111, index = 55 */, "letter-spacing" /* hash value = 116, index = 56 */, "page-break-inside" /* hash value = 117, index = 57 */, "page-break-after" /* hash value = 121, index = 58 */ }; static signed char lookup[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, -1, -1, 2, 3, -1, 4, 5, -1, 6, 7, 8, 9, -1, 10, 11, 12, -1, 13, 14, 15, 16, -1, -1, 17, 18, 19, 20, -1, 21, -1, 22, 23, 24, 25, 26, 27, -1, -1, 28, 29, -1, -1, -1, 30, 31, -1, 32, -1, 33, 34, -1, 35, -1, 36, -1, 37, 38, -1, 39, 40, -1, 41, -1, 42, 43, -1, 44, 45, 46, 47, 48, -1, -1, 49, -1, -1, -1, -1, 50, 51, -1, -1, -1, 52, -1, -1, 53, -1, -1, -1, -1, -1, -1, -1, 54, -1, -1, -1, 55, -1, -1, -1, -1, 56, 57, -1, -1, -1, 58 }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) { register int key = hash (str, len); if (key <= MAX_HASH_VALUE && key >= 0) { register int index = lookup[key]; if (index >= 0) { if (len == lengthtable[index]) { register const char *s = wordlist[index]; if (*str == *s && !memcmp (str + 1, s + 1, len - 1)) return s; } } } } return 0; }
static int64_t lookup_uid(void *private_data, const char *uname, int64_t uid) { int h; struct bucket *b; struct bucket *ucache = (struct bucket *)private_data; /* If no uname, just use the uid provided. */ if (uname == NULL || *uname == '\0') return (uid); /* Try to find uname in the cache. */ h = hash(uname); b = &ucache[h % cache_size ]; if (b->name != NULL && b->hash == h && strcmp(uname, b->name) == 0) return ((uid_t)b->id); /* Free the cache slot for a new entry. */ if (b->name != NULL) free(b->name); b->name = strdup(uname); /* Note: If strdup fails, that's okay; we just won't cache. */ b->hash = h; #if HAVE_PWD_H # if HAVE_GETPWNAM_R { char _buffer[128]; size_t bufsize = 128; char *buffer = _buffer; struct passwd pwent, *result; int r; for (;;) { result = &pwent; /* Old getpwnam_r ignores last arg. */ r = getpwnam_r(uname, &pwent, buffer, bufsize, &result); if (r == 0) break; if (r != ERANGE) break; bufsize *= 2; if (buffer != _buffer) free(buffer); buffer = malloc(bufsize); if (buffer == NULL) break; } if (result != NULL) uid = result->pw_uid; if (buffer != _buffer) free(buffer); } # else /* HAVE_GETPWNAM_R */ { struct passwd *result; result = getpwnam(uname); if (result != NULL) uid = result->pw_uid; } #endif /* HAVE_GETPWNAM_R */ #elif defined(_WIN32) && !defined(__CYGWIN__) /* TODO: do a uname->uid lookup for Windows. */ #else #error No way to look up uids on this platform #endif b->id = uid; return (uid); }
static int64_t lookup_gid(void *private_data, const char *gname, int64_t gid) { int h; struct bucket *b; struct bucket *gcache = (struct bucket *)private_data; /* If no gname, just use the gid provided. */ if (gname == NULL || *gname == '\0') return (gid); /* Try to find gname in the cache. */ h = hash(gname); b = &gcache[h % cache_size ]; if (b->name != NULL && b->hash == h && strcmp(gname, b->name) == 0) return ((gid_t)b->id); /* Free the cache slot for a new entry. */ if (b->name != NULL) free(b->name); b->name = strdup(gname); /* Note: If strdup fails, that's okay; we just won't cache. */ b->hash = h; #if HAVE_GRP_H # if HAVE_GETGRNAM_R { char _buffer[128]; size_t bufsize = 128; char *buffer = _buffer; struct group grent, *result; int r; for (;;) { result = &grent; /* Old getgrnam_r ignores last arg. */ r = getgrnam_r(gname, &grent, buffer, bufsize, &result); if (r == 0) break; if (r != ERANGE) break; bufsize *= 2; if (buffer != _buffer) free(buffer); buffer = malloc(bufsize); if (buffer == NULL) break; } if (result != NULL) gid = result->gr_gid; if (buffer != _buffer) free(buffer); } # else /* HAVE_GETGRNAM_R */ { struct group *result; result = getgrnam(gname); if (result != NULL) gid = result->gr_gid; } # endif /* HAVE_GETGRNAM_R */ #elif defined(_WIN32) && !defined(__CYGWIN__) /* TODO: do a gname->gid lookup for Windows. */ #else #error No way to perform gid lookups on this platform #endif b->id = gid; return (gid); }
/*! Returns the hash of \a data using \a method. */ QByteArray QCryptographicHash::hash(const QByteArray &data, Algorithm method) { QCryptographicHash hash(method); hash.addData(data); return hash.result(); }
static struct hashtable * build_hash_table (char const * file, int nfields, int keyfield, int islist, int tablesize, int ignorenis, char delimiter) { struct hashtable* ht; size_t len; unsigned int h; struct mypasswd *hashentry, *hashentry1; char *list; char *nextlist=0; int i; char buffer[1024]; ht = (struct hashtable *) rad_malloc(sizeof(struct hashtable)); if(!ht) { return NULL; } memset(ht, 0, sizeof(struct hashtable)); ht->filename = strdup(file); if(!ht->filename) { free(ht); return NULL; } ht->tablesize = tablesize; ht->nfields = nfields; ht->keyfield = keyfield; ht->islist = islist; ht->ignorenis = ignorenis; if (delimiter) ht->delimiter = delimiter; else ht->delimiter = ':'; if(!tablesize) return ht; if(!(ht->fp = fopen(file,"r"))) { free(ht->filename); free(ht); return NULL; } /* * @todo: This code is SHIT. It's badly formatted. It's * hard to understand. It re-implements tons of things * which are already in the server core. */ memset(ht->buffer, 0, 1024); ht->table = (struct mypasswd **) rad_malloc (tablesize * sizeof(struct mypasswd *)); if (!ht->table) { /* * Unable allocate memory for hash table * Still work without it */ ht->tablesize = 0; return ht; } memset(ht->table, 0, tablesize * sizeof(struct mypasswd *)); while (fgets(buffer, 1024, ht->fp)) { if(*buffer && *buffer!='\n' && (!ignorenis || (*buffer != '+' && *buffer != '-')) ){ if(!(hashentry = mypasswd_malloc(buffer, nfields, &len))){ release_hash_table(ht); return ht; } len = string_to_entry(buffer, nfields, ht->delimiter, hashentry, len); if(!hashentry->field[keyfield] || *hashentry->field[keyfield] == '\0') { free(hashentry); continue; } if (islist) { list = hashentry->field[keyfield]; for (nextlist = list; *nextlist && *nextlist!=','; nextlist++); if (*nextlist) *nextlist++ = 0; else nextlist = 0; } h = hash(hashentry->field[keyfield], tablesize); hashentry->next = ht->table[h]; ht->table[h] = hashentry; if (islist) { for(list=nextlist; nextlist; list = nextlist){ for (nextlist = list; *nextlist && *nextlist!=','; nextlist++); if (*nextlist) *nextlist++ = 0; else nextlist = 0; if(!(hashentry1 = mypasswd_malloc("", nfields, &len))){ release_hash_table(ht); return ht; } for (i=0; i<nfields; i++) hashentry1->field[i] = hashentry->field[i]; hashentry1->field[keyfield] = list; h = hash(list, tablesize); hashentry1->next = ht->table[h]; ht->table[h] = hashentry1; } } } } fclose(ht->fp); ht->fp = NULL; return ht; #undef passwd }
TYPED_TEST(StringHashTest, HashForEmptySubstringsAreEqual) { StringHash<TypeParam> hash("abacaba"); EXPECT_EQ(hash.hash(3, 3), hash.hash(5, 5)); }
TYPED_TEST(StringHashTest, SmallDifferentStringHaveDifferentHash) { StringHash<TypeParam> hash("abacaba"); EXPECT_NE(hash.hash(1, 3), hash.hash()); EXPECT_NE(hash.hash(0, 1), hash.hash(3, 4)); EXPECT_NE(hash.prefixHash(1), hash.prefixHash(2)); }
TYPED_TEST(StringHashTest, PrefixSuffixHash) { StringHash<TypeParam> hash("abacaba"); EXPECT_EQ(hash.prefixHash(5), hash.hash(0, 5)); EXPECT_EQ(hash.prefixHash(3), hash.suffixHash(4)); EXPECT_EQ(hash.suffixHash(6), hash.hash(6, 7)); }
// the meat of it. pretty self explanitory. void interpret(char* line) { //fputs(line, stdout); char cmd[4] = {0}; strncpy(cmd, line, 3); line += 4; int cmd_hash = hash(cmd); if (cmd_hash == IFF) { nest_count++; } if (cmd_hash == END) { nest_count--; } if (jump_seeking && cmd_hash != LBL ) { return; } // Jump value 0 means execute normally // Jump value -1 means jump, but continue to check eif's // Jump value -2 means go straight to end if (jump == -2 && cmd_hash != END) { return; } if (jump && cmd_hash != IFF && cmd_hash != EIF && cmd_hash != ELS && cmd_hash != END) { return; } // the max three arguments passed to each command char args[3][16] = {0}; int argc = sscanf(line, "%s %s %s", args[0], args[1], args[2]); int* vars[3] = {0}; int literals[3] = {0}; for (int i = 0; i < argc; i++) { if (args[i][0] == '$') { // if just $, store to temp if (!args[i][1]) { vars[i] = &script_vars[26]; } else { vars[i] = script_vars + args[i][1] - 'a'; } } else { literals[i] = atoi(args[i]); vars[i] = &literals[i]; } } switch (hash(cmd)) { case CPY: *vars[1] = *vars[0]; break; case SHO: printf("%d", *vars[0]); if (REPL == 1) { puts(""); } break; case DIS: printf("%c", (char)*vars[0]); if (REPL == 1) { puts(""); } break; case INC: *vars[0] = *vars[0] + 1; break; case DEC: *vars[0] = *vars[0] - 1; break; case IIN: ; char int_str[16]; if (REPL == 1) { fputs(": ", stdout); } fgets(int_str, 16, stdin); *vars[0] = atoi(int_str); break; case CIN: ; char char_str[4]; if (REPL == 1) { fputs(": ", stdout); } fgets(char_str, 4, stdin); *vars[0] = char_str[0]; break; case PUS: script_arr[stack_pos++] = *vars[0]; break; case POP: if (stack_pos == 0) { // IGNORE ALLLLL THE ERRORSSSSSSSS fputs("POP'd empty stack", stderr); break; } *vars[0] = script_arr[--stack_pos]; break; case PUT: script_arr[*vars[1]] = *vars[0]; break; case GET: *vars[0] = script_arr[*vars[1]]; break; case ADD: *vars[2] = *vars[0] + *vars[1]; break; case SUB: *vars[2] = *vars[0] - *vars[1]; break; case MUL: *vars[2] = *vars[0] * *vars[1]; break; case DIV: if ( *vars[1] == 0 ) { fputs("Attempted to divide by 0", stderr); break; } *vars[2] = *vars[0] / *vars[1]; break; case RAN: if ( *vars[0] < 2 ) { fputs("Attempted to modulo less than 2", stderr); break; } *vars[1] = rand() % *vars[0]; break; case MOD: if ( *vars[1] < 2 ) { fputs("Attempted to modulo less than 2", stderr); break; } *vars[2] = *vars[0] % *vars[1]; break; case EQL: *vars[2] = (*vars[0] == *vars[1]) ? 1 : 0; break; case GRT: *vars[2] = *vars[0] > *vars[1] ? 1 : 0; break; case IFF: // Jump value 0 means execute normally // Jump value -1 means jump, but continue to check eif's // Jump value -2 means go straight to end if (jump == -1) { jump = -2; } if (jump == 0) { if (*vars[0]) { jump = 0; } else { jump = -1; } } jump_stack[nest_count-1] = jump; //printf("stored jump val of %d to stack pos %d\n", jump, nest_count-1); break; case EIF: if (jump == 0 ) { jump = -2; break; } if (*vars[0]) { jump = 0; break; } else { jump = -1; } break; case ELS: if (jump == -1) { jump = 0; } else { jump = -2; } break; case END: if (nest_count < 0) { exit(0); } jump = nest_count > 0 ? jump_stack[nest_count-1] : 0; //printf("retreived jump val of %d from stack pos %d\n", jump, nest_count-1); break; case LBL: ; if (jump_seeking == *vars[0]) { jump_seeking = 0; } break; case MOV: ; if (argc == 1 || *vars[1] != 0) { jump_seeking = *vars[0]; current_line = -1; } break; } }
// Adds an item to the Hash Table. void HashTable::insertItem( Item * newItem ) { int index = hash( newItem -> key ); array[ index ].insertItem( newItem ); }
int emit_hrr_build_macro() { int new_am = Params.new_am; int max_class_size = Params.max_class_size; int am_to_inline = Params.max_am_to_inline_hrr_worker; FILE *code; int p,q,r,s; int ax,ay,az,bx,by,bz,cx,cy,cz,dx,dy,dz; int t0, t1, t2, t3, t4; int i,j,nj,i_i0,i_i1; int k,l,nl,k_i0,k_i1; int i0_step,i1_step; int a, b; int flag; int am_in[2]; int am[2][3]; int current_highest_am, to_inline; int xyz; int class_size; int split; int la, lb; int ld, lc, ld_max; int curr_count,curr_subfunction; int num_subfunctions, subbatch_length; int f; char code_name[20]; char function_name[18]; char **subfunction_name; for(lc=0;lc<=new_am;lc++) { ld_max = lc/2 + 1; if (ld_max > lc) ld_max = lc; for(ld=1;ld<=ld_max;ld++) { /*----------------------- HRR on centers C and D -----------------------*/ am_in[0] = lc-ld; am_in[1] = ld; /* Is this function to be made inline */ current_highest_am = (am_in[0] > am_in[1]) ? am_in[0] : am_in[1]; to_inline = (current_highest_am <= am_to_inline) ? 1 : 0; if (!to_inline) continue; class_size = ((am_in[0]+1)*(am_in[0]+2)*(am_in[1]+1)*(am_in[1]+2))/4; /* If the routine has to be split into several - user probably doesn't know what he/she is doing */ if (class_size > max_class_size) punt("MAX_CLASS_SIZE is too small for the given inlining threshold"); else { split = 0; } sprintf(function_name,"hrr3_build_%c%c",am_letter[am_in[0]],am_letter[am_in[1]]); sprintf(code_name,"%s.h",function_name); code = fopen(code_name,"w"); fprintf(code,"#ifndef _libint_%s\n",function_name); fprintf(code,"#define _libint_%s\n",function_name); fprintf(code," /* These machine-generated functions compute a quartet of |%c%c) integrals */\n\n", am_letter[am_in[0]],am_letter[am_in[1]]); fprintf(code,"#define %s(CD, vp, I0, I1, ab_num)\\\n{\\\n", function_name); fprintf(code," const REALTYPE CD0 = CD[0];\\\n"); fprintf(code," const REALTYPE CD1 = CD[1];\\\n"); fprintf(code," const REALTYPE CD2 = CD[2];\\\n"); fprintf(code," int ab;\\\n"); fprintf(code," REALTYPE *target = (vp);\\\n"); fprintf(code," REALTYPE *i0 = (I0);\\\n"); fprintf(code," REALTYPE *i1 = (I1);\\\n\\\n"); nl = (am_in[1]*(am_in[1]+1))/2; i0_step = (am_in[0]+2)*(am_in[0]+3)*nl/2; i1_step = (am_in[0]+1)*(am_in[0]+2)*nl/2; fprintf(code," for(ab=0;ab<ab_num;ab++) {\\\n"); for(p = 0; p <= am_in[0]; p++){ am[0][0] = am_in[0] - p; for(q = 0; q <= p; q++){ am[0][1] = p - q; am[0][2] = q; for(r = 0; r <= am_in[1]; r++){ am[1][0] = am_in[1] - r; for(s = 0; s <= r; s++){ am[1][1] = r - s; am[1][2] = s; if (am[1][0]) /* build along x */ xyz = 0; else if (am[1][1]) /* build along y */ xyz = 1; else /*build along z */ xyz = 2; am[0][xyz] += 1; am_in[0] += 1; am[1][xyz] -= 1; am_in[1] -= 1; t0 = hash(am,am_in); am[0][xyz] -= 1; am_in[0] -= 1; t1 = hash(am,am_in); am[1][xyz] += 1; am_in[1] += 1; fprintf(code, " *(target++) = i0[%d] + CD%d*i1[%d];\\\n",t0,xyz,t1); curr_count++; } } } } fprintf(code," i0 += %d;\\\n i1 += %d;\\\n",i0_step,i1_step); fprintf(code," }\\\n}\n"); fprintf(code,"\n#endif\n"); /* end of #ifndef _libint_.... */ fclose(code); printf("Done with %s\n",code_name); /*----------------------- HRR on centers A and B -----------------------*/ la = lc-ld; lb = ld; am_in[0] = la; am_in[1] = lb; class_size = ((am_in[0]+1)*(am_in[0]+2)*(am_in[1]+1)*(am_in[1]+2))/4; sprintf(function_name,"hrr1_build_%c%c",am_letter[am_in[0]],am_letter[am_in[1]]); sprintf(code_name,"%s.h",function_name); code = fopen(code_name,"w"); fprintf(code,"#ifndef _libint_%s\n",function_name); fprintf(code,"#define _libint_%s\n",function_name); fprintf(code," /* This machine-generated function computes a quartet of (%c%c| integrals */\n\n", am_letter[am_in[0]],am_letter[am_in[1]]); fprintf(code,"#define %s(AB, vp, I0, I1, cd_num)\\\n{\\\n", function_name); fprintf(code," const REALTYPE AB0 = AB[0];\\\n"); fprintf(code," const REALTYPE AB1 = AB[1];\\\n"); fprintf(code," const REALTYPE AB2 = AB[2];\\\n"); fprintf(code," REALTYPE *i0, *i1;\\\n"); fprintf(code," int cd;\\\n"); fprintf(code," REALTYPE *target = (vp);\\\n\\\n"); nj = (lb*(lb+1))/2; for(p = 0; p <= am_in[0]; p++){ am[0][0] = am_in[0] - p; for(q = 0; q <= p; q++){ am[0][1] = p - q; am[0][2] = q; for(r = 0; r <= am_in[1]; r++){ am[1][0] = am_in[1] - r; for(s = 0; s <= r; s++){ am[1][1] = r - s; am[1][2] = s; if (am[1][0]) /* build along x */ xyz = 0; else if (am[1][1]) /* build along y */ xyz = 1; else /* build along z */ xyz = 2; am[0][xyz] += 1; am_in[0] += 1; am[1][xyz] -= 1; am_in[1] -= 1; t0 = hash(am,am_in); am[0][xyz] -= 1; am_in[0] -= 1; t1 = hash(am,am_in); am[1][xyz] += 1; am_in[1] += 1; if (t0) fprintf(code," i0 = (I0) + %d*cd_num;\\\n",t0); else fprintf(code," i0 = (I0);\\\n"); if (t1) fprintf(code," i1 = (I1) + %d*cd_num;\\\n",t1); else fprintf(code," i1 = (I1);\\\n"); fprintf(code," for(cd=0;cd<cd_num;cd++)\\\n"); fprintf(code," *(target++) = *(i0++) + AB%d*(*(i1++));\\\n",xyz); curr_count++; } } } } fprintf(code,"}\n"); fprintf(code,"\n#endif\n"); /* end of #ifndef _libint_.... */ fclose(code); printf("Done with %s\n",code_name); } } }
// Deletes an Item by key from the Hash Table. // Returns true if the operation is successful. bool HashTable::removeItem( string itemKey ) { int index = hash( itemKey ); return array[ index ].removeItem( itemKey ); }
static void test(const char* ptr, long len) { init(); hash(ptr, len); dump(); }
// Returns an item from the Hash Table by key. // If the item isn't found, a null pointer is returned. Item * HashTable::getItemByKey( string itemKey ) { int index = hash( itemKey ); return array[ index ].getItem( itemKey ); }
/* -------------------------------------------------------------------- */ void newPW(void) { char InitPw[42]; char passWord[42]; char Initials[42]; char oldPw[42]; char *semicolon; int goodpw; /* display old pw & initials */ displaypw(logBuf.lbname, logBuf.lbin, logBuf.lbpw); if (!getYesNo(confirm, 0)) return; strcpy(oldPw, logBuf.lbpw); getNormStr("your new initials", InitPw, 40, NO_ECHO); dospCR(); semicolon = strchr(InitPw, ';'); if(semicolon) { normalizepw(InitPw, Initials, passWord); } else strcpy(Initials, InitPw); /* dont allow anything over 19 characters */ Initials[19] = '\0'; do { if (!semicolon) { getNormStr("new password", passWord, NAMESIZE, NO_ECHO); dospCR(); } goodpw = ( ((pwexists(passWord) == ERROR) && strlen(passWord) >= 2) || (strcmpi(passWord, oldPw) == SAMESTRING)); if ( !goodpw) mPrintf("\n Poor password\n "); semicolon = FALSE; } while ( !goodpw && CARRIER); strcpy(logBuf.lbin, Initials); strcpy(logBuf.lbpw, passWord); /* insure against loss of carrier */ if (CARRIER) { logTab[0].ltinhash = hash(Initials); logTab[0].ltpwhash = hash(passWord); storeLog(); } /* display new pw & initials */ displaypw(logBuf.lbname, logBuf.lbin, logBuf.lbpw); /* trap it */ trap("Password changed", T_PASSWORD); }
int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const { QString path = QDir::cleanPath(_path); // QDir::cleanPath does not remove two trailing slashes under _Windows_ // due to support for UNC paths. Remove those manually. if (path.startsWith(QLatin1String("//"))) path.remove(0, 1); { QString root = mappingRoot(); if(!root.isEmpty()) { if(root == path) { path = QLatin1String("/"); } else { if(!root.endsWith(QLatin1String("/"))) root += QLatin1String("/"); if(path.size() >= root.size() && path.startsWith(root)) path = path.mid(root.length()-1); if(path.isEmpty()) path = QLatin1String("/"); } } } #ifdef DEBUG_RESOURCE_MATCH qDebug() << "!!!!" << "START" << path << locale.country() << locale.language(); #endif if(path == QLatin1String("/")) return 0; //the root node is always first int child_count = (tree[6] << 24) + (tree[7] << 16) + (tree[8] << 8) + (tree[9] << 0); int child = (tree[10] << 24) + (tree[11] << 16) + (tree[12] << 8) + (tree[13] << 0); //now iterate up the tree int node = -1; QStringList segments = path.split(QLatin1Char('/'), QString::SkipEmptyParts); #ifdef DEBUG_RESOURCE_MATCH qDebug() << "****" << segments; #endif for(int i = 0; child_count && i < segments.size(); ++i) { const QString &segment = segments[i]; #ifdef DEBUG_RESOURCE_MATCH qDebug() << " CHILDREN" << segment; for(int j = 0; j < child_count; ++j) { qDebug() << " " << child+j << " :: " << name(child+j); } #endif const int h = qHash(segment); //do the binary search for the hash int l = 0, r = child_count-1; int sub_node = (l+r+1)/2; while(r != l) { const int sub_node_hash = hash(child+sub_node); if(h == sub_node_hash) break; else if(h < sub_node_hash) r = sub_node - 1; else l = sub_node; sub_node = (l + r + 1) / 2; } sub_node += child; //now do the "harder" compares bool found = false; if(hash(sub_node) == h) { while(sub_node > child && hash(sub_node-1) == h) //backup for collisions --sub_node; for(; sub_node < child+child_count && hash(sub_node) == h; ++sub_node) { //here we go... if(name(sub_node) == segment) { found = true; int offset = findOffset(sub_node); #ifdef DEBUG_RESOURCE_MATCH qDebug() << " TRY" << sub_node << name(sub_node) << offset; #endif offset += 4; //jump past name const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0); offset += 2; if(i == segments.size()-1) { if(!(flags & Directory)) { const short country = (tree[offset+0] << 8) + (tree[offset+1] << 0); offset += 2; const short language = (tree[offset+0] << 8) + (tree[offset+1] << 0); offset += 2; #ifdef DEBUG_RESOURCE_MATCH qDebug() << " " << "LOCALE" << country << language; #endif if(country == locale.country() && language == locale.language()) { #ifdef DEBUG_RESOURCE_MATCH qDebug() << "!!!!" << "FINISHED" << __LINE__ << sub_node; #endif return sub_node; } else if((country == QLocale::AnyCountry && language == locale.language()) || (country == QLocale::AnyCountry && language == QLocale::C && node == -1)) { node = sub_node; } continue; } else { #ifdef DEBUG_RESOURCE_MATCH qDebug() << "!!!!" << "FINISHED" << __LINE__ << sub_node; #endif return sub_node; } } if(!(flags & Directory)) return -1; child_count = (tree[offset+0] << 24) + (tree[offset+1] << 16) + (tree[offset+2] << 8) + (tree[offset+3] << 0); offset += 4; child = (tree[offset+0] << 24) + (tree[offset+1] << 16) + (tree[offset+2] << 8) + (tree[offset+3] << 0); break; } } } if(!found) break; } #ifdef DEBUG_RESOURCE_MATCH qDebug() << "!!!!" << "FINISHED" << __LINE__ << node; #endif return node; }
//Main program entry point int main(int argc, char** argv) { g_bProgressOverwrite = false; g_iNumThreads = 0; g_iCompressAmount = Z_DEFAULT_COMPRESSION; DWORD iTicks = GetTickCount(); vfs.Prepare(); //read in the resource names to pack initResMap(); initSoundManifest(); parseCmdLine(argc, argv); if(argc < 2) { cout << "Usage: liCompress [pakfile1] [pakfile2] ... [pakfileN]" << endl; return 0; } for(int iArg = 1; iArg < argc; iArg++) { if(argv[iArg][0] == '-') //Skip over commandline switches continue; list<wstring> lFilenames; //Files in this pakfile that we're going to compress wstring sArg = s2ws(argv[iArg]); size_t pos = sArg.find(TEXT(".filelist.txt")); if(pos != wstring::npos) sArg.erase(pos, wstring::npos); //Erase a .filelist.pak extension if there is one cout << endl << "Packing resource blob file " << ws2s(sArg) << endl; //Determine what files to pack into this .pak file wstring sInfilename = sArg; sInfilename += TEXT(".filelist.txt"); ifstream infile(ws2s(sInfilename).c_str()); if(infile.fail()) { cout << "Cannot open " << ws2s(sInfilename) << " to pack " << ws2s(sArg) << " Skipping..." << endl; continue; } while(!infile.fail() && !infile.eof()) //Pull in all the lines out of this file { string ss; getline(infile, ss); wstring s = s2ws(ttvfs::FixSlashes(ss)); if(!s.length() || s == TEXT("")) continue; //Ignore blank lines lFilenames.push_back(s); //Add this to our list of files to package } threadedCompress(lFilenames); //Compress everything //Ok, now we have all the compressed files in RAM. Stick them in the .pak file and call it a day if(g_pakHelping.size() != lFilenames.size()) //These should be the same { cout << "Error: size of file list: " << g_pakHelping.size() << " differs from size of files to pak: " << lFilenames.size() << endl; continue; } //Create a mini residmap.dat file and stick it into g_pakHelping to compress if we need to //See what IDs are known and unknown map<wstring, u32> mResIDs; map<u32, wstring> mUnknownIDs; for(list<wstring>::iterator i = lFilenames.begin(); i != lFilenames.end(); i++) { u32 id = getKnownResID(*i); if(!id) //The ID mapping is unknown { id = hash(*i); mUnknownIDs[id] = toBackslashes(*i); //Make sure we use backslashes inside a residmap.dat } mResIDs[*i] = id; } //If there are any unknown mappings, make our residmap.dat if(mUnknownIDs.size()) { lFilenames.push_front(TEXT(RESIDMAP_NAME)); //Add this to the front, so it'll decompress first so we'll have all the filenames mResIDs[TEXT(RESIDMAP_NAME)] = RESIDMAP_ID; //Add this to the IDs we'll compress createMiniResidMap(&mUnknownIDs); //And create the file in memory } //Open our output pakfile for writing FILE* f = _wfopen(sArg.c_str(), TEXT("wb")); if(f == NULL) { cout << "Unable to open file " << ws2s(sArg) << " for writing. Skipping..." << endl; continue; } //Add the header blobHeader bh; bh.pakVersion = 0x01; bh.numItems = lFilenames.size(); fwrite(&bh, 1, sizeof(blobHeader), f); //Get the starting file pos for where we (should) be writing objects to size_t offsetPos = sizeof(blobHeader) + (lFilenames.size() * sizeof(resourceHeader)); //Add the table of contents cout << "\rAdding table of contents... " << endl; for(list<wstring>::iterator i = lFilenames.begin(); i != lFilenames.end(); i++) { resourceHeader rH; rH.id = mResIDs[*i]; rH.flags = 0x01; rH.offset = offsetPos; //Offset rH.size = g_pakHelping[*i].dataSz; if(g_pakHelping[*i].bCompressed) rH.size += sizeof(compressedHeader); //Compressed files have a compression header also else rH.flags = 0x00; //Set the flags to uncompressed fwrite(&rH, 1, sizeof(resourceHeader), f); //Write this to the file offsetPos += rH.size; //Add this size to our running tally of where we are } //Add actual resource data cout << "Adding compressed files..." << endl; for(list<wstring>::iterator i = lFilenames.begin(); i != lFilenames.end(); i++) { pakHelper pH = g_pakHelping[*i]; //Write the compressed header only if compressed if(pH.bCompressed) fwrite(&(pH.cH), 1, sizeof(compressedHeader), f); fwrite(pH.data, 1, pH.dataSz, f); //One pass to write this file. Simple enough. //Don't free the memory here, in case there's more than one .pak file with this data in it. } fclose(f); //Done packing this .pak file //Clear memory for(map<wstring, pakHelper>::iterator i = g_pakHelping.begin(); i != g_pakHelping.end(); i++) free(i->second.data); g_pakHelping.clear(); } cout << "Done." << endl; iTicks = GetTickCount() - iTicks; float iSeconds = (float)iTicks / 1000.0; //Get seconds elapsed int iMinutes = iSeconds / 60; iSeconds -= iMinutes * 60; cout << "Time elapsed: " << iMinutes << " min, " << iSeconds << " sec" << endl; return 0; }
const TAO_operation_db_entry * TAO_Skeleton_Inheritance_Interface_2_Perfect_Hash_OpTable::lookup (const char *str, unsigned int len) { enum { TOTAL_KEYWORDS = 10, MIN_WORD_LENGTH = 5, MAX_WORD_LENGTH = 16, MIN_HASH_VALUE = 5, MAX_HASH_VALUE = 26, HASH_VALUE_RANGE = 22, DUPLICATES = 2, WORDLIST_SIZE = 15 }; static const TAO_operation_db_entry wordlist[] = { {"",0,0},{"",0,0},{"",0,0},{"",0,0},{"",0,0}, {"_is_a", &TAO_ServantBase::_is_a_thru_poa_skel, 0}, {"_component", &TAO_ServantBase::_component_thru_poa_skel, 0}, {"operation_1", &POA_Skeleton_Inheritance::Interface_1::operation_1_skel, &POA_Skeleton_Inheritance::_TAO_Interface_1_Direct_Proxy_Impl::operation_1}, {"_non_existent", &TAO_ServantBase::_non_existent_thru_poa_skel, 0}, {"_repository_id", &TAO_ServantBase::_repository_id_thru_poa_skel, 0}, {"_interface", &TAO_ServantBase::_interface_skel, 0}, {"_get_attribute_1", &POA_Skeleton_Inheritance::Interface_1::_get_attribute_1_skel, &POA_Skeleton_Inheritance::_TAO_Interface_1_Direct_Proxy_Impl::_get_attribute_1}, {"_set_attribute_1", &POA_Skeleton_Inheritance::Interface_1::_set_attribute_1_skel, &POA_Skeleton_Inheritance::_TAO_Interface_1_Direct_Proxy_Impl::_set_attribute_1}, {"operation_2", &POA_Skeleton_Inheritance::Interface_2::operation_2_skel, &POA_Skeleton_Inheritance::_TAO_Interface_2_Direct_Proxy_Impl::operation_2}, {"_get_attribute_2", &POA_Skeleton_Inheritance::Interface_2::_get_attribute_2_skel, &POA_Skeleton_Inheritance::_TAO_Interface_2_Direct_Proxy_Impl::_get_attribute_2}, }; static const signed char lookup[] = { -1, -1, -1, -1, -1, 5, -1, -1, -11, -2, 6, 7, -1, 8, 9, 10, -34, -1, -1, -1, -1, 13, -1, -1, -1, -1, 14, }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) { unsigned int key = hash (str, len); if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE) { int slot = lookup[key]; if (slot >= 0 && slot < WORDLIST_SIZE) { const char *s = wordlist[slot].opname; if (*str == *s && !ACE_OS::strncmp (str + 1, s + 1, len - 1)) return &wordlist[slot]; } else if (slot < 0 && slot >= -MAX_HASH_VALUE) return 0; else { unsigned int offset = key + slot + (slot > 0 ? -MAX_HASH_VALUE : MAX_HASH_VALUE); const TAO_operation_db_entry *base = &wordlist[-lookup[offset]]; const TAO_operation_db_entry *ptr = base + -lookup[offset + 1]; while (--ptr >= base) if (*str == *ptr->opname && !ACE_OS::strncmp (str + 1, ptr->opname + 1, len - 1)) return ptr; } } } return 0; }
/* refcount == 0 is safe since nobody can incr while item_lock is held. * refcount != 0 is impossible since flags/etc can be modified in other * threads. instead, note we found a busy one and bail. logic in do_item_get * will prevent busy items from continuing to be busy * NOTE: This is checking it_flags outside of an item lock. I believe this * works since it_flags is 8 bits, and we're only ever comparing a single bit * regardless. ITEM_SLABBED bit will always be correct since we're holding the * lock which modifies that bit. ITEM_LINKED won't exist if we're between an * item having ITEM_SLABBED removed, and the key hasn't been added to the item * yet. The memory barrier from the slabs lock should order the key write and the * flags to the item? * If ITEM_LINKED did exist and was just removed, but we still see it, that's * still safe since it will have a valid key, which we then lock, and then * recheck everything. * This may not be safe on all platforms; If not, slabs_alloc() will need to * seed the item key while holding slabs_lock. */ static int slab_rebalance_move(void) { slabclass_t *s_cls; int x; int was_busy = 0; int refcount = 0; uint32_t hv; void *hold_lock; enum move_status status = MOVE_PASS; pthread_mutex_lock(&slabs_lock); s_cls = &slabclass[slab_rebal.s_clsid]; for (x = 0; x < slab_bulk_check; x++) { hv = 0; hold_lock = NULL; item *it = slab_rebal.slab_pos; item_chunk *ch = NULL; status = MOVE_PASS; if (it->it_flags & ITEM_CHUNK) { /* This chunk is a chained part of a larger item. */ ch = (item_chunk *) it; /* Instead, we use the head chunk to find the item and effectively * lock the entire structure. If a chunk has ITEM_CHUNK flag, its * head cannot be slabbed, so the normal routine is safe. */ it = ch->head; assert(it->it_flags & ITEM_CHUNKED); } /* ITEM_FETCHED when ITEM_SLABBED is overloaded to mean we've cleared * the chunk for move. Only these two flags should exist. */ if (it->it_flags != (ITEM_SLABBED|ITEM_FETCHED)) { /* ITEM_SLABBED can only be added/removed under the slabs_lock */ if (it->it_flags & ITEM_SLABBED) { assert(ch == NULL); slab_rebalance_cut_free(s_cls, it); status = MOVE_FROM_SLAB; } else if ((it->it_flags & ITEM_LINKED) != 0) { /* If it doesn't have ITEM_SLABBED, the item could be in any * state on its way to being freed or written to. If no * ITEM_SLABBED, but it's had ITEM_LINKED, it must be active * and have the key written to it already. */ hv = hash(ITEM_key(it), it->nkey); if ((hold_lock = item_trylock(hv)) == NULL) { status = MOVE_LOCKED; } else { refcount = refcount_incr(it); if (refcount == 2) { /* item is linked but not busy */ /* Double check ITEM_LINKED flag here, since we're * past a memory barrier from the mutex. */ if ((it->it_flags & ITEM_LINKED) != 0) { status = MOVE_FROM_LRU; } else { /* refcount == 1 + !ITEM_LINKED means the item is being * uploaded to, or was just unlinked but hasn't been freed * yet. Let it bleed off on its own and try again later */ status = MOVE_BUSY; } } else { if (settings.verbose > 2) { fprintf(stderr, "Slab reassign hit a busy item: refcount: %d (%d -> %d)\n", it->refcount, slab_rebal.s_clsid, slab_rebal.d_clsid); } status = MOVE_BUSY; } /* Item lock must be held while modifying refcount */ if (status == MOVE_BUSY) { refcount_decr(it); item_trylock_unlock(hold_lock); } } } else { /* See above comment. No ITEM_SLABBED or ITEM_LINKED. Mark * busy and wait for item to complete its upload. */ status = MOVE_BUSY; } } int save_item = 0; item *new_it = NULL; size_t ntotal = 0; switch (status) { case MOVE_FROM_LRU: /* Lock order is LRU locks -> slabs_lock. unlink uses LRU lock. * We only need to hold the slabs_lock while initially looking * at an item, and at this point we have an exclusive refcount * (2) + the item is locked. Drop slabs lock, drop item to * refcount 1 (just our own, then fall through and wipe it */ /* Check if expired or flushed */ ntotal = ITEM_ntotal(it); /* REQUIRES slabs_lock: CHECK FOR cls->sl_curr > 0 */ if (ch == NULL && (it->it_flags & ITEM_CHUNKED)) { /* Chunked should be identical to non-chunked, except we need * to swap out ntotal for the head-chunk-total. */ ntotal = s_cls->size; } if ((it->exptime != 0 && it->exptime < current_time) || item_is_flushed(it)) { /* Expired, don't save. */ save_item = 0; } else if (ch == NULL && (new_it = slab_rebalance_alloc(ntotal, slab_rebal.s_clsid)) == NULL) { /* Not a chunk of an item, and nomem. */ save_item = 0; slab_rebal.evictions_nomem++; } else if (ch != NULL && (new_it = slab_rebalance_alloc(s_cls->size, slab_rebal.s_clsid)) == NULL) { /* Is a chunk of an item, and nomem. */ save_item = 0; slab_rebal.evictions_nomem++; } else { /* Was whatever it was, and we have memory for it. */ save_item = 1; } pthread_mutex_unlock(&slabs_lock); unsigned int requested_adjust = 0; if (save_item) { if (ch == NULL) { assert((new_it->it_flags & ITEM_CHUNKED) == 0); /* if free memory, memcpy. clear prev/next/h_bucket */ memcpy(new_it, it, ntotal); new_it->prev = 0; new_it->next = 0; new_it->h_next = 0; /* These are definitely required. else fails assert */ new_it->it_flags &= ~ITEM_LINKED; new_it->refcount = 0; do_item_replace(it, new_it, hv); /* Need to walk the chunks and repoint head */ if (new_it->it_flags & ITEM_CHUNKED) { item_chunk *fch = (item_chunk *) ITEM_data(new_it); fch->next->prev = fch; while (fch) { fch->head = new_it; fch = fch->next; } } it->refcount = 0; it->it_flags = ITEM_SLABBED|ITEM_FETCHED; #ifdef DEBUG_SLAB_MOVER memcpy(ITEM_key(it), "deadbeef", 8); #endif slab_rebal.rescues++; requested_adjust = ntotal; } else { item_chunk *nch = (item_chunk *) new_it; /* Chunks always have head chunk (the main it) */ ch->prev->next = nch; if (ch->next) ch->next->prev = nch; memcpy(nch, ch, ch->used + sizeof(item_chunk)); ch->refcount = 0; ch->it_flags = ITEM_SLABBED|ITEM_FETCHED; slab_rebal.chunk_rescues++; #ifdef DEBUG_SLAB_MOVER memcpy(ITEM_key((item *)ch), "deadbeef", 8); #endif refcount_decr(it); requested_adjust = s_cls->size; } } else { /* restore ntotal in case we tried saving a head chunk. */ ntotal = ITEM_ntotal(it); do_item_unlink(it, hv); slabs_free(it, ntotal, slab_rebal.s_clsid); /* Swing around again later to remove it from the freelist. */ slab_rebal.busy_items++; was_busy++; } item_trylock_unlock(hold_lock); pthread_mutex_lock(&slabs_lock); /* Always remove the ntotal, as we added it in during * do_slabs_alloc() when copying the item. */ s_cls->requested -= requested_adjust; break; case MOVE_FROM_SLAB: it->refcount = 0; it->it_flags = ITEM_SLABBED|ITEM_FETCHED; #ifdef DEBUG_SLAB_MOVER memcpy(ITEM_key(it), "deadbeef", 8); #endif break; case MOVE_BUSY: case MOVE_LOCKED: slab_rebal.busy_items++; was_busy++; break; case MOVE_PASS: break; } slab_rebal.slab_pos = (char *)slab_rebal.slab_pos + s_cls->size; if (slab_rebal.slab_pos >= slab_rebal.slab_end) break; } if (slab_rebal.slab_pos >= slab_rebal.slab_end) { /* Some items were busy, start again from the top */ if (slab_rebal.busy_items) { slab_rebal.slab_pos = slab_rebal.slab_start; STATS_LOCK(); stats.slab_reassign_busy_items += slab_rebal.busy_items; STATS_UNLOCK(); slab_rebal.busy_items = 0; } else { slab_rebal.done++; } } pthread_mutex_unlock(&slabs_lock); return was_busy; }
int Servicios::tomarTexto(string ruta) { //parsear el libro Parser *unParser = new Parser(); cout << "Procesando Libro...." << endl; if (unParser->parsear(ruta) != EXITOSO) { string rutaLibros = Parametros().getParametro(CARPETA_LIBROS); ruta = rutaLibros + ruta; if (unParser->parsear(ruta) != EXITOSO) return ERROR_RUTA_INVALIDA; } Libro *unLibro = unParser->getLibro(); //cout << unLibro->toString() << endl; //BORRAR SOLO PARA PROBAR LA IMPRESION //cout << "parsie el libro" << endl; //meter el libro en el archivo de registros variables string rutaArcLibros = Parametros().getParametro(ARCHIVO_LIBROS); if (rutaArcLibros == "") return ERROR_RUTA_ARCHIVO_LIBROS; ArchivoLibros *archivo = new ArchivoLibros(rutaArcLibros); //cout << "creo archivo de libros" << endl; unsigned int offset = 0; offset = archivo->agregarLibro(unLibro); delete archivo; //cout << "agrego el libro" << endl; string pathArbolPrimario = Parametros().getParametro(CARPETA_DATOS); pathArbolPrimario += NOMBRE_BMAS_PRIMARIO; if (pathArbolPrimario == "") return ERROR_RUTA_BMAS_PRIMARIO; ArbolBMasNumerico *arbolP = new ArbolBMasNumerico(pathArbolPrimario, TAMANIO_BLOQUE_BMAS_NUMERICO); //cout << "id: "<< unLibro->getId() << endl; arbolP->insertarNumerico(unLibro->getId(),offset); delete arbolP; //cout << "agrego al indice primario" << endl; /*******************AGREGADO ENTREGA II*************************/ //crear el arbol de parlabras string pathArbolPalabras = Parametros().getParametro(CARPETA_DATOS); pathArbolPalabras += NOMBRE_BMAS_PALABRAS; pathArbolPalabras += "_" + Util().UIntToString(unLibro->getId()); ArbolBMasAlfabetico *arbolPal = new ArbolBMasAlfabetico(pathArbolPalabras, TAMANIO_BLOQUE_BMAS_PALABRAS); map<string, list<int> > mapa = unParser->obtenerPalabras2(); map<string, list<int> >::iterator itMap; string clave; unsigned int idLista; unsigned int posPal; string mejorP; unsigned int vieja,nueva,mejor = 0; //cout << "llego a insertar las cosas al arbol" << endl; //cin.get(); /////////////////////// agrego la funcionalidad para guardar normas infinito /////// string pathArbolPrim = Parametros().getParametro(CARPETA_DATOS); pathArbolPrim+= NOMBRE_BMAS_PRIMARIO; ArbolBMasNumerico* arbolPrimario = new ArbolBMasNumerico(pathArbolPrim, TAMANIO_BLOQUE_BMAS_NUMERICO); resultadoOperacion result(OK); Registro* regActual = arbolPrimario->buscarRegistroNumerico(0, &result); unsigned int N = 1; while (regActual != NULL) { regActual = arbolPrimario->siguiente(); N++; } delete arbolPrimario; double acumuladoNormaInf=0; for (itMap = mapa.begin(); itMap != mapa.end(); itMap++) { clave = itMap->first; posPal = itMap->second.front(); nueva = itMap->second.size(); list<unsigned int> listaIds; double aij = itMap->second.size(); string rutahash= Parametros().getParametro(CARPETA_DATOS); rutahash+=NOMBRE_HASH_PALABRAS; Hash hash(rutahash); Registro* registro= hash.buscar(itMap->first); double ni= 1; if (registro!= NULL){ offset= registro->getAtributosEnteros()->front(); ListasIds().obtenerListaIds(offset, &listaIds); ni= listaIds.size(); } double pesoGlobal= log10((double)N/(double)ni); double peso= aij*pesoGlobal; acumuladoNormaInf+= pow(peso,2); ListasIds().agregarPosPalabra(&idLista,posPal,true); arbolPal->insertar(clave,idLista); list<int>::iterator itPos = itMap->second.begin(); itPos++; //para salir del front por que ya se cargo antes for ( ; itPos != itMap->second.end() ; itPos++) { posPal = *itPos; ListasIds().agregarPosPalabra(&idLista,posPal,false); } delete registro; } double normaInfinito= sqrt(acumuladoNormaInf); //cout<<normaInfinito<<endl; archivoNormasInf archivoNormas; archivoNormas.escribirNorma(normaInfinito); delete arbolPal; /**********************************************borrar***************************************************/ // list<unsigned int> *lista = new list<unsigned int>(); // ListasIds().obtenerListaIds(1,lista); // // for (list<unsigned int>::iterator it = lista->begin(); it != lista->end() ; it ++) // cout << *it << endl; /*******************AGREGADO ENTREGA II*************************/ delete unParser; //agregar el libro a las listas SinIndice *listas = SinIndice().getInstancia(); //ProcesadorConsultas().actualizarPesos(); unsigned int id = unLibro->getId(); delete unLibro; return listas->agregarLibroPendienteATodasLasListas(id); //cout << "agrego a las listas no procesadas" << endl; }
const CBlockIndex* getBlockIndex(int height) { std::string hex = getBlockHash(height); uint256 hash(hex); return mapBlockIndex[hash]; }
void Downloader::readDataGZip(Job* job, HINTERNET hResourceHandle, QFile* file, QString* sha1, int64_t contentLength, QCryptographicHash::Algorithm alg) { QString initialTitle = job->getTitle(); // download/compute SHA1 loop QCryptographicHash hash(alg); const int bufferSize = 512 * 1024; unsigned char* buffer = new unsigned char[bufferSize]; const int buffer2Size = 512 * 1024; unsigned char* buffer2 = new unsigned char[buffer2Size]; bool zlibStreamInitialized = false; z_stream d_stream; int err = 0; int64_t alreadyRead = 0; DWORD bufferLength; do { if (!internetReadFileFully(hResourceHandle, buffer, bufferSize, &bufferLength)) { QString errMsg; WPMUtils::formatMessage(GetLastError(), &errMsg); job->setErrorMessage(errMsg); break; } if (bufferLength == 0) break; // http://www.gzip.org/zlib/rfc-gzip.html if (!zlibStreamInitialized) { unsigned int cur = 0; /* if (cur + 10 > bufferLength) { job->setErrorMessage("Less than 10 bytes"); goto out; } unsigned char flg = buffer[3]; cur = 10; // FLG.FEXTRA if (flg & 4) { uint16_t xlen; if (cur + 2 > bufferLength) { job->setErrorMessage("XLEN missing"); goto out; } else { xlen = *((uint16_t*) (buffer + cur)); cur += 2; } if (cur + xlen > bufferLength) { job->setErrorMessage("EXTRA missing"); goto out; } else { cur += xlen; } } // FLG.FNAME if (flg & 8) { while (true) { if (cur + 1 > bufferLength) { job->setErrorMessage("FNAME missing"); goto out; } else { uint8_t c = *((uint8_t*) (buffer + cur)); cur++; if (c == 0) break; } } } // FLG.FCOMMENT if (flg & 16) { while (true) { if (cur + 1 > bufferLength) { job->setErrorMessage("COMMENT missing"); goto out; } else { uint8_t c = *((uint8_t*) (buffer + cur)); cur++; if (c == 0) break; } } } // FLG.FHCRC if (flg & 2) { if (cur + 2 > bufferLength) { job->setErrorMessage("CRC16 missing"); goto out; } else { cur += 2; } }*/ d_stream.zalloc = (alloc_func) 0; d_stream.zfree = (free_func) 0; d_stream.opaque = (voidpf) 0; d_stream.next_in = buffer + cur; d_stream.avail_in = bufferLength - cur; d_stream.avail_out = buffer2Size; d_stream.next_out = buffer2; zlibStreamInitialized = true; // 15 = maximum buffer size, 32 = zlib and gzip formats are parsed int err = inflateInit2(&d_stream, 15 + 32); if (err != Z_OK) { job->setErrorMessage(QString(QObject::tr("zlib error %1")). arg(err)); break; } } else { d_stream.next_in = buffer; d_stream.avail_in = bufferLength; } // see http://zlib.net/zpipe.c do { d_stream.avail_out = buffer2Size; d_stream.next_out = buffer2; int err = inflate(&d_stream, Z_NO_FLUSH); if (err == Z_NEED_DICT) { job->setErrorMessage(QString(QObject::tr("zlib error %1")). arg(err)); err = Z_DATA_ERROR; inflateEnd(&d_stream); break; } else if (err == Z_MEM_ERROR || err == Z_DATA_ERROR) { job->setErrorMessage(QString(QObject::tr("zlib error %1")). arg(err)); inflateEnd(&d_stream); break; } else { if (sha1) hash.addData((char*) buffer2, buffer2Size - d_stream.avail_out); file->write((char*) buffer2, buffer2Size - d_stream.avail_out); } } while (d_stream.avail_out == 0); if (!job->getErrorMessage().isEmpty()) break; alreadyRead += bufferLength; if (contentLength > 0) { job->setProgress(((double) alreadyRead) / contentLength); job->setTitle(initialTitle + " / " + QString(QObject::tr("%L0 of %L1 bytes")). arg(alreadyRead). arg(contentLength)); } else { job->setProgress(0.5); job->setTitle(initialTitle + " / " + QString(QObject::tr("%L0 bytes")). arg(alreadyRead)); } } while (bufferLength != 0 && !job->isCancelled()); err = inflateEnd(&d_stream); if (err != Z_OK) { job->setErrorMessage(QString(QObject::tr("zlib error %1")). arg(err)); } if (sha1 && !job->isCancelled() && job->getErrorMessage().isEmpty()) *sha1 = hash.result().toHex().toLower(); // out: delete[] buffer; delete[] buffer2; if (!job->isCancelled() && job->getErrorMessage().isEmpty()) job->setProgress(1); job->complete(); }
// ----------------------------------------------------- // Lookup key in symbol table // If found, return pointer to corresponding value // If not found, return special pointer NOT_FOUND void* lookup( const_symtab table, const char* key ) { int bn = hash( key, NBuckets ); cell c = find_cell( table->bucket[ bn ], key ); return (c == NULL) ? NOT_FOUND : c->value; }
const struct keyword * in_word_set(register const char *str, register int len) { static const struct keyword wordlist[] = { {"",}, {"",}, {"",}, {"for", DBV_Prehistory, tFOR}, {"",}, {"endif", DBV_Prehistory, tENDIF}, {"endfor", DBV_Prehistory, tENDFOR}, {"e_range", DBV_Prehistory, tERROR, E_RANGE}, {"endwhile", DBV_Prehistory, tENDWHILE}, {"e_recmove", DBV_Prehistory, tERROR, E_RECMOVE}, {"",}, {"e_none", DBV_Prehistory, tERROR, E_NONE}, {"",}, {"e_propnf", DBV_Prehistory, tERROR, E_PROPNF}, {"fork", DBV_Prehistory, tFORK}, {"break", DBV_BreakCont, tBREAK}, {"endtry", DBV_Exceptions, tENDTRY}, {"endfork", DBV_Prehistory, tENDFORK}, {"",}, {"",}, {"",}, {"",}, {"finally", DBV_Exceptions, tFINALLY}, {"",}, {"",}, {"",}, {"",}, {"e_quota", DBV_Prehistory, tERROR, E_QUOTA}, {"",}, {"else", DBV_Prehistory, tELSE}, {"",}, {"elseif", DBV_Prehistory, tELSEIF}, {"",}, {"any", DBV_Exceptions, tANY}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"e_div", DBV_Prehistory, tERROR, E_DIV}, {"e_args", DBV_Prehistory, tERROR, E_ARGS}, {"e_varnf", DBV_Prehistory, tERROR, E_VARNF}, {"e_verbnf", DBV_Prehistory, tERROR, E_VERBNF}, {"",}, {"",}, {"e_perm", DBV_Prehistory, tERROR, E_PERM}, {"if", DBV_Prehistory, tIF}, {"",}, {"",}, {"",}, {"",}, {"in", DBV_Prehistory, tIN}, {"e_invind", DBV_Prehistory, tERROR, E_INVIND}, {"",}, {"while", DBV_Prehistory, tWHILE}, {"e_nacc", DBV_Prehistory, tERROR, E_NACC}, {"",}, {"continue", DBV_BreakCont, tCONTINUE}, {"",}, {"",}, {"e_type", DBV_Prehistory, tERROR, E_TYPE}, {"e_float", DBV_Float, tERROR, E_FLOAT}, {"e_invarg", DBV_Prehistory, tERROR, E_INVARG}, {"",}, {"",}, {"return", DBV_Prehistory, tRETURN}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"try", DBV_Exceptions, tTRY}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"e_maxrec", DBV_Prehistory, tERROR, E_MAXREC}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"except", DBV_Exceptions, tEXCEPT}, }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) { register int key = hash(str, len); if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE) { register const char *s = wordlist[key].name; if (*s == tolower(*str) && !case_strcmp(str + 1, s + 1)) return &wordlist[key]; } } return 0; }