Example #1
0
static void menu_insstr(WMenu *menu, const char *buf, size_t n)
{
    size_t oldlen=(menu->typeahead==NULL ? 0 : strlen(menu->typeahead));
    char *newta=(char*)malloc(oldlen+n+1);
    char *newta_orig;
    int entry;
    
    if(newta==NULL)
        return;
    
    if(oldlen!=0)
        memcpy(newta, menu->typeahead, oldlen);
    if(n!=0)
        memcpy(newta+oldlen, buf, n);
    newta[oldlen+n]='\0';
    newta_orig=newta;
    
    while(*newta!='\0'){
        bool found=FALSE;
        entry=menu->selected_entry;
        do{
            if(menu->entries[entry].title!=NULL){
                size_t l=strlen(menu->entries[entry].title);
                if(libtu_strcasestr(menu->entries[entry].title, newta)){
                    found=TRUE;
                    break;
                }
            }
            entry=(entry+1)%menu->n_entries;
        }while(entry!=menu->selected_entry);
        if(found){
            menu_do_select_nth(menu, entry);
            break;
        }
        newta++;
    }
    
    if(newta_orig!=newta){
        if(*newta=='\0'){
            free(newta_orig);
            newta=NULL;
        }else{
            char *p=scopy(newta);
            free(newta_orig);
            newta=p;
        }
    }
    if(menu->typeahead!=NULL)
        free(menu->typeahead);
    menu->typeahead=newta;
}
Example #2
0
static const char *get_font_element(const char *pattern, char *buf,
                                    int bufsiz, ...)
{
    const char *p, *v;
    char *p2;
    va_list va;

    va_start(va, bufsiz);
    buf[bufsiz-1]=0;
    buf[bufsiz-2]='*';
    while((v=va_arg(va, char *))!=NULL){
        p=libtu_strcasestr(pattern, v);
        if(p){
            strncpy(buf, p+1, bufsiz-2);
            p2=strchr(buf, '-');
            if(p2) *p2=0;
            va_end(va);
            return p;
        }
    }
    va_end(va);
    strncpy(buf, "*", bufsiz);
    return NULL;
}