Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5072 was 5072, checked in by bensch, 20 years ago

orxonox/trunk: started function implementation for Shell

File size: 5.2 KB
RevLine 
[4744]1/*
[1853]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.
[1855]10
11   ### File Specific:
[5068]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[3955]16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
[1853]17
[5068]18#include "shell.h"
[1853]19
[5072]20#include "text_engine.h"
21#include "list.h"
22
[1856]23using namespace std;
[1853]24
[1856]25
[3245]26/**
[4838]27 * standard constructor
[5068]28 */
29Shell::Shell ()
[3365]30{
[5072]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);
[5068]39}
[4320]40
41
[5068]42Shell* Shell::singletonRef = NULL;
[1853]43
[3245]44/**
[4838]45 * standard deconstructor
[5068]46 */
47Shell::~Shell ()
[3543]48{
49  // delete what has to be deleted here
[5068]50
51  Shell::singletonRef = NULL;
[3543]52}
[5068]53
[5072]54void Shell::setBufferDisplaySize(unsigned int bufferDisplaySize)
55{
56  this->bufferDisplaySize = bufferDisplaySize;
[5068]57
[5072]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}
[5068]70
71/**
72 * deletes all the Buffers
73 */
74void Shell::flushBuffers()
75{
[5072]76  // remove all chars from the BufferTexts.
77  tIterator<Text>* textIterator = this->bufferText->getIterator();
78  Text* textElem = textIterator->nextElement();
[5068]79
[5072]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;
[5068]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
[5072]106 *
107 * @todo optimize
[5068]108 */
109void Shell::addBufferLine(const char* line, va_list args)
110{
[5072]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  }
[5068]124}
125
126/**
127 * moves the buffer around lineCount lines upwards (negative values move down)
128 * @param lineCount the Count of lines to move upwards
[5072]129 *
130 * @todo
[5068]131 */
132void Shell::moveBuffer(int lineCount)
133{
134}
135
136/**
137 * @param lineNumber the n-th line from the bottom
138 * @returns the Buffer at Line lineNumber
139 */
140const char* Shell::getBufferLine(unsigned int lineNumber)
141{
[5072]142  tIterator<char>* charIterator = this->buffer->getIterator();
143  char* charElem = charIterator->nextElement();
144
145  int i = 1;
146  while (charElem != NULL)
147  {
148    if (i++ < lineNumber)
149    {
150      delete charIterator;
151      return charElem;
152    }
153
154    charElem = charIterator->nextElement();
155  }
156  delete charIterator;
[5068]157}
158
159
160/**
161 * deletes the InputLine
162 */
163void Shell::flushInputLine()
164{
[5072]165  if (likely(this->inputLine != NULL))
166  {
167    delete [] this->inputLine;
168  }
169  this->inputLine = new char[1];
170  *this->inputLine = '\0';
171
[5068]172}
173
174/**
175 * adds one character to the inputLine
176 * @param character the character to add to the inputLine
177 */
178void Shell::addCharacter(char character)
179{
[5072]180  char* addCharLine = new char[strlen(inputLine)+2];
181
182  sprintf(addCharLine, "%s%c", this->inputLine, character);
183  delete this->inputLine;
184  this->inputLine = addCharLine;
[5068]185}
186
187/**
188 * adds multiple Characters to thr inputLine
189 * @param characters a '\0' terminated char-array to add to the InputLine
190 */
191void Shell::addCharacters(const char* characters)
192{
[5072]193  char* addCharLine = new char[strlen(inputLine)+strlen(characters)+1];
194
195  sprintf(addCharLine, "%s%s", this->inputLine, characters);
196  delete this->inputLine;
197  this->inputLine = addCharLine;
[5068]198}
199
200/**
201 * removes characterCount characters from the InputLine
202 * @param characterCount the count of Characters to remove from the input Line
203 */
204void Shell::removeCharacters(unsigned int characterCount)
205{
[5072]206  if (characterCount > strlen(this->inputLine))
207    characterCount = strlen(this->inputLine);
208
209  char* removeCharLine = new char[strlen(inputLine)-characterCount+1];
210
211  strncpy(removeCharLine, this->inputLine, strlen(inputLine)-characterCount);
212  delete this->inputLine;
213  this->inputLine = removeCharLine;
[5068]214}
215
[5069]216/**
217 * listens for some event
218 * @param event the Event happened
219 */
220void Shell::process(const Event &event)
221{
222//  if (event.type)
[5068]223
[5069]224}
225
[5068]226/**
227 * ticks the Shell for dt Seconds
228 * @param dt the elapsed time since the last tick();
229 */
230void Shell::tick(float dt)
231{
232}
233
234/**
235 * displays the Shell
236 */
237void Shell::draw() const
238{
239}
240
241
242/**
243 * autocompletes the Shell's inputLine
244 * @returns true, if a result was found, false otherwise
245 */
246bool Shell::autoComplete()
247{
248
249}
250
251/**
252 * displays some nice output from the Shell
253 */
254void Shell::debug() const
255{
256
257}
Note: See TracBrowser for help on using the repository browser.