added: mount points
(reading /etc/fstab from db not working yet)
core/mount.h
core/mountparser.h
core/mountparser.cpp
core/mounts.h
core/mounts.cpp
content/thread.cpp
content/createthread.cpp
templates/thread.cpp
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@495 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
146
core/mountparser.cpp
Executable file
146
core/mountparser.cpp
Executable file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user