datos_personaje_t *buscarPersonajePorSimbolo(datos_planificador_t *datosPlan, char simbolo) { int _is_personaje(datos_personaje_t *unPersonaje) { return unPersonaje->simbolo == simbolo; } datos_personaje_t *unPersonaje = NULL; pthread_mutex_lock(datosPlan->mutexColas); if (datosPlan->personajeEnMovimiento != NULL ) { if (datosPlan->personajeEnMovimiento->simbolo == simbolo) { unPersonaje = datosPlan->personajeEnMovimiento; } } if (unPersonaje == NULL ) { unPersonaje = list_find(datosPlan->personajesListos->elements, (void *) _is_personaje); } if (unPersonaje == NULL ) { unPersonaje = list_find(datosPlan->personajesBloqueados->elements, (void *) _is_personaje); } pthread_mutex_unlock(datosPlan->mutexColas); return unPersonaje; }
/* Determine if name is of type "corporate" or if it * should be added "as-is"; both should not be mangled. * * First check tag for prefixes ":CORP" and ":ASIS", * then optionally check lists, bailing if "corporate" * type can be identified. * * "corporate" is the same as "as-is" plus getting * special MODS treatment, so "corporate" type takes * priority */ static void name_determine_flags( int *ctf, int *clf, int *atf, int *alf, char *tag, char *data, list *asis, list *corps ) { int corp_tag_flag = 0, corp_list_flag = 0; int asis_tag_flag = 0, asis_list_flag = 0; if ( strstr( tag, ":CORP" ) ) corp_tag_flag = 1; else if ( list_find( corps, data ) != -1 ) corp_list_flag = 1; if ( strstr( tag, ":ASIS" ) ) { asis_tag_flag = 1; if ( list_find( corps, data ) != -1 ) corp_list_flag = 1; } else { if ( list_find( corps, data ) != -1 ) corp_list_flag = 1; else if ( list_find( asis, data ) != -1 ) asis_list_flag = 1; } *ctf = corp_tag_flag; *clf = corp_list_flag; *atf = asis_tag_flag; *alf = asis_list_flag; }
char buscarSimbolo(int i,global tabla){ bool _is_PID(t_player*personaje) { if(personaje->pid==i)return true; return false; } t_player*jugador; jugador=list_find(tabla.ready,(void*)_is_PID); if(jugador==NULL){ jugador=list_find(tabla.sleeps,(void*)_is_PID); if(jugador==NULL){ jugador=list_find(tabla.deads,(void*)_is_PID); if(jugador==NULL){ if(tabla.exe->player!=NULL)jugador=tabla.exe->player; else { if(mtexto)puts("NO SE ENCONTRO A NADIE"); if(mtexto)printf("Sym:X--%s\n",tabla.cabecera->name); return 'X'; } } } } if(jugador==NULL){ if(mtexto)puts("NO SE ENCONTRO A NADIE"); if(mtexto)printf("Sym:X--%s\n",tabla.cabecera->name); return 'X'; } if(mtexto)printf("Sym:%c--%s\n",jugador->sym,tabla.cabecera->name); return jugador->sym; }
int main() { list_t l = list_create(5); if (!l) { printf("list create error.\n"); return -1; } assert(1 == list_is_empty(l)); assert(0 == list_insert(l, (position_t)l, 333)); position_t p = list_first(l); assert(p->elm == 333); p = list_find(l, 333); assert(0 == list_insert(l, p, 444)); assert(p->elm == 333); p = list_find_previous(l, 444); assert(p->elm == 333); assert(p->next->elm == 444); p = list_find(l, 444); assert(p->elm == 444); list_make_empty(l); assert(NULL == list_find(l, 444)); list_destroy(l); return 0; }
static void * _routine_insert1(void *arg) { thread_t *thread = (thread_t *) arg; list_t *l = (list_t *) thread_arg(thread); long i; kerrno_t ret; kitem_t result; long t[] = {16, 14, 10, 12, 8, 6, 4, 2}; for (i = 0; i < sizeof(t)/sizeof(long); ++i) { ret = list_insert(l, thread, (kitem_t) t[i]); if (ret!=KSUCCESS && ret!=KEEXIST) kerror("insert error: %ld[%d]\n", t[i], ret); result = list_find(l, thread, (kitem_t) t[i]); if ((long) result != t[i]) kerror("find %ld error\n", t[i]); list_delete(l, thread, (kitem_t) t[i]); result = list_find(l, thread, (kitem_t) t[i]); if ((long) result != (long) KITEM_LONG_NULL) kerror("delete %ld[%ld] error\n", t[i], (long) result); } list_print(l, thread); return NULL; }
int luaX_script_load(lua_State *L) { const char *file = luaL_checkstring(L, 1); luna_script *result; luna_state *state = api_getstate(L); result = list_find(state->scripts, file, &script_cmp); if (result) { return luaL_error(L, "script '%s' already loaded", file); } else { if (!script_load(state, file)) { result = list_find(state->scripts, file, &script_cmp); return luaX_push_scriptinfo(L, result); } else { return luaL_error(L, "failed to load script '%s'", file); } } }
/* поиск значения по выбранному полю */ int find_mode(LPLIST lpList) { static int string; static char a[TEXT_LEN]; static DATE dt; int d, res = -1; printf("select field find\n"); printf("t - text change string\na - page\ns - string\nd - date\n"); switch (getch()) { case 't': /* фамилия */ printf("text = "); scanf("%s", a); res = list_index_of(lpList, list_find(lpList, FT_TIS, a)); break; case 'a': /* номер счета */ printf("page = "); scanf("%d", &d); res = list_index_of(lpList, list_find(lpList, FT_PAGE, (void*)d)); break; case 's': /* сумма на счете */ string = check_input_int("string = "); res = list_index_of(lpList, list_find(lpList, FT_STRING, &string)); break; case 'd': /* дата изменения */ printf("input date: dd mm yyyy \n"); do { d = check_input_int("day\t= "); } while (d < 1 || d > 31); dt.dmy.day = d; do { d = check_input_int("month\t= "); } while (d < 1 || d > 12); dt.dmy.month = d; do { d = check_input_int("year\t= "); } while (d < 1970 || d > 16000); dt.dmy.year = d; res = list_index_of(lpList, list_find(lpList, FT_DATE, (void*)&dt)); break; } return res; }
int main() { struct list *l; struct node *n; struct node *n1; printf("\ntesting node_create..."); n = node_create('e'); n1 = node_create('i'); if( n == NULL || n->c != 'e' || n->next != NULL ) goto fail; if( n1 == NULL || n1->c != 'i' || n1->next != NULL ) goto fail; printf("[ok]\n"); printf("\ntesting list_create..."); l = list_create(); if(l) printf("[ok]\n"); else goto fail; printf("testing list_add_head..."); list_add_head(l,n); if (l->head != n) goto fail; list_add_head(l,n1); if(l->head != n1) goto fail; printf("[ok]\n"); printf("testing list_find..."); if ( list_find( l, 'e' ) != n || list_find( l, 'i' ) != n1 ) goto fail; printf("[ok]\n"); printf("testing list_del..."); list_del(l, n); if(l->head == n) goto fail; else printf("[ok]\n"); printf("testing list_find..."); if ( list_find( l, 'e' ) != NULL || list_find( l, 'i' ) != n1 ) goto fail; printf("[ok]\n"); return 0; fail: printf("[failed]\n"); return -1; }
/* Code coverage test for Node and List functions. */ void test_task_f(void *user_data) { List l; Node n1; Node n2; list_init(&l); n1.prio = 3; n1.name = "one"; n2.prio = 8; n2.name = "two"; assert(true == list_is_empty(&l)); assert(NULL == list_get_head(&l)); list_add_tail(&l, &n1); assert(false == list_is_empty(&l)); assert(&n1 == list_get_head(&l)); list_add_tail(&l, &n2); assert(&n1 == list_get_head(&l)); assert(&n1 == list_find(&l, "one")); assert(&n2 == list_find(&l, "two")); list_rem_head(&l); assert(&n2 == list_get_head(&l)); assert(NULL == list_find(&l, "one")); list_rem_head(&l); list_enqueue(&l, &n1); assert(&n1 == list_get_head(&l)); list_enqueue(&l, &n2); assert(&n2 == list_get_head(&l)); list_unlink(&n1); assert(&n2 == list_get_head(&l)); list_enqueue(&l, &n1); assert(&n2 == list_get_head(&l)); assert(&n2 == list_rem_head(&l)); assert(&n1 == list_rem_head(&l)); assert(NULL == list_rem_head(&l)); assert(NULL == list_rem_head(&l)); assert(3 == n1.prio); assert(8 == n2.prio); assert(NULL == list_find(&l, "one")); assert(NULL == list_find(&l, "two")); test_pass(); }
void agregarBloqueANodoParaEnviar(infoBloque* bloque,infoNodo* nodo,respuestaSolicitudTransformacion* respuestaMaster,int job){ workerDesdeYama* worker; bloquesConSusArchivosTransformacion* bloquesArchivos = malloc(sizeof(bloquesConSusArchivosTransformacion)); bool nodoConNumero(workerDesdeYama* worker){ return worker->numeroWorker == nodo->numero; } if( list_find(respuestaMaster->workers, (void*) nodoConNumero)){ worker = list_find(respuestaMaster->workers, (void*) nodoConNumero); } else{ worker = malloc(sizeof(workerDesdeYama)); worker->numeroWorker = nodo->numero; worker->puerto = nodo->puerto; worker->ip.longitud = nodo->ip.longitud; worker->ip.cadena = strdup(nodo->ip.cadena); worker->bloquesConSusArchivos = list_create(); list_add(respuestaMaster->workers,worker); } char* rutaTemporal = dameUnNombreArchivoTemporal(job,bloque->numeroBloque,TRANSFORMACION,worker->numeroWorker); bloquesArchivos->numBloque = bloque->numeroBloque; bloquesArchivos->bytesOcupados = bloque->bytesOcupados; bloquesArchivos->archivoTemporal.cadena = strdup(rutaTemporal); bloquesArchivos->archivoTemporal.longitud = string_length(rutaTemporal); if(bloque->ubicacionCopia0.numeroNodo == nodo->numero){ bloquesArchivos->numBloqueEnNodo = bloque->ubicacionCopia0.numeroBloqueEnNodo; } else{ bloquesArchivos->numBloqueEnNodo = bloque->ubicacionCopia1.numeroBloqueEnNodo; } list_add(worker->bloquesConSusArchivos,bloquesArchivos); registroTablaEstados* registro = malloc(sizeof(registroTablaEstados)); registro->bloque= bloquesArchivos->numBloque; registro->estado=EN_EJECUCION; registro->etapa= TRANSFORMACION; registro->job = job; registro->nodo= nodo->numero; registro->rutaArchivoTemp = strdup(bloquesArchivos->archivoTemporal.cadena); pthread_mutex_lock(&mutexTablaEstados); list_add(tablaDeEstados,registro); pthread_mutex_unlock(&mutexTablaEstados); }
void test_list_move_to_middle( ) { list_type *list; list_type *ptr0, *ptr1; TEST_INIT("list_move_to (middle)", "tenstig"); list = create_testing(); ptr0 = list_find(list, (void *) 'n'); ptr1 = list_find(list, (void *) 's'); list = list_move_to(list, ptr0, ptr1); TEST_FINISH(list); }
/* copac names appear to always start with last name first, but don't * always seem to have a comma after the name * * editors seem to be stuck in as authors with the tag "[Editor]" in it */ static int copacin_person( fields *bibin, newstr *intag, newstr *invalue, int level, param *pm, char *outtag, fields *bibout ) { char *usetag = outtag, editor[]="EDITOR"; newstr usename, *s; list tokens; int comma = 0, i, ok; if ( list_find( &(pm->asis), invalue->data ) !=-1 || list_find( &(pm->corps), invalue->data ) !=-1 ) { ok = name_add( bibout, outtag, invalue->data, level, &(pm->asis), &(pm->corps) ); if ( ok ) return BIBL_OK; else return BIBL_ERR_MEMERR; } list_init( &tokens ); newstr_init( &usename ); list_tokenize( &tokens, invalue, " ", 1 ); for ( i=0; i<tokens.n; ++i ) { s = list_get( &tokens, i ); if ( !strcmp( s->data, "[Editor]" ) ) { usetag = editor; newstr_strcpy( s, "" ); } else if ( s->len && s->data[s->len-1]==',' ) { comma++; } } if ( comma==0 && tokens.n ) { s = list_get( &tokens, 0 ); newstr_addchar( s, ',' ); } for ( i=0; i<tokens.n; ++i ) { s = list_get( &tokens, i ); if ( s->len==0 ) continue; if ( i ) newstr_addchar( &usename, ' ' ); newstr_newstrcat( &usename, s ); } list_free( &tokens ); ok = name_add( bibout, usetag, usename.data, level, &(pm->asis), &(pm->corps) ); newstr_free( &usename ); if ( ok ) return BIBL_OK; else return BIBL_ERR_MEMERR; }
int main () { list_t* listPtr; #ifdef LIST_NO_DUPLICATES long data1[] = {3, 1, 4, 1, 5, -1}; #else long data1[] = {3, 1, 4, 5, -1}; #endif long data2[] = {3, 1, 4, 1, 5, -1}; long i; puts("Starting..."); puts("List sorted by values:"); listPtr = list_alloc(&compare); for (i = 0; data1[i] >= 0; i++) { insertInt(listPtr, &data1[i]); assert(*((long*)list_find(listPtr, &data1[i])) == data1[i]); } for (i = 0; data1[i] >= 0; i++) { removeInt(listPtr, &data1[i]); assert(list_find(listPtr, &data1[i]) == NULL); } list_free(listPtr); puts("List sorted by addresses:"); listPtr = list_alloc(NULL); for (i = 0; data2[i] >= 0; i++) { insertInt(listPtr, &data2[i]); assert(*((long*)list_find(listPtr, &data2[i])) == data2[i]); } for (i = 0; data2[i] >= 0; i++) { removeInt(listPtr, &data2[i]); assert(list_find(listPtr, &data2[i]) == NULL); } list_free(listPtr); puts("Done."); return 0; }
int ipv4_init(struct fins_module *module, uint32_t flows_num, uint32_t *flows, metadata_element *params, struct envi_record *envi) { PRINT_IMPORTANT("Entered: module=%p, params=%p, envi=%p", module, params, envi); module->state = FMS_INIT; module_create_structs(module); ipv4_init_params(module); module->data = secure_malloc(sizeof(struct ipv4_data)); struct ipv4_data *md = (struct ipv4_data *) module->data; if (module->flows_max < flows_num) { PRINT_ERROR("todo error"); return 0; } md->flows_num = flows_num; int i; for (i = 0; i < flows_num; i++) { md->flows[i] = flows[i]; } md->addr_list = list_create(IPV4_ADDRESS_LIST_MAX); list_for_each1(envi->if_list, ipv4_ifr_get_addr_func, md->addr_list); if (envi->if_loopback) { md->addr_loopback = (struct addr_record *) list_find(envi->if_loopback->addr_list, addr_is_v4); } if (envi->if_main) { md->addr_main = (struct addr_record *) list_find(envi->if_main->addr_list, addr_is_v4); } md->route_list = list_filter(envi->route_list, route_is_addr4, route_clone); if (md->route_list->len > IPV4_ROUTE_LIST_MAX) { PRINT_ERROR("todo"); struct linked_list *leftover = list_split(md->route_list, IPV4_ROUTE_LIST_MAX - 1); list_free(leftover, free); } md->route_list->max = IPV4_ROUTE_LIST_MAX; //when recv pkt would need to check addresses //when send pkt would need to check routing table & addresses (for ip address) //both of these would need to be updated by switch etc //routing_table = IP4_get_routing_table(); PRINT_DEBUG("after ip4 sort route table"); memset(&md->stats, 0, sizeof(struct ipv4_stats)); return 1; }
/* Get color item properties given an item (enumerated). * * On error, it aborts. * On success, the color item properties are returned, or NULL if no match * found. */ GColors * get_color (GColorItem item) { GColorItem normal = COLOR_NORMAL; GSLList *match = NULL; if ((match = list_find (color_list, find_color_item_in_list, &item))) return (GColors *) match->data; if ((match = list_find (color_list, find_color_item_in_list, &normal))) return (GColors *) match->data; /* should not get here */ FATAL ("Unable to find color item %d", item); }
/** Repeatedly looks for the specified item in the list using list_find() and removes all of the matching items. @param l The list to remove the items from @param item Remove all items that match this one @return 1 if success, 0 if fail. */ int list_remove_all(list *l, void *item) { int found = list_find(l, item); while(found >= 0) { list_remove(l, found, NULL); found = list_find(l, item); } if(found == -2) return 0; // fail if(found == -1) return 1; // success return 0; // fail }
/*! * Delete timer * \param timerid Timer descriptor (user descriptor) * \return status 0 for success */ int sys__timer_delete ( void *p ) { timer_t *timerid; ktimer_t *ktimer; int retval; kobject_t *kobj; timerid = *( (timer_t **) p ); ASSERT_ERRNO_AND_EXIT ( timerid, EINVAL ); kobj = timerid->ptr; ASSERT_ERRNO_AND_EXIT ( kobj, EINVAL ); ASSERT_ERRNO_AND_EXIT ( list_find ( &kobjects, &kobj->list ), EINVAL ); ktimer = kobj->kobject; ASSERT_ERRNO_AND_EXIT ( ktimer && ktimer->id == timerid->id, EINVAL ); retval = ktimer_delete ( ktimer ); kfree_kobject ( kobj ); EXIT ( retval ); }
ITEM_NIVEL* _search_item_by_id(t_list* items, char id) { bool _search_by_id(ITEM_NIVEL* item) { return item->id == id; } return list_find(items, (void*) _search_by_id); }
/*! * Decrement (lock) semaphore value by 1 (if not 0 when thread is blocked) * \param sem Semaphore descriptor (user level descriptor) * \return 0 if successful, -1 otherwise and appropriate error number is set */ int sys__sem_wait ( void *p ) { sem_t *sem; ksem_t *ksem; kobject_t *kobj; kthread_t *kthread; sem = *( (sem_t **) p ); ASSERT_ERRNO_AND_EXIT ( sem, EINVAL ); kthread = kthread_get_active (); kobj = sem->ptr; ASSERT_ERRNO_AND_EXIT ( kobj, EINVAL ); ASSERT_ERRNO_AND_EXIT ( list_find ( &kobjects, &kobj->list ), EINVAL ); ksem = kobj->kobject; ASSERT_ERRNO_AND_EXIT ( ksem && ksem->id == sem->id, EINVAL ); kthread_set_errno ( kthread, EXIT_SUCCESS ); if ( ksem->sem_value > 0 ) { ksem->sem_value--; ksem->last_lock = kthread; } else { kthread_enqueue ( kthread, &ksem->queue, 1, NULL, NULL ); kthreads_schedule (); } return EXIT_SUCCESS; }
/*! * Destroy semaphore object * \param sem Semaphore descriptor (user level descriptor) * \return 0 if successful, -1 otherwise and appropriate error number is set */ int sys__sem_destroy ( void *p ) { sem_t *sem; ksem_t *ksem; kobject_t *kobj; sem = *( (sem_t **) p ); ASSERT_ERRNO_AND_EXIT ( sem, EINVAL ); kobj = sem->ptr; ASSERT_ERRNO_AND_EXIT ( kobj, EINVAL ); ASSERT_ERRNO_AND_EXIT ( list_find ( &kobjects, &kobj->list ), EINVAL ); ksem = kobj->kobject; ASSERT_ERRNO_AND_EXIT ( ksem && ksem->id == sem->id, EINVAL ); ASSERT_ERRNO_AND_EXIT (kthreadq_get (&ksem->queue) == NULL, ENOTEMPTY); ksem->ref_cnt--; /* additional cleanup here (e.g. if semaphore is shared leave it) */ if ( ksem->ref_cnt ) EXIT2 ( EBUSY, EXIT_FAILURE ); kfree_kobject ( kobj ); sem->ptr = NULL; sem->id = 0; EXIT2 ( EXIT_SUCCESS, EXIT_SUCCESS ); }
/*! * Destroy conditional variable object * \param cond conditional variable descriptor (user level descriptor) * \return 0 if successful, -1 otherwise and appropriate error number is set */ int sys__pthread_cond_destroy ( void *p ) { pthread_cond_t *cond; kpthread_cond_t *kcond; kobject_t *kobj; cond = *( (pthread_cond_t **) p ); ASSERT_ERRNO_AND_EXIT ( cond, EINVAL ); kobj = cond->ptr; ASSERT_ERRNO_AND_EXIT ( kobj, EINVAL ); ASSERT_ERRNO_AND_EXIT ( list_find ( &kobjects, &kobj->list ), EINVAL ); kcond = kobj->kobject; ASSERT_ERRNO_AND_EXIT ( kcond && kcond->id == cond->id, EINVAL ); kcond->ref_cnt--; /* additional cleanup here (e.g. if cond.var. is shared leave it) */ if ( kcond->ref_cnt ) EXIT2 ( EBUSY, EXIT_FAILURE ); kfree_kobject ( kobj ); cond->ptr = NULL; cond->id = 0; EXIT2 ( EXIT_SUCCESS, EXIT_SUCCESS ); }
/*! * Unlock mutex object * \param mutex Mutex descriptor (user level descriptor) * \return 0 if successful, -1 otherwise and appropriate error number is set */ int sys__pthread_mutex_unlock ( void *p ) { pthread_mutex_t *mutex; kpthread_mutex_t *kmutex; kobject_t *kobj; mutex = *( (pthread_mutex_t **) p ); ASSERT_ERRNO_AND_EXIT ( mutex, EINVAL ); kobj = mutex->ptr; ASSERT_ERRNO_AND_EXIT ( kobj, EINVAL ); ASSERT_ERRNO_AND_EXIT ( list_find ( &kobjects, &kobj->list ), EINVAL ); kmutex = kobj->kobject; ASSERT_ERRNO_AND_EXIT ( kmutex && kmutex->id == mutex->id, EINVAL ); if ( kmutex->owner != kthread_get_active() ) { SET_ERRNO ( EPERM ); return EXIT_FAILURE; } SET_ERRNO ( EXIT_SUCCESS ); kmutex->owner = kthreadq_get ( &kmutex->queue ); if ( kmutex->owner ) { kthreadq_release ( &kmutex->queue ); kthreads_schedule (); } return EXIT_SUCCESS; }
/*! * Lock mutex object * \param mutex Mutex descriptor (user level descriptor) * \return 0 if successful, -1 otherwise and appropriate error number is set */ int sys__pthread_mutex_lock ( void *p ) { pthread_mutex_t *mutex; kpthread_mutex_t *kmutex; kobject_t *kobj; int retval = EXIT_SUCCESS; mutex = *( (pthread_mutex_t **) p ); ASSERT_ERRNO_AND_EXIT ( mutex, EINVAL ); kobj = mutex->ptr; ASSERT_ERRNO_AND_EXIT ( kobj, EINVAL ); ASSERT_ERRNO_AND_EXIT ( list_find ( &kobjects, &kobj->list ), EINVAL ); kmutex = kobj->kobject; ASSERT_ERRNO_AND_EXIT ( kmutex && kmutex->id == mutex->id, EINVAL ); retval = mutex_lock ( kmutex, kthread_get_active () ); if ( retval == 1 ) kthreads_schedule (); return retval != -1; }
void desserializeMapResult(void *buffer, size_t offset, t_job *job) { bool result; uint16_t idMap; void *bufferOffset = buffer + offset; memcpy(&result, bufferOffset, sizeof(result)); bufferOffset += sizeof(result); memcpy(&idMap, bufferOffset, sizeof(idMap)); free(buffer); idMap = ntohs(idMap); bool findMap(t_map *map) { return isMap(map, idMap); } t_map *map = list_find(job->maps, (void *) findMap); uint16_t cantMaps = list_size(job->maps); log_info(logger, "|JOB %d| Map(%d/%d): %d Done on Node: %s -> Result: %d", job->id, job->mapsDone, cantMaps, map->id, map->nodeName, result); removeMapNode(map); if (result) { map->done = true; job->mapsDone++; } else { pthread_mutex_lock(&Mnodes); deactivateNode(map->nodeName); pthread_mutex_unlock(&Mnodes); if (!rePlanMap(job, map)) notifFileUnavailable(job); } }
pagina_t* buscar_pagina_segun_id_en_lista_paginas(uint16_t id_pagina, t_list* lista_paginas){ bool _es_pagina(pagina_t* pagina) { return pagina->id==id_pagina; } pagina_t* pagina_requerida =(pagina_t*)list_find(lista_paginas, (void*) _es_pagina); return pagina_requerida; }
/* ============================================================================= * hashtable_remove * -- Returns TRUE if successful, else FALSE * ============================================================================= */ bool_t hashtable_remove (hashtable_t* hashtablePtr, void* keyPtr) { long numBucket = hashtablePtr->numBucket; long i = hashtablePtr->hash(keyPtr) % numBucket; list_t* chainPtr = hashtablePtr->buckets[i]; pair_t* pairPtr; pair_t removePair; removePair.firstPtr = keyPtr; pairPtr = (pair_t*)list_find(chainPtr, &removePair); if (pairPtr == NULL) { return FALSE; } bool_t status = list_remove(chainPtr, &removePair); assert(status); pair_free(pairPtr); #ifdef HASHTABLE_SIZE_FIELD hashtablePtr->size--; assert(hashtablePtr->size >= 0); #endif return TRUE; }
/* replace_strings() * * do string replacement -- only if unprotected by quotation marks or curly brackets */ static void replace_strings( list *tokens, fields *bibin ) { int i, n, ok; newstr *s; char *q; i = 0; while ( i < tokens->n ) { s = list_get( tokens, i ); if ( !strcmp( s->data, "#" ) ) { } else if ( s->data[0]!='\"' && s->data[0]!='{' ) { n = list_find( &find, s->data ); if ( n!=-1 ) { newstr_newstrcpy( s, list_get( &replace, n ) ); } else { q = s->data; ok = 1; while ( *q && ok ) { if ( !isdigit( *q ) ) ok = 0; q++; } if ( !ok ) { fprintf( stderr, "%s: Warning: Non-numeric " "BibTeX elements should be in quotations or " "curly brackets in reference.\n", progname ); } } } i++; } }
/* process_string() * * Handle lines like: * * '@STRING{TL = {Tetrahedron Lett.}}' * * p should point to just after '@STRING' * * In BibTeX, if a string is defined several times, the last one is kept. * */ static int process_string( char *p ) { int n, status = BIBL_OK; newstr s1, s2, *t; newstrs_init( &s1, &s2, NULL ); while ( *p && *p!='{' && *p!='(' ) p++; if ( *p=='{' || *p=='(' ) p++; p = process_bibtexline( skip_ws( p ), &s1, &s2, 0, NULL ); if ( p==NULL ) { status = BIBL_ERR_MEMERR; goto out; } if ( s2.data ) { newstr_findreplace( &s2, "\\ ", " " ); } if ( s1.data ) { n = list_find( &find, s1.data ); if ( n==-1 ) { t = list_add( &find, &s1 ); if ( t==NULL ) { status = BIBL_ERR_MEMERR; goto out; } if ( s2.data ) t = list_add( &replace, &s2 ); else t = list_addc( &replace, "" ); if ( t==NULL ) { status = BIBL_ERR_MEMERR; goto out; } } else { if ( s2.data ) t = list_set( &replace, n, &s2 ); else t = list_setc( &replace, n, "" ); if ( t==NULL ) { status = BIBL_ERR_MEMERR; goto out; } } } out: newstrs_free( &s1, &s2, NULL ); return status; }
/** * Rezerwuje ciągły obszar w danym segmencie. * @param vseg deskryptor segmentu. * @param size rozmiar ciągłego obszaru. * @param _res adres zmiennej, do uzupełnienia przydzielonym adresem. */ int vm_seg_reserve(vm_seg_t *vseg, vm_size_t size, void *_res) { int expand = EXPAND_UP; vm_addr_t *res = _res; size = PAGE_ROUND(size); vm_region_t *region = list_head(&vseg->regions); if (region == NULL) { if (do_first_region(vseg, ®ion)) return -1; } // sprawdzamy czy istnieje dziura pomiędzy początkiem segmentu // a pierwszym regionem if (size < region->begin - vseg->base) { *res = region->begin - size; return expand_region(vseg, region, size, EXPAND_DOWN, _res); } // Ok, no to szukamy dziury za regionem region = list_find(&vseg->regions, has_hole_after_reg, size); if (region == NULL) { if (vseg->flags & VM_SEG_EXPDOWN) { expand = EXPAND_DOWN; region = list_head(&vseg->regions); *res = region->begin - size; } else { region = list_tail(&vseg->regions); *res = region->end; } } else { *res = region->end; } return expand_region(vseg, region, size, expand, _res); }
/*! * Get timer expiration time * \param timerid Timer descriptor (user descriptor) * \param value Where to store time to next timer expiration (+period) * \return status 0 for success */ int sys__timer_gettime ( void *p ) { timer_t *timerid; itimerspec_t *value; ktimer_t *ktimer; int retval; kobject_t *kobj; timerid = *( (timer_t **) p ); p += sizeof (timer_t *); value = *( (itimerspec_t **) p ); ASSERT_ERRNO_AND_EXIT ( timerid, EINVAL ); kobj = timerid->ptr; ASSERT_ERRNO_AND_EXIT ( kobj, EINVAL ); ASSERT_ERRNO_AND_EXIT ( list_find ( &kobjects, &kobj->list ), EINVAL ); ktimer = kobj->kobject; ASSERT_ERRNO_AND_EXIT ( ktimer && ktimer->id == timerid->id, EINVAL ); retval = ktimer_gettime ( ktimer, value ); EXIT ( retval ); }