1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "EditorString.h"
22 #include "StringUtilities.h"
26 EditorString::EditorString(UBSocket
* sock
, std::string
& target
) :
31 OnLine(Global::Get()->EmptyString
);
34 EditorString::~EditorString()
36 std::string result
= String::Get()->unlines(m_strings
, " ");
40 EditorString::E_STATE
EditorString::ParseMode(char mode
, bool silent
)
42 E_STATE choice
= M_FIRST
;
48 m_sock
->Sendf("Unknown mode '%c'.\n", mode
);
52 m_sock
->Send("Switching to 'append' mode.\n");
57 m_sock
->Send("Allright, done!\n");
58 choice
= M_WAITING_FOR_INPUT
;
62 m_sock
->Send("Switching to 'replacement' mode.\n");
68 m_sock
->Send("Switching to 'viewing' mode.\n");
76 void EditorString::ParseDot(const std::string
& line
)
78 std::string command
= line
;
81 E_STATE changedstate
= ParseMode(command
[0]);
82 if(changedstate
!= M_FIRST
)
84 m_state
= changedstate
;
88 if(!command
.compare("c"))
90 m_sock
->Send("Text cleared.\n");
95 if(!command
.compare("q"))
97 m_sock
->Send("Quitting now.\n");
102 if(!command
.compare("h"))
104 m_sock
->Send("Some descriptive help text goes here.\n");
108 m_sock
->Sendf("Unknown dot command '%s'.\n", command
.c_str());
112 void EditorString::OnLine(const std::string
& line
)
114 if(!line
.compare("~"))
116 m_sock
->Send("Allright, done!\n");
130 Global::Get()->bug("EditorString::OnLine(), default m_state!\n");
131 m_sock
->Send("BUG! Disconnecting you now...\n");
132 m_sock
->SetCloseAndDelete();
138 m_state
= M_WAITING_FOR_INPUT
;
139 m_sock
->Send("Welcome to the string editor.\n");
141 } /* case M_FIRST: */
143 case M_WAITING_FOR_INPUT
:
147 m_sock
->Send("Please choose an editing mode.\n");
148 m_sock
->Send("If you need help please type '.h'.\n");
159 E_STATE choice
= ParseMode(mode
);
161 if(choice
== M_FIRST
)
162 m_state
= M_WAITING_FOR_INPUT
;
166 OnLine(Global::Get()->EmptyString
);
168 } /* case M_WAITING_FOR_INPUT: */
174 m_sock
->Sendf("If you want to append a newline type '.n' on an empty line.\n");
178 m_strings
.push_back(line
);
180 } /* case M_APPEND: */
186 m_sock
->Send("Not yet implemented - Alturin 30-12-2007.\n");
196 m_sock
->Send("At the moment all you can do here is hit enter to show the entire string.\n");
200 m_sock
->Send(String::Get()->unlines(m_strings
, " "));
211 } /* switch(state) */