Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Shell is running, but only in orxonox-world, not all-over
I do not know why this behaviour occurs, but maybe it is because of some errors in other pointers…
who knows

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