コード例 #1
0
ファイル: trie.c プロジェクト: JSefara/foma
void fsm_trie_add_word(struct fsm_trie_handle *th, char *word) {
    int i, len;
    char *wcopy;
    wcopy = xxstrdup(word);
    len = strlen(wcopy);
    for (i=0 ; *word != '\0' && i < len; word = word + utf8skip(word)+1, i++) {
	strncpy(wcopy, word, utf8skip(word)+1);
	*(wcopy+utf8skip(word)+1) = '\0';
	fsm_trie_symbol(th, wcopy, wcopy);
    }
    xxfree(wcopy);
    fsm_trie_end_word(th);
}
コード例 #2
0
ファイル: utf8.c プロジェクト: StudioEtrange/foma
int utf8strlen(char *str) {
    int i,j, len;
    len = strlen(str);
    for (i=0, j=0; *(str+i) != '\0' && i < len;j++ ) {
        i = i + utf8skip(str+i) + 1;
    }
    return j;
}
コード例 #3
0
ファイル: utf8.c プロジェクト: StudioEtrange/foma
void decode_quoted(char *s) {
    int len, i, j, skip;
    unsigned char *unistr;
    
    len = strlen(s);
    for (i=0, j=0; i < len; ) {
        if (*(s+i) == 0x5c && len-i > 5 && *(s+i+1) == 0x75 && ishexstr(s+i+2)) {
            for (unistr=utf8code16tostr(s+i+2); *unistr; j++, unistr++) {
                *(s+j) = *unistr;
            }
            i += 6;
        } else {
            for(skip = utf8skip(s+i)+1; skip > 0; skip--) {
                *(s+j) = *(s+i);
                i++; j++;
            }
        }
    }
    *(s+j) = *(s+i);
}
コード例 #4
0
ファイル: flags.c プロジェクト: unhammer/hfst3
char *flag_get_name(char *string) {
    int i, start, end, len;
    start = end = 0;
    len = strlen(string);

    for (i=0; i < len; i += (utf8skip(string+i) + 1)) {
	if (*(string+i) == '.' && start == 0) {
	    start = i+1;
	    continue;
	}
	if ((*(string+i) == '.' || *(string+i) == '@')  && start != 0) {
	    end = i;
	    break;
	}
    }
    if (start > 0 && end > 0) {
	return(xxstrndup(string+start,end-start));
    }
    return NULL;
}
コード例 #5
0
bool menu_animation_ticker(const menu_animation_ctx_ticker_t *ticker)
{
   size_t str_len = utf8len(ticker->str);
   size_t offset  = 0;

   if ((size_t)str_len <= ticker->len)
   {
      utf8cpy(ticker->s,
            PATH_MAX_LENGTH,
            ticker->str,
            ticker->len);
      return true;
   }

   if (!ticker->selected)
   {
      utf8cpy(ticker->s, PATH_MAX_LENGTH, ticker->str, ticker->len - 3);
      strlcat(ticker->s, "...", PATH_MAX_LENGTH);
      return true;
   }

   if (str_len > ticker->len)
      menu_animation_ticker_generic(
            ticker->idx,
            ticker->len,
            &offset,
            &str_len);

   utf8cpy(
         ticker->s,
         PATH_MAX_LENGTH,
         utf8skip(ticker->str, offset),
         str_len);

   animation_is_active = true;

   return true;
}
コード例 #6
0
ファイル: apply.c プロジェクト: JSefara/foma
void apply_create_sigmatch(struct apply_handle *h) {
    char *symbol;
    struct sigma_trie *st;
    int i, j, inlen, lastmatch, consumes, cons;
    /* We create a sigmatch array only in case we match against a real string */
    if (((h->mode) & ENUMERATE) == ENUMERATE) {
	return;
    }
    symbol = h->instring;
    inlen = strlen(symbol);
    h->current_instring_length = inlen;
    if (inlen >= h->sigmatch_array_size) {
	xxfree(h->sigmatch_array);
	h->sigmatch_array = xxmalloc(sizeof(struct sigmatch_array)*(inlen));
	h->sigmatch_array_size = inlen;
    }
    /* Find longest match in alphabet at current position */
    /* by traversing the trie of alphabet symbols         */
    for (i=0; i < inlen; i += consumes ) {
	st = h->sigma_trie;
	for (j=0, lastmatch = 0; ; j++) {
	    if (*(symbol+i+j) == '\0') {
		break;
	    }
	    st = st+(unsigned char)*(symbol+i+j);
	    if (st->signum != 0) {
		lastmatch = st->signum;
		if (st->next == NULL)
		    break;
		st = st->next;
	    } else if (st->next != NULL) {
		st = st->next;
	    } else {
		break;
	    }
	}
	if (lastmatch != 0) {
	    (h->sigmatch_array+i)->signumber = lastmatch;
	    consumes = (h->sigs+lastmatch)->length;
	} else {
	    /* Not found in trie */
	    (h->sigmatch_array+i)->signumber = IDENTITY;
	    consumes = utf8skip(symbol+i)+1;
	}

	/* If we now find trailing unicode combining characters (0300-036F):      */
	/* (1) Merge them all with current symbol                                 */
	/* (2) Declare the whole sequence one ? (IDENTITY) symbol                 */
        /*     Step 2 is motivated by the fact that                               */
	/*     if the input is S(symbol) + D(diacritic)                           */
        /*     and SD were a symbol in the alphabet, then this would have been    */
        /*     found when searching the alphabet symbols earlier, so SD+ => ?     */
        /*     Note that this means that a multi-char symbol followed by a        */
        /*     diacritic gets converted to a single ?, e.g.                       */
        /*     [TAG] + D => ? if [TAG] is in the alphabet, but [TAG]+D isn't.     */

	for (  ; cons = utf8iscombining((unsigned char *)(symbol+i+consumes)); consumes += cons) {
	    (h->sigmatch_array+i)->signumber = IDENTITY;
	}
	(h->sigmatch_array+i)->consumes = consumes;
    }
}
コード例 #7
0
ファイル: stdstring.c プロジェクト: Themaister/RetroArch
char *word_wrap(char* buffer, const char *string, int line_width, bool unicode, unsigned max_lines)
{
   unsigned i     = 0;
   unsigned len   = (unsigned)strlen(string);
   unsigned lines = 1;

   while (i < len)
   {
      unsigned counter;
      int pos = (int)(&buffer[i] - buffer);

      /* copy string until the end of the line is reached */
      for (counter = 1; counter <= (unsigned)line_width; counter++)
      {
         const char *character;
         unsigned char_len;
         unsigned j = i;

         /* check if end of string reached */
         if (i == len)
         {
            buffer[i] = 0;
            return buffer;
         }

         character = utf8skip(&string[i], 1);
         char_len  = (unsigned)(character - &string[i]);

         if (!unicode)
            counter += char_len - 1;

         do
         {
            buffer[i] = string[i];
            char_len--;
            i++;
         } while(char_len);

         /* check for newlines embedded in the original input
          * and reset the index */
         if (buffer[j] == '\n')
         {
            lines++;
            counter = 1;
         }
      }

      /* check for whitespace */
      if (string[i] == ' ')
      {
         if ((max_lines == 0 || lines < max_lines))
         {
            buffer[i] = '\n';
            i++;
            lines++;
         }
      }
      else
      {
         int k;

         /* check for nearest whitespace back in string */
         for (k = i; k > 0; k--)
         {
            if (string[k] != ' ' || (max_lines != 0 && lines >= max_lines))
               continue;

            buffer[k] = '\n';
            /* set string index back to character after this one */
            i         = k + 1;
            lines++;
            break;
         }

         if (&buffer[i] - buffer == pos)
            return buffer;
      }
   }

   buffer[i] = 0;

   return buffer;
}
コード例 #8
0
bool menu_animation_ctl(enum menu_animation_ctl_state state, void *data)
{
   static menu_animation_t anim;
   static retro_time_t cur_time    = 0;
   static retro_time_t old_time    = 0;
   static float delta_time         = 0.0f;
   static bool animation_is_active = false;

   switch (state)
   {
      case MENU_ANIMATION_CTL_DEINIT:
         {
            size_t i;

            for (i = 0; i < anim.size; i++)
            {
               if (anim.list[i].subject)
                  anim.list[i].subject = NULL;
            }

            free(anim.list);

            memset(&anim, 0, sizeof(menu_animation_t));
         }
         cur_time                  = 0;
         old_time                  = 0;
         delta_time                = 0.0f;
         break;
      case MENU_ANIMATION_CTL_IS_ACTIVE:
         return animation_is_active;
      case MENU_ANIMATION_CTL_CLEAR_ACTIVE:
         animation_is_active       = false;
         break;
      case MENU_ANIMATION_CTL_SET_ACTIVE:
         animation_is_active       = true;
         break;
      case MENU_ANIMATION_CTL_DELTA_TIME:
         {
            float *ptr = (float*)data;
            if (!ptr)
               return false;
            *ptr = delta_time;
         }
         break;
      case MENU_ANIMATION_CTL_UPDATE_TIME:
         {
            static retro_time_t last_clock_update = 0;
            settings_t *settings     = config_get_ptr();

            cur_time                 = cpu_features_get_time_usec();
            delta_time               = cur_time - old_time;

            if (delta_time >= IDEAL_DELTA_TIME* 4)
               delta_time = IDEAL_DELTA_TIME * 4;
            if (delta_time <= IDEAL_DELTA_TIME / 4)
               delta_time = IDEAL_DELTA_TIME / 4;
            old_time      = cur_time;

            if (((cur_time - last_clock_update) > 1000000) 
                  && settings->menu.timedate_enable)
            {
               animation_is_active   = true;
               last_clock_update     = cur_time;
            }
         }
         break;
      case MENU_ANIMATION_CTL_UPDATE:
         {
            unsigned i;
            unsigned active_tweens = 0;
            float *dt = (float*)data;

            if (!dt)
               return false;

            for(i = 0; i < anim.size; i++)
               menu_animation_iterate(&anim, i, *dt, &active_tweens);

            if (!active_tweens)
            {
               anim.size       = 0;
               anim.first_dead = 0;
               return false;
            }

            animation_is_active = true;
         }
         break;
      case MENU_ANIMATION_CTL_KILL_BY_TAG:
         {
            unsigned i;
            menu_animation_ctx_tag_t *tag = (menu_animation_ctx_tag_t*)data;

            if (!tag || tag->id == -1)
               return false;

            for (i = 0; i < anim.size; ++i)
            {
               if (anim.list[i].tag != tag->id)
                  continue;

               anim.list[i].alive   = false;
               anim.list[i].subject = NULL;

               if (i < anim.first_dead)
                  anim.first_dead = i;
            }
         }
         break;
      case MENU_ANIMATION_CTL_KILL_BY_SUBJECT:
         {
            unsigned i, j,  killed = 0;
            menu_animation_ctx_subject_t *subject = 
               (menu_animation_ctx_subject_t*)data;
            float            **sub = (float**)subject->data;

            for (i = 0; i < anim.size; ++i)
            {
               if (!anim.list[i].alive)
                  continue;

               for (j = 0; j < subject->count; ++j)
               {
                  if (anim.list[i].subject != sub[j])
                     continue;

                  anim.list[i].alive   = false;
                  anim.list[i].subject = NULL;

                  if (i < anim.first_dead)
                     anim.first_dead = i;

                  killed++;
                  break;
               }
            }
         }
         break;
      case MENU_ANIMATION_CTL_TICKER:
         {
            menu_animation_ctx_ticker_t *ticker = (menu_animation_ctx_ticker_t*)
               data;
            size_t           str_len = utf8len(ticker->str);
            size_t           offset  = 0;

            if ((size_t)str_len <= ticker->len)
            {
               utf8cpy(ticker->s,
                     PATH_MAX_LENGTH,
                     ticker->str,
                     ticker->len);
               return true;
            }

            if (!ticker->selected)
            {
               utf8cpy(ticker->s, PATH_MAX_LENGTH, ticker->str, ticker->len - 3);
               strlcat(ticker->s, "...", PATH_MAX_LENGTH);
               return true;
            }

            menu_animation_ticker_generic(
                  ticker->idx,
                  ticker->len,
                  &offset,
                  &str_len);

            utf8cpy(
                  ticker->s,
                  PATH_MAX_LENGTH,
                  utf8skip(ticker->str, offset),
                  str_len);

            animation_is_active = true;
         }
         break;
      case MENU_ANIMATION_CTL_IDEAL_DELTA_TIME_GET:
         {
            menu_animation_ctx_delta_t *delta = 
               (menu_animation_ctx_delta_t*)data;
            if (!delta)
               return false;
            delta->ideal = delta->current / IDEAL_DELTA_TIME;
         }
         break;
      case MENU_ANIMATION_CTL_PUSH:
         return menu_animation_push(&anim, data);
      case MENU_ANIMATION_CTL_NONE:
      default:
         break;
   }

   return true;
}