diff --git a/src/CBot/CBot.cpp b/src/CBot/CBot.cpp index da8109f4..52ea9c60 100644 --- a/src/CBot/CBot.cpp +++ b/src/CBot/CBot.cpp @@ -83,43 +83,3 @@ // Global include #include -///////////////////////////////////////////////////////////////////////////////////// -// file management - -// necessary because it is not possible to do the fopen in the main program -// fwrite and fread in a dll or using the FILE * returned. - - -FILE* fOpen(const char* name, const char* mode) -{ - return fopen(name, mode); -} - -int fClose(FILE* filehandle) -{ - return fclose(filehandle); -} - -size_t fWrite(const void *buffer, size_t elemsize, size_t length, FILE* filehandle) -{ - return fwrite(buffer, elemsize, length, filehandle); -} - -size_t fRead(void *buffer, size_t elemsize, size_t length, FILE* filehandle) -{ - return fread(buffer, elemsize, length, filehandle); -} - -size_t fWrite(const void *buffer, size_t length, FILE* filehandle) -{ - return fwrite(buffer, 1, length, filehandle); -} - -size_t fRead(void *buffer, size_t length, FILE* filehandle) -{ - return fread(buffer, 1, length, filehandle); -} - - -//////////////////////////////////////// - diff --git a/src/CBot/CBotDll.h b/src/CBot/CBotDll.h index fd5939d2..d1d1838e 100644 --- a/src/CBot/CBotDll.h +++ b/src/CBot/CBotDll.h @@ -147,13 +147,6 @@ class CBotCStack; // stack // for example exceptions returned by external routines // and " throw " with any number. -/////////////////////////////////////////////////////////////////////////////// -// routines for file management (* FILE) - FILE* fOpen(const char* name, const char* mode); - int fClose(FILE* filehandle); - size_t fWrite(const void *buffer, size_t elemsize, size_t length, FILE* filehandle); - size_t fRead(void *buffer, size_t elemsize, size_t length, FILE* filehandle); - #if 0 /* diff --git a/src/CBot/CBotFileUtils.cpp b/src/CBot/CBotFileUtils.cpp new file mode 100644 index 00000000..1c585713 --- /dev/null +++ b/src/CBot/CBotFileUtils.cpp @@ -0,0 +1,62 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + +// Modules inlcude +#include "CBotFileUtils.h" + +// Local include + +// Global include + + + +// file management + +// necessary because it is not possible to do the fopen in the main program +// fwrite and fread in a dll or using the FILE * returned. + +//////////////////////////////////////////////////////////////////////////////// +FILE* fOpen(const char* name, const char* mode) +{ + return fopen(name, mode); +} + +//////////////////////////////////////////////////////////////////////////////// +int fClose(FILE* filehandle) +{ + return fclose(filehandle); +} + +//////////////////////////////////////////////////////////////////////////////// +std::size_t fWrite(const void *buffer, + std::size_t elemsize, + std::size_t length, + FILE* filehandle) +{ + return fwrite(buffer, elemsize, length, filehandle); +} + +//////////////////////////////////////////////////////////////////////////////// +std::size_t fRead(void *buffer, + std::size_t elemsize, + std::size_t length, + FILE* filehandle) +{ + return fread(buffer, elemsize, length, filehandle); +} diff --git a/src/CBot/CBotFileUtils.h b/src/CBot/CBotFileUtils.h new file mode 100644 index 00000000..8f76ec4d --- /dev/null +++ b/src/CBot/CBotFileUtils.h @@ -0,0 +1,71 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + +#pragma once + +// Modules inlcude + +// Local include + +// Global include + #include + +/////////////////////////////////////////////////////////////////////////////// +// routines for file management (* FILE) + +/*! + * \brief fOpen + * \param name + * \param mode + * \return + */ +FILE* fOpen(const char* name, const char* mode); + +/*! + * \brief fClose + * \param filehandle + * \return + */ +int fClose(FILE* filehandle); + +/*! + * \brief fWrite + * \param buffer + * \param elemsize + * \param length + * \param filehandle + * \return + */ +std::size_t fWrite(const void *buffer, + std::size_t elemsize, + std::size_t length, + FILE* filehandle); + +/*! + * \brief fRead + * \param buffer + * \param elemsize + * \param length + * \param filehandle + * \return + */ +std::size_t fRead(void *buffer, + std::size_t elemsize, + std::size_t length, + FILE* filehandle); diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt index e2fa17ce..3bb1eb91 100644 --- a/src/CBot/CMakeLists.txt +++ b/src/CBot/CMakeLists.txt @@ -1,5 +1,7 @@ set(SOURCES CBot.cpp + CBotUtils.cpp + CBotFileUtils.cpp CBotClass.cpp CBotProgram.cpp CBotStack.cpp @@ -7,7 +9,6 @@ set(SOURCES CBotString.cpp CBotToken.cpp CBotCall.cpp - CBotUtils.cpp CBotDefParam.cpp CBotCallMethode.cpp CBotStringArray.cpp diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 8ff82eee..7cd1bdb0 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -20,6 +20,7 @@ #include "level/robotmain.h" #include "CBot/CBotDll.h" +#include "CBot/CBotFileUtils.h" // TODO must be replaced by CBot.h #include "CBot/CBotClass.h" diff --git a/src/object/implementation/programmable_impl.cpp b/src/object/implementation/programmable_impl.cpp index fe594e75..379929e5 100644 --- a/src/object/implementation/programmable_impl.cpp +++ b/src/object/implementation/programmable_impl.cpp @@ -40,6 +40,8 @@ #include "ui/controls/edit.h" +#include "CBot/CBotFileUtils.h" + #include #include diff --git a/src/script/script.cpp b/src/script/script.cpp index d87a41a6..92c658f6 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -44,6 +44,7 @@ #include "CBot/CBotToken.h" #include "CBot/CBotVar/CBotVar.h" +#include "CBot/CBotFileUtils.h" const int CBOT_IPF = 100; // CBOT: default number of instructions / frame