1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: ... |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
17 | |
---|
18 | #include "shell_input.h" |
---|
19 | |
---|
20 | #include "text_engine.h" |
---|
21 | |
---|
22 | #include "shell_command.h" |
---|
23 | #include "debug.h" |
---|
24 | #include "list.h" |
---|
25 | #include "compiler.h" |
---|
26 | #include "stdlibincl.h" |
---|
27 | |
---|
28 | using namespace std; |
---|
29 | |
---|
30 | |
---|
31 | /** |
---|
32 | * standard constructor |
---|
33 | * @todo this constructor is not jet implemented - do it |
---|
34 | */ |
---|
35 | ShellInput::ShellInput () |
---|
36 | { |
---|
37 | this->pressedKey = SDLK_FIRST; |
---|
38 | |
---|
39 | this->inputLine = new char[1]; |
---|
40 | this->inputLine[0] = '\0'; |
---|
41 | this->inputHistory = new tList<char>; |
---|
42 | } |
---|
43 | |
---|
44 | /** |
---|
45 | * standard deconstructor |
---|
46 | */ |
---|
47 | ShellInput::~ShellInput () |
---|
48 | { |
---|
49 | // delete what has to be deleted here |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * sets the Repeate-delay and rate |
---|
54 | * @param repeatDelay the Delay it takes, to repeate a key |
---|
55 | * @param repeatRate the rate to repeate a pressed key |
---|
56 | */ |
---|
57 | void ShellInput::setRepeatDelay(float repeatDelay, float repeatRate) |
---|
58 | { |
---|
59 | this->repeatDelay = repeatDelay; |
---|
60 | this->repeatRate = repeatRate; |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | * deletes the InputLine |
---|
66 | */ |
---|
67 | void ShellInput::flush() |
---|
68 | { |
---|
69 | if (likely(this->inputLine != NULL)) |
---|
70 | { |
---|
71 | delete[] this->inputLine; |
---|
72 | } |
---|
73 | this->inputLine = new char[1]; |
---|
74 | *this->inputLine = '\0'; |
---|
75 | this->setText(this->inputLine, true); |
---|
76 | } |
---|
77 | |
---|
78 | /** |
---|
79 | * adds one character to the inputLine |
---|
80 | * @param character the character to add to the inputLine |
---|
81 | */ |
---|
82 | void ShellInput::addCharacter(char character) |
---|
83 | { |
---|
84 | char* addCharLine = new char[strlen(inputLine)+2]; |
---|
85 | |
---|
86 | sprintf(addCharLine, "%s%c", this->inputLine, character); |
---|
87 | delete this->inputLine; |
---|
88 | this->inputLine = addCharLine; |
---|
89 | this->setText(inputLine, true); |
---|
90 | } |
---|
91 | |
---|
92 | /** |
---|
93 | * adds multiple Characters to thr inputLine |
---|
94 | * @param characters a \\0 terminated char-array to add to the InputLine |
---|
95 | */ |
---|
96 | void ShellInput::addCharacters(const char* characters) |
---|
97 | { |
---|
98 | char* addCharLine = new char[strlen(inputLine)+strlen(characters)+1]; |
---|
99 | |
---|
100 | sprintf(addCharLine, "%s%s", this->inputLine, characters); |
---|
101 | delete this->inputLine; |
---|
102 | this->inputLine = addCharLine; |
---|
103 | this->setText(inputLine, true); |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * removes characterCount characters from the InputLine |
---|
108 | * @param characterCount the count of Characters to remove from the input Line |
---|
109 | */ |
---|
110 | void ShellInput::removeCharacters(unsigned int characterCount) |
---|
111 | { |
---|
112 | if (strlen(this->inputLine) == 0) |
---|
113 | return; |
---|
114 | |
---|
115 | if (characterCount > strlen(this->inputLine)) |
---|
116 | characterCount = strlen(this->inputLine); |
---|
117 | |
---|
118 | char* removeCharLine = new char[strlen(inputLine)-characterCount+1]; |
---|
119 | |
---|
120 | strncpy(removeCharLine, this->inputLine, strlen(inputLine)-characterCount); |
---|
121 | removeCharLine[strlen(inputLine)-characterCount] = '\0'; |
---|
122 | delete this->inputLine; |
---|
123 | this->inputLine = removeCharLine; |
---|
124 | this->setText(inputLine, true); |
---|
125 | } |
---|
126 | |
---|
127 | /** |
---|
128 | * executes the command stored in the inputLine |
---|
129 | * @return true if the command was commited successfully, false otherwise |
---|
130 | */ |
---|
131 | bool ShellInput::executeCommand() |
---|
132 | { |
---|
133 | ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine); |
---|
134 | |
---|
135 | char* newCommand = new char[strlen(this->inputLine)+1]; |
---|
136 | strcpy(newCommand, this->inputLine); |
---|
137 | this->inputHistory->add(newCommand); |
---|
138 | |
---|
139 | ShellCommandBase::execute(this->inputLine); |
---|
140 | |
---|
141 | this->flush(); |
---|
142 | |
---|
143 | return false; |
---|
144 | } |
---|
145 | |
---|