Ejemplo n.º 1
0
FCITX_EXPORT_API
void FcitxCandidateWordInsertPlaceHolder(FcitxCandidateWordList* candList, int position)
{
    FcitxCandidateWord candWord;
    memset(&candWord, 0, sizeof(FcitxCandidateWord));
    candWord.callback = DummyHandler;
    utarray_insert(&candList->candWords, &candWord, position);
}
Ejemplo n.º 2
0
OMX_ERRORTYPE
tiz_vector_insert (tiz_vector_t * p_vec, OMX_PTR ap_data, OMX_S32 a_pos)
{
  assert (p_vec);
  assert (a_pos > 0);
  assert (ap_data);
  utarray_insert (p_vec->p_uta, ap_data, a_pos);
  return OMX_ErrorNone;
}
Ejemplo n.º 3
0
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");
  printf("len: %u\n\n", utarray_len(a));
  
  i=10; utarray_insert(a, &i, 10);
  while ( (p=(int*)utarray_next(a,p))) printf("%d ", *p); printf("\n");
  printf("len: %u\n\n", utarray_len(a));

  utarray_free(a);
  return 0;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
0
static void
py_enhance_load_py(PinyinEnhance *pyenhance)
{
    UT_array *array = &pyenhance->py_list;
    if (array->icd)
        return;
    utarray_init(array, fcitx_ptr_icd);
    FILE *fp;
    char *fname;
    fname = fcitx_utils_get_fcitx_path_with_filename(
        "pkgdatadir", "py-enhance/"PY_TABLE_FILE);
    fp = fopen(fname, "r");
    free(fname);
    if (fp) {
        FcitxMemoryPool *pool = pyenhance->static_pool;
        char buff[UTF8_MAX_LENGTH + 1];
        int buff_size = 33;
        int8_t *list_buff = malloc(buff_size);
        size_t res;
        int8_t word_l;
        int8_t count;
        int8_t py_size;
        int i;
        int8_t *py_list;
        int8_t *tmp;
        /**
         * Format:
         * int8_t word_l;
         * char word[word_l];
         * int8_t count;
         * int8_t py[count][3];
         **/
        while (true) {
            res = fread(&word_l, 1, 1, fp);
            if (!res || word_l < 0 || word_l > UTF8_MAX_LENGTH)
                break;
            res = fread(buff, word_l + 1, 1, fp);
            if (!res)
                break;
            count = buff[word_l];
            if (count < 0)
                break;
            if (count == 0)
                continue;
            py_size = count * 3;
            if (buff_size < py_size) {
                buff_size = py_size;
                list_buff = realloc(list_buff, buff_size);
            }
            res = fread(list_buff, py_size, 1, fp);
            if (!res)
                break;
            py_list = fcitx_memory_pool_alloc(pool, word_l + py_size + 3);
            py_list[0] = word_l + 1;
            py_list++;
            memcpy(py_list, buff, word_l);
            tmp = py_list + word_l;
            *tmp = '\0';
            tmp++;
            *tmp = count;
            memcpy(tmp + 1, list_buff, py_size);
            for (i = utarray_len(array) - 1;i >= 0;i--) {
                if (strcmp(*(char**)_utarray_eltptr(array, i),
                           (char*)py_list) < 0) {
                    break;
                }
            }
            utarray_insert(array, &py_list, i + 1);
        }
        free(list_buff);
        fclose(fp);
    }
}
Ejemplo n.º 6
0
FCITX_EXPORT_API
void FcitxCandidateWordInsert(FcitxCandidateWordList* candList, FcitxCandidateWord* candWord, int position)
{
    utarray_insert(&candList->candWords, candWord, position);
}
Ejemplo n.º 7
0
static void
py_enhance_load_py(PinyinEnhance *pyenhance)
{
    UT_array *array = &pyenhance->py_list;
    if (array->icd)
        return;
    utarray_init(array, fcitx_ptr_icd);
    FILE *fp;
    char *fname;
    fname = fcitx_utils_get_fcitx_path_with_filename(
        "pkgdatadir", "py-enhance/"PY_TABLE_FILE);
    fp = fopen(fname, "r");
    free(fname);
    if (fp) {
        FcitxMemoryPool *pool = pyenhance->static_pool;
        char buff[UTF8_MAX_LENGTH + 1];
        int buff_size = 33;
        int8_t *list_buff = malloc(buff_size);
        size_t res;
        int8_t word_l;
        int8_t count;
        int8_t min_size;
        FcitxPYEnhancePYList *py_list;
        int i;
        FcitxPYEnhancePY *py;
        while (true) {
            res = fread(&word_l, 1, 1, fp);
            if (!res || word_l < 0 || word_l > UTF8_MAX_LENGTH)
                break;
            res = fread(buff, word_l, 1, fp);
            if (!res)
                break;
            res = fread(&count, 1, 1, fp);
            if (!res || count < 0)
                break;
            if (count == 0)
                continue;
            min_size = count * 3;
            if (buff_size < min_size) {
                buff_size = min_size;
                list_buff = realloc(list_buff, buff_size);
            }
            res = fread(list_buff, min_size, 1, fp);
            if (!res)
                break;
            py_list = fcitx_memory_pool_alloc_align(
                pool, (sizeof(FcitxPYEnhancePYList) +
                       sizeof(FcitxPYEnhancePY) * count), 1);
            memcpy(py_list->word, buff, word_l);
            py_list->word[word_l] = '\0';
            py_list->count = count;
            for (i = 0;i < count;i++) {
                py = pinyin_enhance_pylist_get(py_list, i);
                int8_t *tmp = list_buff + i * 3;
                py->konsonant = tmp[0];
                py->vokal = tmp[1];
                py->tone = tmp[2];
            }
            for (i = utarray_len(array) - 1;i >= 0;i--) {
                FcitxPYEnhancePYList *ele;
                ele = *(FcitxPYEnhancePYList**)_utarray_eltptr(array, i);
                if (strcmp(ele->word, py_list->word) < 0) {
                    break;
                }
            }
            utarray_insert(array, &py_list, i + 1);
        }
        free(list_buff);
        fclose(fp);
    }
}
Ejemplo n.º 8
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);
}