// TODO/WIP12/* Mednafen - Multi-system Emulator3*4* This program is free software; you can redistribute it and/or modify5* it under the terms of the GNU General Public License as published by6* the Free Software Foundation; either version 2 of the License, or7* (at your option) any later version.8*9* This program is distributed in the hope that it will be useful,10* but WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12* GNU General Public License for more details.13*14* You should have received a copy of the GNU General Public License15* along with this program; if not, write to the Free Software16* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA17*/1819#include "octoshock.h"20#include "Stream.h"2122//#include <trio/trio.h>2324Stream::Stream()25{2627}2829Stream::~Stream()30{3132}3334void Stream::put_line(const std::string& str)35{36char l = '\n';3738write(&str[0], str.size());39write(&l, sizeof(l));40}414243void Stream::print_format(const char *format, ...)44{45//char *str = NULL;46//int rc;4748//va_list ap;4950//va_start(ap, format);5152//rc = trio_vasprintf(&str, format, ap);5354//va_end(ap);5556//if(rc < 0)57// throw MDFN_Error(0, "Error in trio_vasprintf()");58//else59//{60// try // Bleck61// {62// write(str, rc);63// }64// catch(...)65// {66// free(str);67// throw;68// }69// free(str);70//}71}7273int Stream::get_line(std::string &str)74{75uint8 c;7677str.clear(); // or str.resize(0)??7879while(read(&c, sizeof(c), false) > 0)80{81if(c == '\r' || c == '\n' || c == 0)82return(c);8384str.push_back(c);85}8687return(str.length() ? 256 : -1);88}8990StreamFilter::StreamFilter()91{92target_stream = NULL;93}9495StreamFilter::StreamFilter(Stream *target_arg)96{97target_stream = target_arg;98}99100StreamFilter::~StreamFilter()101{102if(target_stream)103delete target_stream;104}105106Stream* StreamFilter::steal(void)107{108Stream *ret = target_stream;109target_stream = NULL;110return ret;111}112113114