71 lines
1.9 KiB
C
71 lines
1.9 KiB
C
/*
|
|
* PVVMUD a 3D MUD
|
|
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*
|
|
*/
|
|
#include "stdinput.H"
|
|
#include <malloc.h>
|
|
#include <iostream.h>
|
|
// Setter standard bufferstørrelse
|
|
CStdInput::CStdInput() {
|
|
m_bufsize = m_BUFFERSIZE = 20; // Standard bufferstørrelse er 20 tegn
|
|
m_buffer = (char*)malloc(m_BUFFERSIZE);
|
|
m_sysbuffer = (char*)malloc(10);
|
|
//cin.rdbuf()->setbuf(m_sysbuffer, 10);
|
|
}
|
|
|
|
// Angir bufferstørrelse eksplisitt
|
|
CStdInput::CStdInput(int bufsize) {
|
|
m_bufsize = m_BUFFERSIZE = bufsize;
|
|
m_buffer = (char*)malloc(m_BUFFERSIZE);
|
|
m_sysbuffer = (char*)malloc(10);
|
|
//cin.rdbuf()->setbuf(m_sysbuffer, 10);
|
|
}
|
|
|
|
CStdInput::~CStdInput() {
|
|
if (m_buffer != NULL) {
|
|
free(m_buffer);
|
|
}
|
|
free (m_sysbuffer);
|
|
}
|
|
|
|
// Sjekker standard input
|
|
CStdInput::poll() {
|
|
}
|
|
|
|
CStdInput::addChar(char c) {
|
|
if (m_numchars < m_bufsize) {
|
|
// More room in buffer, add char
|
|
m_buffer[m_numchars++] = c;
|
|
}
|
|
else {
|
|
// Increase buffer size
|
|
m_buffer = (char*)realloc(m_buffer, m_bufsize+m_BUFFERSIZE);
|
|
m_buffer[m_numchars++] = c;
|
|
}
|
|
}
|
|
|
|
CStdInput::sendMsg() {
|
|
cout << m_buffer;
|
|
free(m_buffer);
|
|
m_buffer = (char*)malloc(m_BUFFERSIZE);
|
|
m_bufsize = m_BUFFERSIZE;
|
|
m_numchars = 0;
|
|
}
|
|
|
|
|