Example #1
0
/*
 * call-seq:
 *   attribute(foo)                         => array
 *
 * Returns array of matching attributes in license
 */
static VALUE rbll_attribute_get(int argc, VALUE *argv, VALUE self) {
	VALUE attribute, locale;
	VALUE attribs;
	int i;
	char **avs;
	ruby_liblicense *license;
	Data_Get_Struct(self, ruby_liblicense, license);

	rb_scan_args(argc, argv, "11", &attribute, &locale);


	avs = ll_get_attribute(
	                  StringValueCStr(license->uri),
	                  StringValueCStr(attribute),
	                  locale);

	attribs = rb_ary_new();
	i = 0;
	while (avs != NULL && avs[i] != NULL) {
		attribs = rb_ary_push(attribs, rb_str_new2(avs[i]));
		i++;
	}
	ll_free_list(avs);

	return attribs;
}
Example #2
0
/*
 * call-seq:
 *   Liblicense.modules_io                         => array
 *
 * Returns array of all IO modules
 */
static VALUE rbll_modules_io(VALUE self) {
	ll_module_t *m = ll_get_io_modules();
	VALUE modules;
	int i;

	NO_WARN_UNUSED( self );
	modules = rb_ary_new();
	i = 0;
	while (m != NULL && m[i] != NULL) {
		modules = rb_ary_push(modules, rb_str_new2(m[i]));
		i++;
	}
	ll_free_list(m);

	return modules;
}
Example #3
0
/**
 *  Append an integer value to a linked_list.
 *
 *  @param (list) Linked list
 *  @param (value) Value to append
 */
void ll_append(linked_list *list, char *val) {
    node *new_node = NEW(node);

    if (!new_node) {
        fprintf(stderr, "Critical error: Failed to allocate memory. Exiting program...");
        ll_free_list(list);
    }
    if (list->head->tail == true) {
        list->head->val = strdup(val);
        list->head->tail = false;

        TAIL_NODE(list->head->next, new_node);
    } else {
        node *n;
        for (n = list->head; n->tail == false; n = n->next)
            ;

        n->val = strdup(val);
        n->tail = false;

        TAIL_NODE(n->next, new_node);
    }

}
Example #4
0
/*
 * call-seq:
 *   Liblicense.licenses                         => array
 *
 * Returns array of all known licenses
 */
static VALUE rbll_licenses_get(int argc, VALUE *argv, VALUE klass) {
	VALUE licenses, juris;
	ll_uri_t *l;
	int i;

	NO_WARN_UNUSED( klass );

	rb_scan_args(argc, argv, "01", &juris);

	if (juris != Qnil)
		l = ll_get_licenses(StringValueCStr(juris));
	else
		l = ll_get_licenses(NULL);

	licenses = rb_ary_new();
	i = 0;
	while (l != NULL && l[i] != NULL) {
		licenses = rb_ary_push(licenses, rb_str_new2(l[i]));
		i++;
	}
	ll_free_list(l);

	return licenses;
}
Example #5
0
/*
 * Get all the useful data out of the uri and store in
 * Ruby friendly variables
 */
static void _rbll_cache_info(ruby_liblicense *license, VALUE uri) {
	ll_juris_t j;
	ll_uri_t u;
	ll_version_t v;
	ll_locale_t* l;

	int i;

	/* URI info */
	u = StringValueCStr(uri);

	license->uri = uri;

	/* name */
	license->name = rb_str_new2(ll_get_first(ll_get_attribute(u, LL_NAME, false)));

	/* Jurisdiction info */
	j = ll_get_first(ll_get_attribute(u, LL_JURISDICTION, false));

	/* in the event of no jurisdiction. */
	if (j == NULL) {
		j = "Unported";
	}

	license->jurisdiction = rb_str_new2(j);

	/* Version info */
	v = ll_parse_version(ll_get_first (ll_get_attribute (u, LL_VERSION, false)));

	if (v) {
		license->version = rb_ary_new();
		for (i=1; i<=v[0]; ++i) {
			license->version = rb_ary_push(license->version, INT2NUM(v[i]));
		}
	} else {
		license->version = 0;
	}

	/* Permits */
	l = ll_get_attribute(u, LL_PERMITS, false);
	license->permits = rb_ary_new();

	i = 0;
	while (l != NULL && l[i] != NULL) {
		license->permits = rb_ary_push(license->permits, rb_str_new2(l[i]));
		i++;
	}
	ll_free_list(l);

	/* Prohibits */
	l = ll_get_attribute(u, LL_PROHIBITS, false);
	license->prohibits = rb_ary_new();

	i = 0;
	while (l != NULL && l[i] != NULL) {
		license->prohibits = rb_ary_push(license->prohibits, rb_str_new2(l[i]));
		i++;
	}
	ll_free_list(l);

	/* Requires */
	l = ll_get_attribute(u, LL_REQUIRES, false);
	license->requires = rb_ary_new();

	i = 0;
	while (l != NULL && l[i] != NULL) {
		license->requires = rb_ary_push(license->requires, rb_str_new2(l[i]));
		i++;
	}
	ll_free_list(l);

}
Example #6
0
int main(int argc, char *argv[]) {
	// 创建一个世界
    WINDOW *world;
	// 创建一条蛇
    Snake *snake;
	// 创建食物所在位置坐标
    Point food_point;
	// 初始移动方向为向右
    Direction direction = RIGHT;

    srand(time(NULL));
 
	// curses库初始化
    initscr();					/* 初始化屏幕							*/
    noecho();					/* 禁止输入字符getch读取回显			*/
    cbreak();					/* 关闭行缓冲							*/
    timeout(TICKRATE);			/* 每隔TICKRATE的时间检测一次窗口读操作 */
    keypad(stdscr, TRUE);		/* 开启键盘的键区,可以使用方向键		*/
    curs_set(0);				/* 禁止显示鼠标指针						*/
    
    refresh();					/* 刷新屏幕,准备重画					*/
 
    // 初始化世界
    world = create_world();
	// 以符号*界定世界窗口的边界
    box(world, '|' , '-');

	// 将世界窗口显示在终端上
    wrefresh(world);

    // 蛇初始化
    snake = snake_create(SNAKE_INITIAL_LENGTH);

	// 食物位置初始化
    food_point = new_food_position();
 
    int ch;
	// 因为没TICKRATE检测一次,并且设置了nodelay模式,getch不会
	// 阻塞,每隔TICKRATE下述循环将被执行一次
	while ((ch = getch()) != 'q')
    {
		// 每当检测到用户输入,重画世界
		wclear(world);
		box(world, '|' , '-');

		// 蛇移动,修改蛇的各个部分移动之后的坐标值
		snake_move(snake, direction, WORLD_WIDTH, WORLD_HEIGHT);

		Point *snake_head = (Point *)snake->head->value;
		// 蛇如果吃掉了食物,在新位置生成新的食物
		if (are_points_equal(food_point, *snake_head)) {
			food_point = new_food_position();
			snake_add_part_to_tail(snake);
		}

      // 绘制出蛇以及食物
      mvwaddch(world, food_point.y, food_point.x, '$');
      draw_snake(world, snake);

	  // 将当前绘制的窗口显示到终端
      wrefresh(world);

	  // 在nodelay模式下,getch读取不到字符则返回ERR
      if(ch != ERR) {
		// 修正移动方向
        direction = direction_for_key(ch);
      }
    }
 
    ll_free_list(snake);
    delwin(world);

    endwin();
 
    return 0;
}
Example #7
0
int main(int argc,char** argv) {
	char * known_good_prohibits[] = {NULL};
	char * known_good_permits[] = {LL_DISTRIBUTION, LL_REPRODUCTION, NULL};
	char * known_good_requires[] = {LL_NOTICE, LL_ATTRIBUTION, NULL};
	char * known_good_bync_permits[] = {
	  LL_DISTRIBUTION, LL_REPRODUCTION, LL_DERIVATIVE_WORKS, NULL};
	
	ll_uri_t license;
	ll_uri_t other_license;
	ll_juris_t j;
	char* name;
	ll_uri_t* p;
	int b;

        (void)argc;
        (void)argv;
	ll_init();

	license = "http://creativecommons.org/licenses/by-nd/2.0/de/";

	test_get_attribute_jurisdiction();
	test_get_attribute_jurisdiction_localized();
	test_get_attribute_name_system_lang();
	test_get_attribute_name_whatever_lang();
	test_get_version();

	p = ll_get_attribute(license, LL_PROHIBITS, false);
	printf("get_prohibits: ");
	assert (ll_sets_equal(p, known_good_prohibits));
	ll_list_print(p);
	ll_free_list(p);

	p = ll_get_attribute(license, LL_PERMITS, false);
	printf("get_permits: ");
	assert (ll_sets_equal(p, known_good_permits));
	ll_list_print(p);
	ll_free_list(p);

	p = ll_get_attribute(license, LL_REQUIRES, false);
	printf("get_requires: ");
	assert (ll_sets_equal(p, known_good_requires));
	ll_list_print(p);
	ll_free_list(p);

	/* Adding a test for http://code.creativecommons.org/issues/issue78 */
	other_license = "http://creativecommons.org/licenses/by-nc/3.0/";
	p = ll_get_attribute(other_license, LL_PERMITS, false);
	assert (ll_sets_equal(p, known_good_bync_permits));

	/* Adding a test for http://code.creativecommons.org/issues/issue78
	 as seen by the Python bindings, which always set the locale
	 parameter to true. */
	other_license = "http://creativecommons.org/licenses/by-nc/3.0/";
	p = ll_get_attribute(other_license, LL_PERMITS, true);
	assert (ll_sets_equal(p, known_good_bync_permits));

	b = ll_verify_uri(license);
	printf("verify_uri: %d\n",b);
	assert (b == 1);

	p = ll_get_all_licenses();
	printf("get_all_licenses: ");
	ll_list_print(p);
	assert (ll_list_contains(p, license));
	ll_free_list(p);

	p = ll_get_licenses("http://creativecommons.org/international/de/");
	printf("get_licenses: ");
	ll_list_print(p);
	assert (ll_list_contains(p, license));
	ll_free_list(p);

	/* Check that printing a license's info at least does something. */
	ll_license_print_info ("http://creativecommons.org/licenses/by/3.0/us");

	/* Check that printing a license's info when passed NULL
	   doesn't explode. */
	ll_license_print_info(NULL);

	ll_stop();
	return 0;
}