Commit 0becd3ed authored by snuverink_j's avatar snuverink_j
Browse files

Resolve "cleanup: remove readline support in Classic parser"

parent 1ac30ff8
// ------------------------------------------------------------------------
// $RCSfile: TerminalStream.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.2 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: TerminalStream
// Implements an input buffer for reading tokens from a terminal.
// Class TerminalStream
// A stream of input tokens.
// The source of tokens is the terminal.
//
// ------------------------------------------------------------------------
// Class category: Parser
// ------------------------------------------------------------------------
// Copyright (c) 2012-2019, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// $Date: 2001/08/24 19:33:11 $
// $Author: jsberg $
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
// ------------------------------------------------------------------------
#include "Parser/TerminalStream.h"
#ifdef READLINE
// Special version using GNU readline().
// This version does not work with I/O redirection.
extern "C"
{
#include <stdio.h>
#ifdef __P
// Corrects a problem in the readline header files
#undef __P
#endif
#include <readline/readline.h>
#include <readline/history.h>
}
#endif // READLINE
#include <iomanip>
#include <iostream>
// Class TerminalStream
// ------------------------------------------------------------------------
// :FIXME: can READLINE support be removed? Why is it not used?
TerminalStream::TerminalStream(
#ifdef READLINE
const char program[]
#else
const char[]
#endif
): AbsFileStream("standard input") {
#ifdef READLINE
// Set up the readline() function.
rl_readline_name = new char[strlen(program) + 1];
strcpy(const_cast<char *>(rl_readline_name), program);
rl_initialize();
#endif
}
TerminalStream::~TerminalStream() {
#ifdef READLINE
delete [] rl_readline_name;
#endif
}
bool TerminalStream::fillLine() {
#ifdef READLINE
char *p = readline("==>");
line = std::string(p) + '\n';
add_history(p);
line += "\n";
curr_line++;
std::cerr.width(5);
std::cerr << curr_line << " " << line;
curr_char = 0;
return true;
#else
if(std::cin.eof()) {
// We must test for end of file, even on terminal, as it may be rerouted.
return false;
......@@ -90,5 +45,4 @@ bool TerminalStream::fillLine() {
curr_char = 0;
return true;
}
#endif
}
}
\ No newline at end of file
#ifndef CLASSIC_TerminalStream_HH
#define CLASSIC_TerminalStream_HH
// ------------------------------------------------------------------------
// $RCSfile: TerminalStream.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: TerminalStream
// Class TerminalStream
// A stream of input tokens.
// The source of tokens is the terminal.
//
// Copyright (c) 2012-2019, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// ------------------------------------------------------------------------
// Class category: Parser
// ------------------------------------------------------------------------
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// $Date: 2000/03/27 09:32:37 $
// $Author: fci $
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
// ------------------------------------------------------------------------
#ifndef CLASSIC_TerminalStream_HH
#define CLASSIC_TerminalStream_HH
#include "Parser/AbsFileStream.h"
// Class TerminalStream
// ------------------------------------------------------------------------
/// A stream of input tokens.
// The source of tokens is the terminal.
class TerminalStream: public AbsFileStream {
public:
/// Constructor.
// The C-style string program name may be used in the readline package.
TerminalStream(const char program[]);
virtual ~TerminalStream();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment