sc.cpp

来自「一个在linux下的shell的计算器」· C++ 代码 · 共 112 行

CPP
112
字号
/* * * * */#include <iostream>#include <cstdlib>#include <readline/readline.h>#include <readline/history.h>#include "sc.h"using namespace std;//////void DisplayBanner(){ cout << endl; cout << "SC " << SCVERSION << ", the shell calculator by SD" << endl; cout << endl;}//////bool GetReadline(string prompt, string & line){#ifdef USE_READLINE char *buf = readline(prompt.c_str()); if (buf == NULL) return false; line = string(buf); free(buf);  return true;#else cout << prompt; getline(cin, line); return true;#endif}//////void InteractiveMode(Interpreter & sc){ string str; bool inLoop = true; DisplayBanner(); while (inLoop) {  if (!GetReadline(sc.GetPrompt(), str))  {   cout << endl;   break;  }  try  {   inLoop = !sc.Execute(str);   #ifdef USE_READLINE   if (inLoop) add_history(str.c_str());   #endif  }  catch (Exception *ex)  {   cerr << ex->ToString() << endl;   delete ex;  };  sc.DisplayStack(10); }}//////void BatchMode(Interpreter & sc, int ncmd, char *cmd[]){ int i; string str; for (i=1;i<ncmd;i++) {  str = string(cmd[i]);  try  {   sc.Execute(str);   }  catch(Exception *ex)  {   cerr << ex->ToString() << endl;   delete ex;  }  }}//////int main(int argc, char *argv[]){ Interpreter sc; srand48(long(time(NULL))); if (argc == 1) InteractiveMode(sc); else BatchMode(sc, argc, argv);  if (sc.stack.Length() > 0) cout << sc.GetResult() << endl; return 0;}

⌨️ 快捷键说明

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