Exemplo n.º 1
0
/**
 * Reads a command from the terminal thread, and processes it appropriately.
 */
void Cli::command()
{
    std::stringstream reader(terminal_.get_line());
    std::string command;
    reader >> command;

    if (command == "")                  ;
    else if (command == "exit")         cmd_exit();
    else if (command == "help")         cmd_help();
    else if (command == "connect")      cmd_connect(reader);
    else if (command == "disconnect")   cmd_disconnect(reader);
    else if (command == "height")       cmd_height();
    else if (command == "watch")        cmd_watch(reader);
    else if (command == "txheight")     cmd_tx_height(reader);
    else if (command == "txdump")       cmd_tx_dump(reader);
    else if (command == "txsend")       cmd_tx_send(reader);
    else if (command == "utxos")        cmd_utxos(reader);
    else if (command == "save")         cmd_save(reader);
    else if (command == "load")         cmd_load(reader);
    else if (command == "dump")         cmd_dump(reader);
    else
        std::cout << "unknown command " << command << std::endl;

    // Display another prompt, if needed:
    if (!done_)
        terminal_.show_prompt();
}
Exemplo n.º 2
0
void
SyncFiles::readInput(void)
{
  ReadLine rL;

  // now switch to std::cin
  rL.connect_cin();  // std::cin

  // read instructions
  while( ! rL.readLine() )
  {
     for( size_t i=0 ; i < rL.size() ; ++i )
     {
       ensemble->member.push_back( new Member );

       if( path.size() )
         ensemble->member.back()->setPath(path);

       ensemble->member.back()->setFilename(rL.getItem(i));
     }
  }

  // sz will be changed corresponding to the effective range
  ensemble->sz = ensemble->member.size() ;
  ensemble->last = ensemble->sz -1 ; // the real size
  return;
}
Exemplo n.º 3
0
// Added to keep the linker happy at step A
malValuePtr readline(const String& prompt)
{
    String input;
    if (s_readLine.get(prompt, input)) {
        return mal::string(input);
    }
    return mal::nilValue();
}
Exemplo n.º 4
0
int main()
{
    ReadLine reader;

    reader.set_auto_complete_func( MatchGenerator );
    reader.set_prompt( "prompt >" );
    //reader.set_prompt( ">" );

    bool loop( false );
    string buffer;

    do
    {
        loop = reader.read( buffer );

        while (!buffer.empty())
        {
            size_t n = buffer.size() - 1;
            if (buffer[n] == ' ')
            {
                buffer.erase(n);
            }
            else break;
        }

        if ( !buffer.empty() )
        {
            reader.add_history_entry( buffer );
        }

        if (buffer == "quit") break;

        if (buffer == "list")
        {
            system("ls -l");
        }

        unsigned int x = 0, y = 0;
        Term::get_cursor_pos(stdout, x, y);

        fprintf(stderr, "[%d,%d]\n", x, y);
    }while( loop );

    return 0;
}
Exemplo n.º 5
0
// Cpptraj::Interactive()
int Cpptraj::Interactive() {
  ReadLine inputLine;
  // By default when interactive do not exit on errors
  State_.SetNoExitOnError();
  // Open log file. If no name has been set, use default.
  CpptrajFile logfile_;
  if (logfilename_.empty())
    logfilename_.SetFileName("cpptraj.log");
  if (File::Exists(logfilename_)) {
    // Load previous history.
    if (logfile_.OpenRead(logfilename_)==0) {
      mprintf("\tLoading previous history from log '%s'\n", logfile_.Filename().full());
      std::string previousLine = logfile_.GetLine();
      while (!previousLine.empty()) {
        if (previousLine[0] != '#') {
          // Remove any newline chars.
          std::size_t found = previousLine.find_first_of("\r\n");
          if (found != std::string::npos)
            previousLine[found] = '\0';
          inputLine.AddHistory( previousLine.c_str() );
        }
        previousLine = logfile_.GetLine();
      }
      logfile_.CloseFile();
    }
  }
  logfile_.OpenAppend(logfilename_);
  if (logfile_.IsOpen())
    logfile_.Printf("# %s\n", TimeString().c_str());
  Command::RetType readLoop = Command::C_OK;
  while ( readLoop != Command::C_QUIT ) {
    if (inputLine.GetInput()) {
      // EOF (Ctrl-D) specified. If state is not empty, ask before exiting.
      if (!State_.EmptyState()) {
        if (inputLine.YesNoPrompt("EOF (Ctrl-D) specified but there are actions/"
                                  "analyses/trajectories queued. Really quit? [y/n]> "))
          break;
      } else
        break;
    }
    if (!inputLine.empty()) {
      readLoop = Command::Dispatch( State_, *inputLine );
      if (logfile_.IsOpen() && readLoop != Command::C_ERR) {
        logfile_.Printf("%s\n", inputLine.c_str());
        logfile_.Flush();
      }
    }
    // If state is not empty, ask before exiting.
    if (readLoop == Command::C_QUIT && !State_.EmptyState()) {
      if (inputLine.YesNoPrompt("There are actions/analyses/trajectories queued. "
                                "Really quit? [y/n]> "))
        break;
      else
        readLoop = Command::C_OK;
    }
  }
  logfile_.CloseFile();
  if (readLoop == Command::C_ERR) return 1;
  return 0;
}
Exemplo n.º 6
0
/**
 * The main loop for the example application. This loop can be woken up
 * by either events from the network or by input from the terminal.
 */
int Cli::run()
{
    std::cout << "type \"help\" for instructions" << std::endl;
    terminal_.show_prompt();

    while (!done_)
    {
        std::vector<zmq_pollitem_t> items;
        items.push_back(terminal_.pollitem());
        auto updaterItems = updater_.pollitems();
        items.insert(items.end(), updaterItems.begin(), updaterItems.end());

        auto nextWakeup = updater_.wakeup();
        int delay = nextWakeup.count() ? nextWakeup.count() : -1;

        zmq::poll(items.data(), items.size(), delay);

        if (items[0].revents)
            command();
    }
    return 0;
}
Exemplo n.º 7
0
int main(int argc, char* argv[])
{
    String prompt = "user> ";
    String input;
    malEnvPtr replEnv(new malEnv);
    installCore(replEnv);
    installFunctions(replEnv);
    makeArgv(replEnv, argc - 2, argv + 2);
    if (argc > 1) {
        String filename = escape(argv[1]);
        safeRep(STRF("(load-file %s)", filename.c_str()), replEnv);
        return 0;
    }
    while (s_readLine.get(prompt, input)) {
        safeRep(input, replEnv);
    }
    return 0;
}
Exemplo n.º 8
0
int main(int argc, char* argv[])
{
    String prompt = "user> ";
    String input;
    installCore(replEnv);
    installFunctions(replEnv);
    makeArgv(replEnv, argc - 2, argv + 2);
    if (argc > 1) {
        String filename = escape(argv[1]);
        safeRep(STRF("(load-file %s)", filename.c_str()), replEnv);
        return 0;
    }
    while (s_readLine.get(prompt, input)) {
        String out = safeRep(input, replEnv);
        if (out.length() > 0)
            std::cout << out << "\n";
    }
    return 0;
}
Exemplo n.º 9
0
int main(int argc, char* argv[])
{
    String prompt = "user> ";
    String input;
    malEnvPtr replEnv(new malEnv);
    installCore(replEnv);
    installFunctions(replEnv);
    while (s_readLine.get(prompt, input)) {
        String out;
        try {
            out = rep(input, replEnv);
        }
        catch (malEmptyInputException&) {
            continue; // no output
        }
        catch (String& s) {
            out = s;
        };
        std::cout << out << "\n";
    }
    return 0;
}
Exemplo n.º 10
0
void
readOptions(std::vector<std::string> &argv)
{
  ReadLine rL;
  std::string file;

  bool isCinProvided=false;

  // find filename of parameter-file.
  for( size_t i=0 ; i<argv.size() ; ++i)
  {
     // find "--file"
     if( argv[i].find("--file") < std::string::npos )
     {
       if( argv[i] == "--file" && (i+1) < argv.size() )
       {
         file = argv[i+1];

         // remove: --file's argument
         argv.erase(argv.begin() + i +1 );
       }
       else
         file = argv[i].substr(7);

       // remove: --file
       argv.erase(argv.begin() + i);
       break;
     }

     if( argv[i].find("--input") < std::string::npos )
     {
       isCinProvided=true;

       // remove argument
       argv.erase(argv.begin() + i);
       break;
     }
  }

  if( file.size() > 0 )
  {
     rL.open(file); // from file

     // read instructions
     while( ! rL.readLine() )
     {
        if( rL.at(0) == '#')
          continue;

        for( size_t j=0 ; j < rL.size() ; ++j)
          argv.push_back( rL.getItem(j) ) ;
     }

    rL.close();
  }

  if( !isCinProvided)
    return;

  // now switch to std::cin
  rL.connect_cin();  // std::cin

  // read instructions
  while( ! rL.readLine() )
  {
     if( rL.at(0) == '#' )
       continue;

     for( size_t j=0 ; j < rL.size() ; ++j)
       argv.push_back( rL.getItem(j) ) ;
  }

  return;
}