/* Retrieve the value associated with key in the current thread, or NULL * if the current thread doesn't have an association for key. */ void * PyThread_get_key_value(int key) { struct key *p = find_key(key, NULL); if (p == NULL) return NULL; else return p->value; }
void release_key(uint32_t key_sym, uint32_t key_code) { uint8_t index = find_key(key_sym, key_code, true); if (index < KEY_STATE_MAX_LENGTH) { last_released.key_sym = key_state_array[index].key_sym; last_released.alt_sym = key_state_array[index].alt_sym; last_released.key_code = key_state_array[index].key_code; struct key_state none = { 0, 0, 0 }; key_state_array[index] = none; } }
int PyThread_set_key_value(int key, void *value) { struct key *p; p = find_key(1, key, value); if (p == NULL) return -1; else return 0; }
float Targets::get_G(string key) { int pos = find_key(key); if(pos == -1) { printf("Warning: Key '%s' not found in target keys!\n",key.c_str()); return 0.0; } else return Gs[pos]; }
static gboolean parse_line_file(char* buf, struct state_s* state) { struct config_key *key = NULL; char *p; unsigned len; len = strlen(buf); if (len <= 1) return TRUE; if (buf[len - 1] == '\n') { buf[len - 1] = '\0'; len--; } if (buf[len - 1] == '\r') { buf[len - 1] = '\0'; len--; } if (*buf == '[') { p = strchr (buf + 1, ']'); if (p) { *p = '\0'; if (state->secname) g_free (state->secname); state->secname = g_strdup (buf + 1); state->section = NULL; } } else { p = strchr (buf, '='); if (p) { *p++ = '\0'; if (!state->section && !state->secname) return TRUE; if (!state->section) find_key (state->filename, state->secname, buf, TRUE, NULL, &state->section, &key); else key = key_in_section (state->section, buf); if (key->value) g_free (key->value); key->value = g_strdup (p); } } return TRUE; }
void fast_sort(int arr[],int low,int high) { int keylocation; if(low<high) { keylocation=find_key(arr,low,high); fast_sort(arr,low,keylocation); fast_sort(arr,keylocation+1,high); } }
bool simple_dtable::present(const dtype & key, bool * found, ATX_DEF) const { size_t data_length; if(find_key(key, &data_length) < 0) { *found = false; return false; } *found = true; return data_length != (size_t) -1; }
static int tolua_region_getkey(lua_State * L) { region *self = (region *)tolua_tousertype(L, 1, 0); const char *name = tolua_tostring(L, 2, 0); int flag = atoi36(name); attrib *a = find_key(self->attribs, flag); lua_pushboolean(L, a != NULL); return 1; }
static size_t find_teacher_grade_key(const std::vector<std::string>& line, const std::string& path) { const static std::vector<std::string> keys = { "[Ik geef de docent(en) het volgende rapportcijfer] Ik geef de docent(en) het volgende rapportcijfer", "Ik geef de docent(en) het volgende rapportcijfer [Ik geef de docent(en) het volgende rapportcijfer]", "[I would rate the lecturer(s)/teacher(s)] On a scale from 1 to 10 (10 being excellent) I would rate the lecturer(s)/teacher(s)", "On a scale from 1 to 10 (10 being excellent) I would rate the lecturer(s)/teacher(s) [I would rate the lecturer(s)/teacher(s)]" }; return find_key(line, keys, path, "teacher_grade"); }
memUnit* findScript(char mode,unsigned char* cmd){ memUnit* prev_script; if(mode==CODE) prev_script =&first_script; else prev_script =&first_var; for(prev_script=&first_script; prev_script!=0; prev_script=prev_script->next) { if(find_key(prev_script->key, cmd)) return prev_script; } return 0; }
static void follow_key(oop_source *oop,const struct find *find) { struct find *next; struct gale_fragment frag; struct gale_location *base; struct gale_text name = gale_key_name(find->loc->key); struct gale_data name_data = gale_text_as_data(name); assert(NULL != find->func && find->is_found); if (!gale_group_lookup( gale_key_data(gale_key_public(find->loc->key,find->now)), G_("key.redirect"),frag_text,&frag) || (NULL != find->map && NULL != gale_map_find(find->map,name_data))) { key_i_graph(oop, find->loc->key, find->flags, G_("key.member"), on_graph,(void *) find); return; } gale_create(next); *next = *find; next->count = 0; next->is_found = 0; if (NULL == next->map) next->map = gale_make_map(0); gale_map_add(next->map,name_data,find->loc->key); base = client_i_get(gale_key_name(find->loc->key)); next->loc = client_i_get(frag.value.text); if (base != find->loc) { assert(base->at_part <= find->loc->at_part && base->at_part > 0 && !gale_text_compare( G_("*"), base->parts[base->at_part - 1])); next->loc = client_i_get(gale_text_concat(4, gale_text_concat_array( next->loc->at_part, next->loc->parts), G_("."), gale_text_concat_array( find->loc->at_part - base->at_part + 1, find->loc->parts + base->at_part - 1), gale_text_concat_array( next->loc->part_count - next->loc->at_part, next->loc->parts + next->loc->at_part))); } find_key(oop,next); }
int keypad_handle_key(keypad_t keypad, int key, void *cb_data) { ilist_iter_t iter; struct key_entry *entry; entry = find_key(&iter, keypad, key); if (!entry) return ENOENT; return entry->handler(key, cb_data); }
/*===========================================================================* * env_get_param * *===========================================================================*/ int env_get_param(const char *key, char *value, int max_len) { message m; static char mon_params[MULTIBOOT_PARAM_BUF_SIZE]; /* copy parameters here */ const char *key_value; int i, s; size_t keylen; if (key == NULL) return EINVAL; keylen= strlen(key); for (i= 1; i<env_argc; i++) { if (strncmp(env_argv[i], key, keylen) != 0) continue; if (strlen(env_argv[i]) <= keylen) continue; if (env_argv[i][keylen] != '=') continue; key_value= env_argv[i]+keylen+1; if (strlen(key_value)+1 > (size_t) max_len) return(E2BIG); strcpy(value, key_value); return OK; } /* Get copy of boot monitor parameters. */ m.m_type = SYS_GETINFO; m.m_lsys_krn_sys_getinfo.request = GET_MONPARAMS; m.m_lsys_krn_sys_getinfo.endpt = SELF; m.m_lsys_krn_sys_getinfo.val_len = sizeof(mon_params); m.m_lsys_krn_sys_getinfo.val_ptr = (vir_bytes)mon_params; if ((s=_kernel_call(SYS_GETINFO, &m)) != OK) { printf("SYS_GETINFO: %d (size %zu)\n", s, sizeof(mon_params)); return(s); } /* We got a copy, now search requested key. */ if ((key_value = find_key(mon_params, key)) == NULL) return(ESRCH); /* Value found, see if it fits in the client's buffer. Callers assume that * their buffer is unchanged on error, so don't make a partial copy. */ if ((strlen(key_value)+1) > (size_t) max_len) return(E2BIG); /* Make the actual copy. */ strcpy(value, key_value); return(OK); }
void Window::View::KeyDown(const char *bytes, int32 numBytes) { BMessage* m = Window()->CurrentMessage(); int32 key; if (B_OK == m->FindInt32("key", &key)) { Translator* t = NULL; if (numBytes == 1) { if (*bytes == B_FUNCTION_KEY) { t = find_key(key, fkey_translators, sizeof(fkey_translators)/sizeof(Translator)); } else { t = find_key(*bytes, key_translators, sizeof(key_translators)/sizeof(Translator)); } } if (t || numBytes == 1) { _event_queue->Lock(); if (_event_queue->IsEmpty()) release_sem(_locker); _event_queue->AddMessage(new BMessage(t ? t->grkey : *bytes)); _event_queue->Unlock(); return; } } BView::KeyDown(bytes, numBytes); }
ll_status_code linked_list_delete(linked_list **list, char *key){ linked_list **found = find_key(list, key); linked_list *cleaner; if (*found) { cleaner = *found; *found = (*found)->next; free(cleaner->kv.value); free(cleaner->kv.key); free(cleaner); } return LL_DELETE_OK; }
// This function tries to find the key/value pair identified by "key" // and returns either either: // - LL_VALUE_FOUND if the key was found in the linked list "l", in which case // it also assigns the associated value to "value" before returning // - LL_VALUE_NOT_FOUND if the "key" parameter can not be found in // the linked list, in which case NULL is assigned to "value" ll_status_code linked_list_get(linked_list *l, char *key, char **value) { linked_list **found = find_key(&l, key); if(*found){ *value = (*found)->kv.value; return LL_VALUE_FOUND; } else{ *value = NULL; return LL_VALUE_NOT_FOUND; } }
arcPTR ParseNoColoredArc(struct arc_object *arc, char *new_var) { list l=NULL; DomainObjPTR d; char *class_name = UNCOLORED_CLASS_NAME; if(arc->place->color != NULL) if((find_key(gListDomain, (generic_ptr) (arc->place)->tag , CmpDomainName, &l))==OK) { d = (DomainObjPTR) DATA(l); if(d->num_el == 1){ YACCobj_name = EmptyString(); LEXtoParsifyString = EmptyString(); sprintf(LEXtoParsifyString,"~f %d<%s>", arc->mult, new_var); yyparse(); } else Error(ERROR_REPETITIONS_AND_NO_FUNCTION, "NoColoredArc", (arc->place)->tag); } else Error(UNDEF_DOM_ERR, "NoColoredArc", (arc->place)->tag); else if((find_key(gListDomain, (generic_ptr) (arc->place)->tag, CmpDomainName, &l))==OK) { d = (DomainObjPTR) DATA(l); YACCobj_name = EmptyString(); LEXtoParsifyString = EmptyString(); sprintf(LEXtoParsifyString,"~f %d<S>", arc->mult); yyparse(); } else Error(UNKN_CLASS_ERR, "NoColoredArc", class_name); return(YACCparsedArc); }
static size_t find_course_grade_key(const std::vector<std::string>& line, const std::string& path) { const static std::vector<std::string> keys = { "[Ik geef deze cursus het volgende rapportcijfer] Ik geef deze cursus het volgende rapportcijfer", "Ik geef deze cursus het volgende rapportcijfer [Ik geef deze cursus het volgende rapportcijfer]", "[I would rate this course] On a scale from 1 to 10 (10 being excellent) I would rate this course", "On a scale from 1 to 10 (10 being excellent) I would rate this course [I would rate this course]", "Rating [I would rate this course overall as]", "Cijfer [Ik geef deze cursus als geheel het volgende cijfer]" }; return find_key(line, keys, path, "course_grade"); }
//validation template<class X> void splay_forest<X>::test_find (Pos eqn) { //test find_pair Pos pos = find_pair(get_root(eqn), get_key(eqn), get_val(eqn)); POMAGMA_ASSERT(pos, "invalid: eqn not found in own " << nameof<X>() << " tree"); POMAGMA_ASSERT(pos == eqn, "invalid: wrong eqn found in own " << nameof<X>() << " tree"); //test find_key pos = find_key(get_root(eqn), get_key(eqn)); POMAGMA_ASSERT(pos, "invalid: key not found in own " << nameof<X>() << " tree"); POMAGMA_ASSERT(get_key(pos) == get_key(eqn), "invalid: wrong key found in own " << nameof<X>() << " tree"); }
int keypad_unbind_key(keypad_t keypad, int key) { ilist_iter_t iter; struct key_entry *entry; entry = find_key(&iter, keypad, key); if (!entry) return ENOENT; ilist_delete(&iter); ipmi_mem_free(entry); return 0; }
int main() { std::ifstream cipher_file("assets/p059_cipher.txt"); std::string num; std::string cipher; while (std::getline(cipher_file, num, ',')) { cipher += (char)std::stoi(num); } std::string decrypted = find_key(cipher); int sum = std::accumulate(decrypted.begin(), decrypted.end(), 0); std::cout << "Sum of ASCII values of decrypted text: " << sum << "\n"; return 0; }
void press_key(uint32_t key_sym, uint32_t key_code) { if (key_code == 0) { return; } // Check if key exists if (!check_key(key_sym, key_code)) { // Check that we don't exceed buffer length int insert = find_key(0, 0, true); if (insert < KEY_STATE_MAX_LENGTH) { key_state_array[insert].key_sym = key_sym; key_state_array[insert].key_code = key_code; } } }
int parse_html(struct alist *parent, int sockfd) { char buf[BUF_LEN]; int size = (int)sizeof(buf); if (find_key("<title", sockfd, buf, size) == 0) { if (get_title(parent, sockfd, buf, size) != 0) { return 1; } printf("`%s`\n", parent->self->title); } while (find_key("<a ", sockfd, buf, size) == 0) { if (find_key("href=", sockfd, buf, size) == 0) { if (get_anchor(parent, sockfd, buf, size) != 0) { return 1; } } else { return 1; } } return 0; }
bool cf_set(const struct CfContext *cf, const char *sect, const char *key, const char *val) { const struct CfSect *s; const struct CfKey *k; void *base, *p; struct CfValue cv; /* find section */ s = find_sect(cf, sect); if (!s) { log_error("Unknown section: %s", sect); return false; } /* find section base */ base = cf->base; if (s->base_lookup) base = s->base_lookup(base, sect); /* handle dynamic keys */ if (s->set_key) return s->set_key(base, key, val); /* set fixed key */ k = find_key(s, key); if (!k) { log_error("Unknown parameter: %s/%s", sect, key); return false; } if (!k->op.setter || (k->flags & CF_READONLY)) { /* silently ignore */ return true; } if ((k->flags & CF_NO_RELOAD) && cf->loaded) { /* silently ignore */ return true; } p = get_dest(base, k); if (!p) { log_error("Bug - no base for relative key: %s/%s", sect, key); return false; } cv.key_name = k->key_name; cv.extra = k->op.op_extra; cv.value_p = p; cv.buf = NULL; cv.buflen = 0; return k->op.setter(&cv, val); }
const void * DNSSD_API TXTRecordGetValuePtr( uint16_t size, const void *buffer, const char *key, uint8_t *value_len) { const uint8_t *p; size_t n, l; AVAHI_WARN_LINKAGE; assert(key); if (!size) goto fail; if (*key == 0 || strchr(key, '=') || strlen(key) > 0xFF) /* Empty or invalid key */ return NULL; assert(buffer); if (!(p = find_key(buffer, size, key))) goto fail; n = *p; l = strlen(key); assert(n >= l); p += 1 + l; n -= l; if (n <= 0) goto fail; assert(*p == '='); p++; n--; if (value_len) *value_len = n; return p; fail: if (value_len) *value_len = 0; return NULL; }
static int tolua_region_setkey(lua_State * L) { region *self = (region *) tolua_tousertype(L, 1, 0); const char *name = tolua_tostring(L, 2, 0); int value = tolua_toboolean(L, 3, 0); int flag = atoi36(name); attrib *a = find_key(self->attribs, flag); if (a == NULL && value) { add_key(&self->attribs, flag); } else if (a != NULL && !value) { a_remove(&self->attribs, a); } return 0; }
blob simple_dtable::lookup(const dtype & key, bool * found, ATX_DEF) const { size_t data_length; off_t data_offset; int r = find_key(key, &data_length, &data_offset); if(r < 0) { *found = false; return blob(); } *found = true; if(data_length == (size_t) -1) return blob(); return get_value(data_length, data_offset); }
int find_key(int arr[], int top, int key, int bottom) { int mid; mid = (top + bottom)/2; if (bottom > top) { return - 1; } if (arr[mid] == key) // if found { return mid; } else if (arr[mid] < key) { return find_key(arr, top, key, mid + 1); // find key in second half of array + 1 } else if (arr[mid] > key) { return find_key(arr, mid - 1, key, bottom); // find key in first half of array } return - 1; }
/** Get floating point number from configuration in memory. * \param sectionname Name of the section where the key is sought. * \param keyname Name of the key to look for. * \param skip Number of values to skip/ignore before returning the value. * This is used to iterate through the values of a multi-valued key: * \c 0 for the first value, \c 1 for the 2nd, ... and \c -1 for the last. * \param default_value Default value if section/key is not found, value is no floating point number * or \c skip exceeds the number of values of the key. * \return Value found / \c default_value */ double config_get_float(const char *sectionname, const char *keyname, int skip, double default_value) { ConfigKey *k = find_key(find_section(sectionname), keyname, skip); if (k != NULL) { char *end; double v = strtod(k->value, &end); if ((end != NULL) && (end != k->value) && (*end == '\0')) /* Conversion successful*/ return v; } return default_value; }
/** Get integer from configuration in memory. * \param sectionname Name of the section where the key is sought. * \param keyname Name of the key to look for. * \param skip Number of values to skip/ignore before returning the value. * This is used to iterate through the values of a multi-valued key: * \c 0 for the first value, \c 1 for the 2nd, ... and \c -1 for the last. * \param default_value Default value if section/key is not found, value is no integer, * or \c skip exceeds the number of values of the key. * \return Value found / \c default_value */ long int config_get_int(const char *sectionname, const char *keyname, int skip, long int default_value) { ConfigKey *k = find_key(find_section(sectionname), keyname, skip); if (k != NULL) { char *end; long int v = strtol(k->value, &end, 0); if ((end != NULL) && (end != k->value) && (*end == '\0')) /* Conversion successful */ return v; } return default_value; }