Darryl: That's from the function parameters.
Code:
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string f[4] = {"end","makevar","print","set_current"};
vector<string>instr(f,f+4);
string current_room;
vector<string>rooms;
vector<string>verb_coms;
vector<string>verb_pars;
//void (*incode[4])(vector<string>) = {&end, &makevar, &print, &set_current};
size_t get_index(vector<string>to_search, string search_str, size_t start=0, int error_number=0, string error_msg = "was not found!")
{
size_t x=start;
if(error_number = 0)
{
error_number = to_search.size();
}
if(to_search.empty())
{
cout << search_str << " " << error_msg << "\n";
return error_number;
}
while(to_search[x] != search_str)
{
if(x == (to_search.size()-1))
{
cout << search_str << " " << error_msg << "\n";
return 0;
}
x++;
}
return x;
}
vector<string>tokenize(string to_tokenize, string delim=" ")
{
size_t x=0;
string check;
vector<string>tokens;
while(to_tokenize != "")
{
x=strcspn(to_tokenize.c_str(), delim.c_str());
check = to_tokenize.substr(0,x);
if(check != "")
{
tokens.push_back(to_tokenize.substr(0, x));
}
x++;
to_tokenize.erase(0, x);
}
return tokens;
}
int load_script(vector<string>&to_commands, vector<string>&to_params, string filename, char br1 = '(', char br2 = ')', char br3 = '^')
{
ifstream scriptfile(filename.c_str(), ios::in);
if(!scriptfile)
{
cout << "File not found!\n";
return 0;
}
string read;
int z =0;
while(read != "#")
{
getline(scriptfile, read, br1);
to_commands.push_back(read);
getline(scriptfile, read, br2);
to_params.push_back(read);
getline(scriptfile, read, br3);
z++;
}
return 0;
}
void execute(vector<string>commands, vector<string>params, int start, int stop=0)
{
vector<string>tok_par;
int x = start+1;
int y = 0;
string test = commands[x];
while(params[x] != "stop")
{
tok_par = tokenize(params[x]);
y=get_index(instr,test);
//incode[y](tok_par);
x++;
}
}
int main(int argc, char *argv[])
{
load_script(verb_coms, verb_pars, "data/verbs.txt");
execute(verb_coms, verb_pars, 0); //Last variable is the start pos. The parser retrieves this.
//parser();
system("PAUSE");
return EXIT_SUCCESS;
}