Пример #1
0
//load existing player from a file
Player* loadYourGame()
{
    int i = 0;
    Player *loadPlayer = malloc(sizeof(Player));
    DlistItem *loadInventory = useItem_new();
    DlistStuff *loadArmory = item_new();
    StuffItem** loadBuild = malloc(sizeof(StuffItem));

    initEqpt(loadPlayer);
    loadInventory = readFromFile_item();
    loadArmory = readFromFile_stuff();
    loadBuild = readFromFile_eqpt();

    FILE * saved_player = fopen("./saved_player.txt", "r");
    if (saved_player != NULL) {
        fread(loadPlayer, sizeof(Player), 1, saved_player);
        fclose(saved_player);
    }

    loadPlayer->inventory = loadInventory;
    loadPlayer->armory = loadArmory;

    for(i = 0; i < 6; i++){
        loadPlayer->build[i] = loadBuild[i];
    }

    return loadPlayer;
}
static void
_list_item_cb2(void *data, Evas_Object *obj, void *event_info)
{
   Evas_Object *ctxpopup;
   Elm_Object_Item *it;
   Evas_Coord x,y;

   if (list_mouse_down > 0) return;

   ctxpopup = elm_ctxpopup_add(obj);
   evas_object_smart_callback_add(ctxpopup, "dismissed", _dismissed_cb, NULL);
   elm_ctxpopup_horizontal_set(ctxpopup, EINA_TRUE);

   item_new(ctxpopup, NULL, "home");
   item_new(ctxpopup, NULL, "file");
   item_new(ctxpopup, NULL, "delete");
   item_new(ctxpopup, NULL, "folder");
   it = item_new(ctxpopup, NULL, "edit");
   elm_object_item_disabled_set(it, EINA_TRUE);
   item_new(ctxpopup, NULL, "clock");

   evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y);
   evas_object_move(ctxpopup, x, y);
   evas_object_show(ctxpopup);

   elm_list_item_selected_set(event_info, EINA_FALSE);
}
static void
_btn_clicked(void *data, Evas_Object *obj, void *event_info)
{
    Evas_Object *win = data;
    Evas_Object *ctxpopup;
    Evas_Coord x,y;

    ctxpopup = elm_ctxpopup_add(win);

    elm_object_style_set(ctxpopup, "1text.1icon");
    elm_object_signal_emit(ctxpopup, "elm,action,focus", "elm");
    item_new(ctxpopup, "Text List1", "home");
    item_new(ctxpopup, "Text List2", "file");
    item_new(ctxpopup, "Text List3", "delete");

    switch (dir) {
        case 0:
            elm_ctxpopup_direction_priority_set(ctxpopup,
                                                ELM_CTXPOPUP_DIRECTION_UP, 0, 0, 0);
            break;
        case 1:
            elm_ctxpopup_direction_priority_set(ctxpopup,
                                                ELM_CTXPOPUP_DIRECTION_DOWN, 0, 0, 0);
            break;
        case 2:
            elm_ctxpopup_direction_priority_set(ctxpopup,
                                                ELM_CTXPOPUP_DIRECTION_LEFT, 0, 0, 0);
            break;
        case 3:
            elm_ctxpopup_direction_priority_set(ctxpopup,
                                                ELM_CTXPOPUP_DIRECTION_RIGHT, 0, 0, 0);
            break;
    }

    evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y);
    evas_object_move(ctxpopup, x, y);
    evas_object_show(ctxpopup);
    eext_object_event_callback_add(ctxpopup, EEXT_CALLBACK_BACK, _ctxpopup_back_key_cb, NULL);
}
Пример #4
0
//
// Copies an item, useful for prototype->instance items
//
item * item_copy(const item * pt)
{
	item * it = item_new(pt->type, pt->ch);

	it->name            = copy_str(pt->name);
	it->weight          = pt->weight;
	it->restore_health  = pt->restore_health;
	it->restore_stamina = pt->restore_stamina;
	it->modify_attack   = pt->modify_attack;
	it->modify_ac       = pt->modify_ac;
	it->slot            = pt->slot;
	it->spikiness       = pt->spikiness;
	it->mat_class       = copy_str(pt->mat_class);
	it->mat             = pt->mat;
	it->gen_id          = pt->gen_id;
	it->gen_mat_id      = pt->gen_mat_id;

	if (it->mat != NULL) it->mat->refs++;

	return it;
}
Пример #5
0
//Give the stuff at start depending on the job chosen
void setStuffAtStart(Player *target)
{
    target->armory = item_new();

    switch(target->job){
        case WARRIOR:
                autoEquip(target, stuffItem_ctor("My First Sword", 10, RIGHT_HAND, 5, 0, 0));
                autoEquip(target, stuffItem_ctor("Textile Armor", 10, ARMOR, 0, 1, 5));
            break;
        case RANGER:
                autoEquip(target, stuffItem_ctor("My First Bow", 10, TWO_HAND, 4, 0, 0));
                autoEquip(target, stuffItem_ctor("A Tiny Short", 10, ARMOR, 0, 1, 4));
            break;
        case WIZARD:
                autoEquip(target, stuffItem_ctor("My First Wand", 10, RIGHT_HAND, 5, 0, 0));
                autoEquip(target, stuffItem_ctor("My First Robe", 10, ARMOR, 0, 2, 3));
            break;
        default:
            break;
    }
}
Пример #6
0
//Read a list of structure to display it
DlistStuff* readFromFile_stuff(){
    DlistStuff *p_list = item_new();
    StuffItem* stuff = malloc(sizeof(StuffItem));
    FILE *fptr;

    fptr=fopen("./list_stuff.txt","r");

    if (fptr) {
        /* File was opened successfully. */

        /* Attempt to read element one by one */
        while (fread(stuff,sizeof(StuffItem),1,fptr) == 1) {
            item_append(p_list, *stuffItem_ctor(stuff->name, stuff->price, stuff->type, stuff->I_bonusATT, stuff->I_bonusDEFRel, stuff->I_bonusDEFAbs));
        }
        printf("\n");
    }

    fclose(fptr);

    return p_list;
}
Пример #7
0
static itemPtr
db_load_item_from_columns (sqlite3_stmt *stmt) 
{
	const gchar	*tmp;

	itemPtr item = item_new ();
	
	item->readStatus	= sqlite3_column_int (stmt, 1)?TRUE:FALSE;
	item->updateStatus	= sqlite3_column_int (stmt, 2)?TRUE:FALSE;
	item->popupStatus	= sqlite3_column_int (stmt, 3)?TRUE:FALSE;
	item->flagStatus	= sqlite3_column_int (stmt, 4)?TRUE:FALSE;
	item->validGuid		= sqlite3_column_int (stmt, 7)?TRUE:FALSE;
	item->time		= sqlite3_column_int (stmt, 9);
	item->commentFeedId	= g_strdup (sqlite3_column_text (stmt, 10));
	item->isComment		= sqlite3_column_int (stmt, 11);
	item->id		= sqlite3_column_int (stmt, 12);
	item->parentItemId	= sqlite3_column_int (stmt, 13);
	item->nodeId		= g_strdup (sqlite3_column_text (stmt, 14));
	item->parentNodeId	= g_strdup (sqlite3_column_text (stmt, 15));

	item->title		= g_strdup (sqlite3_column_text(stmt, 0));
	item->sourceId		= g_strdup (sqlite3_column_text(stmt, 6));
	
	tmp = sqlite3_column_text(stmt, 5);
	if (tmp)
		item->source = g_strdup (tmp);
		
	tmp = sqlite3_column_text(stmt, 8);
	if (tmp)
		item->description = g_strdup (tmp);
	else
		item->description = g_strdup ("");

	item->metadata = db_item_metadata_load (item);

	return item;
}
Пример #8
0
void
queue_add (Queue       *h,
	   const gchar *uri)
{
  GList *trash = NULL;

  g_return_if_fail (h != NULL);
  g_return_if_fail (uri != NULL);

  if (h->current)
    {
      trash = h->current->next;
      h->current->next = NULL;
    }

  h->queue   = g_list_append (h->queue, item_new (uri));
  h->current = g_list_last (h->queue);

  if (trash)
    {
      g_list_foreach (trash, (GFunc) item_free, NULL);
      g_list_free (trash);
    }
}
Пример #9
0
/* method to parse standard tags for each item element */
static itemPtr
atom10_parse_entry (feedParserCtxtPtr ctxt, xmlNodePtr cur)
{
	NsHandler		*nsh;
	parseItemTagFunc	pf;
	atom10ElementParserFunc func;
	static GHashTable	*entryElementHash = NULL;
	
	if (!entryElementHash) {
		entryElementHash = g_hash_table_new (g_str_hash, g_str_equal);
		
		g_hash_table_insert (entryElementHash, "author", &atom10_parse_entry_author);
		g_hash_table_insert (entryElementHash, "category", &atom10_parse_entry_category);
		g_hash_table_insert (entryElementHash, "content", &atom10_parse_entry_content);
		g_hash_table_insert (entryElementHash, "contributor", &atom10_parse_entry_contributor);
		g_hash_table_insert (entryElementHash, "id", &atom10_parse_entry_id);
		g_hash_table_insert (entryElementHash, "link", &atom10_parse_entry_link);
		g_hash_table_insert (entryElementHash, "published", &atom10_parse_entry_published);
		g_hash_table_insert (entryElementHash, "rights", &atom10_parse_entry_rights);
		/* FIXME: Parse "source" */
		g_hash_table_insert (entryElementHash, "summary", &atom10_parse_entry_summary);
		g_hash_table_insert (entryElementHash, "title", &atom10_parse_entry_title);
		g_hash_table_insert (entryElementHash, "updated", &atom10_parse_entry_updated);
	}	

	ctxt->item = item_new ();
	
	cur = cur->xmlChildrenNode;
	while (cur) {
		
		if (cur->type != XML_ELEMENT_NODE || cur->name == NULL || cur->ns == NULL) {
			cur = cur->next;
			continue;
		}
		
		if ((cur->ns->href   && (nsh = (NsHandler *)g_hash_table_lookup (ns_atom10_ns_uri_table, (gpointer)cur->ns->href))) ||
		    (cur->ns->prefix && (nsh = (NsHandler *)g_hash_table_lookup (atom10_nstable, (gpointer)cur->ns->prefix)))) {
			
			pf = nsh->parseItemTag;
			if (pf)
				(*pf) (ctxt, cur);
			cur = cur->next;
			continue;
		}
		
		/* check namespace of this tag */
		if (!cur->ns->href) {
			/* This is an invalid feed... no idea what to do with the current element */
			debug1 (DEBUG_PARSING, "element with no namespace found in atom feed (%s)!", cur->name);
			cur = cur->next;
			continue;
		}
		
		
		if (xmlStrcmp(cur->ns->href, ATOM10_NS)) {
			debug1(DEBUG_PARSING, "unknown namespace %s found!", cur->ns->href);
			cur = cur->next;
			continue;
		}
		/* At this point, the namespace must be the Atom 1.0 namespace */
		func = g_hash_table_lookup (entryElementHash, cur->name);
		if (func) {
			(*func) (cur, ctxt, NULL);
		} else {
			debug1 (DEBUG_PARSING, "unknown entry element \"%s\" found", cur->name);
		}
		
		cur = cur->next;
	}
	
	/* after parsing we fill the infos into the itemPtr structure */
	ctxt->item->readStatus = FALSE;
	
	if (0 == ctxt->item->time)
		ctxt->item->time = ctxt->feed->time;
	
	return ctxt->item;
}
Пример #10
0
GList *
json_api_get_items (const gchar *json, const gchar *root, jsonApiMapping *mapping, jsonApiItemCallbackFunc callback)
{
	GList		*items = NULL;
	JsonParser	*parser = json_parser_new ();

	if (json_parser_load_from_data (parser, json, -1, NULL)) {
		JsonArray	*array = json_node_get_array (json_get_node (json_parser_get_root (parser), root));
		GList		*elements = json_array_get_elements (array);
		GList		*iter = elements;

		debug1 (DEBUG_PARSING, "JSON API: found items root node \"%s\"", root);
                
		while (iter) {
			JsonNode *node = (JsonNode *)iter->data;
			itemPtr item = item_new ();

			/* Parse default feeds */
			item_set_id	(item, json_api_get_string (node, mapping->id));
			item_set_title	(item, json_api_get_string (node, mapping->title));
			item_set_source	(item, json_api_get_string (node, mapping->link));

			item->time       = json_api_get_int (node, mapping->updated);
			item->readStatus = json_api_get_bool (node, mapping->read);
			item->flagStatus = json_api_get_bool (node, mapping->flag);

			if (mapping->negateRead)
				item->readStatus = !item->readStatus;

			/* Handling encoded content */
			const gchar *content; 
			gchar *xhtml;

			content = json_api_get_string (node, mapping->description);
			if (mapping->xhtml) {
				xhtml = xhtml_extract_from_string (content, NULL);
				item_set_description (item, xhtml);
				xmlFree (xhtml);
			} else {
				item_set_description (item, content);
			}

			/* Optional meta data */
			const gchar *tmp = json_api_get_string (node, mapping->author);
			if (tmp)
				item->metadata = metadata_list_append (item->metadata, "author", tmp);
	
			items = g_list_append (items, (gpointer)item);

			/* Allow optional item callback to process stuff */
			if (callback)
				(*callback)(node, item);
				
			iter = g_list_next (iter);
		}

		g_list_free (elements);
		g_object_unref (parser);
	} else {
		debug1 (DEBUG_PARSING, "Could not parse JSON \"%s\"", json);
	}

	return items;
}
Пример #11
0
static void
ttrss_feed_subscription_process_update_result (subscriptionPtr subscription, const struct updateResult* const result, updateFlags flags)
{
	if (result->data && result->httpstatus == 200) {
		JsonParser	*parser = json_parser_new ();

		if (json_parser_load_from_data (parser, result->data, -1, NULL)) {
			JsonArray	*array = json_node_get_array (json_get_node (json_parser_get_root (parser), "content"));
			GList		*elements = json_array_get_elements (array);
			GList		*iter = elements;
			GList		*items = NULL;

			/*
			   We expect to get something like this
			   
			   [{"id":118,
			     "unread":true,
			     "marked":false,
			     "updated":1287927675,
			     "is_updated":false,
			     "title":"IBM Says New ...",
			     "link":"http:\/\/rss.slashdot.org\/~r\/Slashdot\/slashdot\/~3\/ALuhNKO3NV4\/story01.htm",
			     "feed_id":"5",
			     "content":"coondoggie writes ..."
			    },
			    {"id":117,
			     "unread":true,
			     "marked":false,
			     "updated":1287923814,
                           [...]
                         */
                         
			while (iter) {
				JsonNode *node = (JsonNode *)iter->data;
				itemPtr item = item_new ();
				gchar *id;
				const gchar *content; 
				gchar *xhtml;

				id = g_strdup_printf ("%" G_GINT64_FORMAT, json_get_int (node, "id"));
				item_set_id (item, id);
				g_free (id);
				item_set_title (item, json_get_string (node, "title"));
				item_set_source (item, json_get_string (node, "link"));

				content = json_get_string (node, "content");
				xhtml = xhtml_extract_from_string (content, NULL);
				item_set_description (item, xhtml);
				xmlFree (xhtml);

				item->time = json_get_int (node, "updated");
				
				if (json_get_bool (node, "unread")) {
					item->readStatus = FALSE;
				}
				else {
					item->readStatus = TRUE;
				}
				if (json_get_bool (node, "marked"))
					item->flagStatus = TRUE;
					
				items = g_list_append (items, (gpointer)item);
				
				iter = g_list_next (iter);
			}

			g_list_free (elements);

			/* merge against feed cache */
			if (items) {
				itemSetPtr itemSet = node_get_itemset (subscription->node);
				gint newCount = itemset_merge_items (itemSet, items, TRUE /* feed valid */, FALSE /* markAsRead */);
				itemlist_merge_itemset (itemSet);
				itemset_free (itemSet);

				feedlist_node_was_updated (subscription->node, newCount);
			}

			subscription->node->available = TRUE;
		} else {
			subscription->node->available = FALSE;

			g_string_append (((feedPtr)subscription->node->data)->parseErrors, _("Could not parse JSON returned by TinyTinyRSS API!"));
		}

		g_object_unref (parser);
	} else {
		subscription->node->available = FALSE;
	}
}
Пример #12
0
int main(int argc, char * argv[]) {
  ///g_warning("Sample warning");
  ///g_message("Loading *.desktop files");
  
  // pointer array for storing menu items
  GPtrArray *items = g_ptr_array_new ();
  
  // read all files from applications directory
  gchar *path = g_strdup("/usr/share/applications");
  GDir *d = g_dir_open(path,0,NULL);
  const gchar *n;
  while ( (n = g_dir_read_name(d)) ) {
    // get filename from dir content
    gchar *fn = g_build_filename(path,n,NULL);
    //printf("--> fn=%s\n",fn);
    // is it .desktop file
    if (!g_str_has_suffix(fn,".desktop"))
      continue;
    // load .desktop file
    GKeyFile *kf = g_key_file_new();
    gboolean b = g_key_file_load_from_file(kf, fn, G_KEY_FILE_NONE, NULL);
    if (!b) {
        fprintf(stderr, "error: cannot load .desktop file %s\n", fn);
        g_key_file_free(kf);
        continue;
    }
    g_assert(b);
    // load categories
    gsize length = 0;
    char **cats = g_key_file_get_string_list(kf,"Desktop Entry","Categories",&length,NULL);
    gchar *name = g_key_file_get_value(kf,"Desktop Entry","Name",NULL);
    gchar *exec = g_key_file_get_value(kf,"Desktop Entry","Exec",NULL);
 
    fix(exec);

    gchar *icon = g_key_file_get_value(kf,"Desktop Entry","Icon",NULL);
    gchar *type = g_key_file_get_value(kf,"Desktop Entry","Type",NULL);
    gboolean no_display = g_key_file_get_boolean(kf,"Desktop Entry","NoDisplay",NULL);
    // sort it to categories in application menu

    // determine best matching category
    ItemCategory c = icOther;
    for (guint i=0; i<length; i++) {
      //printf("  Category[%d]: %s\n",i,cats[i]);
      if (strstr("DesktopSettings, HardwareSettings, Monitor, PackageManager, Settings, System, X-GNOME-NetworkSettings, X-GNOME-PersonalSettings, X-LXDE-Settings, X-SuSE-ControlCenter-System, X-XFCE",cats[i]))
        c = icSettings;
      if (strstr("ArcadeGame, BlocksGame, BoardGame, CardGame, Game, LogicGame",cats[i]))
        c = icGames;
      if (strstr("Archiving, Compression, Core, DiscBurning, Documentation, FileManager, TerminalEmulator, Utility",cats[i]))
        c = icUtility;
      if (strstr("Astronomy, Dictionary, Education, Math, Science, Translation",cats[i]))
        c = icScienceEducation;
      if (strstr("Audio, AudioVideo, AudioVideoEditing, Mixer, Player, Recorder, Video",cats[i]))
        c = icAudioVideo;
      if (strstr("Calculator, Calendar, ContactManagement, Office, Presentation, Printing, TextEditor, Spreadsheet, WordProcessor",cats[i]))
        c = icOffice;
      if (strstr("Development, Emulator, Engineering, GTK, GUIDesigner, IDE, Qt",cats[i]))
        c = icDevelopment;
      if (strstr("Email, FileTransfer, Chat, InstantMessaging, Internet, IRCClient, Network, P2P, RemoteAccess, Security, WebBrowser",cats[i]))
        c = icInternet;
      if (strstr("Graphics, Photography, RasterGraphics, Scanning, VectorGraphics, Viewer, 2DGraphics, 3DGraphics",cats[i]))
        c = icGraphics;
    }
    
    // add items to array
    if ((!no_display)&&(name)&&(exec)&&(icon))
      g_ptr_array_add (items, item_new(c, name, exec, icon));

    // free temp vars
    g_strfreev(cats);
    g_free(name);
    g_free(exec);
    g_free(icon);
    g_free(type);
    g_key_file_free(kf);
  }
  // close dir
  g_dir_close(d);

  // sort items by categories and by name
  g_ptr_array_sort(items,&item_compare);
  
  // print what we get
  printf("<?xml version=\"1.0\"?>\n");
  printf("<JWM>\n");
  //jwm_category(items,"Accessibility",icAccessibility);
  jwm_category(items,"Audio and video",icAudioVideo);
  jwm_category(items,"Development",icDevelopment);
  jwm_category(items,"Games",icGames);
  jwm_category(items,"Graphics",icGraphics);
  jwm_category(items,"Internet",icInternet);
  jwm_category(items,"Office",icOffice);
  jwm_category(items,"Other",icOther);
  jwm_category(items,"Science and education",icScienceEducation);
  jwm_category(items,"Settings",icSettings);
  jwm_category(items,"Utility",icUtility);
  printf("</JWM>\n");
    
  ///g_error("dont know what to do now");
  return 0;
}
Пример #13
0
void
test_inventory_data(void)
{
    GwyInventoryItemType item_type = {
        0,
        NULL,
        item_get_name,
        item_is_modifiable,
        item_compare,
        item_rename,
        item_destroy,
        item_copy,
        NULL,
        NULL,
        NULL,
    };

    GwyInventory *inventory = gwy_inventory_new();
    g_assert(GWY_IS_INVENTORY(inventory));
    item_type.type = GWY_TYPE_ITEM_TEST;
    gwy_inventory_set_item_type(inventory, &item_type);
    item_destroy_count = 0;

    guint64 insert_log = 0, update_log = 0, delete_log = 0;
    g_signal_connect(inventory, "item-inserted",
                     G_CALLBACK(record_item_change), &insert_log);
    g_signal_connect(inventory, "item-updated",
                     G_CALLBACK(record_item_change), &update_log);
    g_signal_connect(inventory, "item-deleted",
                     G_CALLBACK(record_item_change), &delete_log);

    gwy_inventory_insert(inventory, item_new("Fixme", -1));
    gwy_inventory_insert(inventory, item_new("Second", 2));
    gwy_inventory_insert(inventory, item_new("First", 1));
    g_assert_cmpuint(gwy_inventory_size(inventory), ==, 3);
    g_assert_cmphex(insert_log, ==, 0x121);
    g_assert_cmphex(update_log, ==, 0);
    g_assert_cmphex(delete_log, ==, 0);
    insert_log = 0;

    gwy_inventory_updated(inventory, "Second");
    gwy_inventory_updated(inventory, "First");
    gwy_inventory_updated(inventory, "Second");
    g_assert_cmpuint(gwy_inventory_size(inventory), ==, 3);
    g_assert_cmphex(insert_log, ==, 0);
    // Inventory is sorted so "Second" comes after "Fixme".
    g_assert_cmphex(update_log, ==, 0x313);
    g_assert_cmphex(delete_log, ==, 0);
    update_log = 0;

    gwy_inventory_nth_updated(inventory, 0);
    gwy_inventory_nth_updated(inventory, 1);
    gwy_inventory_nth_updated(inventory, 2);
    g_assert_cmpuint(gwy_inventory_size(inventory), ==, 3);
    g_assert_cmpuint(gwy_listable_size(GWY_LISTABLE(inventory)), ==, 3);
    g_assert_cmphex(insert_log, ==, 0);
    g_assert_cmphex(update_log, ==, 0x123);
    g_assert_cmphex(delete_log, ==, 0);
    update_log = 0;

    GwyItemTest *itemtest;
    g_assert((itemtest = (GwyItemTest*)gwy_inventory_get(inventory, "Fixme")));
    g_assert_cmpint(itemtest->value, ==, -1);
    g_assert((itemtest = (GwyItemTest*)gwy_inventory_get(inventory, "Second")));
    g_assert_cmpint(itemtest->value, ==, 2);
    g_assert((itemtest = (GwyItemTest*)gwy_inventory_get(inventory, "First")));
    g_assert_cmpint(itemtest->value, ==, 1);

    g_assert((itemtest = (GwyItemTest*)gwy_inventory_get_nth(inventory, 0)));
    g_assert_cmpstr(itemtest->name, ==, "First");
    g_assert((itemtest = (GwyItemTest*)gwy_inventory_get_nth(inventory, 1)));
    g_assert_cmpstr(itemtest->name, ==, "Fixme");
    g_assert((itemtest = (GwyItemTest*)gwy_inventory_get_nth(inventory, 2)));
    g_assert_cmpstr(itemtest->name, ==, "Second");

    for (guint i = 0; i < 3; i++) {
        g_assert(gwy_inventory_get_nth(inventory, i)
                 == gwy_listable_get(GWY_LISTABLE(inventory), i));
    }

    gwy_inventory_forget_order(inventory);
    g_assert_cmphex(insert_log, ==, 0);
    g_assert_cmphex(update_log, ==, 0);
    g_assert_cmphex(delete_log, ==, 0);

    gwy_inventory_insert(inventory, item_new("Abel", 0));
    gwy_inventory_insert(inventory, item_new("Kain", 1));
    g_assert_cmphex(insert_log, ==, 0x45);
    g_assert_cmphex(update_log, ==, 0);
    g_assert_cmphex(delete_log, ==, 0);
    insert_log = 0;
    gwy_inventory_restore_order(inventory);
    g_assert_cmpuint(gwy_inventory_size(inventory), ==, 5);
    g_assert_cmphex(insert_log, ==, 0);
    g_assert_cmphex(update_log, ==, 0);
    g_assert_cmphex(delete_log, ==, 0);

    g_assert((itemtest = (GwyItemTest*)gwy_inventory_get_nth(inventory, 0)));
    g_assert_cmpstr(itemtest->name, ==, "Abel");
    g_assert((itemtest = (GwyItemTest*)gwy_inventory_get_nth(inventory, 3)));
    g_assert_cmpstr(itemtest->name, ==, "Kain");

    g_assert((itemtest = (GwyItemTest*)gwy_inventory_get(inventory, "Fixme")));
    itemtest->value = 3;
    gwy_inventory_rename(inventory, "Fixme", "Third");
    g_assert_cmphex(insert_log, ==, 0x0);
    g_assert_cmphex(update_log, ==, 0x5);
    g_assert_cmphex(delete_log, ==, 0x0);
    insert_log = update_log = delete_log = 0;

    g_assert((itemtest = (GwyItemTest*)gwy_inventory_get_nth(inventory, 4)));
    g_assert_cmpstr(itemtest->name, ==, "Third");

    gwy_inventory_delete_nth(inventory, 0);
    gwy_inventory_delete(inventory, "Kain");
    g_assert_cmpuint(gwy_inventory_size(inventory), ==, 3);
    g_assert_cmphex(insert_log, ==, 0);
    g_assert_cmphex(update_log, ==, 0);
    g_assert_cmphex(delete_log, ==, 0x12);
    delete_log = 0;

    g_object_unref(inventory);
    g_assert_cmpuint(item_destroy_count, ==, 5);
}
Пример #14
0
// this function is really ugly
static void generate(zone * z)
{
	static int first = 1;

	int i, x, y, max;
	int rc;
	int ** walls;
	room * rv;
	item * it;
	creature * cr;

	if (first) {
		fill_walls();
		first = 0;
	}

	// generate rooms
	rc = random() % ((z->width * z->height) / ROOM_INFREQ) + ROOM_MIN;
	rv = malloc(sizeof(room) * rc);

	for (i = 0; i < rc; i++) {
		rv[i].w = random() % 12 + 5;
		rv[i].h = random() % 8 + 3;
		rv[i].x = random() % (z->width  - rv[i].w - 1) + 1;
		rv[i].y = random() % (z->height - rv[i].h - 1) + 1;
	}


	// cut out rooms
	walls = malloc(sizeof(int *) * z->width);
	for (x = 0; x < z->width; x++) {
		walls[x] = malloc(sizeof(int) * z->height);

		for (y = 0; y < z->height; y++) {
			for (i = 0; i < rc; i++) {
				if (in_room(rv + i, x, y)) break;
			}
			z->tiles[x][y].ch = '.';
			walls[x][y] = (i == rc);
		}
	}


	// draw walls
	for (x = 0; x < z->width; x++) {
		for (y = 0; y < z->height; y++) {
			if (walls[x][y]) {
				z->tiles[x][y].impassible = 1;
				set_wall_char(walls,z,x,y);
			}
		}
	}

	// place some random junk
	if (world.iform_cnt != 0) {
		max = random() % (z->width * z->height / ITEM_INFREQ) + ITEM_MIN;
		for (i = max; i >= 0; i--) {
			it = item_new(world.iforms[random() % world.iform_cnt]);

			do {
				x = random() % z->width;
				y = random() % z->height;
			} while (z->tiles[x][y].impassible || !inv_try(z->tiles[x][y].inv, it));

			item_tele(it, x, y, z);
			zone_update(z, x, y);
		}
	}

	// place some more random junk
	if (world.cform_cnt != 0) {
		max = random() % (z->width * z->height / CRTR_INFREQ) + CRTR_MIN;
		for (i = max; i >= 0; i--) {
			cr = crtr_new(world.cforms[random() % world.cform_cnt]);

			do {
				x = random() % z->width;
				y = random() % z->height;
			} while (z->tiles[x][y].impassible || z->tiles[x][y].crtr != NULL);

			crtr_tele(cr, x, y, z);
			zone_update(z, x, y);
		}
	}
}
Пример #15
0
void
test_inventory_sorting(void)
{
    GwyInventoryItemType item_type = {
        0,
        NULL,
        item_get_name,
        item_is_modifiable,
        item_compare_tricky,
        item_rename,
        item_destroy,
        item_copy,
        NULL,
        NULL,
        NULL,
    };

    GwyInventory *inventory = gwy_inventory_new();
    g_assert(GWY_IS_INVENTORY(inventory));
    item_type.type = GWY_TYPE_ITEM_TEST;
    gwy_inventory_set_item_type(inventory, &item_type);
    gboolean expect_reorder = FALSE;
    item_destroy_count = 0;
    sort_by_name = TRUE;

    guint64 insert_log = 0, update_log = 0, delete_log = 0;
    g_signal_connect(inventory, "item-inserted",
                     G_CALLBACK(record_item_change), &insert_log);
    g_signal_connect(inventory, "item-updated",
                     G_CALLBACK(record_item_change), &update_log);
    g_signal_connect(inventory, "item-deleted",
                     G_CALLBACK(record_item_change), &delete_log);
    g_signal_connect_swapped(inventory, "items-reordered",
                             G_CALLBACK(check_reordering), &expect_reorder);

    gwy_inventory_insert(inventory, item_new("Bananna", 2));
    gwy_inventory_insert(inventory, item_new("Apple", 8));
    gwy_inventory_insert(inventory, item_new("Date", 4));
    gwy_inventory_insert(inventory, item_new("Citrus", 1));
    g_assert_cmpuint(gwy_inventory_size(inventory), ==, 4);
    g_assert_cmphex(insert_log, ==, 0x1133);
    g_assert_cmphex(update_log, ==, 0);
    g_assert_cmphex(delete_log, ==, 0);
    insert_log = 0;

    // Break the sorting order so that followig items are just appended.
    gwy_inventory_insert_nth(inventory, item_new("Turd", 0), 2);
    g_assert_cmpuint(gwy_inventory_size(inventory), ==, 5);
    g_assert_cmphex(insert_log, ==, 0x3);
    g_assert_cmphex(update_log, ==, 0);
    g_assert_cmphex(delete_log, ==, 0);
    insert_log = 0;

    gwy_inventory_insert(inventory, item_new("Bogus", 3));
    g_assert_cmpuint(gwy_inventory_size(inventory), ==, 6);
    g_assert_cmphex(insert_log, ==, 0x6);
    g_assert_cmphex(update_log, ==, 0);
    g_assert_cmphex(delete_log, ==, 0);
    insert_log = 0;

    g_assert_cmpuint(gwy_inventory_position(inventory, "Apple"), ==, 0);
    g_assert_cmpuint(gwy_inventory_position(inventory, "Bananna"), ==, 1);
    g_assert_cmpuint(gwy_inventory_position(inventory, "Turd"), ==, 2);
    g_assert_cmpuint(gwy_inventory_position(inventory, "Citrus"), ==, 3);
    g_assert_cmpuint(gwy_inventory_position(inventory, "Date"), ==, 4);
    g_assert_cmpuint(gwy_inventory_position(inventory, "Bogus"), ==, 5);

    sort_by_name = FALSE;
    expect_reorder = TRUE;
    gwy_inventory_restore_order(inventory);
    g_assert_cmpuint(gwy_inventory_size(inventory), ==, 6);
    g_assert_cmphex(insert_log, ==, 0);
    g_assert_cmphex(update_log, ==, 0);
    g_assert_cmphex(delete_log, ==, 0);

    g_assert_cmpuint(gwy_inventory_position(inventory, "Turd"), ==, 0);
    g_assert_cmpuint(gwy_inventory_position(inventory, "Citrus"), ==, 1);
    g_assert_cmpuint(gwy_inventory_position(inventory, "Bananna"), ==, 2);
    g_assert_cmpuint(gwy_inventory_position(inventory, "Bogus"), ==, 3);
    g_assert_cmpuint(gwy_inventory_position(inventory, "Date"), ==, 4);
    g_assert_cmpuint(gwy_inventory_position(inventory, "Apple"), ==, 5);

    expect_reorder = FALSE;
    g_object_unref(inventory);
    g_assert_cmpuint(item_destroy_count, ==, 6);
}
Пример #16
0
/* method to parse standard tags for each item element */
itemPtr parseCDFItem(feedParserCtxtPtr ctxt, xmlNodePtr cur, CDFChannelPtr cp) {
	gchar		*tmp = NULL, *tmp2, *tmp3;

	if(CDFToMetadataMapping == NULL) {
		CDFToMetadataMapping = g_hash_table_new(g_str_hash, g_str_equal);
		g_hash_table_insert(CDFToMetadataMapping, "author", "author");
		g_hash_table_insert(CDFToMetadataMapping, "category", "category");
	}
		
	ctxt->item = item_new();
	
	/* save the item link */
	if(!(tmp = (gchar *)xmlGetProp(cur, BAD_CAST"href")))
		tmp = (gchar *)xmlGetProp(cur, BAD_CAST"HREF");
	if(tmp) {
		item_set_source(ctxt->item, tmp);
		g_free(tmp);
	}
	
	cur = cur->xmlChildrenNode;
	while(cur) {

		if(!cur->name || cur->type != XML_ELEMENT_NODE) {
			cur = cur->next;
			continue;
		}
		
		/* save first link to a channel image */
		if(NULL != (tmp = g_ascii_strdown((gchar *)cur->name, -1))) {
			if(NULL != (tmp2 = g_hash_table_lookup(CDFToMetadataMapping, tmp))) {
				if(NULL != (tmp3 = (gchar *)xmlNodeListGetString(cur->doc, cur->xmlChildrenNode, TRUE))) {
					ctxt->item->metadata = metadata_list_append(ctxt->item->metadata, tmp2, tmp3);
					g_free(tmp3);
				}
			}
			g_free(tmp);
		}
		
		if((!xmlStrcasecmp(cur->name, BAD_CAST"logo"))) {
			
			if(!(tmp = (gchar *)xmlGetProp(cur, BAD_CAST"href")))
				tmp = (gchar *)xmlGetProp(cur, BAD_CAST"HREF");
			if(tmp) {
				ctxt->item->metadata = metadata_list_append(ctxt->item->metadata, "imageUrl", tmp);
				g_free(tmp);
			}
			
		} else if((!xmlStrcasecmp(cur->name, BAD_CAST"title"))) {
			if(NULL != (tmp = unhtmlize((gchar *)xmlNodeListGetString(cur->doc, cur->xmlChildrenNode, 1)))) {
				item_set_title(ctxt->item, tmp);
				g_free(tmp);
			}
			
		} else if((!xmlStrcasecmp(cur->name, BAD_CAST"abstract"))) {
			if(NULL != (tmp = (gchar *)xmlNodeListGetString(cur->doc, cur->xmlChildrenNode, 1))) {
				item_set_description(ctxt->item, tmp);
				g_free(tmp);
			}
			
		} else if((!xmlStrcasecmp(cur->name, BAD_CAST"a"))) {
			if(!(tmp = (gchar *)xmlGetProp(cur, BAD_CAST"href")))
				tmp = (gchar *)xmlGetProp(cur, BAD_CAST"HREF");
			if(tmp) {
				item_set_source(ctxt->item, tmp);
				g_free(tmp);
			}
		}
		
		cur = cur->next;
	}

	ctxt->item->readStatus = FALSE;
	
	return ctxt->item;
}
Пример #17
0
void
test_inventory_functional(void)
{
    GwyInventoryItemType item_type = {
        0,
        NULL,
        item_get_name,
        item_is_modifiable,
        item_compare,
        item_rename,
        item_destroy,
        item_copy,
        NULL,
        NULL,
        NULL,
    };

    GwyInventory *inventory = gwy_inventory_new();
    g_assert(GWY_IS_INVENTORY(inventory));
    item_type.type = GWY_TYPE_ITEM_TEST;
    gwy_inventory_set_item_type(inventory, &item_type);
    item_destroy_count = 0;
    sort_by_name = TRUE;

    guint64 insert_log = 0, update_log = 0, delete_log = 0;
    g_signal_connect(inventory, "item-inserted",
                     G_CALLBACK(record_item_change), &insert_log);
    g_signal_connect(inventory, "item-updated",
                     G_CALLBACK(record_item_change), &update_log);
    g_signal_connect(inventory, "item-deleted",
                     G_CALLBACK(record_item_change), &delete_log);

    gwy_inventory_insert(inventory, item_new("Bananna", 2));
    gwy_inventory_insert(inventory, item_new("Apple", 8));
    gwy_inventory_insert(inventory, item_new("Date", 4));
    gwy_inventory_insert(inventory, item_new("Citrus", 1));
    g_assert_cmpuint(gwy_inventory_size(inventory), ==, 4);
    g_assert_cmphex(insert_log, ==, 0x1133);
    g_assert_cmphex(update_log, ==, 0);
    g_assert_cmphex(delete_log, ==, 0);
    insert_log = 0;

    GwyItemTest *itemtest = (GwyItemTest*)gwy_inventory_find(inventory,
                                                             predicate1, NULL);
    g_assert(!itemtest);

    itemtest = (GwyItemTest*)gwy_inventory_find(inventory, predicate2, NULL);
    g_assert(itemtest);
    g_assert_cmpstr(itemtest->name, ==, "Apple");
    g_assert_cmpint(itemtest->value, ==, 8);

    itemtest = (GwyItemTest*)gwy_inventory_find(inventory, predicate3, NULL);
    g_assert(itemtest);
    g_assert_cmpstr(itemtest->name, ==, "Bananna");
    g_assert_cmpint(itemtest->value, ==, 2);

    itemtest = (GwyItemTest*)gwy_inventory_find(inventory, predicate4, NULL);
    g_assert(itemtest);
    g_assert_cmpstr(itemtest->name, ==, "Date");
    g_assert_cmpint(itemtest->value, ==, 4);

    gint sum = 0;
    gwy_inventory_foreach(inventory, sum_values, &sum);
    g_assert_cmpint(sum, ==, 15);

    g_object_unref(inventory);
    g_assert_cmpuint(item_destroy_count, ==, 4);
}
Пример #18
0
/* method to parse standard tags for each item element */
itemPtr parseEntry(feedParserCtxtPtr ctxt, xmlNodePtr cur) {
	xmlChar			*xtmp;
	gchar			*tmp2, *tmp;
	NsHandler		*nsh;
	parseItemTagFunc	pf;
	
	g_assert(NULL != cur);
		
	ctxt->item = item_new();
	
	cur = cur->xmlChildrenNode;
	while(cur) {
		if(!cur->name) {
			g_warning("invalid XML: parser returns NULL value -> tag ignored!");
			cur = cur->next;
			continue;
		}
		
		
		/* check namespace of this tag */
		if(cur->ns) {
			if((cur->ns->href && (nsh = (NsHandler *)g_hash_table_lookup(ns_pie_ns_uri_table, (gpointer)cur->ns->href))) ||
			   (cur->ns->prefix && (nsh = (NsHandler *)g_hash_table_lookup(pie_nstable, (gpointer)cur->ns->prefix)))) {
				
				if(NULL != (pf = nsh->parseItemTag))
					(*pf)(ctxt, cur);
				cur = cur->next;
				continue;
			} else {
				/*g_print("unsupported namespace \"%s\"\n", cur->ns->prefix);*/
			}
		} /* explicitly no following else !!! */
		
		if(!xmlStrcmp(cur->name, BAD_CAST"title")) {
			if(NULL != (tmp = unhtmlize(pie_parse_content_construct(cur)))) {
				item_set_title(ctxt->item, tmp);
				g_free(tmp);
			}
		} else if(!xmlStrcmp(cur->name, BAD_CAST"link")) {
			if(NULL != (tmp2 = xml_get_attribute(cur, "href"))) {
				/* 0.3 link : rel, type and href attribute */
				xtmp = xmlGetProp(cur, BAD_CAST"rel");
				if(xtmp != NULL && !xmlStrcmp(xtmp, BAD_CAST"alternate"))
					item_set_source(ctxt->item, tmp2);
				/* else
					FIXME: Maybe do something with other links? */
				xmlFree(xtmp);
				g_free(tmp2);
			} else {
				/* 0.2 link : element content is the link, or non-alternate link in 0.3 */
				if(NULL != (tmp = (gchar *)xmlNodeListGetString(ctxt->doc, cur->xmlChildrenNode, 1))) {
					item_set_source(ctxt->item, tmp);
					g_free(tmp);
				}
			}
		} else if(!xmlStrcmp(cur->name, BAD_CAST"author")) {
			/* parse feed author */
			tmp =  parseAuthor(cur);
			ctxt->item->metadata = metadata_list_append(ctxt->item->metadata, "author", tmp);
			g_free(tmp);
		} else if(!xmlStrcmp(cur->name, BAD_CAST"contributor")) {
			/* parse feed contributors */
			tmp = parseAuthor(cur);
			ctxt->item->metadata = metadata_list_append(ctxt->item->metadata, "contributor", tmp);
			g_free(tmp);
		} else if(!xmlStrcmp(cur->name, BAD_CAST"id")) {
			if(NULL != (tmp = (gchar *)xmlNodeListGetString(ctxt->doc, cur->xmlChildrenNode, 1))) {
				item_set_id(ctxt->item, tmp);
				g_free(tmp);
			}
		} else if(!xmlStrcmp(cur->name, BAD_CAST"issued")) {
			/* FIXME: is <modified> or <issued> or <created> the time tag we want to display? */
 			if(NULL != (tmp = (gchar *)xmlNodeListGetString(ctxt->doc, cur->xmlChildrenNode, 1))) {
				ctxt->item->time = date_parse_ISO8601 (tmp);
				g_free(tmp);
			}
		} else if(!xmlStrcmp(cur->name, BAD_CAST"content")) {
			/* <content> support */
			if(NULL != (tmp = pie_parse_content_construct(cur))) {
				item_set_description(ctxt->item, tmp);
				g_free(tmp);
			}
		} else if(!xmlStrcmp(cur->name, BAD_CAST"summary")) {			
			/* <summary> can be used for short text descriptions, if there is no
			   <content> description we show the <summary> content */
			if(!item_get_description(ctxt->item)) {
				if(NULL != (tmp = pie_parse_content_construct(cur))) {
					item_set_description(ctxt->item, tmp);
					g_free(tmp);
				}
			}
		} else if(!xmlStrcmp(cur->name, BAD_CAST"copyright")) {
 			if(NULL != (tmp = (gchar *)xmlNodeListGetString(ctxt->doc, cur->xmlChildrenNode, 1))) {
				ctxt->item->metadata = metadata_list_append(ctxt->item->metadata, "copyright", tmp);
				g_free(tmp);
			}
		}
		cur = cur->next;
	}
	
	/* after parsing we fill the infos into the itemPtr structure */
	ctxt->item->readStatus = FALSE;

	return ctxt->item;
}
Пример #19
0
static void create_database (int list)
{
    destroy_database ();

    database = g_hash_table_new_full ((GHashFunc) str_hash, (GEqualFunc)
     str_equal, NULL, (GDestroyNotify) item_free);

    int entries = aud_playlist_entry_count (list);

    for (int e = 0; e < entries; e ++)
    {
        char * title, * artist, * album;
        Item * artist_item, * album_item, * title_item;

        aud_playlist_entry_describe (list, e, & title, & artist, & album, TRUE);

        if (! title)
        {
            str_unref (artist);
            str_unref (album);
            continue;
        }

        if (! artist)
            artist = str_get (_("Unknown Artist"));
        if (! album)
            album = str_get (_("Unknown Album"));

        artist_item = g_hash_table_lookup (database, artist);

        if (! artist_item)
        {
            /* item_new() takes ownership of reference to artist */
            artist_item = item_new (ARTIST, artist, NULL);
            g_hash_table_insert (database, artist, artist_item);
        }
        else
            str_unref (artist);

        g_array_append_val (artist_item->matches, e);

        album_item = g_hash_table_lookup (artist_item->children, album);

        if (! album_item)
        {
            /* item_new() takes ownership of reference to album */
            album_item = item_new (ALBUM, album, artist_item);
            g_hash_table_insert (artist_item->children, album, album_item);
        }
        else
            str_unref (album);

        g_array_append_val (album_item->matches, e);

        title_item = g_hash_table_lookup (album_item->children, title);

        if (! title_item)
        {
            /* item_new() takes ownership of reference to title */
            title_item = item_new (TITLE, title, album_item);
            g_hash_table_insert (album_item->children, title, title_item);
        }
        else
            str_unref (title);

        g_array_append_val (title_item->matches, e);
    }
}