Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
commandI Class Reference

#include <command.h>

Inheritance diagram for commandI:
RText mmoc

Public Member Functions

virtual ~commandI ()
 
 commandI ()
 
bool getmenumode () const
 
void help (std::string &d)
 
void addCommand (TFunctor *com, const char *name)
 
void remCommand (char *name)
 
void remCommand (TFunctor *com)
 
void dummy (std::vector< std::string * > *d)
 
void prompt ()
 
void pcommands ()
 
bool execute (std::string *incommand, bool isDown, int sock_in=0)
 }}} More...
 
bool fexecute (std::string *incommand, bool isDown, int sock_in=0)
 
bool execCommand (std::string *string, bool isDown)
 
bool addMenu (menu *menu2add)
 
bool addMenuItem (mItem *mitem2add, menu *=NULL)
 
bool callMenu (char *name, char *args, std::string &s2manip)
 
std::string setMenu (std::string name)
 
std::string displaymenu ()
 
void breakmenu ()
 
virtual std::string display (std::string &s)
 
- Public Member Functions inherited from RText
 RText ()
 
virtual ~RText ()
 
std::string getcurcommand ()
 
int text_width (char *str)
 
void draw_text (std::string &str, float left, float top, int gl_num)
 
void renderconsole ()
 
void conline (std::string &sf, bool highlight)
 
void conoutf (char *)
 
virtual void conoutf (std::string &s, int a=0, int b=0, int c=0)
 
void saycommand (const char *init)
 
void ConsoleKeyboardI (int code, bool isdown)
 
void conoutn (std::string &in, int a, int b, int c)
 

Static Public Member Functions

static void keypress (int code, int modifiers, bool isDown, int x, int y)
 

Public Attributes

bool console
 
bool immortal
 

Detailed Description

Definition at line 96 of file command.h.

Constructor & Destructor Documentation

commandI::~commandI ( )
virtual

Definition at line 458 of file command.cpp.

References coms::functor, rcCMD, and rcCMDEXISTS.

459 {
460  {
461  HoldCommands::procs *findme = rcCMD->getProc( this );
462  if (findme->rc.size() > 0) {
463  coms *iter = &findme->rc.back();
464  while (findme->rc.size() > 0) {
465  iter = &findme->rc.back();
466  delete iter->functor;
467  findme->rc.pop_back();
468  }
469  }
470  }
471  {
472  menu *iter;
473  while (menus.size() > 0) {
474  iter = menus.back();
475  delete iter;
476  menus.pop_back();
477  }
478  }
479  if (rcCMDEXISTS) {
480  rcCMD->popProc( this );
481  if (rcCMD->finishmeoff) {
482  rcCMDEXISTS = false;
483  delete rcCMD;
484  }
485  }
486 }
commandI::commandI ( )

Definition at line 427 of file command.cpp.

References addCommand(), TFunctor::attribs, console, dummy(), help(), Attributes::hidden, immortal, pcommands(), and prompt().

428 {
429  cout<<"Command Interpretor Created\n\r";
430  //{{{ add some base commands
431 
432  Functor< commandI > *dprompt = new Functor< commandI > ( this, &commandI::prompt );
433  //fill with dummy function.
434  dprompt->attribs.hidden = true;
435  addCommand( dprompt, "prompt" );
436 
437  Functor< commandI > *newFunct = new Functor< commandI > ( this, &commandI::dummy );
438  newFunct->attribs.hidden = true;
439  addCommand( newFunct, "dummy" );
440 
441  Functor< commandI > *dcommands = new Functor< commandI > ( this, &commandI::pcommands );
442  addCommand( dcommands, "commands" );
443 
445  addCommand( dhelp, "help" );
446  //}}}
447  //set some local object variables {{{
448  menumode = false;
449  immortal = false;
450  console = false;
451  new RegisterPythonWithCommandInterpreter( this ); //mem leak - not cleaned up at end of program.
452  //}}}
453 }

Member Function Documentation

void commandI::addCommand ( TFunctor com,
const char *  name 
)

Definition at line 578 of file command.cpp.

References coms::Name, and rcCMDEXISTS.

Referenced by commandI(), mmoc::connectTo(), mmoc::mmoc(), RegisterPythonWithCommandInterpreter::RegisterPythonWithCommandInterpreter(), and ShipCommands::ShipCommands().

579 {
580  cout<<"Adding command: "<<name<<endl;
581  coms *newOne = new coms( com );
582  //See the very bottom of this file for comments about possible optimization
583  newOne->Name.append( name );
584  //push the new command back the vector.
585  if (!rcCMDEXISTS && rcCMD == 0x0) {
586  if (rcCMD != 0x0)
587  cout<<"Apparently rcCMD is not 0x0.. \n";
588  rcCMD = new HoldCommands();
589  rcCMDEXISTS = true;
590  }
591  rcCMD->addCMD( *newOne, this );
592 //rcCMD->rc.push_back(newOne);
593 }
bool commandI::addMenu ( menu menu2add)

Definition at line 1043 of file command.cpp.

Referenced by ShipCommands::ShipCommands().

1044 {
1045  menus.push_back( menu_in );
1046  lastmenuadded = menu_in;
1047  return true;
1048 }
bool commandI::addMenuItem ( mItem mitem2add,
menu menuin = NULL 
)

Definition at line 1092 of file command.cpp.

References menu::items.

Referenced by ShipCommands::ShipCommands().

1093 {
1094  menu *menu2use;
1095  if (menuin == NULL)
1096  menu2use = lastmenuadded;
1097  else
1098  menu2use = menu_in;
1099  //if the command isn't found it will return dummy or prompt.
1100  for (vector< menu* >::iterator iter = menus.begin(); iter < menus.end(); iter++)
1101  if ( menu2use == ( *(iter) ) ) {
1102  menu2use->items.push_back( mi ); //doh! :)
1103  return true;
1104  }
1105  return false;
1106 }
void commandI::breakmenu ( )

Definition at line 1385 of file command.cpp.

1386 {
1387  while (menustack.size() > 0)
1388  menustack.pop_back();
1389  menu_in = NULL;
1390  menumode = false;
1391 }
bool commandI::callMenu ( char *  name,
char *  args,
std::string &  s2manip 
)

Definition at line 1109 of file command.cpp.

References mItem::action, mItem::autoreprint, RText::conoutf(), menu::defaultInput, displaymenu(), menu::escape, execute(), fexecute(), mItem::func2call, menu::idefaultInput, mItem::inputbit, mItem::inputbit2, menu::iselected, menu::items, mItem::menubuf, menu::noescape, menu::selected, mItem::selectstring, setMenu(), x, and y.

Referenced by execute().

1110 {
1111  //if there is a menu operation return true;
1112  string name;
1113  if (name_in != NULL)
1114  name.append( name_in );
1115 //bool freturnfalse = false; //force return false
1116  //{{{ if the name_in is the menu_in's escape charactor
1117  //change the menu_in to the last menu on menustack if there is
1118  //one, and pop the stack. If there is no menustack, set menumode
1119  //off.
1120  if (menumode) {
1121  if (!menu_in->selected) {
1122  if (!menu_in->noescape) {
1123  if (name.compare( menu_in->escape ) == 0) {
1124  if (menustack.size() > 0) {
1125  vector< menu* >::iterator iter = menustack.end();
1126  iter--;
1127  menu_in = ( *(iter) );
1128  menustack.pop_back();
1129  //return true;
1130  } else {
1131  menu_in = NULL;
1132  menumode = false;
1133  return true;
1134  }
1135  }
1136  }
1137  }
1138  }
1139  //}}}
1140  if (menumode) {
1141  if (menu_in->selected) {
1142  //Input mode 1 {{{
1143  if (menu_in->iselected->inputbit == true && menu_in->iselected->inputbit2 == false) {
1144  menu_in->selected = false;
1145  string arg;
1146  arg.append( menu_in->iselected->action );
1147  string funcn;
1148  funcn.append( menu_in->iselected->func2call );
1149  string dreplace;
1150  dreplace.append( d );
1151  d.erase();
1152  d.append( funcn );
1153  d.append( " " );
1154  d.append( arg );
1155  d.append( " " );
1156  d.append( dreplace );
1157  //setMenus {{{
1158  if (funcn.compare( "setMenu" ) == 0) {
1159  string l;
1160  l.append( setMenu( arg ) );
1161  conoutf( l );
1162  return true;
1163  }
1164  //}}}
1165  size_t ylast = 0, xasd = 0;
1166  //login function {{{
1167  if (funcn.compare( "loginfunc" ) == 0) {
1168  vector< string* >d_out;
1169  d.append( " " );
1170  for ( size_t x = d.find( "\r\n" ); x < string::npos; x = d.find( "\r\n", x+3 ) )
1171  d.replace( x, 1, " \r\n" );
1172  for (size_t iter = 0; iter < d.size(); iter++) {
1173  if (d[iter] == 32) {
1174  string *xs = new string();
1175  xs->append( d.substr( ylast, xasd-ylast ) );
1176  ylast = xasd;
1177  d_out.push_back( xs );
1178  }
1179  xasd++;
1180  }
1181 //loginfunc(&d_out); //login function
1182  vector< string* >::iterator itera = d_out.begin();
1183  while (d_out.size() > 0) {
1184  string *s = ( *(itera) );
1185  delete s;
1186  d_out.erase( itera );
1187  itera = d_out.begin();
1188  }
1189  return true;
1190  }
1191  //}}}
1192  //autoreprint {{{
1193  if (menu_in->iselected->autoreprint == true) {
1194  fexecute( &d, true, 0 );
1195  string x;
1196  x.append( displaymenu() );
1197  conoutf( x );
1198  return true;
1199  }
1200  //}}}
1201  return false;
1202  }
1203  //}}}
1204  //input mode 2 {{{
1205  if (menu_in->iselected->inputbit == false && menu_in->iselected->inputbit2 == true) {
1206  //wait until we find an escape seqence alone {{{
1207  if (name.compare( menu_in->escape ) == 0) {
1208  menu_in->selected = false;
1209  string arg;
1210  arg.append( menu_in->iselected->action );
1211  string funcn;
1212  funcn.append( menu_in->iselected->func2call );
1213  d.erase();
1214  d.append( funcn );
1215  d.append( " " );
1216  d.append( arg );
1217  d.append( " " );
1218  {
1219  size_t l = 0;
1220  bool y = false;
1221  for ( size_t x = menu_in->iselected->menubuf.find( "\r\n" );
1222  x < string::npos;
1223  x = menu_in->iselected->menubuf.find( "\r\n", x+1 ) ) {
1224  menu_in->iselected->menubuf.replace( x, 2, "<BR>" );
1225  l = x;
1226  y = true;
1227  }
1228  if (y)
1229  menu_in->iselected->menubuf.replace( l, 4, "" ); //replace the last <BR>
1230  }
1231  d.append( menu_in->iselected->menubuf );
1232  d.append( " " );
1233  menu_in->iselected->menubuf.erase();
1234  if (funcn.compare( "setMenu" ) == 0) {
1235  string buf;
1236  buf.append( setMenu( arg ) );
1237  conoutf( buf );
1238  return true;
1239  }
1240  if (funcn.compare( "loginfunc" ) == 0) {
1241  vector< string* >d_out;
1242  d.append( " " );
1243  for ( size_t x = d.find( "\r\n" ); x < string::npos; x = d.find( "\r\n", x+1 ) )
1244  d.replace( x, 2, "<BR>" );
1245  size_t ylast = 0, xasd = 0;
1246  for (size_t iter = 0; iter < d.size(); iter++) {
1247  if (d[iter] == 32) {
1248  string *xs = new string();
1249  xs->append( d.substr( ylast, xasd-ylast ) );
1250  ylast = xasd;
1251  d_out.push_back( xs );
1252  }
1253  xasd++;
1254  }
1255 //loginfunc(&d_out); //login function
1256  vector< string* >::iterator itera = d_out.begin();
1257  while (d_out.size() > 0) {
1258  string *s = ( *(itera) );
1259  delete s;
1260  d_out.erase( itera );
1261  itera = d_out.begin();
1262  }
1263  return true;
1264  }
1265  if (menu_in->iselected->autoreprint == true) {
1266  fexecute( &d, true, 0 );
1267  string x;
1268  x.append( displaymenu() );
1269  conoutf( x );
1270  return true;
1271  }
1272  return false;
1273  //}}}
1274  //or we append the input to the buffer {{{
1275  } else {
1276  menu_in->iselected->menubuf.append( d );
1277  //}}}
1278  }
1279  return true;
1280  }
1281  //}}}
1282  }
1283  //if we don't have anything selected, select one.. {{{
1284  if (!menu_in->selected) {
1285  for (vector< mItem* >::iterator iter = menu_in->items.begin();
1286  iter < menu_in->items.end(); iter++)
1287  if ( ( *(iter) )->Name.compare( name ) == 0 ) {
1288  menu_in->selected = true;
1289  menu_in->iselected = ( *(iter) );
1290 //if(menu_in->iselected->predisplay.size() > 0) {
1291 //display(menu_in->iselected->predisplay);
1292 //}
1293  if (menu_in->iselected->inputbit2) {
1294  string buf;
1295  buf.append( menu_in->iselected->selectstring );
1296  buf.append( "\n\r" );
1297  buf.append( "Use: " );
1298  if (menu_in->escape.compare( "\r\n" ) == 0)
1299  buf.append( "enter" );
1300  else
1301  buf.append( menu_in->escape );
1302  buf.append( " to confirm: " );
1303 
1304  conoutf( buf );
1305  } else if (menu_in->iselected->inputbit) {
1306  string buf;
1307  buf.append( menu_in->iselected->selectstring );
1308  buf.append( ": " );
1309  conoutf( buf );
1310  }
1311  }
1312  if (menu_in->selected) {
1313  if (!menu_in->iselected->inputbit && !menu_in->iselected->inputbit2) {
1314  menu_in->selected = false;
1315  string arg;
1316  arg.append( menu_in->iselected->action );
1317  string funcn;
1318  funcn.append( menu_in->iselected->func2call );
1319  string dreplace;
1320  dreplace.append( d );
1321  d = string();
1322  d.append( funcn );
1323  d.append( " " );
1324  d.append( arg );
1325  d.append( " " );
1326  d.append( dreplace );
1327  if (funcn.compare( "setMenu" ) == 0) {
1328  string l;
1329  l.append( setMenu( arg ) );
1330  conoutf( l );
1331  return true;
1332  }
1333  return false;
1334  }
1335  return true;
1336  } else if (menu_in->defaultInput) {
1337  menu_in->selected = true;
1338  menu_in->iselected = menu_in->idefaultInput;
1339  execute( &d, true, 0 );
1340  return true;
1341  }
1342  }
1343  //}}}
1344  }
1345  if (menumode && !menu_in->selected) {
1346  //we're in a menu but don't have anything selected {{{
1347  string y;
1348  y.append( displaymenu() );
1349  conoutf( y );
1350  return true;
1351  }
1352  //}}}
1353  return false;
1354 }
string commandI::display ( std::string &  s)
virtual

Definition at line 1001 of file command.cpp.

References f.

Referenced by displaymenu().

1002 {
1003  //If the menusystem has a value to display, eg:
1004  //Editing User
1005  //1) Change Username - Current Name: XXX
1006  //and XXX is replaced with a value here
1007  //basically, call: string.replace(xxx,3, display("uname") )
1008  //then display does:
1009  //if(in.compare(uname) == 0) return current_mob_editing.Name;
1010  //The value to pass to display is set when creating a menuitem
1011  string f;
1012  f.append( "FAKE" );
1013  return f;
1014 }
string commandI::displaymenu ( )

Definition at line 1051 of file command.cpp.

References menu::autoselect, menu::Display, display(), menu::escape, menu::iselected, menu::items, menu::noescape, menu::selected, and mItem::selectstring.

Referenced by callMenu(), and setMenu().

1052 {
1053  if (menumode) {
1054  ostringstream ps;
1055  ps<<menu_in->Display<<"\n";
1056  for (vector< mItem* >::iterator iter = menu_in->items.begin();
1057  iter < menu_in->items.end(); iter++) {
1058  ps<<( *(iter) )->Name<<" "<<( *(iter) )->display;
1059  if ( ( *(iter) )->predisplay.size() > 0 )
1060  ps<<" "<<display( ( *(iter) )->predisplay );
1061  ps<<"\n";
1062  }
1063  string buf;
1064  buf.append( ps.str() );
1065  if (menu_in->autoselect == true) {
1066  if (menu_in->selected == true) {
1067  buf.append( menu_in->iselected->selectstring );
1068  buf.append( ": " );
1069  }
1070  } else {
1071  if (!menu_in->noescape) {
1072  buf.append( "Use: " );
1073  if (menu_in->escape.compare( "\r\n" ) == 0)
1074  buf.append( "enter" );
1075  else
1076  buf.append( menu_in->escape );
1077  buf.append( " to quit: \n" );
1078  } else {
1079  buf.append( "Enter your selection: \n" );
1080  }
1081  }
1082  return buf;
1083 //conoutf(buf);
1084  }
1085  string buf;
1086  buf.append( "Error, not in menumode!" );
1087  return buf;
1088 }
void commandI::dummy ( std::vector< std::string * > *  d)

Definition at line 527 of file command.cpp.

References RText::conoutf(), VSRandom::genrand_int32(), and vsrandom.

Referenced by commandI().

528 {
529  //{{{
530  string outs;
531  int rand = vsrandom.genrand_int32();
532  if (rand%2 == 0)
533  outs.append( "Wtf?\n\r" );
534  else
535  outs.append( "Try: commands\n\r" );
536  conoutf( outs );
537  //}}}
538 }
bool commandI::execCommand ( std::string *  string,
bool  isDown 
)
bool commandI::execute ( std::string *  incommand,
bool  isDown,
int  sock_in = 0 
)

}}}

Definition at line 764 of file command.cpp.

References callMenu(), fexecute(), VsnetOSS::socket(), and y.

Referenced by callMenu(), keypress(), and mmoc::ParseRemoteInput().

765 {
766  int socket = sock_in;
767  //use the menusystem ONLY if the sock_in is the same as socket{{{
768  {
769  if (menumode && sock_in == socket) {
770  string l;
771  string y;
772  size_t x = incommand->find( " " );
773  if (x < string::npos)
774  l.append( incommand->substr( 0, x ) );
775  else
776  l.append( incommand->c_str() );
777  string t;
778  t.append( ( *(incommand) ) );
779  if (x < string::npos)
780  y.append( incommand->substr( x, incommand->size()-1 ) );
781  else
782  y.append( incommand->c_str() );
783  if (l.compare( "\r\n" ) == 0) {} else {
784  size_t lv = l.find( "\r" );
785  while (lv < string::npos) {
786  l.replace( lv, 1, "" );
787  lv = l.find( "\r" );
788  }
789  lv = l.find( "\n" );
790  while (lv < string::npos) {
791  l.replace( lv, 1, "" );
792  lv = l.find( "\n" );
793  }
794  lv = y.find( "\r" );
795  while (lv < string::npos) {
796  y.replace( lv, 1, "" );
797  lv = y.find( "\r" );
798  }
799  lv = y.find( "\n" );
800  while (lv < string::npos) {
801  y.replace( lv, 1, "" );
802  lv = y.find( "\n" );
803  }
804  }
805  char *name_out = NULL;
806  if (l.size() > 0) name_out = (char*) l.c_str();
807  if ( callMenu( name_out, (char*) y.c_str(), t ) ) return false;
808  *incommand = string();
809  incommand->append( t ); //t may have changed if we got this far
810  }
811  }
812  //}}}
813  return fexecute( incommand, isDown, sock_in );
814 }
bool commandI::fexecute ( std::string *  incommand,
bool  isDown,
int  sock_in = 0 
)

Definition at line 823 of file command.cpp.

References TFunctor::Call(), RText::conoutf(), console, e, coms::functor, coms::Name, next, and y.

Referenced by callMenu(), and execute().

824 {
825  size_t ls, y;
826  bool breaker = false;
827 //************
828  while (breaker == false) {
829  ls = incommand->find( " " );
830  if (ls != 0)
831  breaker = true;
832  else
833  incommand->replace( ls, 1, "" );
834  }
835  for ( y = incommand->find( "\r\n" ); y != string::npos; y = incommand->find( "\r\n", y+1 ) )
836  incommand->replace( y, 2, "" );
837  for ( y = incommand->find( " " ); y != string::npos; y = incommand->find( " ", y+1 ) )
838  incommand->replace( y, 1, "" );
839  breaker = false; //reset our exit bool
840  //************ try to replace erase leading space if there is one
841  //eg, someone types: " do_something" instead of "do_something"
842  while (breaker == false) {
843  ls = incommand->find( " " );
844  if (ls != 0)
845  breaker = true;
846  else
847  incommand->erase( ls, 1 );
848  }
849 //Print back what the user typed.. {{{
850 //.. Sometimes people believe they typed python print "hello world\n"
851 //(and saw what they typed when they typed it)
852 //but may have actually typed oython print "hello world\n"
853 //and don't want to admit it, so they blame the system.
854 //So the system must sometimes politely tell the user what they typed
855  {
856  bool printit = false;
857  if (menumode) {
858 //if(menu_in->selected) {
859 //if(menu_in->iselected->inputbit || menu_in->iselected->inputbit2) printit = true;
860 //}
861  } else if (console) {
862  printit = true;
863  }
864  if (printit) {
865  string webout;
866  webout.append( incommand->c_str() );
867  webout.append( "\n\r" );
868  conoutf( webout );
869  }
870  }
871 //}}}
872  //replace \r\n with a space {{{
873  for ( y = incommand->find( "\r\n" ); y != string::npos; y = incommand->find( "\r\n", y+1 ) )
874  incommand->replace( y, 2, " " );
875  //}}}
876  //remove multiple spaces {{{
877  for ( y = incommand->find( " " ); y != string::npos; y = incommand->find( " ", y+1 ) )
878  incommand->replace( y, 1, "" );
879  //}}}
880  //{{{ ! to the last command typed
881  {
882  size_t x = incommand->find( "!" );
883  if (x == 0)
884  incommand->replace( 0, 1, lastcommand );
885  //}}}
886  //{{{ : to python
887  x = incommand->find( ":" );
888  if (x == 0)
889  incommand->replace( 0, 1, "python " );
890  }
891  //}}}
892 
893  breaker = false; //reset our exit bool
894 
895  //done with formatting
896  //now make what our vector<string> {{{
897  vector< string >strvec; //to replace newincommand
898  //to reduce data replication by one;
899  {
900  string::const_iterator scroller = incommand->begin();
901  size_t last = 0, next = 0;
902  bool quote = false;
903  bool escape = false;
904  next = incommand->find( " " );
905  for (next = incommand->find( "\"\"", 0 );
906  ( next = incommand->find( "\"\"", last ), (last != string::npos) );
907  last = (next != string::npos) ? next+1 : string::npos)
908  if (next < string::npos)
909  incommand->replace( next, 2, "\" \"" );
910  //replace "" with " "
911  string starter( "" );
912  strvec.push_back( starter );
913  for (scroller = incommand->begin(); scroller < incommand->end(); scroller++) {
914  if (*scroller == '\\') {
915  escape = true;
916  continue;
917  }
918  if (escape) {
919  if (*scroller == '\"') strvec[strvec.size()-1] += *scroller;
920  continue;
921  }
922  if (*scroller == '\"') {
923  if (quote)
924  quote = false;
925  else
926  quote = true;
927  continue;
928  }
929  if (*scroller == ' ' && !quote) {
930  strvec.push_back( starter );
931  continue;
932  }
933  strvec[strvec.size()-1] += *scroller;
934  }
935  }
936  //}}}
937  {
938  //if the last argument is a space, erase it. {{{
939  vector< string >::iterator iter = strvec.end();
940  iter--;
941  if ( ( *(iter) ).compare( " " ) == 0 )
942  strvec.erase( iter );
943  //}}}
944  }
945  try {
946  coms &theCommand = *findCommand( (char*) strvec[0].c_str(), sock_in );
947 //Now, we try to replace what was typed with the name returned by findCommand {{{
948 //to autocomplete words (EX: translate gos into gossip so the gossip
949 //command only has to find it's access name and not all possible
950 //methods of accessing it.)
951  if (theCommand.Name.compare( "dummy" ) != 0) {
952  size_t x = incommand->find_first_of( strvec[0] );
953  if (x != string::npos) {
954  strvec[0].erase();
955  strvec[0].append( theCommand.Name );
956  }
957 //}}}
958  lastcommand.erase();
959  lastcommand.append( *incommand ); //set the
960  //last command entered - use ! to trigger
961  }
962  //Try to execute now {{{
963  try {
964  //maybe if/else if would be more efficient, if this ever
965  //gets really large.
966  theCommand.functor->Call( strvec, sock_in, &isDown );
967  //try to catch any errors that occured while executing
968  }
969  catch (const char *in) {
970  string l;
971  l.append( in );
972  conoutf( l ); //print the error to the console
973  }
974  catch (exception e) {
975  string l;
976  l.append( "Command processor: Exception occured: " );
977  l.append( e.what() );
978  l.append( "\n\r" );
979  cout<<l;
980  conoutf( l );
981  }
982  catch (...) {
983  string y;
984  y.append(
985  "Command processor: exception occurered: Unknown, most likely cause: Wrong Arg_type arguement sent with addCommand.\n\r" );
986  cout<<y;
987  conoutf( y );
988  }
989 
990  //}}}
991  }
992  catch (const char *in) {
993  //catch findCommand error
994  cout<<in;
995  }
996  return true;
997 }
bool commandI::getmenumode ( ) const
inline

Definition at line 120 of file command.h.

121  {
122  return menumode;
123  }
void commandI::help ( std::string &  d)

Definition at line 505 of file command.cpp.

Referenced by commandI().

506 {
507  string buf;
508  buf.append( "Sorry, there is no help system yet\n\r " );
509  buf.append( "But most commands are self supporting, just type them to see what they do.\n\r" );
510 //conoutf(this, &buf);
511 }
void commandI::keypress ( int  code,
int  modifiers,
bool  isDown,
int  x,
int  y 
)
static

New input wrapper for new Command Processor SDL version

Author
Rogue
Date
Created: 2005-8-16

Definition at line 1441 of file command.cpp.

References console, RText::ConsoleKeyboardI(), execute(), RText::getcurcommand(), restore_main_loop(), WSK_ESCAPE, and WSK_RETURN.

Referenced by ConsoleKeys::BringConsole().

1442 {
1444  if (code == WSK_ESCAPE) {
1445  CommandInterpretor->console = false;
1447 //SDL_EnableUNICODE(false);
1448  return;
1449  }
1450  if (code == WSK_RETURN && isDown) {
1451  string commandBuf = CommandInterpretor->getcurcommand();
1452  commandBuf.append( "\r\n" );
1453  CommandInterpretor->execute( &commandBuf, isDown, 0 ); //execute console on enter
1454  //don't return so the return get's processed by
1455  //CommandInterpretor->ConsoleKeyboardI, so it can clear the
1456  //command buffer
1457  }
1458  CommandInterpretor->ConsoleKeyboardI( code, isDown );
1459  return;
1460  } else {
1462  return;
1463  }
1464 }
void commandI::pcommands ( )

Definition at line 543 of file command.cpp.

References RText::conoutf(), immortal, and x.

Referenced by commandI().

544 {
545  int x = 0;
546  ostringstream cmd;
547  cmd<<"\n\rCommands available:\n\r";
548  vector< coms >::iterator iter;
549  HoldCommands::procs *commands = rcCMD->getProc( this );
550  for (iter = commands->rc.begin(); iter < commands->rc.end(); iter++)
551  if (!( *(iter) ).functor->attribs.hidden && !( *(iter) ).functor->attribs.webbcmd) {
552  if ( ( *(iter) ).functor->attribs.immcmd == true ) {
553  if (immortal) {
554  if (x != 5) cmd<<setiosflags( ios::left )<<setw( 19 );
555  cmd<<( *(iter) ).Name.c_str();
556  x++;
557  } //we don't want to add the command if we arn't immortal
558  } else {
559  if (x != 5) cmd<<setiosflags( ios::left )<<setw( 10 );
560  cmd<<( *(iter) ).Name.c_str();
561  x++;
562  }
563  if (x == 5) {
564  cmd<<"\n\r";
565  x = 0;
566  }
567  }
568  if (x != 5)
569  cmd<<"\n\r";
570  string cmd2;
571  cmd2.append( cmd.str() );
572  conoutf( cmd2 );
573 }
void commandI::prompt ( )

Definition at line 516 of file command.cpp.

References RText::conoutf().

Referenced by commandI().

517 {
518  string l;
519  l.append( "Wooooooooooo\n" );
520  conoutf( l );
521 //std::cout << "Prompt called :)\n";
522 }
void commandI::remCommand ( char *  name)

Definition at line 598 of file command.cpp.

Referenced by startThread(), and ShipCommands::~ShipCommands().

599 {
600  HoldCommands::procs *findme = rcCMD->getProc( this );
601  if (findme->rc.size() < 1) return;
602  for (vector< coms >::iterator iter = findme->rc.begin(); iter < findme->rc.end(); iter++)
603  if ( ( *(iter) ).Name.compare( name ) == 0 ) {
604  cout<<"Removing: "<<name<<endl;
605  delete ( *(iter) ).functor;
606  findme->rc.erase( iter );
607  return;
608  }
609  cout<<"Error, command "<<name
610  <<" not removed, try using the TFunctor *com version instead. Also, this is case sensitive ;)\n";
611 }
void commandI::remCommand ( TFunctor com)

Definition at line 613 of file command.cpp.

614 {
615  HoldCommands::procs *findme = rcCMD->getProc( this );
616  if (findme->rc.size() < 1) return;
617  for (vector< coms >::iterator iter = findme->rc.begin(); iter < findme->rc.end(); iter++)
618  if ( ( *(iter) ).functor == com ) {
619  cout<<"Removing: "<<( *(iter) ).Name<<endl;
620  delete ( *(iter) ).functor;
621  findme->rc.erase( iter );
622  return;
623  }
624  cout<<"Error, couldn't find the command that owns the memory area: "<<com<<endl;
625 }
string commandI::setMenu ( std::string  name)

Definition at line 1360 of file command.cpp.

References menu::aselect, menu::autoselect, displaymenu(), menu::iselected, and menu::selected.

Referenced by callMenu(), and ShipCommands::pymenu().

1361 {
1362  string name;
1363  name.append( name_in );
1364  if (name[0] == 32) name.replace( 0, 1, "" );
1365  for (vector< menu* >::iterator iter = menus.begin();
1366  iter < menus.end(); iter++)
1367  if ( ( *(iter) )->Name.compare( name ) == 0 ) {
1368  if (!menumode)
1369  menumode = true;
1370  else
1371  menustack.push_back( menu_in );
1372  menu_in = ( *(iter) );
1373  menu_in->selected = false;
1374  if (menu_in->autoselect == true) {
1375  menu_in->selected = true;
1376  menu_in->iselected = menu_in->aselect;
1377  }
1378  iter = menus.end();
1379  }
1380  return displaymenu();
1381 }

Member Data Documentation

bool commandI::console

Definition at line 117 of file command.h.

Referenced by ConsoleKeys::BringConsole(), commandI(), fexecute(), and keypress().

bool commandI::immortal

Definition at line 118 of file command.h.

Referenced by commandI(), and pcommands().


The documentation for this class was generated from the following files: