Exemple #1
0
/**
 * Let a shop-keeper React to a purchase
 *
 * We paid "price", it was worth "value", and we thought it was worth "guess"
 */
static void purchase_analyze(s32b price, s32b value, s32b guess)
{
	/* Item was worthless, but we bought it */
	if ((value <= 0) && (price > value))
		msgt(MSG_STORE1, "%s", ONE_OF(comment_worthless));

	/* Item was cheaper than we thought, and we paid more than necessary */
	else if ((value < guess) && (price > value))
		msgt(MSG_STORE2, "%s", ONE_OF(comment_bad));

	/* Item was a good bargain, and we got away with it */
	else if ((value > guess) && (value < (4 * guess)) && (price < value))
		msgt(MSG_STORE3, "%s", ONE_OF(comment_good));

	/* Item was a great bargain, and we got away with it */
	else if ((value > guess) && (price < value))
		msgt(MSG_STORE4, "%s", ONE_OF(comment_great));
}
Exemple #2
0
/* Makes sorted by path list of entries that.  The trie is used to keep track of
 * identical files.  With non-zero dups_only, new files aren't added to the
 * trie. */
static entries_t
make_diff_list(trie_t *trie, FileView *view, int *next_id, CompareType ct,
		int skip_empty, int dups_only)
{
	int i;
	strlist_t files = {};
	entries_t r = {};
	int last_progress = 0;

	show_progress("Listing...", 0);
	if(flist_custom_active(view) &&
			ONE_OF(view->custom.type, CV_REGULAR, CV_VERY))
	{
		list_view_entries(view, &files);
	}
	else
	{
		list_files_recursively(flist_get_dir(view), view->hide_dot, &files);
	}

	show_progress("Querying...", 0);
	for(i = 0; i < files.nitems && !ui_cancellation_requested(); ++i)
	{
		char progress_msg[128];
		int progress;
		int existing_id;
		char *fingerprint;
		const char *const path = files.items[i];
		dir_entry_t *const entry = entry_list_add(view, &r.entries, &r.nentries,
				path);

		if(skip_empty && entry->size == 0)
		{
			free_dir_entry(view, entry);
			--r.nentries;
			continue;
		}

		fingerprint = get_file_fingerprint(path, entry, ct);
		/* In case we couldn't obtain fingerprint (e.g., comparing by contents and
		 * files isn't readable), ignore the file and keep going. */
		if(is_null_or_empty(fingerprint))
		{
			free(fingerprint);
			free_dir_entry(view, entry);
			--r.nentries;
			continue;
		}

		entry->tag = i;
		if(get_file_id(trie, path, fingerprint, &existing_id, ct))
		{
			entry->id = existing_id;
		}
		else if(dups_only)
		{
			entry->id = -1;
		}
		else
		{
			entry->id = *next_id;
			++*next_id;
			put_file_id(trie, path, fingerprint, entry->id, ct);
		}

		free(fingerprint);

		progress = (i*100)/files.nitems;
		if(progress != last_progress)
		{
			last_progress = progress;
			snprintf(progress_msg, sizeof(progress_msg), "Querying... %d (% 2d%%)", i,
					progress);
			show_progress(progress_msg, -1);
		}
	}

	free_string_array(files.items, files.nitems);
	return r;
}