Пример #1
0
//
// Test building a simple sequence
//
void
TestSyckSeqAlloc( CuTest *tc )
{
    SyckNode *n;
    SYMID id;

    n = syck_new_seq( 1 );
    for ( id = 11001; id < 23000; id += 24 )
    {
        syck_seq_add( n, id );
    }

    CuAssert( tc, "Invalid value at '0'", 1 == syck_seq_read( n, 0 ) );
    CuAssert( tc, "Invalid value at '1'", 11001 == syck_seq_read( n, 1 ) );
    CuAssert( tc, "Invalid value at '200'", 15801 == syck_seq_read( n, 201 ) );

    syck_free_node( n );
}
Пример #2
0
static SYMID
rpmsyck_parse_handler(SyckParser *p, SyckNode *n)
{
    rpmsyck_node node = (rpmsyck_node) xcalloc(1, sizeof(*node));

    switch (n->kind)  {
        case syck_str_kind:
            node->type = T_STR;
	    node->value.key = syck_strndup(n->data.str->ptr, n->data.str->len);
        break;

	case syck_seq_kind: {
            rpmsyck_node val;
            rpmsyck_node seq = (rpmsyck_node) xcalloc(n->data.list->idx + 1, sizeof(*node));
	    int i;
            node->type = T_SEQ;

            for (i = 0; i < n->data.list->idx; i++) {
                SYMID oid = syck_seq_read(n, i);
                syck_lookup_sym(p, oid, (char **)&val);
                seq[i] = val[0];
            }
            seq[n->data.list->idx].type = T_END;
            node->value.seq = seq;
	}
	break;

        case syck_map_kind: {
	    hashTable ht = htCreate(n->data.pairs->idx * 2, 0, 0, NULL, NULL);
            rpmsyck_node val;
	    int i;
            node->type = T_MAP;
            for (i = 0; i < n->data.pairs->idx; i++) {
		char *key;
                SYMID oid = syck_map_read(n, map_key, i);
                syck_lookup_sym(p, oid, (char **)&val);
		key = val[0].value.key;

                oid = syck_map_read(n, map_value, i);
                syck_lookup_sym(p, oid, (char **)&val);

		htAddEntry(ht, key, val);
            }
            node->value.map = ht;
	}
        break;
    }

    node->tag = n->type_id ? syck_strndup(n->type_id, strlen(n->type_id)) : NULL;

    return syck_add_sym(p, (char *) node);
}
Пример #3
0
Файл: main.c Проект: jbowes/low
static void
parse_list (SyckNode *node)
{
	GSList *list = NULL;
	int i;

	for (i = 0; i < syck_seq_count (node); i++) {
		gpointer sym_entry = GINT_TO_POINTER (syck_seq_read (node, i));
		gpointer entry = g_hash_table_lookup (symbols, sym_entry);

		list = g_slist_append (list, entry);
	}
	g_hash_table_insert (symbols, GINT_TO_POINTER (node->id), list);
}
Пример #4
0
static SYMID
js_syck_parser_handler(SyckParser *p, SyckNode *n)
{
#ifdef	NOTYET
    struct parser_xtra *bonus = (struct parser_xtra *)p->bonus;
    int o2;
    int o3 = -1;
    int i;
#endif
    int o = 0;
    SYMID oid;

    switch (n->kind) {
    case syck_str_kind:
#ifdef	NOTYET
	if (n->type_id == NULL || strcmp(n->type_id, "str") == 0) {
	    lua_pushlstring(bonus->L, n->data.str->ptr, n->data.str->len);
	    o = lua_gettop(bonus->L);
	} else if (strcmp(n->type_id, "null") == 0) {
	    lua_pushnil(bonus->L);
	    o = lua_gettop(bonus->L);
	} else if (strcmp(n->type_id, "bool#yes") == 0) {
	    lua_pushboolean(bonus->L, 1);
	    o = lua_gettop(bonus->L);
	} else if (strcmp(n->type_id, "bool#no") == 0) {
	    lua_pushboolean(bonus->L, 0);
	    o = lua_gettop(bonus->L);
	} else if (strcmp(n->type_id, "int#hex") == 0) {
	    long intVal = strtol(n->data.str->ptr, NULL, 16);
	    lua_pushnumber(bonus->L, intVal);
	    o = lua_gettop(bonus->L);
	} else if (strcmp(n->type_id, "int") == 0) {
	    long intVal = strtol(n->data.str->ptr, NULL, 10);
	    lua_pushnumber(bonus->L, intVal);
	    o = lua_gettop(bonus->L);
	} else {
	    lua_pushlstring(bonus->L, n->data.str->ptr, n->data.str->len);
	    o = lua_gettop(bonus->L);
	}
#endif
	break;
    case syck_seq_kind:
#ifdef	NOTYET
	lua_newtable(bonus->L);
	o = lua_gettop(bonus->L);
	for (i = 0; i < n->data.list->idx; i++) {
	    oid = syck_seq_read(n, i);
	    syck_lookup_sym(p, oid, (char **)&o2);
	    lua_pushvalue(bonus->L, o2);
	    lua_rawseti(bonus->L, o, i+1);
	}
#endif
	break;
    case syck_map_kind:
#ifdef	NOTYET
	lua_newtable(bonus->L);
	o = lua_gettop(bonus->L);
	for (i = 0; i < n->data.pairs->idx; i++) {
	    oid = syck_map_read(n, map_key, i);
	    syck_lookup_sym(p, oid, (char **)&o2);
	    oid = syck_map_read(n, map_value, i);
	    syck_lookup_sym(p, oid, (char **)&o3);

	    lua_pushvalue(bonus->L, o2);
	    lua_pushvalue(bonus->L, o3);
	    lua_settable(bonus->L, o);
	}
#endif
	break;
    }
    oid = syck_add_sym(p, (char *)((long)o));
    return oid;
}
Пример #5
0
/*
static void stackDump (lua_State *L) {
      int i;
      int top = lua_gettop(L);
      for (i = 1; i <= top; i++) {  // repeat for each level 
        int t = lua_type(L, i);
		printf("%i:	", (top-i+1));
		switch (t) {
    
          case LUA_TSTRING:  // strings 
            printf("[string]");
            break;
    
          case LUA_TBOOLEAN:  // booleans 
            printf(lua_toboolean(L, i) ? "true" : "false");
            break;
    
          case LUA_TNUMBER:  // numbers 
            printf("%g", lua_tonumber(L, i));
            break;
    
          default:  // other values 
            printf("%s", lua_typename(L, t));
            break;
    
        }
        printf("\n");  // put a separator 
      }
      printf("\n----------\n");  // end the listing 
	  }
*/
SYMID
lua_syck_parser_handler(SyckParser *p, SyckNode *n)
{
	struct parser_xtra *bonus = (struct parser_xtra *)p->bonus;
	int o, o2, o3 = -1;
	SYMID oid;
	int i;

	if(!lua_checkstack(bonus->L, 1))
		luaL_error(bonus->orig,"syck parser wanted too much stack space.");
	
	switch (n->kind) {
		case syck_str_kind:
			if (n->type_id == NULL || strcmp(n->type_id, "str") == 0) {
				lua_pushlstring(bonus->L, n->data.str->ptr, n->data.str->len);
				o = lua_gettop(bonus->L);
			}
			else if (strcmp(n->type_id, "null") == 0)
			{
				lua_pushnil(bonus->L);
				o = lua_gettop(bonus->L);
			}
			else if (strcmp(n->type_id, "bool#yes") == 0)
			{
				lua_pushboolean(bonus->L, 1);
				o = lua_gettop(bonus->L);
			}
			else if (strcmp(n->type_id, "bool#no") == 0)
			{
				lua_pushboolean(bonus->L, 0);
				o = lua_gettop(bonus->L);
			}
			else if (strcmp(n->type_id, "float") == 0 || strcmp(n->type_id, "float#fix") == 0 || strcmp(n->type_id, "float#exp") == 0) 
			{
				double f;
				syck_str_blow_away_commas(n);
				f = strtod(n->data.str->ptr, NULL);
				lua_pushnumber(bonus->L, f);
				o = lua_gettop(bonus->L);
			}
			else if (strcmp(n->type_id, "int#hex") == 0)
			{
				long intVal = strtol(n->data.str->ptr, NULL, 16);
				lua_pushnumber(bonus->L, intVal);
				o = lua_gettop(bonus->L);
			}
			else if (strcmp(n->type_id, "int") == 0)
			{
				long intVal = strtol(n->data.str->ptr, NULL, 10);
				lua_pushnumber(bonus->L, intVal);
				o = lua_gettop(bonus->L);                 
			}
			else
			{
				lua_pushlstring(bonus->L, n->data.str->ptr, n->data.str->len);
				o = lua_gettop(bonus->L);
			}
			break;

		case syck_seq_kind:
			lua_newtable(bonus->L);
			o = lua_gettop(bonus->L);
			for ( i=0; i < n->data.list->idx; i++ )
			{
				oid = syck_seq_read(n, i);
				syck_lookup_sym(p, oid, (char **)&o2);
				lua_pushvalue(bonus->L, o2);
				lua_rawseti(bonus->L, o, i+1);
			}
			break;

		case syck_map_kind:
			lua_newtable(bonus->L);
			o = lua_gettop(bonus->L);
			for ( i=0; i < n->data.pairs->idx; i++ )
			{
				oid = syck_map_read(n, map_key, i);
				syck_lookup_sym(p, oid, (char **)&o2);
				oid = syck_map_read(n, map_value, i);
				syck_lookup_sym(p, oid, (char **)&o3);

				lua_pushvalue(bonus->L, o2);
				lua_pushvalue(bonus->L, o3);
				lua_settable(bonus->L, o);
			}
			break;
	}
	oid = syck_add_sym(p, (char *)o);
	return oid;
}