summaryrefslogblamecommitdiff
path: root/src/tool/itemsearch.cpp
blob: cf399e55795b99f1d41fee6dde8e6a5f3ac26f61 (plain) (tree)











































































































                                                                                                        
// This code is GPL, blah blah
//
// Writen for TheManaWorld by Chuck Miller, A.K.A. Kage

#include <iostream>
#include <string>

using namespace std;

int itemID;

int itemCount(string itemData)
{
    int counter = 0;
    int pointer = 0;

    do
    {
        int ending = itemData.find(',', pointer + 1);
        if (ending == string::npos)
            ending = itemData.size();
        if (counter == 1 && atoi(itemData.substr(pointer, ending - pointer).c_str()) != itemID)
            return 0;
        if (counter == 2)
            return atoi(itemData.substr(pointer, ending - pointer).c_str());
        counter++;
    } while ((pointer = itemData.find(',',pointer) + 1) != string::npos + 1);

    return 0;
}

int parseItemData(string &items)
{
    int counter = 0;
    int pointer = 0;

    int total = 0;

    do
    {
        int ending = items.find(' ', pointer + 1);
        if (ending == string::npos)
            ending = items.size();
        total += itemCount(items.substr(pointer, ending - pointer));
        counter++;
    } while ((pointer = items.find(' ',pointer) + 1) != string::npos + 1);

    return total;
}

void parseLine(string &line)
{
    int counter = 0;
    int pointer = 0;

    string AccountId, Name, Items;

    do
    {
         if (counter == 1 || counter == 2 || counter == 15)
         {
             
             int ending = line.find('\t', pointer + 1);
             if (ending == string::npos)
                  ending = line.size();
             switch (counter)
             {
                 case 1:
                     AccountId = line.substr(pointer,ending - pointer);
                     break;
                 case 2:
                     Name = line.substr(pointer, ending - pointer);
                     break;
                 case 15:
                     Items = line.substr(pointer, ending - pointer);
             }
         }
         counter++;
    } while ((pointer = line.find('\t',pointer) + 1) != string::npos + 1 && counter < 16);

    if ((counter = parseItemData(Items)) > 0)
        cout << "Account = " << AccountId << "; Name = \"" << Name << "\"; Count = " << counter << "\n";
}

void parseInput()
{
     string input;
     while (getline(cin, input))
     {
         parseLine(input);
     }
}

int main(int argc,char *argv[])
{
	if(argc < 2) 
        {
		printf("Usage: %s <item ID>\n", argv[0]);
                printf("e.g., %s 701\n", argv[0]);
                printf("Will return all users who own that item\n");
		exit(0);
        }
        itemID = atoi(argv[1]);
        parseInput();

	return 0;
}