Example #1
0
File: skin.c Project: areslp/fcitx
void LoadSkinDirectory(FcitxClassicUI* classicui)
{
    UT_array* skinBuf = &classicui->skinBuf;
    utarray_clear(skinBuf);
    int i ;
    DIR *dir;
    struct dirent *drt;
    struct stat fileStat;
    size_t len;
    char **skinPath = FcitxXDGGetPathWithPrefix(&len, "skin");
    for (i = 0; i < len; i++) {
        dir = opendir(skinPath[i]);
        if (dir == NULL)
            continue;

        while ((drt = readdir(dir)) != NULL) {
            if (strcmp(drt->d_name , ".") == 0 ||
                    strcmp(drt->d_name, "..") == 0)
                continue;
            char *pathBuf;
            fcitx_utils_alloc_cat_str(pathBuf, skinPath[i], "/", drt->d_name);
            int statresult = stat(pathBuf, &fileStat);
            free(pathBuf);
            if (statresult == -1)
                continue;
            if (S_ISDIR(fileStat.st_mode)) {
                /* check duplicate name */
                int j = 0;
                for (; j < skinBuf->i; j++) {
                    char **name = (char**) utarray_eltptr(skinBuf, j);
                    if (strcmp(*name, drt->d_name) == 0)
                        break;
                }
                if (j == skinBuf->i) {
                    char *temp = drt->d_name;
                    utarray_push_back(skinBuf, &temp);
                }
            }
        }

        closedir(dir);
    }

    FcitxXDGFreePath(skinPath);

    return;
}
Example #2
0
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;
}
Example #3
0
UT_array* CharSelectDataFind(CharSelectData* charselect, const char* needle)
{
    UnicodeSet *result = NULL;

    UT_array* returnRes;
    utarray_new(returnRes, fcitx_int32_icd);
    char* simplified = Simplified(needle);
    UT_array* searchStrings = SplitString(simplified);

    if (strlen(simplified) == 1) {
        // search for hex representation of the character
        utarray_clear(searchStrings);
        char* format = FormatCode(simplified[0], 4, "U+");
        utarray_push_back(searchStrings, &format);
        free(format);
    }
    free(simplified);

    if (utarray_len(searchStrings) == 0) {
        return returnRes;
    }

    utarray_foreach(s, searchStrings, char*) {
        char* end = NULL;
        if(IsHexString(*s)) {
            end = NULL;
            uint32_t uni = (uint32_t) strtoul(*s + 2, &end, 16);
            utarray_push_back(returnRes, &uni);

            // search for "1234" instead of "0x1234"
            char* news = strdup(*s + 2);
            free(*s);
            *s = news;
        }
        // try to parse string as decimal number
        end = NULL;
        uint32_t unicode = (uint32_t) strtoul(*s, &end, 10);
        if (*end == '\0') {
            utarray_push_back(returnRes, &unicode);
        }
    }
Example #4
0
void compl_update(fn_context *cx, char *line)
{
  log_msg("COMPL", "compl_update");
  if (!cx || !line || !cx->cmpl)
    return;

  line = strip_shell(line);

  fn_compl *cmpl = cx->cmpl;
  cmpl->matchcount = 0;
  utarray_clear(cmpl->matches);

  for (int i = 0; i < cmpl->rowcount; i++) {
    char *key = cmpl->rows[i]->key;
    if (fuzzy_match(key, line)) {
      utarray_push_back(cmpl->matches, cmpl->rows[i]);
      cmpl->matchcount++;
    }
  }
  utarray_sort(cmpl->matches, cmp_match, line);
  free(line);
}
Example #5
0
File: skin.c Project: areslp/fcitx
void ParsePlacement(UT_array* sps, char* placment)
{
    UT_array* array = fcitx_utils_split_string(placment, ';');
    char** str;
    utarray_clear(sps);
    for (str = (char**) utarray_front(array);
            str != NULL;
            str = (char**) utarray_next(array, str)) {
        char* s = *str;
        char* p = strchr(s, ':');
        if (p == NULL)
            continue;

        int len = p - s;
        SkinPlacement sp;
        sp.name = strndup(s, len);
        int ret = sscanf(p + 1, "%d,%d", &sp.x, &sp.y);
        if (ret != 2)
            continue;
        utarray_push_back(sps, &sp);
    }

    utarray_free(array);
}
Example #6
0
FCITX_EXPORT_API
boolean FcitxInstanceLoadFrontend(FcitxInstance* instance)
{
    UT_array* addons = &instance->addons;
    UT_array* frontends = &instance->frontends;
    FcitxAddon *addon;
    int frontendindex = 0;
    utarray_clear(frontends);
    for (addon = (FcitxAddon *) utarray_front(addons);
            addon != NULL;
            addon = (FcitxAddon *) utarray_next(addons, addon)) {
        if (addon->bEnabled && addon->category == AC_FRONTEND) {
            char *modulePath;
            switch (addon->type) {
            case AT_SHAREDLIBRARY: {
                FILE *fp = FcitxXDGGetLibFile(addon->library, "r", &modulePath);
                void *handle;
                FcitxFrontend* frontend;
                if (!fp)
                    break;
                fclose(fp);
                handle = dlopen(modulePath, RTLD_LAZY | RTLD_GLOBAL);
                if (!handle) {
                    FcitxLog(ERROR, _("Frontend: open %s fail %s") , modulePath , dlerror());
                    break;
                }

                if (!CheckABIVersion(handle)) {
                    FcitxLog(ERROR, "%s ABI Version Error", addon->name);
                    dlclose(handle);
                    break;
                }

                frontend = dlsym(handle, "frontend");
                if (!frontend || !frontend->Create) {
                    FcitxLog(ERROR, _("Frontend: bad frontend"));
                    dlclose(handle);
                    break;
                }
                if ((addon->addonInstance = frontend->Create(instance, frontendindex)) == NULL) {
                    dlclose(handle);
                    break;
                }
                addon->frontend = frontend;
                frontendindex ++;
                utarray_push_back(frontends, &addon);
            }
            break;
            default:
                break;
            }
            free(modulePath);
        }
    }

    if (utarray_len(&instance->frontends) <= 0) {
        FcitxLog(ERROR, _("No available frontend"));
        return false;
    }
    return true;
}
Example #7
0
FCITX_EXPORT_API
void FcitxMenuClear(FcitxUIMenu* menu)
{
    utarray_clear(&menu->shell);
}
Example #8
0
FCITX_EXPORT_API
void FcitxCandidateWordReset(FcitxCandidateWordList* candList)
{
    utarray_clear(&candList->candWords);
    candList->currentPage = 0;
}
Example #9
0
bool cmdline_parse(const char * cmdline) {
    enum parser_state state = search_option_start;

    size_t i = 0;
    char c = cmdline[0];
    size_t option_start = -1;
    size_t value_start = -1;

    char * name = 0;
    char * value = 0;
    UT_array *values;
    //kprintf("creating values array\n");
    utarray_new(values, &ut_str_icd);

    while(c) {
        //kprintf("state=%d c=%c\n", state, c);
        switch(state) {
        case search_option_start:
            if(c != ' ') {
                state = search_option_end;
                option_start = i;
            }
            break;
        case search_option_end:
            if(c == ' ') {
                state = search_option_start;
                name = strndup(cmdline + option_start, i - option_start);
                cmdline_option_add(name, values);
                kfree(name);
                name = 0;
            } else if(c == '=') {
                state = search_value_start;
                name = strndup(cmdline + option_start, i - option_start);
            }
            break;
        case search_value_start:
            if(c == ' ') {
                state = search_option_start;
            } else {
                state = search_value_end;
                value_start = i;
            }
            break;
        case search_value_end:
            if(c == ' ') {
                state = search_option_start;
                value = strndup(cmdline + value_start, i - value_start);
                //kprintf("found value %s end at i=%ld start=%ld\n", value, i, value_start);
                value_start = -1;
                utarray_push_back(values, &value);
                cmdline_option_add(name, values);
                kfree(name);
                name = 0;
                utarray_clear(values);
            } else if(c == ',') {
                state = search_value_start;
                value = strndup(cmdline + value_start, i - value_start);
                //kprintf("found value %s end at i=%ld start=%ld\n", value, i, value_start);
                value_start = -1;
                utarray_push_back(values, &value);
            }
            break;
        }

        // loop
        i++;
        c = cmdline[i];
    }

    if(name) {
        //kprintf("found option %s\n", name);
        if(value_start != -1) {
            value = strndup(cmdline + value_start, i - value_start);
            //kprintf("found value %s end at i=%ld start=%ld\n", value, i, value_start);
            utarray_push_back(values, &value);
        }
        cmdline_option_add(name, values);
        kfree(name);
    }

    utarray_free(values);
}
Example #10
0
static void free_tokens(ParseCtx *ctx)
{
	utarray_clear(ctx->tokens);
	utarray_clear(ctx->token_strings);
	utarray_clear(ctx->exprs);
}
Example #11
0
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);
}
Example #12
0
static UT_array *
lcsubstrings(unicode *seq1, unicode *seq2,
             Py_ssize_t len1, Py_ssize_t len2, Py_ssize_t *max_len)
{
	Py_ssize_t i, j, mlen = -1;
	Py_ssize_t old, last, *column;
	UT_array *stack = NULL;
	struct pair_t pos;
#ifdef SEQUENCE_COMP
	int comp;
#endif
	
	assert(len1 >= len2);
	
	utarray_new(stack, &pair_icd);
	
	if (len2 == 0) {
		*max_len = 0;
		return stack;
	}
	
	if ((column = (Py_ssize_t *)malloc((len2 + 1) * sizeof(Py_ssize_t))) == NULL)
		goto On_Error;
	
	last = 0;
	for (j = 0; j < len2; j++)
		column[j] = j;
	
	for (i = 0; i < len1; i++) {
		for (j = 0; j < len2; j++) {
			old = column[j];
#ifdef SEQUENCE_COMP
			comp = SEQUENCE_COMP(seq1, i, seq2, j);
			if (comp == -1)
				goto On_Error;
			if (comp) {
#else
			if (seq1[i] == seq2[j]) {
#endif
				column[j] = ((i == 0 || j == 0) ? 1 : (last + 1));
				if (column[j] > mlen) {
					mlen = column[j];
					pos.i = i;
					pos.j = j;
					utarray_clear(stack);
					utarray_push_back(stack, &pos);
				}
				else if (column[j] == mlen) {
					pos.i = i;
					pos.j = j;
					utarray_push_back(stack, &pos);
				}
			}
			else
				column[j] = 0;
			last = old;
		}
	}
	
	free(column);

	*max_len = mlen;
	return stack;
	
	On_Error:
		free(column);
		utarray_free(stack);
		return NULL;
}
Example #13
0
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);
}
Example #14
0
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);
}
Example #15
0
File: Array.c Project: awm/atp
void ATP_arrayClear(ATP_Array *p_array)
{
    utarray_clear(CAST(p_array));
}