/* * 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" #include "log.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::ReadParam(std::string & res) { res.clear(); while( *pinput && *pinput!=10 && *pinput!=',' && !IsWhite(*pinput) ) { res += *pinput; ++pinput; } if( *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 ) { mount.dir_id = pdir->id; 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::ReadMountParams() { SkipWhite(); for( ReadParam(temp) ; !temp.empty() ; ReadParam(temp) ) { if( !mount.ParseStrParam(temp) ) { log << log1 << "MP: unknown mount param: " << temp << logend; err = Error::mount_no_param; return; } else { log << log3 << "MP: mount param: " << temp << logend; } } } void MountParser::ReadRow(std::map & output) { ReadMountType(); if( err == Error::ok ) ReadMountPoint(); if( err == Error::ok ) ReadMountParams(); if( err == Error::ok ) { output.insert( std::make_pair(mount.dir_id, mount) ); } SkipLine(); } Error MountParser::Parse(const std::string & input, std::map & output) { pinput = input.c_str(); err = Error::ok; output.clear(); while( *pinput && err == Error::ok ) ReadRow(output); return err; }