Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: minor

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