void process_phrase(const char *loc_str, LibCore & lib) { if(NULL==loc_str) return; #ifndef HAVE_NATSPEC gsize bytes_read; gsize bytes_written; GError *err=NULL; char *str=g_locale_to_utf8(loc_str, -1, &bytes_read, &bytes_written, &err); if(NULL==str){ std::cerr<<"Can not convert "<<loc_str<<" to utf8.\n"<<err->message<<std::endl; g_error_free(err); return; } #else gchar *str = natspec_convert_with_translit(loc_str, "UTF-8", NULL); #endif if(str[0]=='\0') return; std::vector<LibCore::SearchResult> res; bool is_found=false; if(str[0]=='/'){ is_found=lib.LookupWithFuzzy(str+1, res); } else if(bContainRule(str)){ is_found=lib.LookupWithRule(str, res); } else{ if(!(is_found=lib.SimpleLookup(str, res))) is_found=lib.LookupWithFuzzy(str, res); } if(is_found){ std::cout<<"Found "<<res.size()<<" items, similar to "<<PrintUTF8(str)<<"."<<std::endl; if(res.size()>1){ for(size_t i=0; i<res.size(); ++i) std::cout<<PrintUTF8(res[i].phrase)<<"("<<i<<")"<<std::endl; int choise; for(;;){ std::cout<<"Your choice: "; if(std::cin>>choise && choise>=0 && choise<int(res.size())){ std::cout<<PrintUTF8(res[choise].explanation)<<std::endl; break; } else{ std::cin.clear(); char ch; while(std::cin.get(ch) && ch!='\n'); std::cout<<"Invalid choise."<<std::endl<<"It must be from 0 to "<<res.size()-1<<"."<<std::endl; } } } else{
int ExecuteScript (const SOptions &Options) { int i, j; // Load the script file CDatum dScript; CString sError; if (!CDatum::CreateFromFile(Options.sScriptFile, CDatum::formatAEONScript, &dScript, &sError)) { printf("ERROR: %s\n", (LPSTR)sError); return 1; } // Get the server to connect to CString sServer = dScript.GetElement(FIELD_SERVER); if (sServer.IsEmpty()) sServer = Options.sServer; // Connect CSocket theSocket; if (!ConnectToArcology(STR_ARC_CONSOLE, sServer, Options, &theSocket)) return 1; // Run the script CDatum dCommands = dScript.GetElement(FIELD_COMMANDS); for (i = 0; i < dCommands.GetCount(); i++) { CDatum dCommand = dCommands.GetElement(i); // Generate a command-line from the command CStringBuffer Buffer; for (j = 0; j < dCommand.GetCount(); j++) { if (j != 0) Buffer.Write(" ", 1); dCommand.Serialize(CDatum::formatAEONScript, Buffer); } // Run printf("%s\n", (LPSTR)(const CString &)Buffer); CString sResult = ExecuteArcologyCommand(theSocket, Buffer); PrintUTF8(sResult); printf("\n"); } // Done return 0; }
int AI1 (SOptions &Options) { CSocket theSocket; // Help if (!Options.bNoLogo) { printf("AI1 1.0\n"); printf("Copyright (c) 2011-2015 by Kronosaur Productions. All Rights Reserved.\n"); printf("\n"); } if (Options.bHelp) { printf("ai1 [options] [\"command\"]\n"); printf("\n"); printf(" /? Help.\n"); printf(" /h:{filespec} Run HexeDocument.\n"); printf(" /l Lisp engine top-level.\n"); printf(" /n No logo.\n"); printf(" /r:{filespec} Run script file.\n"); printf(" /s:{hostname} Connect to given server.\n"); printf(" /t Time each command.\n"); printf(" /z Do not connect to server.\n"); printf(" /1 V1 authentication.\n"); printf(" /! V1 auth to old server.\n"); if (Options.bNoConnect) return 0; printf("\n"); Options.sSingleCommand = CString("help"); } // Connect (if necessary) if (!ConnectToArcology(STR_ARC_CONSOLE, Options, &theSocket)) return 1; // If we have a HexeDocument, run it. if (!Options.sHexeDocument.IsEmpty()) return ExecuteHexeDocument(Options); // If we have a script file, defer to it. else if (!Options.sScriptFile.IsEmpty()) return ExecuteScript(Options); // PEM file else if (Options.bPEMFile) return ExecuteDebugPEMFile(Options.sSingleCommand); // If we have a single command, send it else if (!Options.sSingleCommand.IsEmpty()) { printf("%s\n", (LPSTR)Options.sSingleCommand); CString sOutput = Execute(theSocket, Options, Options.sSingleCommand); PrintUTF8(sOutput); printf("\n"); return 0; } // Otherwise, do an interactive loop else { while (true) { CString sInput = GetInputLine(STR_PROMPT); if (strEquals(sInput, STR_QUIT)) break; else if (!sInput.IsEmpty()) { CString sOutput = Execute(theSocket, Options, sInput); PrintUTF8(sOutput); printf("\n"); } } return 0; } }