Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION export-subst
VERSION_RAILCONTROL export-subst
VERSION_GIT_HASH export-subst
VERSION_GIT_TIMESTAMP export-subst
360 changes: 15 additions & 345 deletions CMakeLists.txt

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions Documentation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
cmake_minimum_required(VERSION 3.10)

find_program(PANDOC_EXECUTABLE pandoc)
if(NOT PANDOC_EXECUTABLE)
message(WARNING "pandoc not found!")
endif()

set(OUTPUT_HTML ${CMAKE_CURRENT_BINARY_DIR}/doc)
install(DIRECTORY ${OUTPUT_HTML}/ DESTINATION ${CMAKE_INSTALL_DOCDIR})

# common
file(GLOB DOCDATA menu_*.png style.css)
file(COPY ${DOCDATA} DESTINATION ${OUTPUT_HTML})

# DE
set(OUTPUT_HTML_DE ${OUTPUT_HTML}/de)
set(OUTPUT_HTML_DE_INDEX ${OUTPUT_HTML_DE}/index.html)

file(GLOB DOCDATA_DE de/*.png)
file(COPY ${DOCDATA_DE} DESTINATION ${OUTPUT_HTML_DE})

file(GLOB DOC_DE de/*.md)
file(MAKE_DIRECTORY ${OUTPUT_HTML_DE})
add_custom_command(
OUTPUT ${OUTPUT_HTML_DE_INDEX}
COMMAND ${PANDOC_EXECUTABLE} --toc --toc-depth=2 --standalone --css=../style.css
--template=template.html
--metadata-file=de/metadata.yaml ${DOC_DE}
--output=${OUTPUT_HTML_DE_INDEX}
DEPENDS ${DOC_DE} ${OUTPUT_HTML_DE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating German HTML documentation"
VERBATIM
)

# EN
set(OUTPUT_HTML_EN ${OUTPUT_HTML}/en)
set(OUTPUT_HTML_EN_INDEX ${OUTPUT_HTML_EN}/index.html)

file(GLOB DOCDATA_EN en/*.png)
file(COPY ${DOCDATA_EN} DESTINATION ${OUTPUT_HTML_EN})

file(GLOB DOC_EN en/*.md)
file(MAKE_DIRECTORY ${OUTPUT_HTML_EN})
add_custom_command(
OUTPUT ${OUTPUT_HTML_EN_INDEX}
COMMAND ${PANDOC_EXECUTABLE} --toc --toc-depth=2 --standalone --css=../style.css
--template=template.html
--metadata-file=en/metadata.yaml ${DOC_EN}
--output=${OUTPUT_HTML_EN_INDEX}
DEPENDS ${DOC_EN} ${OUTPUT_HTML_EN}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating English HTML documentation"
VERBATIM
)

# ES
set(OUTPUT_HTML_ES ${OUTPUT_HTML}/es)
set(OUTPUT_HTML_ES_INDEX ${OUTPUT_HTML_ES}/index.html)

file(GLOB DOCDATA_ES es/*.png)
file(COPY ${DOCDATA_ES} DESTINATION ${OUTPUT_HTML_ES})

file(GLOB DOC_ES es/*.md)
file(MAKE_DIRECTORY ${OUTPUT_HTML_ES})
add_custom_command(
OUTPUT ${OUTPUT_HTML_ES_INDEX}
COMMAND ${PANDOC_EXECUTABLE} --toc --toc-depth=2 --standalone --css=../style.css
--template=template.html
--metadata-file=es/metadata.yaml ${DOC_ES}
--output=${OUTPUT_HTML_ES_INDEX}
DEPENDS ${DOC_ES} ${OUTPUT_HTML_ES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating Spanish HTML documentation"
VERBATIM
)

add_custom_target(doc ALL
DEPENDS ${OUTPUT_HTML_DE_INDEX} ${OUTPUT_HTML_EN_INDEX} ${OUTPUT_HTML_ES_INDEX}
)

add_custom_target(doc-for-web
DEPENDS doc
)

add_custom_command(TARGET doc-for-web POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/de/documentation-de
${PROJECT_BINARY_DIR}/de/documentation-de
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/en/documentation-en
${PROJECT_BINARY_DIR}/en/documentation-en
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/es/documentation-es
${PROJECT_BINARY_DIR}/es/documentation-es
)
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ endif

CFLAGSSQLITE=-g -O2 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_RTREE -DHAVE_USLEEP
CFLAGSZLIB=-g -O2 -Wno-implicit-function-declaration
CXXFLAGS=-I. -g -O2 -Wall -Wextra -pedantic -Werror -Wno-missing-braces -std=c++11 -D_GNU_SOURCE
CXXFLAGSAMALGAMATION=-I. -g -O2 -Wall -Wextra -pedantic -Werror -Wno-missing-braces -std=c++11
CXXFLAGS=-I. -g -O2 -Wall -Wextra -pedantic -Werror -Wno-missing-braces -std=c++17 -D_GNU_SOURCE
CXXFLAGSAMALGAMATION=-I. -g -O2 -Wall -Wextra -pedantic -Werror -Wno-missing-braces -std=c++17
LDFLAGS=-g
LIBS=-lpthread -ldl
LIBSAMALGAMATION=-lpthread -ldl
Expand Down
9 changes: 6 additions & 3 deletions RailControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ along with RailControl; see the file LICENCE. If not see
#include "Network/Select.h"
#include "RailControl.h"
#include "Version.h"
#include "Utils/Path.h"
#include "Utils/Utils.h"

using std::vector;
using std::string;

void killRailControlIfNeeded(Logger::Logger* logger)
{
if (++stopSignalCounter < MaxStopSignalCounter)
stopSignalCounter = stopSignalCounter + 1;
if (stopSignalCounter < MaxStopSignalCounter)
{
return;
}
Expand Down Expand Up @@ -189,7 +191,7 @@ int main (int argc, char* argv[])

logger->Info(Languages::TextStartArgument, argv[0]);

const string configFileDefaultName("railcontrol.conf");
const string configFileDefaultName = Utils::Path::getConfDir() / "railcontrol.conf";
string configFileName = argumentHandler.GetArgumentString('c', configFileDefaultName);
if (configFileName.compare("") == 0)
{
Expand All @@ -204,7 +206,8 @@ int main (int argc, char* argv[])

if ((configFileName.compare(configFileDefaultName) == 0) && (!Utils::Utils::FileExists(configFileDefaultName)))
{
Utils::Utils::CopyFile(logger, "railcontrol.conf.dist", configFileDefaultName);
const std::filesystem::path defaultConfDistPath = Utils::Path::getDataDir() / "railcontrol.conf.dist";
Utils::Utils::CopyFile(logger, defaultConfDistPath, configFileDefaultName);
}

Config config(configFileName);
Expand Down
11 changes: 3 additions & 8 deletions Server/Web/WebClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ along with RailControl; see the file LICENCE. If not see
#include "Server/Web/WebClientStatic.h"
#include "Server/Web/WebServer.h"
#include "Utils/Integer.h"
#include "Utils/Path.h"

using namespace DataModel;
using LayoutPosition = DataModel::LayoutItem::LayoutPosition;
Expand Down Expand Up @@ -780,14 +781,8 @@ namespace Server { namespace Web

void WebClient::DeliverFile(const string& virtualFile)
{
std::stringstream ss;
char workingDir[128];
if (getcwd(workingDir, sizeof(workingDir)))
{
ss << workingDir << "/html" << virtualFile;
}
string sFile = ss.str();
const char* realFile = sFile.c_str();
const std::filesystem::path virtualFilePath = Utils::Path::getDataDir() / "html" / virtualFile;
const char* realFile = virtualFilePath.c_str();
FILE* f = fopen(realFile, "r");
if (f == nullptr)
{
Expand Down
71 changes: 71 additions & 0 deletions Utils/Path.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
RailControl - Model Railway Control Software

Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org

RailControl 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, or (at your option) any
later version.

RailControl 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 RailControl; see the file LICENCE. If not see
<http://www.gnu.org/licenses/>.
*/

#include <cstdlib>
#include <iostream>

#include "Utils/Path.h"

namespace Utils::Path
{
std::filesystem::path getConfDir()
{
const std::filesystem::path dir;
// systemd may set this if ConfigurationDirectory= is set for a service
const char* env_p = std::getenv("CONFIGURATION_DIRECTORY");
if (env_p)
{
std::filesystem::path dir(env_p);
}
else
{
std::filesystem::path dir(".");
}

return dir;
}

std::filesystem::path getDataDir()
{
#ifdef RAILCONTROL_DATADIR
const std::filesystem::path dir(RAILCONTROL_DATADIR);
#else
const std::filesystem::path dir(".");
#endif
return dir;
}

std::filesystem::path getStateDir()
{
const std::filesystem::path dir;
// systemd may set this if StateDirectory= is set for a service
const char* env_p = std::getenv("STATE_DIRECTORY");
if (env_p)
{
std::filesystem::path dir(env_p);
}
else
{
std::filesystem::path dir(".");
}

return dir;
}
}
46 changes: 46 additions & 0 deletions Utils/Path.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
RailControl - Model Railway Control Software

Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org

RailControl 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, or (at your option) any
later version.

RailControl 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 RailControl; see the file LICENCE. If not see
<http://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <filesystem>

namespace Utils::Path
{
/**
* Get the path to configuration directory
*
* @return path to the configuration directory
*/
std::filesystem::path getConfDir();

/**
* Get the path to read-only architecture independent data.
*
* @return path to read-only architecture independent data.
*/
std::filesystem::path getDataDir();

/**
* Get the directory holding the persistent state
*
* @return path to the persistent state directory
*/
std::filesystem::path getStateDir();
}
Loading