Beispiel #1
0
    regex_slash()
    : tokenizer()
    {
	add_pattern(0, "[^\\/]+");
	add_pattern(1, "\\.");
	add_pattern(2, "/");
	add_pattern(3, "\r?\n");
	
	regex_set_.Compile();
	
    }
Beispiel #2
0
    curlyblock()
    : tokenizer()
    {
	add_pattern(0, "{");
	add_pattern(1, "[^}]+");
	add_pattern(2, "}");
	add_pattern(3, "\r?\n");
	
	regex_set_.Compile();
	
    }
Beispiel #3
0
    regex_quote()
    : tokenizer()
    {
	add_pattern(0, "[^\\\"]+");
	add_pattern(1, "\\.");
	add_pattern(2, "\"");
	add_pattern(3, "\r?\n");
	
	regex_set_.Compile();
	
    }
Beispiel #4
0
static void add_subr(PATTERN subr_pattern, short nparam)
{
	PATTERN pattern;

	//if (has_output)
	//  subr_pattern = PATTERN_set_flag(subr_pattern, RT_OUTPUT);

	add_pattern(subr_pattern);

	pattern = PATTERN_make(RT_PARAM, nparam);
	add_pattern(pattern);
}
Beispiel #5
0
/*
 * Reads searching patterns from a file and adds them with add_pattern().
 */
static void
read_patterns(const char *fn)
{
	struct stat st;
	FILE *f;
	char *line;
	size_t len;
	ssize_t rlen;

	if ((f = fopen(fn, "r")) == NULL)
		err(2, "%s", fn);
	if ((fstat(fileno(f), &st) == -1) || (S_ISDIR(st.st_mode))) {
		fclose(f);
		return;
	}
	len = 0;
	line = NULL;
	while ((rlen = getline(&line, &len, f)) != -1) {
		if (line[0] == '\0')
			continue;
		add_pattern(line, line[0] == '\n' ? 0 : (size_t)rlen);
	}

	free(line);
	if (ferror(f))
		err(2, "%s", fn);
	fclose(f);
}
Beispiel #6
0
void Control::on_open_clicked() {
    Gtk::FileChooserDialog dialog("Please choose a file", Gtk::FILE_CHOOSER_ACTION_OPEN);
    //Add response buttons the the dialog:
    dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL);
    dialog.add_button("_Open", Gtk::RESPONSE_OK);

    auto filter_any = Gtk::FileFilter::create();
    filter_any->set_name("Any files");
    filter_any->add_pattern("*");
    dialog.add_filter(filter_any);

    if (dialog.run() == Gtk::RESPONSE_OK) {
        _image_path = dialog.get_filename();

        _drawArea.signal_x_pos.connect(sigc::mem_fun(this, &Control::monitor_moved_x));
        _drawArea.signal_y_pos.connect(sigc::mem_fun(this, &Control::monitor_moved_y));
        _drawArea.signal_monitor_scale.connect(sigc::mem_fun(this, &Control::monitor_scaled));
        _drawArea.signal_image_scale.connect(sigc::mem_fun(this, &Control::image_scaled));

        _drawArea.loadImage(_image_path);
        _image_scale->set_value(_drawArea.get_last_image_scale());
        _monitor_scale->set_value(_drawArea.get_last_monitor_scale());
        _drawArea.show();
    }
}
aho_corasick_matcher::aho_corasick_matcher(std::vector<char*> patterns){
    // Montar trie
    for(char* pattern : patterns){
        this->root = add_pattern(this->root,pattern);
    }
    // achar funções de falha (transições)
    find_failure_functions(this->root);
}
Beispiel #8
0
void setup(){
set_name("Indra");
set_gender(2);
set_proper_name("Indra");
set_in_room_desc("An elven wench named Indra is here.");
set_long("Indra is a dazzlingly beautiful elven woman. She looks at you"+
" with a smile that almost melts you where you stand. And taking into account"+
" that she is also stark naked, you don't have much to say right now.");
add_pattern("%s smiles.", (: $1 !="Indra Elvenmist" ? "emote smiles happily"+
" at you." : 0 :));
add_pattern("%s kisses%s", "emote returns your kiss and puts her arms around"+
" your neck.");
add_pattern("%s pulls %s", "emote lets her tounge play around in your"+
" mouth, stroking her hands through your hair.");
add_pattern("%s says, \"F**k me gently with a chain saw!\"", "emote starts up"+
" her chainsaw and grins happily at you.");

}
Beispiel #9
0
int
lafe_exclude(struct lafe_matching **matching, const char *pattern)
{

	if (*matching == NULL)
		initialize_matching(matching);
	add_pattern(&((*matching)->exclusions), pattern);
	(*matching)->exclusions_count++;
	return (0);
}
Beispiel #10
0
int
exclude(struct bsdtar *bsdtar, const char *pattern)
{
	struct matching *matching;

	if (bsdtar->matching == NULL)
		initialize_matching(bsdtar);
	matching = bsdtar->matching;
	add_pattern(bsdtar, &(matching->exclusions), pattern);
	matching->exclusions_count++;
	return (0);
}
Beispiel #11
0
int
main(int argc, char *argv[])
{
	const char *zipfile;
	int nopts;

	if (isatty(STDOUT_FILENO))
		tty = 1;

	if (getenv("UNZIP_DEBUG") != NULL)
		unzip_debug = 1;
	for (int i = 0; i < argc; ++i)
		debug("%s%c", argv[i], (i < argc - 1) ? ' ' : '\n');

	/*
	 * Info-ZIP's unzip(1) expects certain options to come before the
	 * zipfile name, and others to come after - though it does not
	 * enforce this.  For simplicity, we accept *all* options both
	 * before and after the zipfile name.
	 */
	nopts = getopts(argc, argv);

	/* 
	 * When more of the zipinfo mode options are implemented, this
	 * will need to change.
	 */
	if (zipinfo_mode && !Z1_opt) {
		printf("Zipinfo mode needs additional options\n");
		exit(1);
	}

	if (argc <= nopts)
		usage();
	zipfile = argv[nopts++];

	if (strcmp(zipfile, "-") == 0)
		zipfile = NULL; /* STDIN */

	while (nopts < argc && *argv[nopts] != '-')
		add_pattern(&include, argv[nopts++]);

	nopts--; /* fake argv[0] */
	nopts += getopts(argc - nopts, argv + nopts);

	if (n_opt + o_opt + u_opt > 1)
		errorx("-n, -o and -u are contradictory");

	time(&now);

	unzip(zipfile);

	exit(0);
}
Beispiel #12
0
static void add_operator_output(short op, short nparam, uint64_t byref)
{
	PATTERN pattern;

	/*
		Why this test?

		add_operator() can be called without operator. See:
		if (RES_priority(op) < prio) ...
	*/

	if (op == RS_NONE || op == RS_UNARY)
		return;

	if (op == RS_EXCL)
	{
		op = RS_LSQR;
		nparam = 2;

		check_last_first(2);
	}

	pattern = PATTERN_make(RT_RESERVED, op);

	//if (op == RS_LBRA && byref)
	//  pattern = PATTERN_set_flag(pattern, RT_OUTPUT);

	add_pattern(pattern);

	add_pattern(PATTERN_make(RT_PARAM, nparam));

	if (op == RS_LBRA && byref)
	{
		while (byref)
		{
			add_pattern(PATTERN_make(RT_PARAM, byref & 0xFFFF));
			byref >>= 16;
		}
	}
}
Beispiel #13
0
int mkdev(const char *name, int _mode)
{
	char *pattern;

	if (chdir("/dev"))
		return 1;

	pattern = add_pattern(name);
	patterns = &pattern;
	mode = _mode;
	n_patterns = 1;
	find_devs(true);
	find_devs(false);
	chdir("/");

	return 0;
}
ChooseFileWindow::ChooseFileWindow(MainWindow* mainWindow, Gtk::FileChooserAction file_chooser_action)
    : Gtk::FileChooserDialog("Select a wavefront file", file_chooser_action),
      mainWindow(mainWindow),
      selected_path("")
{

  add_button("_Cancel", Gtk::RESPONSE_CANCEL);
  add_button("Select", Gtk::RESPONSE_OK);

  set_type_hint(Gdk::WINDOW_TYPE_HINT_DIALOG);
  set_modal();
  set_transient_for(*mainWindow);

  auto filter_obj = Gtk::FileFilter::create();
  filter_obj->set_name("Wavefront .obj files");
  filter_obj->add_pattern("*.obj");
  filter_obj->add_pattern("*.OBJ");
  add_filter(filter_obj);
}
Beispiel #15
0
/**
 * \brief Changes the id of a pattern in the tileset.
 * \param old_pattern_id Old id of the pattern.
 * \param new_pattern_id New id to set.
 * \return \c true in case of success.
 * In case of failure, the old pattern is unchanged.
 */
bool TilesetData::set_pattern_id(
    const std::string& old_pattern_id, const std::string& new_pattern_id) {

  if (!exists(old_pattern_id)) {
    // No pattern was found with the old id.
    return false;
  }

  if (exists(new_pattern_id)) {
    // The new id is already used.
    return false;
  }

  TilePatternData pattern = get_pattern(old_pattern_id);
  remove_pattern(old_pattern_id);
  add_pattern(new_pattern_id, pattern);

  return true;
}
Beispiel #16
0
/*
 * Reads searching patterns from a file and adds them with add_pattern().
 */
static void
read_patterns(const char *fn)
{
	struct stat st;
	FILE *f;
	char *line;
	size_t len;

	if ((f = fopen(fn, "r")) == NULL)
		err(2, "%s", fn);
	if ((fstat(fileno(f), &st) == -1) || (S_ISDIR(st.st_mode))) {
		fclose(f);
		return;
	}
        while ((line = fgetln(f, &len)) != NULL)
		add_pattern(line, line[0] == '\n' ? 0 : len);
	if (ferror(f))
		err(2, "%s", fn);
	fclose(f);
}
Beispiel #17
0
int
main(int argc, char *argv[])
{
	const char *zipfile;
	int nopts;

	if (isatty(STDOUT_FILENO))
		tty = 1;

	if (getenv("UNZIP_DEBUG") != NULL)
		unzip_debug = 1;
	for (int i = 0; i < argc; ++i)
		debug("%s%c", argv[i], (i < argc - 1) ? ' ' : '\n');

	/*
	 * Info-ZIP's unzip(1) expects certain options to come before the
	 * zipfile name, and others to come after - though it does not
	 * enforce this.  For simplicity, we accept *all* options both
	 * before and after the zipfile name.
	 */
	nopts = getopts(argc, argv);

	if (argc <= nopts)
		usage();
	zipfile = argv[nopts++];

	while (nopts < argc && *argv[nopts] != '-')
		add_pattern(&include, argv[nopts++]);

	nopts--; /* fake argv[0] */
	nopts += getopts(argc - nopts, argv + nopts);

	if (n_opt + o_opt + u_opt > 1)
		errorx("-n, -o and -u are contradictory");

	time(&now);

	unzip(zipfile);

	exit(0);
}
Beispiel #18
0
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
    int        i,j,k;
    mwSize dims[] = {1,5};
    mwSize CIdims[] = {0,0,2};
    mwSize DSdims[] = {0,0,2};
    const char* field_names[] = {"Events", "CIs", "Sign", "Nab", "DS", "String"};
    int Events_field, CIs_field, Sign_field, Nab_field, DS_field, String_field;
    char *str;
    int  max_event_name,  max_event_indexes;
    double *pr;
    t_time_series ts;
    int Namax, buf[3], tid;
    t_pattern_list *tmp;
    t_pattern *Ip;
    mxArray *mArray;
    
    iteration_number = 0;
    
    ts.ci_strategy = T_SHORTEST_CI;
    ts.output = stdout;
    ts.alpha = 0.005;
    ts.Nmin = 3;
    ts.nlevels = 0;
    ts.allow_same_events_in_pattern = 1;
  	logfac_table_size = 0;
  	C_iz_N_po_k_table_K = C_iz_N_po_k_table_N = 0;
       

   
        ts.num_event_types = mxGetN( prhs[0] );
        ts.Nt = mxGetScalar(prhs[1]);
        ts.nlevels = mxGetN( prhs[2] );
        ts.event_i = (unsigned int**) malloc( ts.num_event_types * sizeof(unsigned int *));
        ts.event_sign = (char**) malloc( ts.num_event_types * sizeof(char*) );
        ts.N = (int*) malloc( ts.num_event_types * sizeof( unsigned int ) );
        ts.levels = (t_levels*) malloc( ts.nlevels * sizeof( t_levels ) );


        for ( i = 0; i < ts.num_event_types; i++ )
        {
            pr = mxGetField( prhs[0], i,  "indexes" );
            ts.N[i] = mxGetN( pr );
            ts.event_i[i] = (unsigned int*) malloc( ts.N[i] *sizeof( unsigned int ) );
            /*Can't use memcpy here!!*/
            for ( j = 0; j < ts.N[i]; j++ ) ts.event_i[i][j] = (unsigned int) *( mxGetPr(pr) + j) - 1 ;

            pr = mxGetField( prhs[0], i,  "event_name" );
            ts.event_sign[i] = (char*) mxArrayToString( pr );
        }

        /*copy alpha and Nab struct*/
        pr = mxGetPr( prhs[2] );
        for ( i = 0; i < ts.nlevels; i++ )
        {
            ts.levels[i].len =  pr[i*3 + 0];
            ts.levels[i].alpha = pr[i*3 + 1];
            ts.levels[i].Nmin =  pr[i*3 + 2];
        }

        /*Defaults*/
        ts.patterns = (t_pattern_list*) malloc( sizeof( t_pattern_list ) );
        ts.patterns->next=NULL;
        ts.ci_strategy = mxGetScalar(prhs[4]);
        ts.output = stdout;
        ts.alpha = 0.005;
        ts.Nmin = 3;
        ts.allow_same_events_in_pattern = mxGetScalar(prhs[3]);
        logfac_table_size = 0;
        C_iz_N_po_k_table_K = C_iz_N_po_k_table_N = 0; 

        /* Construct pseudo patterns */
        for ( i = 0; i < ts.num_event_types; i++ )
        {
            Namax =  Namax < ts.N[i] ? ts.N[i] : Namax;  
            buf[0] = i;
            tmp = add_pattern(ts.patterns, buf, 1);
            tmp->pat.ind = ( double_series*) malloc( sizeof(double_series) * ts.N[i] );
            tmp->pat.N = ts.N[i];
            for ( j = 0; j < ts.N[i]; j++)
            {
                tmp->pat.ind[j].l = tmp->pat.ind[j].r = ts.event_i[i][j];
            }
        }
        if (logfac_table_size)
        {
            fill_logfac_table( Namax+1 );
            fill_C_iz_N_po_k_table( Namax+1, Namax+1);
        }
    
    #pragma omp parallel private(tid)
    {
        tid = omp_get_thread_num();
        mexPrintf("Hello World from thread = %d\n", tid);
    }

    t_detect_patterns(&ts);
      
    mexPrintf("\n ITERATIONS %d\n", iteration_number); 
    dims[1] = num_patterns[ iteration_number - 1  ];
    plhs[0] = mxCreateStructArray(2, dims, 6, field_names);
    Events_field   = mxGetFieldNumber( plhs[0], "Events" );
    CIs_field      = mxGetFieldNumber( plhs[0], "CIs" );
    Sign_field     = mxGetFieldNumber( plhs[0], "Sign" );
    Nab_field      = mxGetFieldNumber( plhs[0], "Nab" );
    DS_field       = mxGetFieldNumber( plhs[0], "DS" );
    String_field   = mxGetFieldNumber( plhs[0], "String" );
    
    tmp = patterns_it[ iteration_number - 1 ]->next;
    for ( i = 0; i < num_patterns[ iteration_number - 1  ]; i++ )
    {
        Ip = &tmp->pat;
        /* Fill pattern field */
        mArray = mxCreateDoubleMatrix( 1, Ip->nevents, mxREAL );
        mxSetFieldByNumber(plhs[0], i, Events_field,  mArray );
        pr = mxGetPr( mArray );
        for ( j = 0; j < Ip->nevents; j++ )
            pr[j] = Ip->events[j] + 1; /*Matlab base index is 1 !!!*/            
        
        /* Fill significance field */
        mArray = mxCreateDoubleScalar( Ip->significance );
        mxSetFieldByNumber(plhs[0], i, Sign_field,  mArray );
               
        /* Fill Nab field */
        mArray = mxCreateDoubleScalar( Ip->N );
        mxSetFieldByNumber(plhs[0], i, Nab_field,  mArray );
                
        /* Fill CI field */
        mArray = mxCreateDoubleMatrix( Ip->nevents - 1, 2, mxREAL);
        mxSetFieldByNumber(plhs[0], i, CIs_field,  mArray );
        pr = mxGetPr( mArray );
        for ( j = 0; j < Ip->nevents - 1; j++ )
        {
            pr[ 0*(Ip->nevents - 1) + j ] = Ip->CI[j].l;
            pr[ 1*(Ip->nevents - 1) + j ] = Ip->CI[j].r;
        }
        
        /* Fill DS field */
        mArray = mxCreateDoubleMatrix( Ip->N, 2, mxREAL);
        mxSetFieldByNumber(plhs[0], i, DS_field,  mArray );
        pr = mxGetPr( mArray );
        for ( j = 0; j < Ip->N; j++ )
        {
            pr[ 0 * Ip->N + j ] = Ip->ind[j].l + 1; /*Matlab base index is 1 !!!*/   
            pr[ 1 * Ip->N + j ] = Ip->ind[j].r + 1; /*Matlab base index is 1 !!!*/   
        }
        
        mArray = mxCreateCharMatrixFromStrings( 1, &pattern_strings[i]);
        mxSetFieldByNumber(plhs[0], i, String_field,  mArray );
        tmp = tmp->next;
    }
    
}
Beispiel #19
0
int
main(int argc, char *argv[])
{
	char **aargv, **eargv, *eopts;
	char *ep;
	const char *pn;
	long long l;
	unsigned int aargc, eargc, i;
	int c, lastc, needpattern, newarg, prevoptind;

	setlocale(LC_ALL, "");

#ifndef WITHOUT_NLS
	catalog = catopen("grep", NL_CAT_LOCALE);
#endif

	/* Check what is the program name of the binary.  In this
	   way we can have all the funcionalities in one binary
	   without the need of scripting and using ugly hacks. */
	pn = getprogname();
	if (pn[0] == 'b' && pn[1] == 'z') {
		filebehave = FILE_BZIP;
		pn += 2;
	} else if (pn[0] == 'x' && pn[1] == 'z') {
		filebehave = FILE_XZ;
		pn += 2;
	} else if (pn[0] == 'l' && pn[1] == 'z') {
		filebehave = FILE_LZMA;
		pn += 2;
	} else if (pn[0] == 'r') {
		dirbehave = DIR_RECURSE;
		Hflag = true;
	} else if (pn[0] == 'z') {
		filebehave = FILE_GZIP;
		pn += 1;
	}
	switch (pn[0]) {
	case 'e':
		grepbehave = GREP_EXTENDED;
		break;
	case 'f':
		grepbehave = GREP_FIXED;
		break;
	}

	lastc = '\0';
	newarg = 1;
	prevoptind = 1;
	needpattern = 1;
	fileeol = '\n';

	eopts = getenv("GREP_OPTIONS");

	/* support for extra arguments in GREP_OPTIONS */
	eargc = 0;
	if (eopts != NULL && eopts[0] != '\0') {
		char *str;

		/* make an estimation of how many extra arguments we have */
		for (unsigned int j = 0; j < strlen(eopts); j++)
			if (eopts[j] == ' ')
				eargc++;

		eargv = (char **)grep_malloc(sizeof(char *) * (eargc + 1));

		eargc = 0;
		/* parse extra arguments */
		while ((str = strsep(&eopts, " ")) != NULL)
			if (str[0] != '\0')
				eargv[eargc++] = grep_strdup(str);

		aargv = (char **)grep_calloc(eargc + argc + 1,
		    sizeof(char *));

		aargv[0] = argv[0];
		for (i = 0; i < eargc; i++)
			aargv[i + 1] = eargv[i];
		for (int j = 1; j < argc; j++, i++)
			aargv[i + 1] = argv[j];

		aargc = eargc + argc;
	} else {
		aargv = argv;
		aargc = argc;
	}

	while (((c = getopt_long(aargc, aargv, optstr, long_options, NULL)) !=
	    -1)) {
		switch (c) {
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			if (newarg || !isdigit(lastc))
				Aflag = 0;
			else if (Aflag > LLONG_MAX / 10 - 1) {
				errno = ERANGE;
				err(2, NULL);
			}

			Aflag = Bflag = (Aflag * 10) + (c - '0');
			break;
		case 'C':
			if (optarg == NULL) {
				Aflag = Bflag = 2;
				break;
			}
			/* FALLTHROUGH */
		case 'A':
			/* FALLTHROUGH */
		case 'B':
			errno = 0;
			l = strtoll(optarg, &ep, 10);
			if (errno == ERANGE || errno == EINVAL)
				err(2, NULL);
			else if (ep[0] != '\0') {
				errno = EINVAL;
				err(2, NULL);
			} else if (l < 0) {
				errno = EINVAL;
				err(2, "context argument must be non-negative");
			}

			if (c == 'A')
				Aflag = l;
			else if (c == 'B')
				Bflag = l;
			else
				Aflag = Bflag = l;
			break;
		case 'a':
			binbehave = BINFILE_TEXT;
			break;
		case 'b':
			bflag = true;
			break;
		case 'c':
			cflag = true;
			break;
		case 'D':
			if (strcasecmp(optarg, "skip") == 0)
				devbehave = DEV_SKIP;
			else if (strcasecmp(optarg, "read") == 0)
				devbehave = DEV_READ;
			else
				errx(2, getstr(3), "--devices");
			break;
		case 'd':
			if (strcasecmp("recurse", optarg) == 0) {
				Hflag = true;
				dirbehave = DIR_RECURSE;
			} else if (strcasecmp("skip", optarg) == 0)
				dirbehave = DIR_SKIP;
			else if (strcasecmp("read", optarg) == 0)
				dirbehave = DIR_READ;
			else
				errx(2, getstr(3), "--directories");
			break;
		case 'E':
			grepbehave = GREP_EXTENDED;
			break;
		case 'e':
			{
				char *token;
				char *string = optarg;

				while ((token = strsep(&string, "\n")) != NULL)
					add_pattern(token, strlen(token));
			}
			needpattern = 0;
			break;
		case 'F':
			grepbehave = GREP_FIXED;
			break;
		case 'f':
			read_patterns(optarg);
			needpattern = 0;
			break;
		case 'G':
			grepbehave = GREP_BASIC;
			break;
		case 'H':
			Hflag = true;
			break;
		case 'h':
			Hflag = false;
			hflag = true;
			break;
		case 'I':
			binbehave = BINFILE_SKIP;
			break;
		case 'i':
		case 'y':
			iflag =  true;
			cflags |= REG_ICASE;
			break;
		case 'J':
#ifdef WITHOUT_BZIP2
			errno = EOPNOTSUPP;
			err(2, "bzip2 support was disabled at compile-time");
#endif
			filebehave = FILE_BZIP;
			break;
		case 'L':
			lflag = false;
			Lflag = true;
			break;
		case 'l':
			Lflag = false;
			lflag = true;
			break;
		case 'm':
			mflag = true;
			errno = 0;
			mlimit = mcount = strtoll(optarg, &ep, 10);
			if (((errno == ERANGE) && (mcount == LLONG_MAX)) ||
			    ((errno == EINVAL) && (mcount == 0)))
				err(2, NULL);
			else if (ep[0] != '\0') {
				errno = EINVAL;
				err(2, NULL);
			}
			break;
		case 'M':
			filebehave = FILE_LZMA;
			break;
		case 'n':
			nflag = true;
			break;
		case 'O':
			linkbehave = LINK_EXPLICIT;
			break;
		case 'o':
			oflag = true;
			cflags &= ~REG_NOSUB;
			break;
		case 'p':
			linkbehave = LINK_SKIP;
			break;
		case 'q':
			qflag = true;
			break;
		case 'S':
			linkbehave = LINK_READ;
			break;
		case 'R':
		case 'r':
			dirbehave = DIR_RECURSE;
			Hflag = true;
			break;
		case 's':
			sflag = true;
			break;
		case 'U':
			binbehave = BINFILE_BIN;
			break;
		case 'u':
		case MMAP_OPT:
			filebehave = FILE_MMAP;
			break;
		case 'V':
#ifdef WITH_GNU
			printf(getstr(10), getprogname(), VERSION);
#else
			printf(getstr(9), getprogname(), VERSION);
#endif
			exit(0);
		case 'v':
			vflag = true;
			break;
		case 'w':
			wflag = true;
			cflags &= ~REG_NOSUB;
			break;
		case 'x':
			xflag = true;
			cflags &= ~REG_NOSUB;
			break;
		case 'X':
			filebehave = FILE_XZ;
			break;
		case 'z':
			fileeol = '\0';
			break;
		case 'Z':
			filebehave = FILE_GZIP;
			break;
		case BIN_OPT:
			if (strcasecmp("binary", optarg) == 0)
				binbehave = BINFILE_BIN;
			else if (strcasecmp("without-match", optarg) == 0)
				binbehave = BINFILE_SKIP;
			else if (strcasecmp("text", optarg) == 0)
				binbehave = BINFILE_TEXT;
			else
				errx(2, getstr(3), "--binary-files");
			break;
		case COLOR_OPT:
			color = NULL;
			if (optarg == NULL || strcasecmp("auto", optarg) == 0 ||
			    strcasecmp("tty", optarg) == 0 ||
			    strcasecmp("if-tty", optarg) == 0) {
				char *term;

				term = getenv("TERM");
				if (isatty(STDOUT_FILENO) && term != NULL &&
				    strcasecmp(term, "dumb") != 0)
					color = init_color("01;31");
			} else if (strcasecmp("always", optarg) == 0 ||
			    strcasecmp("yes", optarg) == 0 ||
			    strcasecmp("force", optarg) == 0) {
				color = init_color("01;31");
			} else if (strcasecmp("never", optarg) != 0 &&
			    strcasecmp("none", optarg) != 0 &&
			    strcasecmp("no", optarg) != 0)
				errx(2, getstr(3), "--color");
			cflags &= ~REG_NOSUB;
			break;
		case LABEL_OPT:
			label = optarg;
			break;
		case LINEBUF_OPT:
			lbflag = true;
			break;
		case NULL_OPT:
			nullflag = true;
			break;
		case R_INCLUDE_OPT:
			finclude = true;
			add_fpattern(optarg, INCL_PAT);
			break;
		case R_EXCLUDE_OPT:
			fexclude = true;
			add_fpattern(optarg, EXCL_PAT);
			break;
		case R_DINCLUDE_OPT:
			dinclude = true;
			add_dpattern(optarg, INCL_PAT);
			break;
		case R_DEXCLUDE_OPT:
			dexclude = true;
			add_dpattern(optarg, EXCL_PAT);
			break;
		case HELP_OPT:
		default:
			usage();
		}
		lastc = c;
		newarg = optind != prevoptind;
		prevoptind = optind;
	}
	aargc -= optind;
	aargv += optind;

	/* Empty pattern file matches nothing */
	if (!needpattern && (patterns == 0))
		exit(1);

	/* Fail if we don't have any pattern */
	if (aargc == 0 && needpattern)
		usage();

	/* Process patterns from command line */
	if (aargc != 0 && needpattern) {
		char *token;
		char *string = *aargv;

		while ((token = strsep(&string, "\n")) != NULL)
			add_pattern(token, strlen(token));
		--aargc;
		++aargv;
	}

	switch (grepbehave) {
	case GREP_BASIC:
		break;
	case GREP_FIXED:
		/*
		 * regex(3) implementations that support fixed-string searches generally
		 * define either REG_NOSPEC or REG_LITERAL. Set the appropriate flag
		 * here. If neither are defined, GREP_FIXED later implies that the
		 * internal literal matcher should be used. Other cflags that have
		 * the same interpretation as REG_NOSPEC and REG_LITERAL should be
		 * similarly added here, and grep.h should be amended to take this into
		 * consideration when defining WITH_INTERNAL_NOSPEC.
		 */
#if defined(REG_NOSPEC)
		cflags |= REG_NOSPEC;
#elif defined(REG_LITERAL)
		cflags |= REG_LITERAL;
#endif
		break;
	case GREP_EXTENDED:
		cflags |= REG_EXTENDED;
		break;
	default:
		/* NOTREACHED */
		usage();
	}

#ifndef WITHOUT_FASTMATCH
	fg_pattern = grep_calloc(patterns, sizeof(*fg_pattern));
#endif
	r_pattern = grep_calloc(patterns, sizeof(*r_pattern));

	/* Don't process any patterns if we have a blank one */
#ifdef WITH_INTERNAL_NOSPEC
	if (!matchall && grepbehave != GREP_FIXED) {
#else
	if (!matchall) {
#endif
		/* Check if cheating is allowed (always is for fgrep). */
		for (i = 0; i < patterns; ++i) {
#ifndef WITHOUT_FASTMATCH
			/*
			 * Attempt compilation with fastmatch regex and
			 * fallback to regex(3) if it fails.
			 */
			if (fastncomp(&fg_pattern[i], pattern[i].pat,
			    pattern[i].len, cflags) == 0)
				continue;
#endif
			c = regcomp(&r_pattern[i], pattern[i].pat, cflags);
			if (c != 0) {
				regerror(c, &r_pattern[i], re_error,
				    RE_ERROR_BUF);
				errx(2, "%s", re_error);
			}
		}
	}

	if (lbflag)
		setlinebuf(stdout);

	if ((aargc == 0 || aargc == 1) && !Hflag)
		hflag = true;

	if (aargc == 0 && dirbehave != DIR_RECURSE)
		exit(!procfile("-"));

	if (dirbehave == DIR_RECURSE)
		c = grep_tree(aargv);
	else
		for (c = 0; aargc--; ++aargv) {
			if ((finclude || fexclude) && !file_matching(*aargv))
				continue;
			c+= procfile(*aargv);
		}

#ifndef WITHOUT_NLS
	catclose(catalog);
#endif

	/* Find out the correct return value according to the
	   results and the command line option. */
	exit(c ? (file_err ? (qflag ? 0 : 2) : 0) : (file_err ? 2 : 1));
}
Beispiel #20
0
static int 
_mutt_parse_color (BUFFER *buf, BUFFER *s, BUFFER *err, 
		   parser_callback_t callback, short dry_run)
{
  int object = 0, attr = 0, fg = 0, bg = 0, q_level = 0;
  int r = 0;

  if(parse_object(buf, s, &object, &q_level, err) == -1)
    return -1;

  if(callback(buf, s, &fg, &bg, &attr, err) == -1)
    return -1;

  /* extract a regular expression if needed */
  
  if (object == MT_COLOR_HEADER || object == MT_COLOR_BODY || object == MT_COLOR_INDEX)
  {
    if (!MoreArgs (s))
    {
      strfcpy (err->data, _("too few arguments"), err->dsize);
      return (-1);
    }

    mutt_extract_token (buf, s, 0);
  }
   
  if (MoreArgs (s))
  {
    strfcpy (err->data, _("too many arguments"), err->dsize);
    return (-1);
  }
  
  /* dry run? */
  
  if(dry_run) return 0;

  
#ifdef HAVE_COLOR
# ifdef HAVE_USE_DEFAULT_COLORS
  if (!option (OPTNOCURSES) && has_colors()
    /* delay use_default_colors() until needed, since it initializes things */
    && (fg == COLOR_DEFAULT || bg == COLOR_DEFAULT)
    && use_default_colors () != OK)
  {
    strfcpy (err->data, _("default colors not supported"), err->dsize);
    return (-1);
  }
# endif /* HAVE_USE_DEFAULT_COLORS */
#endif
  
  if (object == MT_COLOR_HEADER)
    r = add_pattern (&ColorHdrList, buf->data, 0, fg, bg, attr, err,0);
  else if (object == MT_COLOR_BODY)
    r = add_pattern (&ColorBodyList, buf->data, 1, fg, bg, attr, err, 0);
  else if (object == MT_COLOR_INDEX)
  {
    r = add_pattern (&ColorIndexList, buf->data, 1, fg, bg, attr, err, 1);
    set_option (OPTFORCEREDRAWINDEX);
  }
  else if (object == MT_COLOR_QUOTED)
  {
    if (q_level >= ColorQuoteSize)
    {
      safe_realloc (&ColorQuote, (ColorQuoteSize += 2) * sizeof (int));
      ColorQuote[ColorQuoteSize-2] = ColorDefs[MT_COLOR_QUOTED];
      ColorQuote[ColorQuoteSize-1] = ColorDefs[MT_COLOR_QUOTED];
    }
    if (q_level >= ColorQuoteUsed)
      ColorQuoteUsed = q_level + 1;
    if (q_level == 0)
    {
      ColorDefs[MT_COLOR_QUOTED] = fgbgattr_to_color(fg, bg, attr);
      
      ColorQuote[0] = ColorDefs[MT_COLOR_QUOTED];
      for (q_level = 1; q_level < ColorQuoteUsed; q_level++)
      {
	if (ColorQuote[q_level] == A_NORMAL)
	  ColorQuote[q_level] = ColorDefs[MT_COLOR_QUOTED];
      }
    }
    else
      ColorQuote[q_level] = fgbgattr_to_color(fg, bg, attr);
  }
  else
    ColorDefs[object] = fgbgattr_to_color(fg, bg, attr);

#ifdef HAVE_COLOR
# ifdef HAVE_BKGDSET
  if (object == MT_COLOR_NORMAL && !option (OPTNOCURSES) && has_colors())
    BKGDSET (MT_COLOR_NORMAL);
# endif
#endif

  return (r);
}
Beispiel #21
0
static void add_reserved_pattern(int reserved)
{
	add_pattern(PATTERN_make(RT_RESERVED, reserved));
}
Beispiel #22
0
static int
getopts(int argc, char *argv[])
{
	int opt;

	optreset = optind = 1;
	while ((opt = getopt(argc, argv, "aCcd:fjLlnopqtuvx:Z1")) != -1)
		switch (opt) {
		case '1':
			Z1_opt = 1;
			break;
		case 'a':
			a_opt = 1;
			break;
		case 'C':
			C_opt = 1;
			break;
		case 'c':
			c_opt = 1;
			break;
		case 'd':
			d_arg = optarg;
			break;
		case 'f':
			f_opt = 1;
			break;
		case 'j':
			j_opt = 1;
			break;
		case 'L':
			L_opt = 1;
			break;
		case 'l':
			if (v_opt == 0)
				v_opt = 1;
			break;
		case 'n':
			n_opt = 1;
			break;
		case 'o':
			o_opt = 1;
			q_opt = 1;
			break;
		case 'p':
			p_opt = 1;
			break;
		case 'q':
			q_opt = 1;
			break;
		case 't':
			t_opt = 1;
			break;
		case 'u':
			u_opt = 1;
			break;
		case 'v':
			v_opt = 2;
			break;
		case 'x':
			add_pattern(&exclude, optarg);
			break;
		case 'Z':
			zipinfo_mode = 1;
			break;
		default:
			usage();
		}

	return (optind);
}
Beispiel #23
0
int t_read_structs_from_file(t_time_series* ts, char* fname)
{
    FILE* fp;
    unsigned int i, j, time, Namax=0;
    char c, buf1[1024], buf2[1024];
    int buf[3];
    t_pattern_list *tmp;
    ts->patterns = (t_pattern_list*) malloc( sizeof( t_pattern_list ) );
    ts->patterns->next=NULL;
	
    if (! ( fp = fopen(fname, "r") ) )
    {
        return 0;
    }
	

    ts->allocated_num_event_types = 0;
    ts->num_event_types = 0;

    fscanf(fp, "Time\tEvent\n"); 
    fscanf(fp, "0\t:\n"); 
    
    for ( i = 0; !feof(fp); i++ )
    {
        fscanf(fp, "%s\t%s\n", buf1, buf2);
        time = atoi(buf1);
        if ( buf2[0] == '&' )
        {
            ts->Nt = time;
            break;
        }
	
        t_add_event_type(ts, buf2);
        t_add_event_ent(ts, buf2, time);
    }
    fclose(fp);

	/* Make pattern structs */
	for ( i = 0; i < ts->num_event_types; i++ )
	{
		Namax =  Namax < ts->N[i] ? ts->N[i] : Namax;  
		buf[0] = i;
		tmp = add_pattern(ts->patterns, buf, 1);
        tmp-> pat.tree = (int*) malloc( sizeof(int) );
        
        tmp-> pat.tree[0] = i;
        tmp-> pat.tree_len = 1;
        
        tmp->pat.ind = ( double_series*) malloc( sizeof(double_series) * ts->N[i] );
		tmp->pat.N = ts->N[i];
		for ( j = 0; j < ts->N[i]; j++)
		{
			tmp->pat.ind[j].l = tmp->pat.ind[j].r = ts->event_i[i][j];
		}
	}
	if (logfac_table_size)
	{
		fill_logfac_table( Namax+1 );
		fill_C_iz_N_po_k_table( Namax+1, Namax+1);
	}
	
    return 1;
}
Beispiel #24
0
static void analyze_single(int op)
{
	PATTERN *pattern;
	bool jump_newline;

	jump_newline = PATTERN_is_newline(*current);
	if (jump_newline)
	{
		add_pattern(PATTERN_make(RT_NEWLINE, 0));
		JOB->line++;
		current++;
	}

	if (op == RS_PT && !PATTERN_is_identifier(*current))
		THROW("The '.' operator must be followed by an identifier");
	else if (op == RS_EXCL && !PATTERN_is_string(*current))
		THROW("The '!' operator must be followed by an identifier");

	/* ( expr ) */

	if (PATTERN_is(*current, RS_LBRA))
	{
		int old_length = tree_length;
		PATTERN last;

		current++;
		analyze_expr(0, RS_NONE);

		if (!PATTERN_is(*current, RS_RBRA))
			THROW(E_MISSING, "')'");
		current++;

		if (tree_length == (old_length + 1))
		{
			last = get_last_pattern(1);
			if (PATTERN_is_string(last))
				change_last_pattern(1, PATTERN_make(RT_TSTRING, PATTERN_index(last)));
		}
	}

	/* [ expr, expr, ... ] */

	else if (PATTERN_is(*current, RS_LSQR))
	{
		current++;
		analyze_make_array();
	}

	/* - expr | NOT expr */

	else if (PATTERN_is(*current, RS_MINUS) || PATTERN_is(*current, RS_NOT))
	{
		pattern = current;
		current++;

		analyze_expr(RES_priority(RS_NOT), RS_UNARY);
		add_operator(PATTERN_index(*pattern), 1);
	}

	// . symbol

	else if (PATTERN_is(*current, RS_PT) && PATTERN_is_identifier(current[1]))
	{
		add_operator(PATTERN_index(current[0]), 0);
		add_pattern(PATTERN_set_flag(current[1], RT_POINT));
		current += 2;
	}

	// . [ ... ]

	else if (PATTERN_is(*current, RS_PT) && PATTERN_is(current[1], RS_LSQR))
	{
		add_operator(PATTERN_index(current[0]), 0);
		//add_pattern(PATTERN_set_flag(RS_RSQR, RT_POINT));
		current += 2;
		analyze_array();
	}

	// ! symbol

	else if (PATTERN_is(*current, RS_EXCL) && PATTERN_is_string(current[1]))
	{
		add_operator(RS_PT, 0);
		add_pattern(PATTERN_set_flag(current[1], RT_POINT));
		add_operator(RS_EXCL, 0);
		current += 2;
	}

	/* NULL, TRUE, FALSE, ME, PARENT, LAST, ERROR */
	/* number, string or symbol */

	else if (PATTERN_is(*current, RS_NULL)
					|| PATTERN_is(*current, RS_ME)
					|| PATTERN_is(*current, RS_LAST)
					|| PATTERN_is(*current, RS_TRUE)
					|| PATTERN_is(*current, RS_FALSE)
					|| PATTERN_is(*current, RS_PINF)
					|| PATTERN_is(*current, RS_MINF)
					|| PATTERN_is(*current, RS_ERROR)
					|| (!PATTERN_is_reserved(*current) && !PATTERN_is_newline(*current) && !PATTERN_is_end(*current)))
	{
		add_pattern(*current);

		if (PATTERN_is_identifier(*current))
		{
			/*if ((op == RS_NONE || op == RS_UNARY) && (PATTERN_is_identifier(*current)))
				change_last_pattern(1, PATTERN_set_flag(get_last_pattern(1), RT_FIRST));*/
			if (op == RS_PT)
			{
				change_last_pattern(1, PATTERN_set_flag(get_last_pattern(1), RT_POINT));
				check_last_first(2);
			}
		}

		current++;
	}

	else if (PATTERN_is(*current, RS_SUPER))
	{
		add_pattern(*current);
		current++;
		if (!PATTERN_is(*current, RS_PT)
				&& !PATTERN_is(*current, RS_EXCL)
				&& !PATTERN_is(*current, RS_LBRA)
				&& !PATTERN_is(*current, RS_LSQR))
			THROW("SUPER cannot be used alone");
	}

	else
	{
		if (jump_newline)
		{
			current--;
			JOB->line--;
		}

		THROW_UNEXPECTED(current);
	}
}
Beispiel #25
0
static void analyze_call()
{
	static PATTERN *byref_pattern[MAX_PARAM_FUNC];

	int i, nparam_post = 0;
	PATTERN subr_pattern = NULL_PATTERN;
	PATTERN last_pattern = get_last_pattern(1);
	SUBR_INFO *info;
	bool optional = TRUE;
	uint64_t byref = 0;
	PATTERN *save;

	/*
	get_pattern_subr(last_pattern, &subr);
	*/
	if (PATTERN_is_subr(last_pattern))
	{
		subr_pattern = last_pattern;
		remove_last_pattern();
		optional = FALSE;
	}
	else if (PATTERN_is_identifier(last_pattern))
	{
		check_last_first(1);
	}
	else if (PATTERN_is_string(last_pattern) || PATTERN_is_number(last_pattern))
		THROW(E_SYNTAX);

	/* N.B. Le cas où last_pattern = "." n'a pas de test spécifique */

	if (PATTERN_type(subr_pattern) == RT_SUBR && PATTERN_index(subr_pattern) == SUBR_VarPtr)
	{
		if (!PATTERN_is_identifier(current[0]) || !PATTERN_is(current[1], RS_RBRA))
			THROW("Syntax error. VarPtr() takes only one identifier");
		
		add_pattern(*current);
		current += 2;
		add_subr(subr_pattern, 1);
	}
	else
	{
		for (;;)
		{
			if (PATTERN_is(*current, RS_RBRA))
			{
				current++;
				break;
			}
	
			if (nparam_post > 0)
			{
				if (!PATTERN_is(*current, RS_COMMA))
					THROW(E_MISSING, "',' or ')'");
				current++;
			}
	
			#if 0
			if (FALSE) /*(PATTERN_is(*current, RS_AMP))*/
			{
				current++;
				output[nparam_post] = current;
				has_output = TRUE;
			}
			else
			{
				output[nparam_post] = NULL;
			}
			#endif
			
			if (optional && (PATTERN_is(*current, RS_COMMA) || PATTERN_is(*current, RS_RBRA)))
			{
				add_reserved_pattern(RS_OPTIONAL);
			}
			else if (optional && PATTERN_is(*current, RS_3PTS) && PATTERN_is(current[1], RS_RBRA))
			{
				current++;
				add_reserved_pattern(RS_3PTS);
				nparam_post--;
			}
			else
			{
				if (PATTERN_is(*current, RS_AT) || PATTERN_is(*current, RS_BYREF))
				{
					current++;
					BYREF_SET(byref, nparam_post);
					byref_pattern[nparam_post] = current;
				}
	
				analyze_expr(0, RS_NONE);
			}
	
			nparam_post++;

			if (nparam_post >= MAX_PARAM_FUNC)
				THROW("Too many arguments");
		}

		last_pattern = get_last_pattern(1);
		if (PATTERN_is(last_pattern, RS_OPTIONAL))
			THROW("Syntax error. Needless arguments");
		
		/*
		while (nparam_post > 0)
		{
			if (get_last_pattern(1) != PATTERN_make(RT_RESERVED, RS_OPTIONAL))
				break;
	
			remove_last_pattern();
			nparam_post--;
		}
		*/
	
		if (PATTERN_is_null(subr_pattern))
		{
			add_operator_output(RS_LBRA, nparam_post, byref);
			
			save = current;
			
			for (i = nparam_post - 1; i >= 0; i--)
			{
				if (BYREF_TEST(byref, i))
				{
					current = byref_pattern[i];
					analyze_expr(0, RS_NONE);
					//if (!is_statement())
					//	THROW("The &1 argument cannot be passed by reference", TRANS_get_num_desc(i + 1));
					add_pattern(PATTERN_make(RT_RESERVED, RS_AT));
				}
			}
			
			current = save;
		}
		else
		{
			info = &COMP_subr_info[PATTERN_index(subr_pattern)];
	
			if (nparam_post < info->min_param)
				THROW("Not enough arguments to &1()", info->name);
			else if (nparam_post > info->max_param)
				THROW("Too many arguments to &1()", info->name);
			else if (byref)
				THROW("Subroutine arguments cannot be passed by reference");
	
			add_subr(subr_pattern, nparam_post);
		}
	}

}
/**
 * This function optimizes the given transition.
 */
static void optimize_transition(Variables* v,OutputVariables* output,Fst2* fst2,Transition* transition,
						OptimizedFst2State state,Fst2Tag* tags,Abstract_allocator prv_alloc) {
if (transition->tag_number<0) {
   /* If the transition is a graph call */
   add_graph_call(transition,&(state->graph_calls),prv_alloc);
   add_graph_call(transition,&(state->unoptimized_graph_calls),prv_alloc);
   return;
}
Fst2Tag tag=tags[transition->tag_number];
if (tag==NULL) {
   fatal_error("NULL transition tag in optimize_transition\n");
}
int negation=is_bit_mask_set(tag->control,NEGATION_TAG_BIT_MASK);
/* First, we look if there is a compound pattern associated to this tag */
if (tag->compound_pattern!=NO_COMPOUND_PATTERN) {
   add_pattern(tag->compound_pattern,transition,&(state->compound_patterns),negation,prv_alloc);
}
/* Then, we look the possible kind of transitions */
switch (tag->type) {
   case TOKEN_LIST_TAG: add_token_list(tag->matching_tokens,transition,&(state->token_list),&(state->number_of_tokens),prv_alloc);
                        return;
   case PATTERN_NUMBER_TAG: add_pattern(tag->pattern_number,transition,&(state->patterns),negation,prv_alloc);
                            return;
   case META_TAG: {
	   add_meta(tag->meta,transition,&(state->metas),negation,prv_alloc);
	   add_meta(tag->meta,transition,&(state->unoptimized_metas),negation,prv_alloc);
       return;
   }
   case BEGIN_VAR_TAG: {
	   add_input_variable(v,tag->variable,transition,&(state->input_variable_starts),prv_alloc);
	   add_input_variable(v,tag->variable,transition,&(state->unoptimized_input_variable_starts),prv_alloc);
       return;
   }
   case END_VAR_TAG: {
	   add_input_variable(v,tag->variable,transition,&(state->input_variable_ends),prv_alloc);
	   add_input_variable(v,tag->variable,transition,&(state->unoptimized_input_variable_ends),prv_alloc);
       return;
   }
   case BEGIN_OUTPUT_VAR_TAG: {
	   add_output_variable(output,tag->variable,transition,&(state->output_variable_starts),prv_alloc);
	   add_output_variable(output,tag->variable,transition,&(state->unoptimized_output_variable_starts),prv_alloc);
       return;
   }
   case END_OUTPUT_VAR_TAG: {
	   add_output_variable(output,tag->variable,transition,&(state->output_variable_ends),prv_alloc);
	   add_output_variable(output,tag->variable,transition,&(state->unoptimized_output_variable_ends),prv_alloc);
       return;
   }
   case BEGIN_POSITIVE_CONTEXT_TAG: add_positive_context(fst2,state,transition,prv_alloc); return;
   case BEGIN_NEGATIVE_CONTEXT_TAG: add_negative_context(fst2,state,transition,prv_alloc); return;
   case END_CONTEXT_TAG: add_end_context(state,transition,prv_alloc); return;
   case LEFT_CONTEXT_TAG: {
	   add_meta(META_LEFT_CONTEXT,transition,&(state->metas),0,prv_alloc);
	   add_meta(META_LEFT_CONTEXT,transition,&(state->unoptimized_metas),0,prv_alloc);
	   return;
   }
   case BEGIN_MORPHO_TAG: {
	   struct opt_meta* new_meta=add_meta(META_BEGIN_MORPHO,transition,&(state->metas),0,prv_alloc);
	   get_reachable_closing_morphological_mode(fst2,transition->state_number,&(new_meta->morphological_mode_ends),prv_alloc);
	   add_meta(META_BEGIN_MORPHO,transition,&(state->unoptimized_metas),0,prv_alloc);
	   return;
   }
   case END_MORPHO_TAG: {
	   add_meta(META_END_MORPHO,transition,&(state->metas),0,prv_alloc);
	   add_meta(META_END_MORPHO,transition,&(state->unoptimized_metas),0,prv_alloc);
	   return;
   }
   case TEXT_START_TAG: {
	   add_meta(META_TEXT_START,transition,&(state->metas),0,prv_alloc);
	   add_meta(META_TEXT_START,transition,&(state->unoptimized_metas),0,prv_alloc);
	   return;
   }
   case TEXT_END_TAG: {
	   add_meta(META_TEXT_END,transition,&(state->metas),0,prv_alloc);
	   add_meta(META_TEXT_END,transition,&(state->unoptimized_metas),0,prv_alloc);
	   return;
   }
   default: fatal_error("Unexpected transition tag type in optimize_transition\n");
}
}
Beispiel #27
0
/**
 * This function analyses the inputs of all the tags of the given .fst2 in
 * order to determine their kind. 'tokens' contains all the text tokens.
 * After the execution of the function, 'number_of_patterns' will contain
 * the number of patterns found in the grammar, and 'is_DIC'/'is_CDIC'/'is_SDIC'/'is_TDIC'
 * will contain 1 if the tag 'DIC'/'CDIC'/'SDIC'/'TDIC' has been found. See
 * the comment below about the special case for '<!DIC>'.
 */
void process_tags(int *number_of_patterns,
                  struct string_hash* semantic_codes,
                  int *is_DIC,int *is_CDIC,
                  int *is_SDIC,struct locate_parameters* parameters,
                  Abstract_allocator prv_alloc) {
(*number_of_patterns)=0;
(*is_DIC)=0;
(*is_CDIC)=0;
(*is_SDIC)=0;
Fst2* fst2=parameters->fst2;
struct string_hash* tokens=parameters->tokens;
Fst2Tag* tag=fst2->tags;
/* We get the number of the SPACE token */
unichar t[2];
t[0]=' ';
t[1]='\0';
parameters->SPACE=get_value_index(t,tokens,DONT_INSERT);
/* Then, we test all the tags */
for (int i=0;i<fst2->number_of_tags;i++) {
   if (tag[i]->type!=UNDEFINED_TAG) {
      /* We don't need to process again things like variables and contexts
       * that have already been processed at the time of loading the fst2 */
      continue;
   }
   int length=u_strlen(tag[i]->input);
   if (!u_strcmp(tag[i]->input,"#")) {
      /* If we have a #, we must check if it is the meta one that
       * forbids space or the "#" token */
      if (is_bit_mask_set(tag[i]->control,RESPECT_CASE_TAG_BIT_MASK)) {
         /* If the case respect bit is set to 1, then we have the "#" token */
         tag[i]->type=PATTERN_TAG;
         tag[i]->pattern=build_token_pattern(tag[i]->input,prv_alloc);
      }
      else {
         /* If we have the meta # */
         tag[i]->type=META_TAG;
         tag[i]->meta=META_SHARP;
      }
   }
   else if (!u_strcmp(tag[i]->input,"<E>")) {
      /* If we have a transition tagged by the empty word epsilon */
      tag[i]->type=META_TAG;
      tag[i]->meta=META_EPSILON;
   }
   else {
      int token_number=get_value_index(tag[i]->input,tokens,DONT_INSERT);
      if (token_number!=-1) {
         /* If the input is an existing token */
         if (token_number==parameters->SPACE) {
            /* If it is a space */
            tag[i]->type=META_TAG;
            tag[i]->meta=META_SPACE;
         } else {
            /* If it is a normal token */
            tag[i]->type=PATTERN_TAG;
            tag[i]->pattern=build_token_pattern(tag[i]->input,prv_alloc);
         }
      }
      else {
         /* This input is not an existing token. Two cases can happen:
          * 1) metas like <!MOT> or patterns like <V:K>
          * 2) a word that is not in the text tokens */
         if (tag[i]->input[0]!='<' || tag[i]->input[length-1]!='>') {
            /* If we are in case 2, it may not be an error. For instance,
             * if the tag contains "foo" and if it is a tag that allows
             * case variations, we could match "FOO" if this token is in the
             * text. */
            tag[i]->type=PATTERN_TAG;
            tag[i]->pattern=build_token_pattern(tag[i]->input,prv_alloc);
         } else {
            /* If we have something of the form <...>, we must test first if it is
             * or not a negative tag like <!XXX> */
            int negative_tag=(tag[i]->input[1]=='!')?1:0;
            if (negative_tag) {
               set_bit_mask(&(tag[i]->control),NEGATION_TAG_BIT_MASK);
            }
            /* Then, we must test if we have or not a meta. To do that, we
             * extract the content without < > and ! if any.*/
            unichar* content=u_strdup(&(tag[i]->input[1+negative_tag]),length-2-negative_tag,prv_alloc);
            /* And we test all the possible metas */
            if (!u_strcmp(content,"MOT")) {
               tag[i]->type=META_TAG;
               tag[i]->meta=META_MOT;
            }
            else if (!u_strcmp(content,"DIC")) {
               tag[i]->type=META_TAG;
               tag[i]->meta=META_DIC;
               if (!negative_tag) {
                  /* We mark that the DIC tag has been found, but only
                   * if it is not the negative one (<!DIC>). We do this
                   * because things matched by <DIC> will be taken from
                   * the 'dlf' and 'dlc' files, whereas things matched by <!DIC>
                   * will be taken from the 'err' file. Such a trick is necessary
                   * if we don't want 'priori' to be taken as an unknown word since
                   * it is  part of the compound word 'a priori' */
                  (*is_DIC)=1;
               }
            }
            else if (!u_strcmp(content,"CDIC")) {
               tag[i]->type=META_TAG;
               tag[i]->meta=META_CDIC;
               (*is_CDIC)=1;
            }
            else if (!u_strcmp(content,"SDIC")) {
               tag[i]->type=META_TAG;
               tag[i]->meta=META_SDIC;
               (*is_SDIC)=1;
            }
            else if (!u_strcmp(content,"TDIC")) {
               tag[i]->type=META_TAG;
               tag[i]->meta=META_TDIC;
            }
            else if (!u_strcmp(content,"MAJ")) {
               tag[i]->type=META_TAG;
               tag[i]->meta=META_MAJ;
            }
            else if (!u_strcmp(content,"MIN")) {
               tag[i]->type=META_TAG;
               tag[i]->meta=META_MIN;
            }
            else if (!u_strcmp(content,"PRE")) {
               tag[i]->type=META_TAG;
               tag[i]->meta=META_PRE;
            }
            else if (!u_strcmp(content,"NB")) {
               tag[i]->type=META_TAG;
               tag[i]->meta=META_NB;
               if (negative_tag) {
                  error("Negative mark will be ignored in <!NB>\n");
               }
            }
            else if (!u_strcmp(content,"TOKEN")) {
               tag[i]->type=META_TAG;
               tag[i]->meta=META_TOKEN;
            }
            else {
               /* If we arrive here, we have not a meta but a pattern like
                * <be>, <be.V>, <V:K>, ... */
               tag[i]->type=PATTERN_TAG;
               tag[i]->pattern=build_pattern(content,semantic_codes,parameters->tilde_negation_operator,prv_alloc);
               if (tag[i]->pattern->type==CODE_PATTERN ||
                   tag[i]->pattern->type==LEMMA_AND_CODE_PATTERN ||
                   tag[i]->pattern->type==FULL_PATTERN || 
                   tag[i]->pattern->type==INFLECTED_AND_LEMMA_PATTERN) {
                  /* If the pattern we obtain contains grammatical/semantic
                   * codes, then we put it in the pattern tree and we note its number. */
                  tag[i]->pattern_number=add_pattern(number_of_patterns,tag[i]->pattern,parameters->pattern_tree_root,prv_alloc);
                  if (tag[i]->pattern->type==CODE_PATTERN) {
                     /* If we have a code pattern, then the tag will just need to contain
                      * the pattern number, BUT, WE DO NOT FREE THE PATTERN,
                      * since this pattern still could be used in morphological mode */
                     tag[i]->type=PATTERN_NUMBER_TAG;
                  }
               }
            }
            /* We don't forget to free the content */
            free_cb(content,prv_alloc);
         }
      }
   }
}
}