Пример #1
0
Match::Match(const char *start_of_array, size_t array_size, size_t match_start_offset, size_t match_end_offset, long long line_number)
{
	auto line_ending = "\n";
	// Find the start of the line.
	std::reverse_iterator<const char*> rstart(start_of_array+match_start_offset);
	std::reverse_iterator<const char*> rend(start_of_array);

	auto line_start_rit = std::find(rstart, rend, line_ending[0]);
	const char *line_start;
	if(line_start_rit == rend)
	{
		// The line has no starting '\n', so it must be the first line.
		line_start = start_of_array;
	}
	else
	{
		// The line had a starting '\n', clip it off.
		line_start = line_start_rit.base();
	}

	// Find the end of the matched line.
	auto line_end = std::find(start_of_array+match_start_offset, start_of_array+array_size, line_ending[0]);

	// Form the match substrings.
	m_pre_match = std::string(line_start, start_of_array+match_start_offset);
	m_match = std::string(start_of_array+match_start_offset, start_of_array+match_end_offset);
	m_post_match = std::string(start_of_array+match_start_offset+(match_end_offset-match_start_offset), line_end);
	m_line_number = line_number;
}
Пример #2
0
void rinit(int ijkl)
{
	int i, j, k, l, ij, kl;

	/* check ijkl is within range */
	if( (ijkl < 0) || (ijkl > 900000000) )
		{
		printf("rinit: ijkl = %d -- out of range\n\n", ijkl);
		exit(3);
               	}

/*        printf("rinit: seed_ijkl = %d\n", ijkl); */

	/* decompose the long integer into the the equivalent four
	 * integers for rstart. This should be a 1-1 mapping
 	 *	ijkl <--> (i, j, k, l)
	 * though not quite all of the possible sets of (i, j, k, l)
	 * can be produced.
	 */

	ij = ijkl/30082;
	kl = ijkl - (30082 * ij);

	i = ((ij/177) % 177) + 2;
	j = (ij % 177) + 2;
	k = ((kl/169) % 178) + 1;
	l = kl % 169;

	if( (i <= 0) || (i > 178) )
		{
		printf("rinit: i = %d -- out of range\n\n", i);
		exit(3);
               	}

	if( (j <= 0) || (j > 178) )
		{
		printf("rinit: j = %d -- out of range\n\n", j);
		exit(3);
               	}

	if( (k <= 0) || (k > 178) )
		{
		printf("rinit: k = %d -- out of range\n\n", k);
		exit(3);
               	}

	if( (l < 0) || (l > 168) )
		{
		printf("rinit: l = %d -- out of range\n\n", l);
		exit(3);
               	}

	if (i == 1 && j == 1 && k == 1)
		{
                printf("rinit: 1 1 1 not allowed for 1st 3 seeds\n\n");
		exit(4);
                }

/*        printf("rinit: initialising RNG via rstart(%d, %d, %d, %d)\n",
				i, j, k, l); */

        rstart(i, j, k, l);

}