Beispiel #1
0
Datei: x.c Projekt: knusbaum/Wily
int
main(int argc, char *argv[])
{
	char *p, *re;
	size_t len;
	Subrange *r;
	void (*fn)(ulong p0, ulong p1);

	/* This isn't wonderful: assume that the regexp is delimited by // */
	if (argc < 2 || *(re = argv[1]) != '/'  || (len = strlen(re)) < 2) {
		fprintf(stderr,"Usage: x /regexp/\n");
		exit(1);
	}
	if (re[--len] == '/')
		re[len] = 0;
	re++;		/* skip / */
	if (len == 0) {
		fprintf(stderr,"null regexp\n");
		exit(1);
	}
	if (init_regexp(re)) {
		fprintf(stderr,"Invalid regexp\n");
		exit(1);
	}
	p = strrchr(argv[0], '/');
	p = p? p+1 : argv[0];
	switch (*p) {
		case 'x' :	fn = fn_x;	break;
		case 'y' :	fn = fn_y;	break;
		case 'g' :	fn = fn_g;	break;
		case 'v' :	fn = fn_v;	break;
		default:
			fprintf(stderr,"Uknown program name!\n");
			exit(1);
	}
	read_info(0);		/* Don't reverse ranges */
	Finit(&runefile, tmpfilename);
	write_info();
	while (r = next_range())
		(*fn)(r->p0, r->p1);
	exit(0);
}
Beispiel #2
0
	atom< TColl, rrange_filter<range_t, TPred> > where(TPred pred) {
		typedef rrange_filter<range_t, TPred> next_range_t;
		next_range_t next_range(range_, pred);
		return atom< TColl, next_range_t > (next_range);
	}
Beispiel #3
0
	atom< TColl, rrange_map<range_t, TFoo> > foreach(TFoo foo) {
		typedef rrange_map<range_t, TFoo> next_range_t;
		next_range_t next_range(range_, foo);
		return atom< TColl, next_range_t > (next_range);
	}
Beispiel #4
0
void test_empty_range_does_not_contain_anything(void)
{
	struct live_range range = { .start = 0, .end = 0 };

	assert_false(in_range(&range, 0));
	assert_false(in_range(&range, 1));
}

void test_empy_range_is_empty(void)
{
	struct live_range range = { .start = 0, .end = 0 };

	assert_true(range_is_empty(&range));
}

void test_range_length_treats_end_as_exclusive(void)
{
	struct live_range range = { .start = 0, .end = 2 };

	assert_int_equals(2, range_len(&range));
}

void test_in_range_treats_end_as_exclusive(void)
{
	struct live_range range = { .start = 0, .end = 2 };

	assert_true(in_range(&range, 0));
	assert_true(in_range(&range, 1));
	assert_false(in_range(&range, 2));
}

void test_range_that_is_within_another_range_intersects(void)
{
	struct live_range range1 = { .start = 0, .end = 3 };
	struct live_range range2 = { .start = 1, .end = 2 };

	assert_true(ranges_intersect(&range1, &range2));
	assert_true(ranges_intersect(&range2, &range1));
}

void test_ranges_that_intersect(void)
{
	struct live_range range1 = { .start = 0, .end = 2 };
	struct live_range range2 = { .start = 1, .end = 3 };

	assert_true(ranges_intersect(&range1, &range2));
	assert_true(ranges_intersect(&range2, &range1));
}

void test_ranges_that_do_not_intersect(void)
{
	struct live_range range1 = { .start = 0, .end = 2 };
	struct live_range range2 = { .start = 2, .end = 4 };

	assert_false(ranges_intersect(&range1, &range2));
	assert_false(ranges_intersect(&range2, &range1));
}

void test_interval_add_range(void)
{
#if 0
	struct live_interval it;
	struct live_range *r;

	INIT_LIST_HEAD(&it.range_list);

	interval_add_range(&it, 1, 3);
	r = interval_first_range(&it);
	assert_int_equals(1, r->start);
	assert_int_equals(3, r->end);
	assert_ptr_equals(NULL, next_range(&it.range_list, r));

	interval_add_range(&it, 5, 7);
	r = interval_first_range(&it);
	assert_int_equals(1, r->start);
	assert_int_equals(3, r->end);
	r = next_range(&it.range_list, r);
	assert_int_equals(5, r->start);
	assert_int_equals(7, r->end);
	assert_ptr_equals(NULL, next_range(&it.range_list, r));

	interval_add_range(&it, 3, 5);
	r = interval_first_range(&it);
	assert_int_equals(1, r->start);
	assert_int_equals(7, r->end);
	assert_ptr_equals(NULL, next_range(&it.range_list, r));

	interval_add_range(&it, 7, 8);
	r = interval_first_range(&it);
	assert_int_equals(1, r->start);
	assert_int_equals(8, r->end);
	assert_ptr_equals(NULL, next_range(&it.range_list, r));

	interval_add_range(&it, 10, 13);
	r = interval_first_range(&it);
	assert_int_equals(1, r->start);
	assert_int_equals(8, r->end);
	r = next_range(&it.range_list, r);
	assert_int_equals(10, r->start);
	assert_int_equals(13, r->end);
	assert_ptr_equals(NULL, next_range(&it.range_list, r));

	interval_add_range(&it, 0, 14);
	r = interval_first_range(&it);
	assert_int_equals(0, r->start);
	assert_int_equals(14, r->end);
	assert_ptr_equals(NULL, next_range(&it.range_list, r));
#endif
}
Beispiel #5
0
//次のトークンを返す
string CToken::next() 
{
  range_type range = next_range();
  return str_.substr(range.first, range.second);
}
Beispiel #6
0
 //--------------------------------------------------//
 // 名称 : next()									//
 // 用途 : 切り出されたトークン取得					//
 // 引数 : なし										//
 // 戻値 : 切り出されたトークン						//
 //--------------------------------------------------//
 std::wstring next()
 {
     range_type range = next_range();
     return token_.substr(range.first, range.second);
 }