winix/core/mountparser.cpp

147 lines
1.9 KiB
C++
Raw Normal View History

/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2009, Tomasz Sowa
* All rights reserved.
*
*/
#include "mountparser.h"
#include "data.h"
bool MountParser::IsWhite(int c)
{
if( c==' ' || c=='\t' || c==13 )
return true;
return false;
}
void MountParser::SkipWhite()
{
while( IsWhite(*pinput) )
++pinput;
}
void MountParser::SkipLine()
{
while( *pinput && *pinput != 10 )
++pinput;
if( *pinput == 10 )
++pinput;
}
void MountParser::ReadWord(std::string & res)
{
res.clear();
while( *pinput && *pinput!=10 && !IsWhite(*pinput) )
{
res += *pinput;
++pinput;
}
}
void MountParser::ReadMountType()
{
SkipWhite();
ReadWord(temp);
if( temp == "cms" )
{
mount_type = Mount::cms;
log << log3 << "MP: mount type: cms" << logend;
}
else
if( temp == "thread" )
{
mount_type = Mount::thread;
log << log3 << "MP: mount type: thread" << logend;
}
else
{
err = Error::mount_unknown;
log << log1 << "MP: unknown mount type: " << temp << logend;
}
}
void MountParser::ReadMountPoint()
{
SkipWhite();
// !! narazie bez cudzyslowow
ReadWord(temp);
pdir = data.dirs.GetDir(temp);
if( pdir )
{
log << log3 << "MP: mount point: " << temp << logend;
}
else
{
err = Error::no_mountpoint;
log << log1 << "MP: there is no such a mount point: " << temp << logend;
}
}
void MountParser::ReadRow(std::map<long, Mount> & output)
{
ReadMountType();
if( err == Error::ok )
ReadMountPoint();
if( err == Error::ok )
{
Mount m;
m.dir_id = pdir->id;
m.type = mount_type;
output.insert( std::make_pair(pdir->id, m) );
}
SkipLine();
}
Error MountParser::Parse(const std::string & input, std::map<long, Mount> & output)
{
pinput = input.c_str();
err = Error::ok;
output.clear();
while( *pinput && err == Error::ok )
ReadRow(output);
return err;
}