OpenTTD Source  14.0-beta3
textfile_gui.cpp File Reference
#include "stdafx.h"
#include "core/backup_type.hpp"
#include "fileio_func.h"
#include "fontcache.h"
#include "gfx_type.h"
#include "gfx_func.h"
#include "string_func.h"
#include "textfile_gui.h"
#include "widgets/dropdown_type.h"
#include "gfx_layout.h"
#include "debug.h"
#include "openttd.h"
#include "widgets/misc_widget.h"
#include "table/strings.h"
#include "table/control_codes.h"
#include <zlib.h>
#include <lzma.h>
#include <regex>
#include "safeguards.h"

Go to the source code of this file.

Enumerations

enum  HyperlinkType { HyperlinkType::Internal, HyperlinkType::Web, HyperlinkType::File, HyperlinkType::Unknown }
 Types of link we support in markdown files. More...
 

Functions

static HyperlinkType ClassifyHyperlink (const std::string &destination, bool trusted)
 Classify the type of hyperlink the destination describes. More...
 
static std::string MakeAnchorSlug (const std::string &line)
 Create a valid slug for the anchor. More...
 
static void Gunzip (byte **bufp, size_t *sizep)
 Do an in-memory gunzip operation. More...
 
static void Xunzip (byte **bufp, size_t *sizep)
 Do an in-memory xunzip operation. More...
 
std::optional< std::string > GetTextfile (TextfileType type, Subdirectory dir, const std::string &filename)
 Search a textfile file next to the given content. More...
 

Variables

static constexpr NWidgetPart _nested_textfile_widgets []
 Widgets for the textfile window.
 
static WindowDesc _textfile_desc (__FILE__, __LINE__, WDP_CENTER, "textfile", 630, 460, WC_TEXTFILE, WC_NONE, 0, std::begin(_nested_textfile_widgets), std::end(_nested_textfile_widgets))
 Window definition for the textfile window.
 
static const std::regex _markdown_link_regex {"\\[(.+?)\\]\\((.+?)\\)", std::regex_constants::ECMAScript | std::regex_constants::optimize}
 Regular expression that searches for Markdown links.
 

Detailed Description

Implementation of textfile window.

Definition in file textfile_gui.cpp.

Enumeration Type Documentation

◆ HyperlinkType

enum HyperlinkType
strong

Types of link we support in markdown files.

Enumerator
Internal 

Internal link, or "anchor" in HTML language.

Web 

Link to an external website.

File 

Link to a local file.

Unknown 

Unknown link.

Definition at line 169 of file textfile_gui.cpp.

Function Documentation

◆ ClassifyHyperlink()

static HyperlinkType ClassifyHyperlink ( const std::string &  destination,
bool  trusted 
)
static

Classify the type of hyperlink the destination describes.

Parameters
destinationThe hyperlink destination.
trustedWhether we trust the content of this file.
Returns
HyperlinkType The classification of the link.

Definition at line 183 of file textfile_gui.cpp.

References File, Internal, Unknown, and Web.

Referenced by TextfileWindow::FindHyperlinksInMarkdown(), and TextfileWindow::OnHyperlinkClick().

◆ GetTextfile()

std::optional<std::string> GetTextfile ( TextfileType  type,
Subdirectory  dir,
const std::string &  filename 
)

Search a textfile file next to the given content.

Parameters
typeThe type of the textfile to search for.
dirThe subdirectory to search in.
filenameThe filename of the content to look for.
Returns
The path to the textfile, nullptr otherwise.

Definition at line 865 of file textfile_gui.cpp.

References lengthof.

Referenced by GRFConfig::GetTextfile(), and ScriptConfig::GetTextfile().

◆ Gunzip()

static void Gunzip ( byte **  bufp,
size_t *  sizep 
)
static

Do an in-memory gunzip operation.

This works on a raw deflate stream, or a file with gzip or zlib header.

Parameters
bufpA pointer to a buffer containing the input data. This buffer will be freed and replaced by a buffer containing the uncompressed data.
sizepA pointer to the buffer size. Before the call, the value pointed to should contain the size of the input buffer. After the call, it contains the size of the uncompressed data.

When decompressing fails, *bufp is set to nullptr and *sizep to 0. The compressed buffer passed in is still freed in this case.

Definition at line 667 of file textfile_gui.cpp.

References free(), and ReallocT().

Referenced by TextfileWindow::LoadTextfile().

◆ MakeAnchorSlug()

static std::string MakeAnchorSlug ( const std::string &  line)
static

Create a valid slug for the anchor.

Parameters
lineThe line to create the slug for.
Returns
std::string The slug.

Definition at line 203 of file textfile_gui.cpp.

◆ Xunzip()

static void Xunzip ( byte **  bufp,
size_t *  sizep 
)
static

Do an in-memory xunzip operation.

This works on a .xz or (legacy) .lzma file.

Parameters
bufpA pointer to a buffer containing the input data. This buffer will be freed and replaced by a buffer containing the uncompressed data.
sizepA pointer to the buffer size. Before the call, the value pointed to should contain the size of the input buffer. After the call, it contains the size of the uncompressed data.

When decompressing fails, *bufp is set to nullptr and *sizep to 0. The compressed buffer passed in is still freed in this case.

Definition at line 723 of file textfile_gui.cpp.

References free(), and ReallocT().

Referenced by TextfileWindow::LoadTextfile().