void tiz_vector_pop_back (tiz_vector_t * p_vec) { assert (p_vec); TIZ_LOG (TIZ_PRIORITY_TRACE, "poping back in vector [%p]", p_vec); utarray_pop_back (p_vec->p_uta); return; }
/*----------------------------------------------------------------------------- * Pop and return expression *----------------------------------------------------------------------------*/ static Expr *pop_expr(ParseCtx *ctx) { Expr *expr; expr = *((Expr **)utarray_back(ctx->exprs)); *((Expr **)utarray_back(ctx->exprs)) = NULL; /* do not destroy */ utarray_pop_back(ctx->exprs); return expr; }
int mtex2MML_fetch_eqn_number(UT_array **environment_data_stack) { /* if no information was provided, expect nothing */ if (utarray_len(*environment_data_stack) == 0) { return 0; } envdata_t *row_data_elem = (envdata_t*) utarray_front(*environment_data_stack); if (utarray_len(row_data_elem->eqn_numbers) == 0) { return 0; } int *e = (int*) utarray_back(row_data_elem->eqn_numbers); utarray_pop_back(row_data_elem->eqn_numbers); return *e; }
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; }
void restore_scan_state(void) { ScanState *save; init_module(); save = (ScanState *)utarray_back(scan_state); sym = save->sym; str_set(input_buf, save->input_buf); at_bol = save->at_bol; EOL = save->EOL; cs = save->cs; act = save->act; p = save->p >= 0 ? str_data(input_buf) + save->p : NULL; pe = save->pe >= 0 ? str_data(input_buf) + save->pe : NULL; eof = save->eof >= 0 ? str_data(input_buf) + save->eof : NULL; ts = save->ts >= 0 ? str_data(input_buf) + save->ts : NULL; te = save->te >= 0 ? str_data(input_buf) + save->te : NULL; // str_set(sym_string, save->sym_string); expect_opcode = save->expect_opcode; utarray_pop_back(scan_state); }
static void asm_ENDIF(ParseCtx *ctx) { OpenStruct *open_struct; open_struct = (OpenStruct *)utarray_back(ctx->open_structs); if (open_struct == NULL) error_unbalanced_struct(); else { switch (open_struct->open_tok) { case TK_IF: case TK_IFDEF: case TK_IFNDEF: case TK_ELSE: utarray_pop_back(ctx->open_structs); break; default: error_unbalanced_struct_at(open_struct->filename, open_struct->line_nr); } } }
static void overlord_apply_deferred_rules(struct zsession *sess) { if (utarray_len(&sess->client->deferred_rules)) { struct zcrules parsed_rules; uint64_t curr_clock = zclock(false); pthread_spin_lock(&sess->client->lock); crules_init(&parsed_rules); while (utarray_back(&sess->client->deferred_rules)) { struct zrule_deferred *rule = *(struct zrule_deferred **) utarray_back(&sess->client->deferred_rules); if (rule->when > curr_clock) { break; } if (0 != crules_parse(&parsed_rules, rule->rule)) { zero_syslog(LOG_INFO, "Failed to parse deferred rule '%s' for client %s", rule->rule, ipv4_to_str(htonl(sess->ip))); } else { zero_syslog(LOG_INFO, "Applying deferred rule '%s' for client %s", rule->rule, ipv4_to_str(htonl(sess->ip))); } free(rule->rule); free(rule); utarray_pop_back(&sess->client->deferred_rules); } pthread_spin_unlock(&sess->client->lock); client_apply_rules(sess->client, &parsed_rules); crules_free(&parsed_rules); } }
/* Runtime Error */ void postorderInterative(struct TreeNode* node, UT_array* v) { UT_array* stk; utarray_new(stk, &ut_ptr_icd); utarray_reserve(stk, 8); struct TreeNode* pre = NULL; while (utarray_len(stk) > 0 || node != NULL) { if (node != NULL) { utarray_push_back(stk, node); node = node->left; } else { struct TreeNode* tmp = utarray_back(stk); if (tmp->right != NULL && pre != tmp->right) { node = tmp->right; } else { utarray_pop_back(stk); utarray_push_back(v, &tmp->val); pre = tmp; } } } utarray_free(stk); }
void drop_scan_state(void) { init_module(); utarray_pop_back(scan_state); }
void RulesHandlerEndElement(void *ctx, const xmlChar *name) { FCITX_UNUSED(name); FcitxXkbRulesHandler* ruleshandler = (FcitxXkbRulesHandler*) ctx; utarray_pop_back(ruleshandler->path); }
void mtex2MML_env_replacements(UT_array **environment_data_stack, encaseType **encase, const char *environment) { /* TODO: these next detections are gross, but substack and cases are rather special */ if (strstr(environment, BEGIN_SUBSTACK) != NULL) { UT_array *eqn_number_stack; utarray_new(eqn_number_stack, &ut_int_icd); envdata_t env_data; env_data.rowspacing = ""; env_data.rowlines = ""; env_data.environment_type = ENV_SUBSTACK; env_data.eqn_numbers = eqn_number_stack; env_data.line_count = 0; utarray_push_back(*environment_data_stack, &env_data); utarray_free(eqn_number_stack); return; } if (strstr(environment, BEGIN_CASES) != NULL) { UT_array *eqn_number_stack; utarray_new(eqn_number_stack, &ut_int_icd); envdata_t env_data; env_data.rowspacing = ""; env_data.rowlines = ""; env_data.environment_type = ENV_CASES; env_data.eqn_numbers = eqn_number_stack; env_data.line_count = 0; utarray_push_back(*environment_data_stack, &env_data); utarray_free(eqn_number_stack); return; } /* if not an environment, don't bother going on */ if ((strstr(environment, BEGIN) == NULL && strstr(environment, END) == NULL) || strstr(environment, BEGIN_SVG)) { return; } UT_array *array_stack; UT_array *row_spacing_stack; UT_array *rowlines_stack; UT_array *eqn_number_stack; char *tok = NULL, *at_top = NULL, *temp = "", **prev_stack_item, *a, *em_str; unsigned int rowlines_stack_len = 0, eqn = 0, i = 0, insertion_idx = 0; char *dupe_environment = string_dup(environment); char *line = strtok(dupe_environment, "\n"); /* set up the array stack */ utarray_new(array_stack, &ut_str_icd); utarray_new(row_spacing_stack, &ut_str_icd); utarray_new(rowlines_stack, &ut_str_icd); utarray_new(eqn_number_stack, &ut_int_icd); while (line != NULL) { utarray_push_back(array_stack, &line); if (strstr(line, END) != NULL) { envType environment_type = mtex2MML_determine_environment(line); while (utarray_len(array_stack) > 0) { prev_stack_item = (char **)utarray_back(array_stack); rowlines_stack_len = utarray_len(rowlines_stack); at_top = strstr(*prev_stack_item, BEGIN); /* we've reached the top, but there looks like there might be some data */ if (at_top != NULL && strstr(*prev_stack_item, LINE_SEPARATOR) == NULL && \ strstr(*prev_stack_item, CR_SEPARATOR) == NULL && \ strstr(*prev_stack_item, NEWLINE_SEPARATOR) == NULL) { if (strstr(*prev_stack_item, HLINE) != NULL || strstr(*prev_stack_item, HDASHLINE) != NULL) { *encase = (encaseType*)TOPENCLOSE; } /* TODO: not super confident this is bulletproof */ if (rowlines_stack_len == 0) { eqn = mtex2MML_identify_eqn_number(environment_type, *prev_stack_item); utarray_push_back(eqn_number_stack, &eqn); } break; } /* these environments are a bit...special. they still use the same line separators, so they tend to mess with "proper" labelled environments, because they exist within \begin{equation} if we find one, erase all the stored row info. */ if (strstr(*prev_stack_item, "\\eqalign") != NULL || \ strstr(*prev_stack_item, "\\split") != NULL) { for (i = rowlines_stack_len; i > 1; i--) { utarray_pop_back(rowlines_stack); utarray_pop_back(eqn_number_stack); } } /* looking for a hline/hdashline match */ if (strstr(*prev_stack_item, HLINE) != NULL) { if (rowlines_stack_len > 0) { utarray_pop_back(rowlines_stack); } a = "solid"; utarray_push_back(rowlines_stack, &a); } else if (strstr(*prev_stack_item, HDASHLINE) != NULL) { if (rowlines_stack_len > 0) { utarray_pop_back(rowlines_stack); } a = "dashed"; utarray_push_back(rowlines_stack, &a); } else { a = "none"; utarray_push_back(rowlines_stack, &a); } eqn = mtex2MML_identify_eqn_number(environment_type, *prev_stack_item); utarray_push_back(eqn_number_stack, &eqn); /* if there's a line break... */ if (strstr(*prev_stack_item, LINE_SEPARATOR) != NULL || \ strstr(*prev_stack_item, CR_SEPARATOR) != NULL || \ strstr(*prev_stack_item, NEWLINE_SEPARATOR) != NULL) { /* ...with an emphasis match, add it... */ if ( (tok = strstr(*prev_stack_item, EM_PATTERN_BEGIN)) != NULL) { temp = tok + 2; /* skip the first part ("\[") */ if ( (tok = strstr(temp, EM_PATTERN_END)) != NULL) { mtex2MML_remove_last_char(temp); char *s = string_dup(temp); utarray_push_back(row_spacing_stack, &s); free(s); } } /* ...otherwise, use the default emphasis */ else { if (environment_type == ENV_SMALLMATRIX) { em_str = "0.2em"; } else if (environment_type == ENV_GATHERED) { em_str = "1.0ex"; } else if (environment_type == ENV_EQNARRAY || environment_type == ENV_ALIGNAT || environment_type == ENV_ALIGNED) { em_str = "3pt"; } else if (environment_type == ENV_MULTLINE || environment_type == ENV_MULTLINESTAR) { em_str = "0.5em"; } else { em_str = "0.5ex"; } utarray_push_back(row_spacing_stack, &em_str); } } /* make sure to pop at the end here; it messes with some references in Travis/Ubuntu for some reason */ utarray_pop_back(array_stack); /* we've reached the top, so stop. */ if (at_top != NULL) { break; } } /* some environments only have one label for the whole environment, rather than a label per row. in that case, jam a label in the middle. */ if (environment_type == ENV_GATHER || environment_type == ENV_MULTLINE) { insertion_idx = ceil(utarray_len(eqn_number_stack) / 2); eqn = 1; utarray_insert(eqn_number_stack, &eqn, insertion_idx); utarray_pop_back(eqn_number_stack); } mtex2MML_perform_replacement(environment_data_stack, rowlines_stack, environment_type, eqn_number_stack, row_spacing_stack); utarray_clear(row_spacing_stack); utarray_clear(rowlines_stack); utarray_clear(eqn_number_stack); rowlines_stack_len = 0; } line = strtok(NULL, "\n"); } utarray_free(array_stack); utarray_free(row_spacing_stack); utarray_free(rowlines_stack); utarray_free(eqn_number_stack); free(dupe_environment); }
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); }
FcitxAddon* FcitxAddonsLoadInternal(UT_array* addons, boolean reloadIM) { char **addonPath; size_t len; size_t start; if (!reloadIM) utarray_clear(addons); start = utarray_len(addons); FcitxStringHashSet* sset = FcitxXDGGetFiles("addon", NULL, ".conf"); addonPath = FcitxXDGGetPathWithPrefix(&len, "addon"); char *paths[len]; HASH_FOREACH(string, sset, FcitxStringHashSet) { // FIXME: if it will cause realloc, then it's evil for fcitx 4.2 series if (reloadIM && addons->i == addons->n) { break; } int i; for (i = len - 1; i >= 0; i--) { fcitx_utils_alloc_cat_str(paths[i], addonPath[len - i - 1], "/", string->name); FcitxLog(DEBUG, "Load Addon Config File:%s", paths[i]); } FcitxConfigFile* cfile = FcitxConfigParseMultiConfigFile(paths, len, FcitxAddonGetConfigDesc()); if (cfile) { utarray_extend_back(addons); FcitxAddon *a = (FcitxAddon*) utarray_back(addons); utarray_init(&a->functionList, fcitx_ptr_icd); FcitxAddonConfigBind(a, cfile, FcitxAddonGetConfigDesc()); FcitxConfigBindSync((FcitxGenericConfig*)a); FcitxLog(DEBUG, _("Addon Config %s is %s"), string->name, (a->bEnabled) ? "Enabled" : "Disabled"); boolean error = false; if (reloadIM) { if (a->category != AC_INPUTMETHOD) error = true; } /* if loaded, don't touch the old one */ if (FcitxAddonsGetAddonByNameInternal(addons, a->name, true) != a) error = true; if (error) utarray_pop_back(addons); else FcitxLog(INFO, _("Load Addon Config File:%s"), string->name); } for (i = len - 1;i >= 0;i--) { free(paths[i]); } } FcitxXDGFreePath(addonPath); fcitx_utils_free_string_hash_set(sset); size_t to = utarray_len(addons); utarray_sort_range(addons, AddonPriorityCmp, start, to); return (FcitxAddon*)utarray_eltptr(addons, start); }