void test_get_attribute_name_system_lang() { const char * license; char * name; license = "http://creativecommons.org/licenses/by-nd/2.0/de/"; name = ll_get_first(ll_get_attribute(license, LL_NAME, true)); printf("get_name: '%s'\n",name); assert (strcmp(name, "Attribution-NoDerivs") == 0); /* UTF-8 */ free(name); }
void test_get_attribute_jurisdiction_localized() { char * license; char * j; license = "http://creativecommons.org/licenses/by-nd/2.0/de/"; j = ll_get_first(ll_get_attribute(license, LL_JURISDICTION, true)); printf("get_jurisdiction: '%s'\n",j); assert (strcmp(j, "http://creativecommons.org/international/de/") == 0); free(j); }
static statement *parse_array_index(linked_list *tokens) { statement *index = new(index); index->type = OP_INDEX; index->data = new_slice(""); index->children = ll_new(); statement *name = new(name); name->type = NAME; name->data = ((parse_token*)ll_get_first(tokens))->data; name->children = NULL; ll_add_first(index->children, name); linked_list *inside_list = ll_duplicate(tokens); ll_remove_first(inside_list); //Remove name ll_remove_first(inside_list); //Remove [ ll_remove_last(inside_list); //Remove ] statement *inside = parse_simple_expression(inside_list); ll_destroy(inside_list); ll_add_last(index->children, inside); return index; }
void test_get_version() { int known_good_version[] = {2,2,0}; const char * license; int* version; license = "http://creativecommons.org/licenses/by-nd/2.0/de/"; version = ll_parse_version(ll_get_first (ll_get_attribute (license, LL_VERSION, false))); printf("get_version: "); assert (ll_int_arrays_equal(version, known_good_version)); if (version) { int i; for (i=1; i<=version[0]; ++i) { if (i!=1) printf("."); printf("%d",version[i]); } printf("\n"); free(version); } else { printf("unversioned\n"); } }
static statement *parse_single_token(linked_list *tokens) { parse_token token = *((parse_token*)ll_get_first(tokens)); statement *expression = new(expression); expression->data = token.data; expression->children = NULL; switch(token.type) { case WORD: expression->type = NAME; break; case NUMBER: expression->type = NUM; break; case STRING_LIT: expression->type = STRING; break; case CHAR_LIT: expression->type = CHAR; break; case SYMBOL: printf("Symbol case in parse_simple_expression should not have executed\n"); break; } return expression; }
/* * 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); }
static statement *parse_simple_expression(linked_list *tokens) { while(equals_string(((parse_token*)ll_get_first(tokens))->data, "(") && equals_string(((parse_token*)ll_get_last(tokens))->data, ")")) { ll_remove_first(tokens); ll_remove_last(tokens); } int size = ll_size(tokens); switch(size) { case 0: return NULL; case 1: return parse_single_token(tokens); default: { if(size == 2) { parse_token *token = ll_get_first(tokens); bool isStack; if((isStack = equals_string(token->data, "new")) || equals_string(token->data, "newref")) { statement *expression = new(expression); expression->children = ll_new(); expression->type = isStack ? STACK_INIT : HEAP_INIT; linked_list *name = ll_duplicate(tokens); ll_remove_first(name); ll_add_first(expression->children, parse_simple_expression(name)); return expression; } } int paren_level = 1; linked_iter iterator = ll_iter_head(tokens); bool is_index = true, is_call = true; ll_iter_next(&iterator); parse_token *second = ll_iter_next(&iterator); if(equals_string(second->data, "(")) { is_index = false; } else if(equals_string(second->data, "[")) { is_call = false; } else { is_index = is_call = false; } while((is_index || is_call) && ll_iter_has_next(&iterator)) { parse_token *token = ll_iter_next(&iterator); if(equals_string(token->data, "(") || equals_string(token->data, "[")) { paren_level += 1; } else if(paren_level == 0) { is_index = false; is_call = false; } else if(equals_string(token->data, ")") || equals_string(token->data, "]")) { paren_level -= 1; } } if(is_index) { return parse_array_index(tokens); } else if(is_call) { return parse_func_call(tokens); } linked_list *operator = get_node(); linked_iter level = ll_iter_head(operator); while(ll_iter_has_next(&level)) { int paren_level = 0; linked_list *currentLevel = ll_iter_next(&level); linked_iter iterator = ll_iter_head(tokens); for(parse_token *current = ll_iter_next(&iterator); ll_iter_has_next(&iterator); current = ll_iter_next(&iterator)) { char currentChar = current->data.data[0]; if(currentChar == '(') { paren_level += 1; } else if(currentChar == ')') { paren_level -= 1; } if(paren_level != 0) continue; linked_iter innerMost = ll_iter_head(currentLevel); while(ll_iter_has_next(&innerMost)) { operator_node *currentOperator = ll_iter_next(&innerMost); if(equals_string(current->data, currentOperator->data)) { if(!is_unary_operator(new_slice(currentOperator->data))) { linked_list *op1 = ll_duplicate(tokens); while(ll_get_last(op1) != current) ll_remove_last(op1); ll_remove_last(op1); linked_list *op2 = tokens; while(ll_get_first(op2) != current) ll_remove_first(op2); ll_remove_first(op2); statement *expression = new(expression); expression->data = new_slice(""); expression->children = ll_new(); expression->type = currentOperator->operatorType; statement *op1_exp = parse_simple_expression(op1); statement *op2_exp = parse_simple_expression(op2); ll_add_last(expression->children, op1_exp); ll_add_last(expression->children, op2_exp); return expression; } else { statement *expression = new(expression); expression->data = new_slice(currentOperator->data); expression->type = currentOperator->operatorType; linked_list *rest = ll_duplicate(tokens); ll_remove_first(rest); expression->children = ll_new(); ll_add_first(expression->children, parse_simple_expression(rest)); return expression; } } } } } return NULL; } } }