/*----------------------------------------------------------------------------- * 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; }
Bool parse_file(char *filename) { ParseCtx *ctx; OpenStruct *open_struct; int num_errors = get_num_errors(); ctx = ParseCtx_new(); if (opts.verbose) printf("Reading '%s'...\n", filename); /* display name of file */ src_push(); { if (src_open(filename, opts.inc_path)) { sym.tok = TK_NIL; while (sym.tok != TK_END) parseline(ctx); /* before parsing it */ open_struct = (OpenStruct *)utarray_back(ctx->open_structs); if (open_struct != NULL) error_unbalanced_struct_at(open_struct->filename, open_struct->line_nr); } } src_pop(); sym.tok = TK_NEWLINE; /* when called recursively, need to make tok != TK_NIL */ ParseCtx_delete(ctx); return num_errors == get_num_errors(); }
/* Create a new category with name <cat_name>. * The new category is pushed at the back of cat_table. * Aslo, a new hash entry is added for the category in cat_hash. * Return the newly created category. */ static cat_table_entry_t *MPIR_T_cat_create(const char *cat_name) { int cat_idx; cat_table_entry_t *cat; name2index_hash_t *hash_entry; /* New a category */ utarray_extend_back(cat_table); cat =(cat_table_entry_t *)utarray_back(cat_table); cat->name = MPL_strdup(cat_name); cat->desc = NULL; utarray_new(cat->cvar_indices, &ut_int_icd); utarray_new(cat->pvar_indices, &ut_int_icd); utarray_new(cat->subcat_indices, &ut_int_icd); /* Record <cat_name, cat_idx> in cat_hash */ cat_idx = utarray_len(cat_table) - 1; hash_entry = MPL_malloc(sizeof(name2index_hash_t)); MPIU_Assert(hash_entry); /* Need not to Strdup cat_name, since cat_table and cat_hash co-exist */ hash_entry->name = cat_name; hash_entry->idx = cat_idx; HASH_ADD_KEYPTR(hh, cat_hash, hash_entry->name, strlen(hash_entry->name), hash_entry); return cat; }
FCITX_EXPORT_API UT_array* fcitx_utils_string_list_append_no_copy(UT_array *list, char *str) { utarray_extend_back(list); *(char**)utarray_back(list) = str; return list; }
Token* cmdline_last(Cmdline *cmdline) { if (!cmdline->tokens || utarray_len(cmdline->tokens) < 1) return NULL; Token *word = (Token*)utarray_back(cmdline->tokens); return word; }
void hook_set_tmp(int id) { EventHandler *evh = get_event(id); if (!evh) return; Hook *hk = (Hook*)utarray_back(evh->hooks); hk->type = HK_TMP; }
/*----------------------------------------------------------------------------- * String pool for the current statement *----------------------------------------------------------------------------*/ static char *token_strings_add(ParseCtx *ctx, char *str) { if (!str) /* NULL string */ return NULL; utarray_push_back(ctx->token_strings, &str); return *((char **)utarray_back(ctx->token_strings)); }
/* code borrow from kde-workspace/kcontrol/keyboard/xkb_rules.cpp */ void RulesHandlerStartElement(void *ctx, const xmlChar *name, const xmlChar **atts) { FcitxXkbRulesHandler* ruleshandler = (FcitxXkbRulesHandler*) ctx; FcitxXkbRules* rules = ruleshandler->rules; utarray_push_back(ruleshandler->path, &name); char* strPath = fcitx_utils_join_string_list(ruleshandler->path, '/'); if ( StringEndsWith(strPath, "layoutList/layout/configItem") ) { utarray_extend_back(rules->layoutInfos); } else if ( StringEndsWith(strPath, "layoutList/layout/variantList/variant") ) { FcitxXkbLayoutInfo* layoutInfo = (FcitxXkbLayoutInfo*) utarray_back(rules->layoutInfos); utarray_extend_back(layoutInfo->variantInfos); } else if ( StringEndsWith(strPath, "modelList/model") ) { utarray_extend_back(rules->modelInfos); } else if ( StringEndsWith(strPath, "optionList/group") ) { utarray_extend_back(rules->optionGroupInfos); FcitxXkbOptionGroupInfo* optionGroupInfo = (FcitxXkbOptionGroupInfo*) utarray_back(rules->optionGroupInfos); int i = 0; while(atts && atts[i*2] != 0) { if (strcmp(XMLCHAR_CAST atts[i*2], "allowMultipleSelection") == 0) { optionGroupInfo->exclusive = (strcmp(XMLCHAR_CAST atts[i*2 + 1], "true") != 0); } i++; } } else if ( StringEndsWith(strPath, "optionList/group/option") ) { FcitxXkbOptionGroupInfo* optionGroupInfo = (FcitxXkbOptionGroupInfo*) utarray_back(rules->optionGroupInfos); utarray_extend_back(optionGroupInfo->optionInfos); } else if ( strcmp(strPath, "xkbConfigRegistry") == 0 ) { int i = 0; while(atts && atts[i*2] != 0) { if (strcmp(XMLCHAR_CAST atts[i*2], "version") == 0 && strlen(XMLCHAR_CAST atts[i*2 + 1]) != 0) { rules->version = strdup(XMLCHAR_CAST atts[i*2 + 1]); } i++; } } free(strPath); }
/* A low level, generic and internally used interface to register * a pvar to MPIR_T. Other modules should use interfaces defined * for concrete pvar classes. * * IN: varclass, MPI_T_PVAR_CLASS_* * IN: dtype, MPI datatype for this pvar * IN: name, Name of the pvar * IN: addr, Pointer to the pvar if known at registeration, otherwise NULL. * IN: count, # of elements of this pvar if known at registeration, otherwise 0. * IN: etype, MPI_T_enum or MPI_T_ENUM_NULL * IN: verb, MPI_T_PVAR_VERBOSITY_* * IN: binding, MPI_T_BIND_* * IN: flags, Bitwise OR of MPIR_T_R_PVAR_FLAGS_{} * IN: get_value, If not NULL, it is a callback to read the pvar. * IN: get_count, If not NULL, it is a callback to read count of the pvar. * IN: cat, Catogery name of the pvar * IN: desc, Description of the pvar */ void MPIR_T_PVAR_REGISTER_impl( int varclass, MPI_Datatype dtype, const char* name, void *addr, int count, MPIR_T_enum_t *etype, int verb, int binding, int flags, MPIR_T_pvar_get_value_cb get_value, MPIR_T_pvar_get_count_cb get_count, const char * cat, const char * desc) { name2index_hash_t *hash_entry; pvar_table_entry_t *pvar; int pvar_idx; int seq = varclass - MPIR_T_PVAR_CLASS_FIRST; /* Check whether this is a replicated pvar, whose name is unique per class */ HASH_FIND_STR(pvar_hashs[seq], name, hash_entry); if (hash_entry != NULL) { /* Found it, the pvar already exists */ pvar_idx = hash_entry->idx; pvar = (pvar_table_entry_t *)utarray_eltptr(pvar_table, pvar_idx); /* Should never override an existing & active var */ MPIU_Assert(pvar->active != TRUE); pvar->active = TRUE; /* FIXME: Do we need to check consistency between the old and new? */ } else { /* Not found, so push the pvar to back of pvar_table */ utarray_extend_back(pvar_table); pvar = (pvar_table_entry_t *)utarray_back(pvar_table); pvar->active = TRUE; pvar->varclass = varclass; pvar->datatype = dtype; pvar->name = MPL_strdup(name); MPIU_Assert(pvar->name); pvar->addr = addr; pvar->count = count; pvar->enumtype = etype; pvar->verbosity = verb; pvar->bind = binding; pvar->flags = flags; pvar->get_value = get_value; pvar->get_count = get_count; pvar->desc = MPL_strdup(desc); MPIU_Assert(pvar->desc); /* Record <name, index> in hash table */ pvar_idx = utarray_len(pvar_table) - 1; hash_entry = MPL_malloc(sizeof(name2index_hash_t)); MPIU_Assert(hash_entry); /* Need not to Strdup name, since pvar_table and pvar_hashs co-exist */ hash_entry->name = name; hash_entry->idx = pvar_idx; HASH_ADD_KEYPTR(hh, pvar_hashs[seq], hash_entry->name, strlen(hash_entry->name), hash_entry); /* Add the pvar to a category */ MPIR_T_cat_add_pvar(cat, utarray_len(pvar_table)-1); } }
/*----------------------------------------------------------------------------- * Read tokens from the current statement into tokensd[], to be parsed * by state machine *----------------------------------------------------------------------------*/ static void read_token(ParseCtx *ctx) { STR_DEFINE(buffer, STR_SIZE); Sym sym_copy; int p_index; int expr_start_index; p_index = ctx->p ? ctx->p - (Sym *)utarray_front(ctx->tokens) : -1; expr_start_index = ctx->expr_start ? ctx->expr_start - (Sym *)utarray_front(ctx->tokens) : -1; sym_copy = sym; /* make text to be used while concatenating tokens to build an expression to parse */ switch (sym_copy.tok) { case TK_NUMBER: str_sprintf(buffer, "%d", sym_copy.number); sym_copy.tstart = token_strings_add(ctx, str_data(buffer)); sym_copy.tlen = str_len(buffer); break; case TK_NAME: case TK_LABEL: case TK_STRING: break; case TK_END: sym_copy.tstart = ""; sym_copy.tlen = 0; break; default:; // if (!*(sym_copy.text)) // assert(*(sym_copy.text)); } // sym_copy.string = token_strings_add(sym.string); utarray_push_back(ctx->tokens, &sym_copy); ctx->p = (Sym *)utarray_front(ctx->tokens) + (p_index >= 0 ? p_index : 0); ctx->pe = (Sym *)utarray_back(ctx->tokens) + 1; if (sym.tok == TK_END) ctx->eof = ctx->pe; else ctx->eof = NULL; ctx->expr_start = expr_start_index >= 0 ? ((Sym *)utarray_front(ctx->tokens)) + expr_start_index : NULL; GetSym(); STR_DELETE(buffer); }
/* Add an item to an exisiting enum. * IN: handle, handle to the enum * IN: item_name, name of the item * IN: item_value, value associated with item_name */ void MPIR_T_enum_add_item(MPI_T_enum handle, const char *item_name, int item_value) { enum_item_t *item; MPIU_Assert(handle); MPIU_Assert(item_name); utarray_extend_back(handle->items); item = (enum_item_t *)utarray_back(handle->items); item->name = MPL_strdup(item_name); MPIU_Assert(item->name); item->value = item_value; }
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); } }
/*----------------------------------------------------------------------------- * IF, IFDEF, IFNDEF, ELSE, ENDIF *----------------------------------------------------------------------------*/ static void start_struct(ParseCtx *ctx, tokid_t open_tok, Bool condition) { OpenStruct *parent_os, os; os.open_tok = open_tok; os.filename = get_error_file(); os.line_nr = get_error_line(); os.active = condition; parent_os = (OpenStruct *)utarray_back(ctx->open_structs); if (parent_os) os.parent_active = parent_os->active && parent_os->parent_active; else os.parent_active = TRUE; utarray_push_back(ctx->open_structs, &os); }
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; }
/* Create an enum. * IN: enum_name, name of the enum * OUT: handle, handle of the enum */ void MPIR_T_enum_create(const char *enum_name, MPI_T_enum *handle) { MPIR_T_enum_t *e; static const UT_icd enum_item_icd = {sizeof(enum_item_t), NULL, NULL, NULL}; MPIU_Assert(enum_name); MPIU_Assert(handle); utarray_extend_back(enum_table); e = (MPIR_T_enum_t *)utarray_back(enum_table); e->name = MPL_strdup(enum_name); MPIU_Assert(e->name); #ifdef HAVE_ERROR_CHECKING e->kind = MPIR_T_ENUM_HANDLE; #endif utarray_new(e->items, &enum_item_icd); (*handle) = 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; }
static Value *findOrCreateEntry(ATP_Array *p_array, unsigned int p_index) { Value *l_entry; unsigned int l_length = utarray_len(CAST(p_array)); if (p_index > l_length) { ERR("Index out of bounds\n"); return NULL; } else if (p_index == l_length) { utarray_extend_back(CAST(p_array)); l_entry = (Value *) utarray_back(CAST(p_array)); } else { l_entry = (Value *) utarray_eltptr(CAST(p_array), p_index); } return l_entry; }
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); } } }
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); }
/* 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 RulesHandlerCharacters(void *ctx, const xmlChar *ch, int len) { FcitxXkbRulesHandler* ruleshandler = (FcitxXkbRulesHandler*) ctx; FcitxXkbRules* rules = ruleshandler->rules; char* temp = strndup(XMLCHAR_CAST ch, len); char* trimmed = fcitx_utils_trim(temp); free(temp); if ( strlen(trimmed) != 0 ) { char* strPath = fcitx_utils_join_string_list(ruleshandler->path, '/'); FcitxXkbLayoutInfo* layoutInfo = (FcitxXkbLayoutInfo*) utarray_back(rules->layoutInfos); FcitxXkbModelInfo* modelInfo = (FcitxXkbModelInfo*) utarray_back(rules->modelInfos); FcitxXkbOptionGroupInfo* optionGroupInfo = (FcitxXkbOptionGroupInfo*) utarray_back(rules->optionGroupInfos); if ( StringEndsWith(strPath, "layoutList/layout/configItem/name") ) { if ( layoutInfo != NULL ) layoutInfo->name = strdup(trimmed); } else if ( StringEndsWith(strPath, "layoutList/layout/configItem/description") ) { layoutInfo->description = strdup(trimmed); } else if ( StringEndsWith(strPath, "layoutList/layout/configItem/languageList/iso639Id") ) { utarray_push_back(layoutInfo->languages, &trimmed); } else if ( StringEndsWith(strPath, "layoutList/layout/variantList/variant/configItem/name") ) { FcitxXkbVariantInfo* variantInfo = (FcitxXkbVariantInfo*) utarray_back(layoutInfo->variantInfos); variantInfo->name = strdup(trimmed); } else if ( StringEndsWith(strPath, "layoutList/layout/variantList/variant/configItem/description") ) { FcitxXkbVariantInfo* variantInfo = (FcitxXkbVariantInfo*) utarray_back(layoutInfo->variantInfos); fcitx_utils_free(variantInfo->description); variantInfo->description = strdup(trimmed); } else if ( StringEndsWith(strPath, "layoutList/layout/variantList/variant/configItem/languageList/iso639Id") ) { FcitxXkbVariantInfo* variantInfo = (FcitxXkbVariantInfo*) utarray_back(layoutInfo->variantInfos); utarray_push_back(variantInfo->languages, &trimmed); } else if ( StringEndsWith(strPath, "modelList/model/configItem/name") ) { modelInfo->name = strdup(trimmed); } else if ( StringEndsWith(strPath, "modelList/model/configItem/description") ) { modelInfo->description = strdup(trimmed); } else if ( StringEndsWith(strPath, "modelList/model/configItem/vendor") ) { modelInfo->vendor = strdup(trimmed); } else if ( StringEndsWith(strPath, "optionList/group/configItem/name") ) { optionGroupInfo->name = strdup(trimmed); } else if ( StringEndsWith(strPath, "optionList/group/configItem/description") ) { optionGroupInfo->description = strdup(trimmed); } else if ( StringEndsWith(strPath, "optionList/group/option/configItem/name") ) { FcitxXkbOptionInfo* optionInfo = (FcitxXkbOptionInfo*) utarray_back(optionGroupInfo->optionInfos); optionInfo->name = strdup(trimmed); } else if ( StringEndsWith(strPath, "optionList/group/option/configItem/description") ) { FcitxXkbOptionInfo* optionInfo = (FcitxXkbOptionInfo*) utarray_back(optionGroupInfo->optionInfos); fcitx_utils_free(optionInfo->description); optionInfo->description = strdup(trimmed); } free(strPath); } free(trimmed); }
static Token* cmdline_parse(Cmdline *cmdline, Token *word, UT_array *parent) { char ch; bool seek; Cmdstr cmd = {.ed = 0}; if (word) cmd.st = word->start; QUEUE *stack = &cmd.stack; QUEUE_INIT(stack); cmd.args = list_new(cmdline); stack_push(stack, cmd.args); Token *headref = stack_head(stack); utarray_new(cmd.chlds, &chld_icd); check_flags(cmdline, &cmd); int idx = 0; while ((word = (Token*)utarray_next(cmdline->tokens, word))) { char *str = token_val(word, VAR_STRING); if (word->quoted) { push(*word, stack, word->start); pop(stack, cmdline, &idx); continue; } switch(ch = str[0]) { case '(': cmdline->lvl++; word = cmdline_parse(cmdline, word, cmd.chlds); ((Cmdstr*)utarray_back(cmd.chlds))->idx = idx - 1; if (!word) goto breakout; break; case ')': if (cmdline->lvl < 1) break; cmdline->lvl--; cmd.ed = word->start; goto breakout; case '[': push(list_new(cmdline), stack, word->start); stack_head(stack)->start = word->start; break; case ']': if (!valid_arry(cmdline, stack, headref)) break; stack_head(stack)->end = word->end; push_arry_container(cmdline, headref, word); pop(stack, cmdline, &idx); break; case '|': if (cmdline->lvl < 1) { cmd.bar = true; cmd.ed = word->start; goto breakout; } /*FALLTHROUGH*/ case '.': case ':': case ',': break; case '%': case '$': word = valid_var(cmdline, word, ch); case '!': if (valid_exec(cmdline, &cmd, word)) break; /*FALLTHROUGH*/ default: seek = seek_ahead(cmdline, stack, word); push(*word, stack, word->start); if (!seek) pop(stack, cmdline, &idx); } } breakout: while (!QUEUE_EMPTY(stack)) stack_pop(stack); utarray_push_back(parent, &cmd); return word; } void cmdline_build_tokens(Cmdline *cmdline, char *line) { log_msg("CMDSTR", "cmdline_build_tokens"); SWAP_ALLOC_PTR(cmdline->line, strdup(line)); Token *word = NULL; while ((word = (Token*)utarray_next(cmdline->tokens, word))) free(word->var.vval.v_string); utarray_clear(cmdline->tokens); cmdline_tokenize(cmdline); }
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); }
FCITX_EXPORT_API void FcitxUIRegisterComplexStatus( struct _FcitxInstance* instance, void* arg, const char* name, const char* shortDesc, const char* longDesc, void (*toggleStatus)(void *arg), const char*(*getIconName)(void *arg) ) { FcitxUIComplexStatus compstatus; memset(&compstatus, 0 , sizeof(FcitxUIComplexStatus)); compstatus.name = strdup(name); compstatus.shortDescription = strdup(shortDesc); compstatus.longDescription = strdup(longDesc); compstatus.getIconName = getIconName; compstatus.toggleStatus = toggleStatus; compstatus.arg = arg; compstatus.visible = true; UT_array* uicompstats = &instance->uicompstats; utarray_push_back(uicompstats, &compstatus); if (UI_FUNC_IS_VALID(RegisterComplexStatus)) instance->ui->ui->RegisterComplexStatus(instance->ui->addonInstance, (FcitxUIComplexStatus*) utarray_back(uicompstats)); if (UI_FUNC_IS_VALID_FALLBACK(RegisterComplexStatus)) instance->uifallback->ui->RegisterComplexStatus(instance->uifallback->addonInstance, (FcitxUIComplexStatus*) utarray_back(uicompstats)); }
FCITX_EXPORT_API void FcitxInstanceRealEnd(FcitxInstance* instance) { FcitxProfileSave(instance->profile); FcitxInstanceSaveAllIM(instance); if (instance->uinormal && instance->uinormal->ui->Destroy) instance->uinormal->ui->Destroy(instance->uinormal->addonInstance); if (instance->uifallback && instance->uifallback->ui->Destroy) instance->uifallback->ui->Destroy(instance->uifallback->addonInstance); instance->uifallback = NULL; instance->ui = NULL; instance->uinormal = NULL; /* handle exit */ FcitxAddon** pimclass; FcitxAddon** pfrontend; FcitxFrontend* frontend; FcitxInputContext* rec = NULL; for (pimclass = (FcitxAddon**)utarray_front(&instance->imeclasses); pimclass != NULL; pimclass = (FcitxAddon**)utarray_next(&instance->imeclasses, pimclass) ) { if ((*pimclass)->imclass->Destroy) (*pimclass)->imclass->Destroy((*pimclass)->addonInstance); } for (rec = instance->ic_list; rec != NULL; rec = rec->next) { pfrontend = (FcitxAddon**)utarray_eltptr(&instance->frontends, (unsigned int)rec->frontendid); frontend = (*pfrontend)->frontend; frontend->CloseIM((*pfrontend)->addonInstance, rec); } for (rec = instance->ic_list; rec != NULL; rec = rec->next) { pfrontend = (FcitxAddon**)utarray_eltptr(&instance->frontends, (unsigned int)rec->frontendid); frontend = (*pfrontend)->frontend; frontend->DestroyIC((*pfrontend)->addonInstance, rec); } for (pfrontend = (FcitxAddon**)utarray_front(&instance->frontends); pfrontend != NULL; pfrontend = (FcitxAddon**)utarray_next(&instance->frontends, pfrontend) ) { if (pfrontend == NULL) continue; FcitxFrontend* frontend = (*pfrontend)->frontend; frontend->Destroy((*pfrontend)->addonInstance); } FcitxAddon** pmodule; for (pmodule = (FcitxAddon**) utarray_back(&instance->modules); pmodule != NULL; pmodule = (FcitxAddon**) utarray_prev(&instance->modules, pmodule)) { if (pmodule == NULL) return; FcitxModule* module = (*pmodule)->module; if (module->Destroy) module->Destroy((*pmodule)->addonInstance); } if (instance->sem) { sem_post(instance->sem); } }
OMX_PTR tiz_vector_back (tiz_vector_t * p_vec) { assert (p_vec); return utarray_back (p_vec->p_uta); }
/* A low level, generic and internally used interface to register * a cvar to the MPIR_T. * * IN: dtype, MPI datatype for this cvar * IN: name, Name of the cvar * IN: addr, Pointer to the cvar if known at registeration, otherwise NULL. * IN: count, # of elements of this cvar if known at registeration, otherwise 0. * IN: etype, MPI_T_enum or MPI_T_ENUM_NULL * IN: verb, MPI_T_PVAR_VERBOSITY_* * IN: binding, MPI_T_BIND_* * IN: Scope, MPI_T_SCOPE_* * IN: get_addr, If not NULL, it is a callback to get address of the cvar. * IN: get_count, If not NULL, it is a callback to read count of the cvar. * IN: cat, Catogery name of the cvar * IN: desc, Description of the cvar */ void MPIR_T_CVAR_REGISTER_impl( MPI_Datatype dtype, const char* name, const void *addr, int count, MPIR_T_enum_t *etype, MPIR_T_verbosity_t verb, MPIR_T_bind_t binding, MPIR_T_scope_t scope, MPIR_T_cvar_get_addr_cb get_addr, MPIR_T_cvar_get_count_cb get_count, MPIR_T_cvar_value_t defaultval, const char *cat, const char * desc) { name2index_hash_t *hash_entry; cvar_table_entry_t *cvar; int cvar_idx; /* Check whether this is a replicated cvar, whose name is unique. */ HASH_FIND_STR(cvar_hash, name, hash_entry); if (hash_entry != NULL) { /* Found it, the cvar already exists */ cvar_idx = hash_entry->idx; cvar = (cvar_table_entry_t *)utarray_eltptr(cvar_table, cvar_idx); /* Should never override an existing & active var */ MPIU_Assert(cvar->active != TRUE); cvar->active = TRUE; /* FIXME: Do we need to check consistency between the old and new? */ } else { /* Not found, so push the cvar to back of cvar_table */ utarray_extend_back(cvar_table); cvar = (cvar_table_entry_t *)utarray_back(cvar_table); cvar->active = TRUE; cvar->datatype = dtype; cvar->name = MPL_strdup(name); MPIU_Assert(cvar->name); if (dtype != MPI_CHAR) { cvar->addr = (void *)addr; } else { cvar->addr = MPL_malloc(count); MPIU_Assert(cvar->addr); if (defaultval.str == NULL) { ((char *)(cvar->addr))[0] = '\0'; } else { /* Use greater (>), since count includes the terminating '\0', but strlen does not */ MPIU_Assert(count > strlen(defaultval.str)); strcpy(cvar->addr, defaultval.str); } } cvar->count = count; cvar->verbosity = verb; cvar->bind = binding; cvar->scope = scope; cvar->get_addr = get_addr; cvar->get_count = get_count; cvar->defaultval = defaultval; cvar->desc = MPL_strdup(desc); MPIU_Assert(cvar->desc); /* Record <name, index> in hash table */ cvar_idx = utarray_len(cvar_table) - 1; hash_entry = MPL_malloc(sizeof(name2index_hash_t)); MPIU_Assert(hash_entry); /* Need not to Strdup name, since cvar_table and cvar_hash co-exist */ hash_entry->name =name; hash_entry->idx = cvar_idx; HASH_ADD_KEYPTR(hh, cvar_hash, hash_entry->name, strlen(hash_entry->name), hash_entry); /* Add the cvar to a category */ MPIR_T_cat_add_cvar(cat, cvar_idx); } }
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); }