Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/util/shell.cc @ 5073

Last change on this file since 5073 was 5073, checked in by bensch, 19 years ago

orxonox/trunk: added new Function addFirst to list, that adds an entity at the beginning of the List

File size: 5.2 KB
Line 
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: Benjamin Grauer
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
17
18#include "shell.h"
19
20#include "text_engine.h"
21#include "list.h"
22
23using namespace std;
24
25
26/**
27 * standard constructor
28 */
29Shell::Shell ()
30{
31  this->setClassID(CL_SHELL, "Shell");
32  this->setName("Shell");
33
34  this->bufferText = new tList<Text>;
35  this->buffer = new tList<char>;
36
37  this->setBufferSize(100);
38  this->setBufferDisplaySize(5);
39}
40
41
42Shell* Shell::singletonRef = NULL;
43
44/**
45 * standard deconstructor
46 */
47Shell::~Shell ()
48{
49  // delete what has to be deleted here
50
51  Shell::singletonRef = NULL;
52}
53
54void Shell::setBufferDisplaySize(unsigned int bufferDisplaySize)
55{
56  this->bufferDisplaySize = bufferDisplaySize;
57
58  while (bufferDisplaySize < this->bufferText->getSize())
59  {
60    delete this->bufferText->lastElement();
61    this->bufferText->removeLast();
62  }
63  while(bufferDisplaySize > this->bufferText->getSize())
64  {
65    Text* newText = TextEngine::getInstance()->createText("fonts/earth.ttf", 30, TEXT_DYNAMIC, 0, 255, 0);
66    this->bufferText->add(newText);
67    // add the Text here
68  }
69}
70
71/**
72 * deletes all the Buffers
73 */
74void Shell::flushBuffers()
75{
76  // remove all chars from the BufferTexts.
77  tIterator<Text>* textIterator = this->bufferText->getIterator();
78  Text* textElem = textIterator->nextElement();
79
80  while (textElem != NULL)
81  {
82    textElem->setText(NULL);
83
84    textElem = textIterator->nextElement();
85  }
86  delete textIterator;
87
88
89  // delete all the Chars in the Buffers
90  tIterator<char>* charIterator = this->buffer->getIterator();
91  char* charElem = charIterator->nextElement();
92
93  while (charElem != NULL)
94  {
95    delete charElem;
96
97    charElem = charIterator->nextElement();
98  }
99  delete charIterator;
100}
101
102/**
103 * adds a new Line to the List of Buffers
104 * @param line the Line as in the first argument in printf
105 * @param args the arguments as a va_list
106 *
107 * @todo optimize
108 */
109void Shell::addBufferLine(const char* line, va_list args)
110{
111  char tmp[1024];// = new char*
112  vsprintf(tmp, line, args);
113
114  char* newLine = new char[strlen(tmp)+1];
115  strcpy(newLine, tmp);
116
117  this->buffer->add(newLine);
118
119  if (this->buffer->getSize() > this->bufferSize)
120  {
121    delete this->buffer->firstElement();
122    this->buffer->remove(this->buffer->firstElement());
123  }
124
125
126}
127
128/**
129 * moves the buffer around lineCount lines upwards (negative values move down)
130 * @param lineCount the Count of lines to move upwards
131 *
132 * @todo
133 */
134void Shell::moveBuffer(int lineCount)
135{
136}
137
138/**
139 * @param lineNumber the n-th line from the bottom
140 * @returns the Buffer at Line lineNumber
141 */
142const char* Shell::getBufferLine(unsigned int lineNumber)
143{
144  tIterator<char>* charIterator = this->buffer->getIterator();
145  char* charElem = charIterator->nextElement();
146
147  int i = 1;
148  while (charElem != NULL)
149  {
150    if (i++ < lineNumber)
151    {
152      delete charIterator;
153      return charElem;
154    }
155
156    charElem = charIterator->nextElement();
157  }
158  delete charIterator;
159}
160
161
162/**
163 * deletes the InputLine
164 */
165void Shell::flushInputLine()
166{
167  if (likely(this->inputLine != NULL))
168  {
169    delete [] this->inputLine;
170  }
171  this->inputLine = new char[1];
172  *this->inputLine = '\0';
173
174}
175
176/**
177 * adds one character to the inputLine
178 * @param character the character to add to the inputLine
179 */
180void Shell::addCharacter(char character)
181{
182  char* addCharLine = new char[strlen(inputLine)+2];
183
184  sprintf(addCharLine, "%s%c", this->inputLine, character);
185  delete this->inputLine;
186  this->inputLine = addCharLine;
187}
188
189/**
190 * adds multiple Characters to thr inputLine
191 * @param characters a '\0' terminated char-array to add to the InputLine
192 */
193void Shell::addCharacters(const char* characters)
194{
195  char* addCharLine = new char[strlen(inputLine)+strlen(characters)+1];
196
197  sprintf(addCharLine, "%s%s", this->inputLine, characters);
198  delete this->inputLine;
199  this->inputLine = addCharLine;
200}
201
202/**
203 * removes characterCount characters from the InputLine
204 * @param characterCount the count of Characters to remove from the input Line
205 */
206void Shell::removeCharacters(unsigned int characterCount)
207{
208  if (characterCount > strlen(this->inputLine))
209    characterCount = strlen(this->inputLine);
210
211  char* removeCharLine = new char[strlen(inputLine)-characterCount+1];
212
213  strncpy(removeCharLine, this->inputLine, strlen(inputLine)-characterCount);
214  delete this->inputLine;
215  this->inputLine = removeCharLine;
216}
217
218/**
219 * listens for some event
220 * @param event the Event happened
221 */
222void Shell::process(const Event &event)
223{
224//  if (event.type)
225
226}
227
228/**
229 * ticks the Shell for dt Seconds
230 * @param dt the elapsed time since the last tick();
231 */
232void Shell::tick(float dt)
233{
234}
235
236/**
237 * displays the Shell
238 */
239void Shell::draw() const
240{
241}
242
243
244/**
245 * autocompletes the Shell's inputLine
246 * @returns true, if a result was found, false otherwise
247 */
248bool Shell::autoComplete()
249{
250
251}
252
253/**
254 * displays some nice output from the Shell
255 */
256void Shell::debug() const
257{
258
259}
Note: See TracBrowser for help on using the repository browser.