2828#include " llvm/Support/ManagedStatic.h" // llvm_shutdown
2929#include " llvm/Support/Signals.h"
3030#include " llvm/Support/TargetSelect.h"
31+ #include " llvm/Support/raw_ostream.h"
3132#include " llvm/TargetParser/Host.h"
3233#include < optional>
3334
@@ -347,11 +348,15 @@ int main(int argc, const char **argv) {
347348 }
348349 }
349350
350- const char *percent_commands = " %help\t list clang-repl %commands\n "
351- " %undo\t undo the previous input\n "
352- " %quit\t exit clang-repl\n " ;
351+ // if we add more % commands, there should be better architecture than this
352+ const char *help_output = " %help\t list clang-repl %commands\n "
353+ " %undo\t undo the previous input\n "
354+ " %quit\t exit clang-repl\n " ;
355+ const char *help_prompt = " type %help to list clang-repl commands\n " ;
356+
357+ llvm::raw_ostream &OS = llvm::outs ();
353358 if (OptInputs.empty ()) {
354- printf ( " type %%help to list clang-repl commands \n " ) ;
359+ OS << help_prompt ;
355360 llvm::LineEditor LE (" clang-repl" );
356361 std::string Input;
357362 LE.setListCompleter (ReplListCompleter (CB, *Interp));
@@ -375,7 +380,9 @@ int main(int argc, const char **argv) {
375380 if (auto Err = Interp->Undo ())
376381 llvm::logAllUnhandledErrors (std::move (Err), llvm::errs (), " error: " );
377382 } else if (Input == R"( %help)" ) {
378- printf (" %s\n " , percent_commands);
383+ OS << help_output << ' \n ' ;
384+ } else if (Input[0 ] == ' %' ) { // make sure this is evaluated last
385+ OS << " Invalid % command: \" " << Input << " \" . " << help_prompt;
379386 } else if (Input.rfind (" %lib " , 0 ) == 0 ) {
380387 if (auto Err = Interp->LoadDynamicLibrary (Input.data () + 5 ))
381388 llvm::logAllUnhandledErrors (std::move (Err), llvm::errs (), " error: " );
0 commit comments