gsmoper.cc

来自「Gambit 是一个游戏库理论软件」· CC 代码 · 共 2,227 行 · 第 1/5 页

CC
2,227 行
字号
    Portion *p = GSM_Read_List(gsm, param, porBOOLEAN, GSM_Read_Bool, false);    delete temp;    return p;  }  catch (gclRuntimeError &)  {    ((ListPortion *) param[1])->AssignFrom(temp);    delete temp;    throw;  }}static Portion *GSM_Read_List_Number(GSM &gsm, Portion** param){  Portion *temp = param[1]->ValCopy();  try  {    Portion *p = GSM_Read_List(gsm, param, porNUMBER, GSM_Read_Number, false);    delete temp;    return p;  }  catch (gclRuntimeError &)  {    ((ListPortion *) param[1])->AssignFrom(temp);    throw;  }}static Portion *GSM_Read_List_Text(GSM &gsm, Portion** param){  Portion *temp = param[1]->ValCopy();  try  {    Portion *p = GSM_Read_List(gsm, param, porTEXT, GSM_Read_Text, false);    delete temp;    return p;  }  catch (gclRuntimeError &)  {    ((ListPortion *) param[1])->AssignFrom(temp);    throw;  }}static Portion *GSM_Read_Undefined(GSM &gsm, Portion** param){  /* will go through and try to read the input as different format until     it succeeds */  Portion *sub_param[2];  char c = ' ';    gInput& input = ((InputPortion*) param[0])->Value();  long old_pos = input.getpos();  Portion *result = 0;  while(!input.eof() && isspace(c))    input.get(c);  if (input.eof())    throw gclRuntimeError("End of file reached");  if (c == '{') {    param[1] = new ListPortion;    bool read_success = true;    do {      sub_param[0] = param[0];      sub_param[1] = 0;      try {	result = GSM_Read_Undefined(gsm, sub_param);	((ListPortion*) param[1])->Append(sub_param[1]);	// okay, complicated things going on here	// we want to delete the return value, but	//   result is actually swapped with sub_param[0] in the	//   GSM_Read() functions!  So, can't just delete p;	//   need to swap result and sub_param[0] first.		// delete and swap	delete sub_param[0];	sub_param[0] = result;	result = NULL;      }      catch (gclRuntimeError &) {	read_success = false;      }      c = ' ';      while(!input.eof() && isspace(c))	input.get(c);      if(!input.eof() && c != ',')	input.unget(c);    } while (read_success && !input.eof());    c = ' ';    while(!input.eof() && isspace(c))      input.get(c);    if (input.eof()) {      delete param[1];      param[1] = 0;      throw gclRuntimeError("End of file reached");    }    else if (c != '}') {      delete param[1];      param[1] = 0;      throw gclRuntimeError("Mismatching braces");    }    else {      // swap the first parameter with the return value, so things like      //   Input["..."] >> x >> y  would work      result = param[0];      param[0] = result->RefCopy();    }  }  else  { // not a list    input.unget(c);    param[1] = new BoolPortion(false);        try {      return GSM_Read_Bool(gsm, param);    }    catch (gclRuntimeError &) {      delete param[1];      param[1] = new NumberPortion(0);    }    try {      return GSM_Read_Number(gsm, param);        }    catch (gclRuntimeError &) {      delete param[1];      param[1] = new TextPortion("");    }    try {      return GSM_Read_Text(gsm, param);        }    catch (gclRuntimeError &) {      delete param[1];      param[1] = 0;      gsm.OutputStream() << old_pos << '\n';       // Not sure if this line is needed... if it's included,      // segfaults occur.      //      input.setpos(old_pos);      throw gclRuntimeError("Cannot determine data type");    }  }  return result;}//----------// Times//----------static Portion *GSM_Times_Number(GSM &, Portion** param){  return new NumberPortion(((NumberPortion *) param[0])->Value() *                           ((NumberPortion *) param[1])->Value());}static Portion *GSM_Times_Mixed(GSM &, Portion** param){  MixedPortion *result = new MixedPortion(new MixedSolution(*((MixedPortion *) param[1])->Value()));  *result->Value() *= ((NumberPortion*) param[0])->Value();  return result;}static Portion *GSM_Times_Behav(GSM &, Portion** param){  BehavPortion *result = new BehavPortion(new BehavSolution(*((BehavPortion *) param[1])->Value()));  *result->Value() *= ((NumberPortion*) param[0])->Value();  return result;}//----------// Version//----------static Portion *GSM_Version(GSM &, Portion **){  return new TextPortion(VERSION);}//--------// Write//--------static Portion *GSM_Write(GSM &, Portion** param){  gOutput& s = ((OutputPortion*) param[0])->Value();  s << param[1];  return param[0]->ValCopy();}static Portion *GSM_Write_Nfg(GSM &, Portion** param){  gOutput &s = ((OutputPortion*) param[0])->Value();  Nfg *nfg = ((NfgPortion *) param[1])->Value();  nfg->WriteNfgFile(s, _WriteGameDecimals.Value());  return param[0]->ValCopy();}static Portion *GSM_Write_Efg(GSM &, Portion** param){  gOutput &s = ((OutputPortion*) param[0])->Value();  efgGame *efg = ((EfgPortion*) param[1])->Value();  efg->WriteEfgFile(s, _WriteGameDecimals.Value());  return param[0]->ValCopy();}//-----------------------------------------------------//---------------------// Formatting//---------------------//----------// *Format//----------static Portion *GSM_ListFormat(GSM &, Portion** param){  _WriteListBraces.SetValue(((BoolPortion*) param[0])->Value());  _WriteListCommas.SetValue(((BoolPortion*) param[1])->Value());  _WriteListLF.SetValue(((NumberPortion*) param[2])->Value());  _WriteListIndent.SetValue(((NumberPortion*) param[3])->Value());  GSM_SetWriteOptions();  return new BoolPortion(triTRUE);}static Portion *GSM_GetListFormat(GSM &, Portion** param){  ((BoolPortion*) param[0])->SetValue(_WriteListBraces.Value());  ((BoolPortion*) param[1])->SetValue(_WriteListCommas.Value());  ((NumberPortion*) param[2])->SetValue(_WriteListLF.Value());  ((NumberPortion*) param[3])->SetValue(_WriteListIndent.Value());  return new BoolPortion(triTRUE);}static Portion *GSM_NumberFormat(GSM &, Portion** param){  _WriteWidth.SetValue(((NumberPortion*) param[1])->Value());  _WritePrecis.SetValue(((NumberPortion*) param[2])->Value());  _WriteExpmode.SetValue(((BoolPortion*) param[3])->Value());  GSM_SetWriteOptions();  return param[0]->ValCopy();}static Portion *GSM_GetNumberFormat(GSM &, Portion** param){  ((NumberPortion*) param[1])->SetValue(_WriteWidth.Value());  ((NumberPortion*) param[2])->SetValue(_WritePrecis.Value());  ((BoolPortion*) param[3])->SetValue(_WriteExpmode.Value());  return param[0]->ValCopy();}static Portion *GSM_TextFormat(GSM &, Portion** param){  _WriteQuoted.SetValue(((BoolPortion*) param[1])->Value());  GSM_SetWriteOptions();  return param[0]->ValCopy();}static Portion *GSM_GetTextFormat(GSM &, Portion** param){  ((BoolPortion*) param[1])->SetValue(_WriteQuoted.Value());  return param[0]->ValCopy();}static Portion *GSM_SolutionFormat(GSM &, Portion** param){  _WriteSolutionInfo.SetValue(((BoolPortion*) param[1])->Value());  _WriteSolutionLabels.SetValue(((BoolPortion *) param[2])->Value());  GSM_SetWriteOptions();  return param[0]->ValCopy();}static Portion *GSM_GetSolutionFormat(GSM &, Portion** param){  ((BoolPortion*) param[1])->SetValue(_WriteSolutionInfo.Value());  return param[0]->ValCopy();}static Portion *GSM_GameFormat(GSM &, Portion **param){  _WriteGameDecimals.SetValue(((NumberPortion *) param[1])->Value());  GSM_SetWriteOptions();  return param[0]->ValCopy();}static Portion *GSM_GetGameFormat(GSM &, Portion **param){  ((NumberPortion *) param[1])->SetValue(_WriteGameDecimals.Value());  return param[0]->ValCopy();}//--------------// Environment//--------------static Portion *GSM_GetEnv(GSM &, Portion** param){  if (((TextPortion*) param[0])->Value().Length() == 0)    throw gclRuntimeError("Invalid environment variable name");  return new TextPortion(System::GetEnv(((TextPortion *) param[0])->Value()));}static Portion *GSM_SetEnv(GSM &, Portion** param){  if (((TextPortion*) param[0])->Value().Length() == 0)    throw gclRuntimeError("Invalid environment variable name");  if (System::SetEnv(((TextPortion*) param[0])->Value(),		     ((TextPortion*) param[1])->Value()) == 0)    return new BoolPortion(true);  else    throw gclRuntimeError("Insufficient environment space");}static Portion *GSM_UnSetEnv(GSM &, Portion** param){  if (((TextPortion*) param[0])->Value().Length() == 0)    throw gclRuntimeError("Invalid environment variable name");  if (System::UnSetEnv(((TextPortion*) param[0])->Value()) == 0)    return new BoolPortion(true);  else    throw gclRuntimeError("Insufficient environment space");}static Portion *GSM_Shell(GSM &, Portion** param){  gText str = ((TextPortion*) param[0])->Value();  bool spawn = ((BoolPortion*) param[1])->Value();  if (!spawn)  {    if (str.Length() > 0)      return new NumberPortion(System::Shell(str));    else      return new NumberPortion(System::Shell(0));  }  else  {    if (str.Length() > 0)      return new NumberPortion(System::Spawn(str));    else      return new NumberPortion(System::Spawn(0));  }}extern char* _ExePath;static Portion *GSM_ExePath(GSM &, Portion** param){#ifdef __GNUG__  const char SLASH = '/';#elif defined __BORLANDC__  const char SLASH = '\\';#endif   // __GNUG__  bool file = ((BoolPortion*) param[0])->Value();  bool path = ((BoolPortion*) param[1])->Value();  gText txt(_ExePath);  if (file && path) {  }  else if (file) {    if (txt.LastOccur(SLASH) > 0)      txt = txt.Right(txt.Length() - txt.LastOccur(SLASH));    else      txt = "";  }  else if (path) {    if (txt.LastOccur(SLASH) > 0)      txt = txt.Left(txt.LastOccur(SLASH));  }  if (!file && !path)    txt = "";  return new TextPortion(txt);}//-------------------------------------------//              Assign//-------------------------------------------Portion *GSM_Assign(GSM &gsm, Portion** param){  Portion *p = 0;  Portion *result = 0;  if( param[1]->IsReference() )  {    p = param[1]->RefCopy();    result = param[1]->RefCopy();  }  else  {    p = param[1]->ValCopy();    result = param[1]->ValCopy();  }  gText txt = ((TextPortion*) param[0])->Value();  if (!isalpha(txt[0u]))       throw gclRuntimeError("Bad Variable Name");  for(unsigned int i = 1;i<txt.Length();i++)     if(!isalnum(txt[i]))      throw gclRuntimeError("Bad Variable Name");  gsm.VarDefine(txt,p);  return result;}static Portion *GSM_UnAssign(GSM &gsm, Portion **param){  gText txt = ((TextPortion*) param[0])->Value();  return new BoolPortion(gsm.VarRemove(txt));}static Portion *GSM_Platform(GSM &, Portion**){#ifdef __svr4__  return new TextPortion("SVR4");#elif defined sparc  return new TextPortion("SPARC");#elif defined sun  return new TextPortion("SUN");#elif defined _AIX32  return new TextPortion("AIX32");#elif defined _AIX  return new TextPortion("AIX");#elif defined hpux  return new TextPortion("HP UX");#elif defined hppa  return new TextPortion("HPPA");#elif defined linux  return new TextPortion("Linux");

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?