/* clean up the client output buffers and slots in fd/buf arrays */ void discard_client_buffers(int pos) { UT_string **s = (UT_string**)utarray_eltptr(cfg.outbufs,pos); utstring_free(*s); // deep free string utarray_erase(cfg.outbufs,pos,1); // erase string pointer utarray_erase(cfg.outidxs,pos,1); // erase write index utarray_erase(cfg.clients,pos,1); // erase client descriptor }
int main() { UT_array *a; int i, *p; utarray_new(a, &ut_int_icd); for(i=0;i<10;i++) utarray_push_back(a,&i); for(p=(int*)utarray_front(a); p; p=(int*)utarray_next(a,p)) printf("%d ",*p); printf("\n"); utarray_sort(a,reverse); while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p); printf("\n"); utarray_erase(a,3,3); while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p); printf("\n"); utarray_erase(a,1,2); while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p); printf("\n"); utarray_erase(a,0,1); while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p); printf("\n"); utarray_erase(a,3,1); while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p); printf("\n"); utarray_resize(a,5); while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p); printf("\n"); utarray_resize(a,3); while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p); printf("\n"); utarray_erase(a,0,3); while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p); printf("\n"); utarray_free(a); return 0; }
/** @copydoc popup_button::event_func */ static int popup_button_event_func(popup_button *button) { size_t len; (void) button; len = utarray_len(book_help_history); if (len >= 2) { size_t pos; char **p; pos = len - 2; p = (char **) utarray_eltptr(book_help_history, pos); if (p) { help_show(*p); utarray_erase(book_help_history, pos, 2); } } else { utarray_clear(book_help_history); help_show("main"); } return 1; }
FCITX_EXPORT_API void FcitxCandidateWordRemoveByIndex(FcitxCandidateWordList *candList, int idx) { if (idx < 0 || idx >= utarray_len(&candList->candWords)) return; utarray_erase(&candList->candWords, idx, 1); }
char *mtex2MML_combine_row_data(UT_array **environment_data_stack) { /* if no information was provided, give a standard sizing */ if (utarray_len(*environment_data_stack) == 0) { const char* s = "rowspacing=\"0.5ex\" rowlines=\"none\""; char* c = (char*)malloc(strlen(s) + 1); strcpy(c, s); return c; } envdata_t *row_data_elem = (envdata_t*) utarray_front(*environment_data_stack); char *row_spacing_data = row_data_elem->rowspacing, *row_lines_data = row_data_elem->rowlines, *row_attr; UT_string *row_attr_data; utstring_new(row_attr_data); /* combine the row spacing and row lines data */ utstring_printf(row_attr_data, "%s%s\" %s\"", "rowspacing=\"", row_spacing_data, row_lines_data); row_attr = string_dup(utstring_body(row_attr_data)); utarray_erase(*environment_data_stack, 0, 1); utstring_free(row_attr_data); return row_attr; }
void drain_clients() { int rc, *fd, pos; char buf[1024]; fd=NULL; while ( (fd=(int*)utarray_next(cfg.fds,fd))) { do { rc = read(*fd, buf, sizeof(buf)); switch(rc) { default: fprintf(stderr,"received %d bytes\n", rc); break; case 0: fprintf(stderr,"fd %d closed\n", *fd); break; case -1: if (errno == EWOULDBLOCK || errno == EAGAIN) break; fprintf(stderr, "recv: %s\n", strerror(errno)); break; } } while(rc > 0); if (rc==0) { fprintf(stderr,"client %d has closed\n", *fd); close(*fd); *fd = -1; /* mark for cleanup after forward iteration */ } } /* cleanup any sockets that we closed, reverse iteration */ fd=NULL; while ( (fd=(int*)utarray_prev(cfg.fds,fd))) { pos = utarray_eltidx(cfg.fds,fd); if (*fd == -1) utarray_erase(cfg.fds,pos,1); } }
void hook_add_intl(int id, Plugin *host, Plugin *caller, hook_cb fn, int ev) { log_msg("HOOK", "ADD_INTL"); EventHandler *evh = get_event(ev); Hook hook = { id, HK_INTL, NULL, caller, host, NULL, .data.fn = fn }; utarray_push_back(evh->hooks, &hook); } static void hook_rm_container(UT_array *ary, Plugin *host, Plugin *caller) { for (int i = 0; i < utarray_len(ary); i++) { Hook *it = (Hook*)utarray_eltptr(ary, i); if (it->host == host && it->caller == caller) { log_err("HOOK", "RM_INTL"); utarray_erase(ary, i, 1); } } } void hook_rm_intl(Plugin *host, Plugin *caller, hook_cb fn, int ev) { log_msg("HOOK", "RM_INTL"); EventHandler *evh = get_event(ev); if (!evh) return; hook_rm_container(evh->hooks, host, caller); }
int param_reset(param_t param) { struct param_wbuf_s *s = NULL; bool param_found = false; param_lock(); if (handle_in_range(param)) { /* look for a saved value */ s = param_find_changed(param); /* if we found one, erase it */ if (s != NULL) { int pos = utarray_eltidx(param_values, s); utarray_erase(param_values, pos, 1); } param_found = true; } param_unlock(); if (s != NULL) { param_notify_changes(); } return (!param_found); }
FCITX_EXPORT_API void FcitxCandidateWordRemove(FcitxCandidateWordList* candList, FcitxCandidateWord* candWord) { int idx = utarray_eltidx(&candList->candWords, candWord); if (idx < 0 || idx >= utarray_len(&candList->candWords)) return; utarray_erase(&candList->candWords, idx, 1); }
void tiz_vector_erase (tiz_vector_t * p_vec, OMX_S32 a_pos, OMX_S32 a_len) { assert (p_vec); assert (a_pos >= 0); assert (a_len >= 0); utarray_erase (p_vec->p_uta, a_pos, a_len); }
int ATP_arrayErase(ATP_Array *p_array, unsigned int p_index) { if (p_index >= utarray_len(CAST(p_array))) { ERR("Index out of bounds\n"); return 0; } utarray_erase(CAST(p_array), p_index, 1); return 1; }
/** * Delete firewall rule. * @param[in] fire Firewall handle. * @param[in] proto Protocol. * @param[in] rule Rule type. * @param[in] port Port number (network order). */ void zfwall_del_rule(struct zfirewall *fire, enum ipproto proto, enum port_rule rule, uint16_t port) { pthread_spin_lock(&fire->lock); uint16_t *ptr = utarray_find(&fire->rules[proto][rule], &port, uint16_cmp); if (NULL != ptr) { size_t idx = utarray_eltidx(&fire->rules[proto][rule], ptr); utarray_erase(&fire->rules[proto][rule], idx, 1); } pthread_spin_unlock(&fire->lock); }
void hook_add(char *group, char *event, char *pattern, char *expr, int id) { log_msg("HOOK", "ADD"); log_msg("HOOK", "<%s> %s `%s`", event, pattern, expr); EventHandler *evh = get_event(event_idx(event)); if (!evh) return; expr = strip_quotes(expr); Pattern *pat = NULL; if (pattern) pat = regex_pat_new(pattern); Hook hook = { id, HK_CMD, NULL, NULL, NULL, pat, .data.cmd = expr }; augroup_insert(group, &hook); utarray_push_back(evh->hooks, &hook); } static void hook_delete(EventHandler *evh, Augroup *aug) { for (int i = 0; i < utarray_len(evh->hooks); i++) { Hook *it = (Hook*)utarray_eltptr(evh->hooks, i); if (it->type == HK_CMD && it->aug == aug) { free(it->data.cmd); utarray_erase(evh->hooks, i, 1); } } } void hook_remove(char *group, char *event, char *pattern) { log_msg("HOOK", "REMOVE"); log_msg("HOOK", "<%s> %s `%s`", event, pattern, group); Augroup *aug = NULL; if (group) HASH_FIND_STR(aug_tbl, group, aug); if (event) { EventHandler *evh = get_event(event_idx(event)); if (!evh) return; return hook_delete(evh, aug); } EventHandler *it; for (it = default_events; it != NULL; it = it->hh.next) hook_delete(it, aug); }
void hook_clear_host(int id) { log_msg("HOOK", "CLEAR HOST"); EventHandler *evh; for (evh = default_events; evh != NULL; evh = evh->hh.next) { for (int i = 0; i < utarray_len(evh->hooks); i++) { Hook *it = (Hook*)utarray_eltptr(evh->hooks, i); if (it->bufno == id) { if (it->type == HK_CMD) free(it->data.cmd); utarray_erase(evh->hooks, i, 1); } } } }
int main() { UT_array *a; int i, *p=NULL; utarray_new(a, &ut_int_icd); for(i=0;i<10;i++) utarray_push_back(a,&i); utarray_pop_back(a); utarray_erase(a,0,1); while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ",*p); printf("\n"); i = 100; utarray_insert(a,&i,3); while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ",*p); printf("\n"); utarray_extend_back(a); p = (int*)utarray_back(a); *p = 1000; p = NULL; while ( (p=(int*)utarray_next(a,p)) != NULL ) printf("%d ",*p); printf("\n"); utarray_clear(a); utarray_free(a); return 0; }
/** * Deactivate monitor connection. * @param[in] conn Monitor connection. */ void zmonitor_conn_deactivate(struct zmonitor_conn *conn) { assert(conn->active); if (conn->active) { pthread_rwlock_wrlock(&conn->mon->lock); struct zmonitor_conn **ptr = (struct zmonitor_conn **) utarray_front(&conn->mon->monitors); while (ptr) { if (*ptr == conn) { ssize_t idx = utarray_eltidx(&conn->mon->monitors, ptr); utarray_erase(&conn->mon->monitors, idx, 1); conn->active = false; break; } ptr = (struct zmonitor_conn **) utarray_next(&conn->mon->monitors, ptr); } pthread_rwlock_unlock(&conn->mon->lock); } }
void mtex2MML_perform_replacement(UT_array **environment_data_stack, UT_array *rowlines_stack, envType environment_type, UT_array *eqn_number_stack, UT_array *row_spacing_stack) { char *a, *attr_rowlines, *attr_rowspacing; envdata_t env_data; /* we cut the last char because we can always skip the first row */ if (utarray_len(rowlines_stack) != 0) { utarray_pop_back(rowlines_stack); } if (utarray_len(eqn_number_stack) > 1) { utarray_erase(eqn_number_stack, 0, 1); } unsigned int line_count = utarray_len(rowlines_stack); /* empty rowlines should be reset */ if (line_count == 0) { a = "none"; utarray_push_back(rowlines_stack, &a); } /* given the row_attribute values, construct an attribute list (separated by spaces) */ UT_string *l; utstring_new(l); char **o=NULL; a = "rowlines=\""; utstring_printf(l, "%s", a); while ( (o=(char**)utarray_prev(rowlines_stack,o))) { utstring_printf(l, "%s ", *o); } attr_rowlines = utstring_body(l); if (strlen(attr_rowlines) > 0) { mtex2MML_remove_last_char(attr_rowlines); /* remove the final space */ } /* given the row_spacing values, construct an attribute list (separated by spaces) */ UT_string *s; utstring_new(s); char **p=NULL; while ( (p=(char**)utarray_prev(row_spacing_stack,p))) { if (environment_type == ENV_SMALLMATRIX && strcmp(*p, "0.5ex") == 0) { utstring_printf(s, "%s ", "0.2em"); } else if (environment_type == ENV_GATHERED && strcmp(*p, "0.5ex") == 0) { utstring_printf(s, "%s ", "1.0ex"); } else { utstring_printf(s, "%s ", *p); } } attr_rowspacing = utstring_body(s); if (strlen(attr_rowspacing) > 0) { mtex2MML_remove_last_char(attr_rowspacing); /* remove the final space */ } else { if (environment_type == ENV_SMALLMATRIX) { attr_rowspacing = "0.2em"; } else if (environment_type == ENV_GATHERED) { attr_rowspacing = "1.0ex"; } else { attr_rowspacing = "0.5ex"; } } /* store pertinent metadata */ env_data.rowspacing = attr_rowspacing; env_data.rowlines = attr_rowlines; env_data.environment_type = environment_type; env_data.eqn_numbers = eqn_number_stack; env_data.line_count = line_count; utarray_push_back(*environment_data_stack, &env_data); utstring_free(l); utstring_free(s); }
static int param_set_internal(param_t param, const void *val, bool mark_saved) { int result = -1; bool params_changed = false; param_lock(); if (param_values == NULL) utarray_new(param_values, ¶m_icd); if (param_values == NULL) { debug("failed to allocate modified values array"); goto out; } if (handle_in_range(param)) { struct param_wbuf_s *s = param_find_changed(param); if (s == NULL) { /* construct a new parameter */ struct param_wbuf_s buf = { .param = param, .val.p = NULL, .unsaved = false }; /* add it to the array and sort */ utarray_push_back(param_values, &buf); utarray_sort(param_values, param_compare_values); /* find it after sorting */ s = param_find_changed(param); } /* update the changed value */ switch (param_type(param)) { case PARAM_TYPE_INT32: s->val.i = *(int32_t *)val; break; case PARAM_TYPE_FLOAT: s->val.f = *(float *)val; break; case PARAM_TYPE_STRUCT ... PARAM_TYPE_STRUCT_MAX: if (s->val.p == NULL) { s->val.p = malloc(param_size(param)); if (s->val.p == NULL) { debug("failed to allocate parameter storage"); goto out; } } memcpy(s->val.p, val, param_size(param)); break; default: goto out; } s->unsaved = !mark_saved; params_changed = true; result = 0; } out: param_unlock(); /* * If we set something, now that we have unlocked, go ahead and advertise that * a thing has been set. */ if (params_changed) param_notify_changes(); return result; } int param_set(param_t param, const void *val) { return param_set_internal(param, val, false); } void param_reset(param_t param) { struct param_wbuf_s *s = NULL; param_lock(); if (handle_in_range(param)) { /* look for a saved value */ s = param_find_changed(param); /* if we found one, erase it */ if (s != NULL) { int pos = utarray_eltidx(param_values, s); utarray_erase(param_values, pos, 1); } } param_unlock(); if (s != NULL) param_notify_changes(); } void param_reset_all(void) { param_lock(); if (param_values != NULL) { utarray_free(param_values); } /* mark as reset / deleted */ param_values = NULL; param_unlock(); param_notify_changes(); }