Пример #1
0
/*
static void filefiltergui_add_filetypes(gpointer key,gpointer value,gpointer data) {
	Tfilefiltergui *ffg = data;

	if (strlen(key)>0 && g_hash_table_lookup(main_v->filetypetable, key) == NULL) {
		GtkTreeIter it;
		gtk_list_store_prepend(ffg->lstore,&it);
		gtk_list_store_set(ffg->lstore,&it,0,key,2,0,-1);
	}
}
*/
static void
filefiltergui_2right_clicked(GtkWidget * widget, Tfilefiltergui * ffg)
{
	GtkTreeIter iter;
	GtkTreeSelection *select;
	GtkTreeModel *model;

	/* get the selection */
	select = gtk_tree_view_get_selection(GTK_TREE_VIEW(ffg->out_view));
	if (gtk_tree_selection_get_selected(select, &model, &iter)) {
		gchar *name;
		gint type;
		gtk_tree_model_get(model, &iter, 0, &name, 2, &type, -1);
		/* add the selection to the filter */
		DEBUG_MSG("filefiltergui_2right_clicked, adding %s\n", name);
		if (type == 0) {
			if (!ffg->curfilter->filetypes) {
				ffg->curfilter->filetypes = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
			}
			g_hash_table_replace(ffg->curfilter->filetypes, name, GINT_TO_POINTER(1));
		} else {
			ffg->curfilter->patterns = g_list_append(ffg->curfilter->patterns, new_pattern(name));
		}

		DEBUG_MSG("filefiltergui_2right_clicked, refilter\n");
		/* refilter */
		gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(ffg->in_model));
		gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(ffg->out_model));
	} else {
		DEBUG_MSG("filefiltergui_2right_clicked, nothing selected\n");
	}
}
Пример #2
0
bool FileComparer::overwritePattern() {
    string line;

    if(!createNew("tmp.txt"))
        return false;

    ifstream tmp("tmp.txt");
    if(!tmp.is_open())
        return false;

    fs_pattern.close();
    ofstream new_pattern(path_pattern);

    while(tmp.good()) {
        getline(tmp, line);
        new_pattern << line << endl;
    }

    tmp.close();
    new_pattern.close();
    setPatternFile(path_pattern);

    if(remove("tmp.txt") != 0)
        cout << "NIE USUNIETO PLIKU TYMCZASOWEGO" << endl;

    return true;
};
Пример #3
0
static GList *
patternlist_from_string(const gchar * patterns)
{
	if (patterns) {
		GList *list = NULL;
		gchar **pats = g_strsplit(patterns, ":", 127);
		gchar **pattern = pats;
		while (*pattern) {
			/* do something */
			if (strlen(*pattern) > 0) {
				list = g_list_append(list, new_pattern(*pattern));
			}
			pattern++;
		}
		g_strfreev(pats);
		return list;
	}
	return NULL;
}
Пример #4
0
/**
 * This function builds a token pattern from the given information.
 */
struct pattern* build_token_pattern(const unichar* token,Abstract_allocator prv_alloc) {
struct pattern* p=new_pattern(prv_alloc);
p->type=TOKEN_PATTERN;
p->inflected=u_strdup(token,prv_alloc);
return p;
}
Пример #5
0
/**
 * This function takes a string representing a pattern like
 * <be.V:K>, but without the < and > characters. It splits it
 * and builds a pattern from it. Raises a fatal error in case
 * of malformed pattern.
 */
struct pattern* build_pattern(const unichar* s,struct string_hash* semantic_codes,int tilde_negation_operator,Abstract_allocator prv_alloc) {
struct pattern* p=new_pattern(prv_alloc);
int pos;
unichar tmp[2048];
if ((s==NULL)||(s[0]=='\0')) {
   fatal_error("The empty pattern <> has been found\n");
}
pos=0;
if (P_BACKSLASH_AT_END==parse_string(s,&pos,tmp,P_COMMA_DOT)) {
   fatal_error("Backslash at end of pattern\n");
}
/* If we are in the <XXX> case, we must decide if XXX is a lemma
 * or a combination of grammatical/semantic/inflectional codes */
if (s[pos]=='\0') {
   /* We must test on s and NOT on inflected, because of patterns like
    * <A+faux\~ami>. In fact, s contains "A+faux\~ami" and inflected
    * contains "A+faux~ami". So, if we consider inflected instead of s,
    * the tilde will be taken as a negation and not as a part of the code
    * "faux~ami", and then, no difference will be made between
    * "<A+faux\~ami>" and "<A+faux~ami>".
    *
    * NOTE: I (S.P.) know that "faux~ami" is not a convincing example, but
    *       previously, the '-' was the negation sign, and now that it's '~',
    *       I'm too lazy to build a realistic example with the tilde
    */
   p->type=is_code_pattern(s,semantic_codes,tilde_negation_operator);
   if (p->type==CODE_PATTERN) {
      /* If we are in the <V> case */
      build_code_pattern(p,s,tilde_negation_operator,prv_alloc);
      return p;
   }
   else {
      /* If we are in the <XXX> where XXX is either a lemma or an unknown element
       * that can be both lemma and grammatical code */
      p->lemma=u_strdup(tmp,prv_alloc);
      return p;
   }
}
else if (s[pos]=='.' && s[pos+1]=='\0') {
   if (tmp[0]=='\0') {
      fatal_error("Invalid pattern <.> has been found\n");
   }
   /* If we are in the case <be.>, we know that we have a lemma pattern */
   p->type=LEMMA_PATTERN;
   p->lemma=u_strdup(tmp,prv_alloc);
   return p;
}
/* If are in the <be.V> or <.V> case */
if (s[pos]=='.') {
   if (tmp[0]=='\0') {
      /* If we are in the <.V> case */
      p->type=CODE_PATTERN;
      build_code_pattern(p,&(s[pos+1]),tilde_negation_operator,prv_alloc);
      return p;
   }
   /* If we are in the <be.V> case */
   p->lemma=u_strdup(tmp,prv_alloc);
   p->type=LEMMA_AND_CODE_PATTERN;
   build_code_pattern(p,&(s[pos+1]),tilde_negation_operator,prv_alloc);
   return p;
}
/* If we are in the  <am,be.V> case */
if (tmp[0]=='\0') {
   fatal_error("Invalid pattern <,XXX> has been found\n");
}
p->type=FULL_PATTERN;
p->inflected=u_strdup(tmp,prv_alloc);

pos++;
switch(parse_string(s,&pos,tmp,P_DOT)) {
   case P_BACKSLASH_AT_END: {fatal_error("Backslash at end of pattern\n");}
   case P_EOS: {
      if (s[pos]=='\0') {
         fatal_error("Invalid pattern <XXX,> has been found\n");
      }
   }
}
if (s[pos]=='\0') {
   /* We have a <XXX,YYY> pattern */
   p->lemma=u_strdup(tmp,prv_alloc);
   p->type=INFLECTED_AND_LEMMA_PATTERN;
   return p;
}
p->lemma=u_strdup(tmp,prv_alloc);
build_code_pattern(p,&(s[pos+1]),tilde_negation_operator,prv_alloc);
return p;
}