Example #1
0
void check_reserved_names(file const& f)
{
    // Remove this exception once this file has been reworked.
    if(f.phyloanalyze("^ledger_xml_io.cpp$"))
        {
        return;
        }

    if(f.is_of_phylum(e_log))
        {
        return;
        }

    static boost::regex const r("(\\b\\w*__\\w*\\b)");
    boost::sregex_iterator i(f.data().begin(), f.data().end(), r);
    boost::sregex_iterator const omega;
    for(; i != omega; ++i)
        {
        boost::smatch const& z(*i);
        std::string const s = z[0];
        static boost::regex const not_all_underscore("[A-Za-z0-9]");
        if
            (   !check_reserved_name_exception(s)
            &&  boost::regex_search(s, not_all_underscore)
            )
            {
            std::ostringstream oss;
            oss << "contains reserved name '" << s << "'.";
            complain(f, oss.str());
            }
        }
}
Example #2
0
void luaStore_writeStrings(stringtable * strt, file&f)
{
	GCObject * list;
	int i;

	// The total amount of strings
	f.write(strt->nuse);
	
	for(i = 0;i < strt->size;i++)
	{
		list = strt->hash[i];
		while(list)
		{
			// write the object pointer
			f.write(&list, sizeof(void*));

			// write the string length
			if(list->ts.tsv.len > 0xFFFF)
				dbgError("string too long");
			f.write((ushort)list->ts.tsv.len);

			// write the string
			f.write(&list->ts + 1, list->ts.tsv.len);

			// next!
			list = list->gch.next;
		}
	}
}
Example #3
0
//==============================================================================
static file resolvexdgfolder (const char* const type, const char* const fallbackfolder)
{
    file userdirs ("~/.config/user-dirs.dirs");
    stringarray conflines;

    if (userdirs.existsasfile())
    {
        fileinputstream in (userdirs);

        if (in.openedok())
            conflines.addlines (in.readentirestreamasstring());
    }

    for (int i = 0; i < conflines.size(); ++i)
    {
        const string line (conflines[i].trimstart());

        if (line.startswith (type))
        {
            // eg. resolve xdg_music_dir="$home/music" to /home/user/music
            const file f (line.replace ("$home", file ("~").getfullpathname())
                              .fromfirstoccurrenceof ("=", false, false)
                              .trim().unquoted());

            if (f.isdirectory())
                return f;
        }
    }

    return file (fallbackfolder);
}
Example #4
0
void check_label_indentation(file const& f)
{
    if(!f.is_of_phylum(e_c_or_cxx))
        {
        return;
        }

    static boost::regex const r("\\n( *)([A-Za-z][A-Za-z0-9_]*)( *:)(?!:)");
    boost::sregex_iterator i(f.data().begin(), f.data().end(), r);
    boost::sregex_iterator const omega;
    for(; i != omega; ++i)
        {
        boost::smatch const& z(*i);
        if
            (   "default" != z[2]
            &&  "  "      != z[1]
            &&  "      "  != z[1]
            )
            {
            std::ostringstream oss;
            oss << "has misindented label '" << z[1] << z[2] << z[3] << "'.";
            complain(f, oss.str());
            }
        }
}
Example #5
0
void luaStore_writeLongString(GCObject * obj, file& f)
{
	// Long String format:
	// ushort length
	// length bytes
	if(obj->ts.tsv.len > 0xFFFF)
		dbgError("string too long");
	f.write((ushort)obj->ts.tsv.len);

	f.write(&obj->ts + 1, obj->ts.tsv.len);
}
Example #6
0
bool fileList::updatefile(file& oldFile, file& updFile)
{
    for(list<fileList::entry>::iterator it=filelst.begin();
    it!=filelst.end(); ++it)
    {
        if(it->getpath()==oldFile.getpath())
        {
            it->setpath(updFile.getpath());
            return true;
        }
    }
    return false;
}
    directory get_parent_directory (
        const file& f
    )
    {
        if (f.full_name().size() == 0)
            return directory();

        std::string::size_type pos = f.full_name().find_last_of("\\/");
        
        if (pos == std::string::npos)
            return directory();

        return directory(f.full_name().substr(0,pos));
    }
Example #8
0
bool fileList::checkfile(file& chkFile)
{
	fileList::entry e;
	e.setpath(chkFile.getpath());
	for(list<fileList::entry>::iterator it=filelst.begin();
		it!=filelst.end(); ++it)
	{
		if(it->getpath()==chkFile.getpath())
		{
			return true;
		}
	}
	return false;
}
Example #9
0
static file::size_type getDirSize(const file& d) {
	file::size_type res = 0;
	string path = d.path();
	vector<struct dirent> files = d.list_files((flags & F_ALL) != 0);
	for(auto it = files.begin(); it != files.end(); ++it) {
		file f(path,it->d_name);
		if(f.is_dir()) {
			string name = f.name();
			if(name != "." && name != "..")
				res += getDirSize(f);
		}
		else
			res += f.size();
	}
	return res;
}
Example #10
0
position::position(const file& source, size_t line, size_t col, size_t index) : source_(&source), line_(line), col_(col), index_(index) {
    assert(line >= 1);
    assert(col >= 1);
    if (index > source.length()) {
        throw std::logic_error("position (" + std::to_string(index) + ") is out of range (" + std::to_string(source.length()) + ")");
    }
}
Example #11
0
bool fileList::addfile(file& newFile)
{
    fileList::entry e;
    e.setpath(newFile.getpath());
    filelst.push_back(e);
    return true;
}
Example #12
0
void assay_non_latin(file const& f)
{
    static boost::regex const forbidden("[\\x00-\\x08\\x0e-\\x1f\\x7f-\\x9f]");
    if(boost::regex_search(f.data(), forbidden))
        {
        throw std::runtime_error("File contains a forbidden character.");
        }
}
Example #13
0
    bool file::operator==( const file &other ) const
    {
        if( sorting == by_size )
        return size() == other.size();

        if( sorting == by_date )
        return date() == other.date();

        if( sorting == by_extension )
        return ext() == other.ext();

        if( sorting == by_type )
        return is_dir() == other.is_dir();

        //if( sorting == by_name )
        return pathfile == other.pathfile;
    }
Example #14
0
File: File.cpp Project: ss23/rpcs3
void fs::file_ptr::reset(const file& f)
{
	reset();

	if (f)
	{
#ifdef _WIN32
		const HANDLE handle = ::CreateFileMapping((HANDLE)f.m_fd, NULL, PAGE_READONLY, 0, 0, NULL);
		m_ptr = (char*)::MapViewOfFile(handle, FILE_MAP_READ, 0, 0, 0);
		m_size = f.size();
		::CloseHandle(handle);
#else
		m_ptr = (char*)::mmap(nullptr, m_size = f.size(), PROT_READ, MAP_SHARED, f.m_fd, 0);
		if (m_ptr == (void*)-1) m_ptr = nullptr;
#endif
	}
}
Example #15
0
void check_preamble(file const& f)
{
    if
        (   f.is_of_phylum(e_gpl)
        ||  f.is_of_phylum(e_md5)
        ||  f.is_of_phylum(e_patch)
        ||  f.is_of_phylum(e_rates)
        ||  f.is_of_phylum(e_touchstone)
        ||  f.is_of_phylum(e_xml_input)
        )
        {
        return;
        }

    static std::string const url("http://savannah.nongnu.org/projects/lmi");
    require(f, url, "lacks lmi URL.");
}
Example #16
0
    bool file::operator<( const file &other ) const
    {
        if( sorting == by_size )
        return size() < other.size();

        if( sorting == by_date )
        return date() < other.date();

        if( sorting == by_extension ) //@todo: lower!, buggy
        return ext() < other.ext();

        if( sorting == by_type )
        return is_dir() < other.is_dir();

        //if( sorting == by_name )
        return pathfile < other.pathfile;
    }
//This function is called when a capture is stopped
//"block" holds an object representing the current script block on the flowchart
void OnStopCapture(ScriptBlock block)
{
    if (bFileOpen == true) {
        handle.close();
    }
 
    //block.ClearOutputText(); //Clear this scripts output window
    block.PrintOutputText("Binary file write stopped\n", false, false, false, false); //Print to the output window
}
Example #18
0
void check_config_hpp(file const& f)
{
    static std::string const loose  ("# *include *[<\"]config.hpp[>\"]");
    static std::string const strict ("\\n(#include \"config.hpp\")\\n");
    static std::string const indent ("\\n(#   include \"config.hpp\")\\n");

    if
        (   f.is_of_phylum(e_log)
        ||  f.phyloanalyze("^test_coding_rules_test.sh$")
        ||  f.phyloanalyze("^GNUmakefile$")
        ||  f.phyloanalyze("^pchfile(_.*)?\\.hpp$")
        )
        {
        return;
        }
    else if(f.is_of_phylum(e_header) && f.phyloanalyze("^pchlist(_.*)?\\.hpp$"))
        {
        require(f, loose , "must include 'config.hpp'.");
        require(f, indent, "lacks line '#   include \"config.hpp\"'.");
        boost::smatch match;
        static boost::regex const first_include("(# *include[^\\n]*)");
        boost::regex_search(f.data(), match, first_include);
        if("#   include \"config.hpp\"" != match[1])
            {
            complain(f, "must include 'config.hpp' first.");
            }
        }
    else if(f.is_of_phylum(e_header) && !f.phyloanalyze("^config(_.*)?\\.hpp$"))
        {
        require(f, loose , "must include 'config.hpp'.");
        require(f, strict, "lacks line '#include \"config.hpp\"'.");
        boost::smatch match;
        static boost::regex const first_include("(# *include[^\\n]*)");
        boost::regex_search(f.data(), match, first_include);
        if("#include \"config.hpp\"" != match[1])
            {
            complain(f, "must include 'config.hpp' first.");
            }
        }
    else
        {
        forbid(f, loose, "must not include 'config.hpp'.");
        }
}
Example #19
0
void luaStore_writeTable(GCObject * obj, file& f, std::vector<void *>& functions)
{
	// Table format:
	// int sizearray
	// sizearray objects
	f.write(obj->h.sizearray);

	int i;
	for(i = 0;i < obj->h.sizearray;i++)
		luaStore_writeValue(&obj->h.array[i], f, functions);
}
Example #20
0
void check_include_guards(file const& f)
{
    if(!f.is_of_phylum(e_cxx_header))
        {
        return;
        }

    std::string const guard = boost::regex_replace
        (f.leaf_name()
        ,boost::regex("\\.hpp$")
        ,"_hpp"
        );
    std::string const guards =
            "\\n#ifndef "   + guard
        +   "\\n#define "   + guard + "\\n"
        +   ".*"
        +   "\\n#endif // " + guard + "\\n+$"
        ;
    require(f, guards, "lacks canonical header guards.");
}
Example #21
0
void forbid
    (file const&        f
    ,std::string const& regex
    ,std::string const& complaint
    )
{
    if(boost::regex_search(f.data(), boost::regex(regex)))
        {
        complain(f, complaint);
        }
}
Example #22
0
//==============================================================================
bool file::copyinternal (const file& dest) const
{
    fileinputstream in (*this);

    if (dest.deletefile())
    {
        {
            fileoutputstream out (dest);

            if (out.failedtoopen())
                return false;

            if (out.writefrominputstream (in, -1) == getsize())
                return true;
        }

        dest.deletefile();
    }

    return false;
}
Example #23
0
void check_copyright(file const& f)
{
    if
        (   f.is_of_phylum(e_gpl)
        ||  f.is_of_phylum(e_md5)
        ||  f.is_of_phylum(e_patch)
        ||  f.is_of_phylum(e_touchstone)
        ||  f.is_of_phylum(e_xml_input)
        )
        {
        return;
        }

    std::time_t const t0 = std::time(nullptr);
    std::tm const*const t1 = std::localtime(&t0);
    LMI_ASSERT(nullptr != t1);
    int const year = 1900 + t1->tm_year;

    std::ostringstream oss;
    oss << "Copyright \\(C\\)[^\\n]*" << year;
    require(f, oss.str(), "lacks current copyright.");

    if(f.is_of_phylum(e_html) && !f.phyloanalyze("^COPYING"))
        {
        std::ostringstream oss;
        oss << "Copyright &copy;[^\\n]*" << year;
        require(f, oss.str(), "lacks current secondary copyright.");
        }
}
//This function is called everytime a message is received on an input port
//"inPort" will hold the port the message was received by (1, 2, or 3)
//"block" holds an object representing the current script block on the flowchart
//"msg" holds an object representing the message received
//type "block." or "msg." to see a list of available parameters and functions
void OnReceiveMessage(uint8 inPort, ScriptBlock block, Message &msg)
{
    if (!bFileOpen) {
        return;
    }
 
    //Here we pretend that we get some sort of ACK or response from the embedded device that indicates that
    //it is ready to receive the next packet of data containing the firmware image.  Most reprogramming/flash
    //protocols has some sort of similar indicator meaing something to the effect of "read for data".
    //For testing, you can simply use a 29-bit transmitter that sends a packet with ID=1234 at a repeating
    //interval
    if (msg.GetID() == 1234) {
 
        //Prep our data payload packet that will be sent to the embedded device
        Message dataMsg;
        dataMsg.SetID(12345);       
        dataMsg.Set11Bit(0);          //I am assuming its 29-bit CAN messages       
 
        block.PrintOutputText("Sending CAN packet ID=" + dataMsg.GetID() + " with data:", false, false, true, false);
        //Read up to 8 bytes of data from the firmware image to fill the next packet of CAN data   
        int i = 0;
        for (i = 0; i < 8; ++i) {
            if (handle.isEOF()) {   //Check for end of file
                block.PrintOutputText("\nEnd of file reached", false, false, false, true);  //print a message indicating the data
                handle.close();        //Close file and release flag that indicates its open
                bFileOpen = false;
                break;
            }
            uint8 dataByte = handle.readUInt8();  //read a single byte of data from the file
            block.PrintOutputText(" " + dataByte, false, false, true, false);  //print a message indicating the data
            dataMsg.SetData(i, dataByte);  //and store the byte from the file directly into our CAN packet structure       
        }
        block.PrintOutputText("\n", false, false, true, false);
 
        dataMsg.SetDataLength(i);  //set the length to the number of bytes read from the file
 
        //And finally send the data packet
        block.SendMessage(1, dataMsg);               
    }
} 
Example #25
0
void file::pipe(file &read_end, file &write_end) {
  // Close the descriptors first to make sure that assignments don't throw
  // and there are no leaks.
  read_end.close();
  write_end.close();
  int fds[2] = {};
#ifdef _WIN32
  // Make the default pipe capacity same as on Linux 2.6.11+.
  enum { DEFAULT_CAPACITY = 65536 };
  int result = FMT_POSIX_CALL(pipe(fds, DEFAULT_CAPACITY, _O_BINARY));
#else
  // Don't retry as the pipe function doesn't return EINTR.
  // http://pubs.opengroup.org/onlinepubs/009696799/functions/pipe.html
  int result = FMT_POSIX_CALL(pipe(fds));
#endif
  if (result != 0)
    FMT_THROW(system_error(errno, "cannot create pipe"));
  // The following assignments don't throw because read_fd and write_fd
  // are closed.
  read_end = file(fds[0]);
  write_end = file(fds[1]);
}
Example #26
0
void decryptContent(file & someFile, key & someKey, vector<string> & decryptedContent)
{
    unsigned int fileLen = someFile.length();
    for (unsigned int i = 0; i < fileLen; i++)
    {
        string output = "";
        for (unsigned int j = 0; j < someFile[i].length(); j++)
        {
            output.push_back(decryptChar(someFile[i][j], someKey));
        }
        decryptedContent.push_back(output);
    }
}
Example #27
0
bool fileList::removefile(file& delFile)
{
    for(list<fileList::entry>::iterator it=filelst.begin();
    it!=filelst.end(); ++it)
    {
        if(it->getpath()==delFile.getpath())
        {
            filelst.erase(it);
            return true;
        }
    }
    return false;
}
Example #28
0
void taboo
    (file const&             f
    ,std::string const&      regex
    ,boost::regex::flag_type flags = boost::regex::ECMAScript
    )
{
    boost::regex::flag_type syntax = flags | boost::regex::ECMAScript;
    if(boost::regex_search(f.data(), boost::regex(regex, syntax)))
        {
        std::ostringstream oss;
        oss << "breaks taboo '" << regex << "'.";
        complain(f, oss.str());
        }
}
Example #29
0
void luaStore_writeGC(GCObject * gc, file& f, std::vector<void *>& functions)
{
	GCObject * tmp = gc;
	uint i;
	for(i = 0;gc;i++)
		gc = gc->gch.next;
	f.write(i); // list size
	gc = tmp;
	while(gc)
	{
		luaStore_writeObject(gc, f, functions);
		gc = gc->gch.next;
	}
}
Example #30
0
void luaStore_writeThread(lua_State * L, file& f, std::vector<void *>& functions)
{
	int i;
	StkId stack;

	// Write the thread stack
	stack = L->stack;
	f.write(L->stacksize);
	for(i = 0;i < L->stacksize;i++)
	{
		luaStore_writeValue(stack, f, functions);
		stack++;
	}
}