1 //===-- InputReaderEZ.cpp ---------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/Core/InputReaderEZ.h"
11
12 using namespace lldb;
13 using namespace lldb_private;
14
15 size_t
Callback_Impl(void * baton,InputReader & reader,lldb::InputReaderAction notification,const char * bytes,size_t bytes_len)16 InputReaderEZ::Callback_Impl(void *baton,
17 InputReader &reader,
18 lldb::InputReaderAction notification,
19 const char *bytes,
20 size_t bytes_len)
21
22 {
23 HandlerData hand_data(reader,
24 bytes,
25 bytes_len,
26 baton);
27
28 switch (notification)
29 {
30 case eInputReaderActivate:
31 reader.ActivateHandler(hand_data);
32 break;
33 case eInputReaderDeactivate:
34 reader.DeactivateHandler(hand_data);
35 break;
36 case eInputReaderReactivate:
37 reader.ReactivateHandler(hand_data);
38 break;
39 case eInputReaderAsynchronousOutputWritten:
40 reader.AsynchronousOutputWrittenHandler(hand_data);
41 break;
42 case eInputReaderGotToken:
43 {
44 if (reader.GetSaveUserInput())
45 reader.GetUserInput().AppendString(bytes, bytes_len);
46 reader.GotTokenHandler(hand_data);
47 }
48 break;
49 case eInputReaderInterrupt:
50 reader.InterruptHandler(hand_data);
51 break;
52 case eInputReaderEndOfFile:
53 reader.EOFHandler(hand_data);
54 break;
55 case eInputReaderDone:
56 reader.DoneHandler(hand_data);
57 break;
58 }
59 return bytes_len;
60 }
61
62 Error
Initialize(void * baton,lldb::InputReaderGranularity token_size,const char * end_token,const char * prompt,bool echo)63 InputReaderEZ::Initialize(void* baton,
64 lldb::InputReaderGranularity token_size,
65 const char* end_token,
66 const char *prompt,
67 bool echo)
68 {
69 return InputReader::Initialize(Callback_Impl,
70 baton,
71 token_size,
72 end_token,
73 prompt,
74 echo);
75 }
76
77 Error
Initialize(InitializationParameters & params)78 InputReaderEZ::Initialize(InitializationParameters& params)
79 {
80 Error ret = Initialize(params.m_baton,
81 params.m_token_size,
82 params.m_end_token,
83 params.m_prompt,
84 params.m_echo);
85 m_save_user_input = params.m_save_user_input;
86 return ret;
87 }
88
~InputReaderEZ()89 InputReaderEZ::~InputReaderEZ ()
90 {
91 }
92