Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/commandbuffer.cc')
-rw-r--r--src/core/commandbuffer.cc116
1 files changed, 58 insertions, 58 deletions
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index fbb9cfd..eb13382 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -37,7 +37,7 @@ void func_print_file(std::string const &args)
std::istringstream argstream(args);
std::string filename;
if (!(argstream >> filename))
- return;
+ return;
CommandBuffer::print_file(filename);
}
@@ -155,7 +155,7 @@ void func_toggle(std::string const &args)
if (cvar->flags() && Cvar::Info) {
localplayer()->set_dirty();
}
-
+
con_debug << " " << cvar->name() << " " << cvar->str() << "\n";
}
@@ -164,16 +164,16 @@ void func_exec(std::string const &args)
std::istringstream argstream(args);
std::string filename;
if (!(argstream >> filename))
- return;
+ return;
- CommandBuffer::exec_file(filename);
+ CommandBuffer::exec_file(filename);
}
void func_remote(std::string const &args)
{
if (connection()) {
if ((args[0] == '\\') || (args[0] == '/')) {
- connection()->forward(args.substr(1, args.size()-1));
+ connection()->forward(args.substr(1, args.size() - 1));
} else {
connection()->forward(args);
}
@@ -256,11 +256,11 @@ void CommandBuffer::exec(std::string const &cmdline)
std::istringstream cmdstream(cmdline);
std::string command;
-
+
if (!(cmdstream >> command))
return;
-
- aux::to_lowercase(command);
+
+ aux::to_lowercase(command);
//con_debug << "Executing '" << cmdline << "'\n";
if ((command[0] == '\\') || (command[0] == '/')) {
@@ -294,7 +294,7 @@ void CommandBuffer::exec(std::string const &cmdline)
}
f->exec(game()->localplayer(), args);
}
- }
+ }
} else {
// regular function
std::string args;
@@ -307,13 +307,13 @@ void CommandBuffer::exec(std::string const &cmdline)
}
return;
}
-
+
// is it a cvar
Cvar *cvar = Cvar::find(command);
if (cvar) {
// cvar exists
std::string value;
- if (((cvar->flags() & Cvar::ReadOnly) == 0) && (cmdstream >> value)) {
+ if (((cvar->flags() & Cvar::ReadOnly) == 0) && (cmdstream >> value)) {
// we're setting a new value
char c;
while (cmdstream.get(c))
@@ -324,15 +324,15 @@ void CommandBuffer::exec(std::string const &cmdline)
localplayer()->set_dirty();
}
}
-
+
con_print << " " << command << " " << cvar->str() << " ^N" << cvar->info() << "\n";
return;
}
-
+
// this gets forwarded to the server
if (connection()) {
if ((cmdline[0] == '\\') || (cmdline[0] == '/')) {
- connection()->forward(cmdline.substr(1, cmdline.size()-1));
+ connection()->forward(cmdline.substr(1, cmdline.size() - 1));
} else {
connection()->forward(cmdline);
}
@@ -345,13 +345,13 @@ void CommandBuffer::exec()
{
if (cmdbuf.eof())
return;
-
+
std::string line;
char c;
bool quote = false;
- while ( core::cmd().read(&c , 1) && c) {
- if ( c =='\n') {
+ while (core::cmd().read(&c , 1) && c) {
+ if (c == '\n') {
exec(line);
line.clear();
} else if (c == '"') {
@@ -360,13 +360,13 @@ void CommandBuffer::exec()
exec(line);
line.clear();
} else {
- line +=c;
+ line += c;
}
}
if (line.size())
exec(line);
-
+
cmdbuf.clear();
}
@@ -389,7 +389,7 @@ void CommandBuffer::complete(std::string &input, size_t &pos)
//con_print << " " << (*f).first << "\n";
}
}
-
+
// search cvar registry for matches
for (Cvar::Registry::iterator c = Cvar::registry().begin(); c != Cvar::registry().end(); c++) {
if (partial == (*c).first.substr(0, partial.size())) {
@@ -397,17 +397,17 @@ void CommandBuffer::complete(std::string &input, size_t &pos)
//con_print << " " << (*c).first << "\n";
}
}
-
+
if (!match.size())
return;
-
+
std::string maxmatch(*match.begin());
-
+
if (match.size() > 1) {
std::list<std::string>::iterator l;
- for (l = match.begin(); l !=match.end(); l++) {
+ for (l = match.begin(); l != match.end(); l++) {
if (maxmatch.size()) {
- size_t i =0;
+ size_t i = 0;
while ((i < maxmatch.size() && i < (*l).size()) && (maxmatch[i] == (*l)[i])) {
i++;
}
@@ -417,70 +417,70 @@ void CommandBuffer::complete(std::string &input, size_t &pos)
con_print << " " << (*l) << "\n";
}
con_print << match.size() << " matches\n";
-
+
}
-
+
if (maxmatch.size() > partial.size()) {
- if (match.size()==1) maxmatch += ' ';
+ if (match.size() == 1) maxmatch += ' ';
input.replace(start, pos, maxmatch);
pos = maxmatch.size();
}
-
+
}
void CommandBuffer::exec_file(std::string const & filename)
{
- filesystem::File *f = filesystem::open(filename.c_str());
- if (!f) {
- con_warn << "Could not open " << filename << std::endl;
- return;
- }
+ filesystem::File *f = filesystem::open(filename.c_str());
+ if (!f) {
+ con_warn << "Could not open " << filename << std::endl;
+ return;
+ }
- std::string fn = f->path();
- fn.append(f->name());
- filesystem::close(f);
+ std::string fn = f->path();
+ fn.append(f->name());
+ filesystem::close(f);
std::ifstream ifs;
ifs.open(fn.c_str());
- if (!ifs.is_open()) {
- con_warn << "Could not stream " << fn << "!\n";
- return;
- }
+ if (!ifs.is_open()) {
+ con_warn << "Could not stream " << fn << "!\n";
+ return;
+ }
con_print << "Executing " << fn.c_str() << std::endl;
char line[MAXCMDSIZE];
- while (ifs.getline(line, MAXCMDSIZE-1)) {
- if (line[0] && line[0] != '#' && line[0] != ';')
+ while (ifs.getline(line, MAXCMDSIZE - 1)) {
+ if (line[0] && line[0] != '#' && line[0] != ';')
exec(std::string(line));
- }
+ }
ifs.close();
}
void CommandBuffer::print_file(std::string const & filename)
{
- filesystem::File *f = filesystem::open(filename.c_str());
- if (!f) {
- con_warn << "Could not open " << filename << std::endl;
- return;
- }
+ filesystem::File *f = filesystem::open(filename.c_str());
+ if (!f) {
+ con_warn << "Could not open " << filename << std::endl;
+ return;
+ }
- std::string fn = f->path();
- fn.append(f->name());
- filesystem::close(f);
+ std::string fn = f->path();
+ fn.append(f->name());
+ filesystem::close(f);
std::ifstream ifs;
ifs.open(fn.c_str());
- if (!ifs.is_open()) {
- con_warn << "Could not stream " << fn << "!\n";
- return;
- }
+ if (!ifs.is_open()) {
+ con_warn << "Could not stream " << fn << "!\n";
+ return;
+ }
char line[MAXCMDSIZE];
- while (ifs.getline(line, MAXCMDSIZE-1)) {
+ while (ifs.getline(line, MAXCMDSIZE - 1)) {
con_print << line << "\n";
- }
+ }
ifs.close();
}