editor.cc
./mud++0.26/src/editor.cc · 2.2 KB
From the archive mud++0.26f.tar.gz
Download the archive « Back to the archive contents
/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project. All
................................................ contributions are welcome.
....Copyright(C).1995.Melvin.Smith.............. Enjoy.
------------------------------------------------------------------------------
Melvin Smith (aka Fusion) msmith@hom.net
MUD++ development mailing list mudpp-list@mailhost.net
------------------------------------------------------------------------------
editor.cc
*/
#include "string.h"
#include "edit.h"
#include "pc.h"
#include "global.h"
const String & Editor::getPrompt()
{
if ( !text )
return prompt;
else
return text->getPrompt();
}
void Editor::editText( const String & initial )
{
if( pc->getTextEditor() )
{
String temp = initial;
temp.strip( '\r' );
filename = pc->getName();
filename += ".tmp";
OutFile outf( filename );
if( !outf )
{
pc->out( "Error creating edit file.\n\r" );
return;
}
outf << temp << endl;
outf.close();
pcs.remove( pc );
shellpcs.addTop( pc );
pc->startShell( pc->getTextEditor(), filename );
return;
}
text = new TextEditor( pc, initial );
pc->out( text->format() );
return;
}
void Editor::editFile( const String & name )
{
savefile = name;
if ( pc->getTextEditor() )
{
InFile inf(savefile);
String init;
if ( inf )
{
init = String(inf.getBuf());
inf.close();
}
init.strip( '\r' );
filename = pc->getName();
filename += ".tmp";
OutFile outf( filename );
if( !outf )
{
pc->out( "Error creating edit file.\n\r" );
return;
}
outf << init << endl;
outf.close();
pcs.remove( pc );
shellpcs.addTop( pc );
pc->startShell( pc->getTextEditor(), filename );
return;
}
else
{
InFile inf(savefile);
if ( !inf )
{
text = new TextEditor( pc, String("") );
}
else
{
text = new TextEditor( pc, String( inf.getBuf() ) );
inf.close();
}
pc->out( text->format() );
return;
}
}