diff --git a/HACKING.md b/HACKING.md
index c3d89059a..943d611ca 100644
--- a/HACKING.md
+++ b/HACKING.md
@@ -86,4 +86,7 @@ Note that all true-color capable messages extend but don't replace 'base' 16 pal
(a la global parameters `Opt.ShowFilenameMarks` and `Opt.FilenameMarksAlign`):
- `OPIF_HL_MARKERS_NOSHOW` and `OPIF_HL_MARKERS_NOALIGN` (in `enum OPENPLUGININFO_FLAGS`);
- `PFLAGS_HL_MARKERS_NOSHOW` and `PFLAGS_HL_MARKERS_NOALIGN` (in `enum PANELINFOFLAGS`).
+* Flag which prevents the removal of ampersand characters from menu items being iterated in `VMenu::FindItem()`
+(for the proper work of `History::GetAllSimilar()` function and in other similar situations):
+ - `LIFIND_KEEPAMPERSAND` (in `enum FARLISTFINDFLAGS`);
diff --git a/README.md b/README.md
index 2c96ad2bd..0c17fc6ab 100644
--- a/README.md
+++ b/README.md
@@ -25,29 +25,31 @@ FreeBSD/MacOS (Cirrus CI): [![Cirrus](https://api.cirrus-ci.com/github/elfmz/far
### UI Backends
FAR2L has base UI Backends (see details in build-in help section **UI backends**):
-- **GUI** (**WX**): uses wxWidgets, works in graphics mode, ideal UX, requires a lot of X11 dependencies;
+- **GUI** (**WX**): uses wxWidgets, works in graphics mode, **ideal UX**
+(might add dependencies to your desktop environment, e.g. wxWidgets toolkit and related packages);
-- **TTY|Xi**: works in terminal mode, requires a dependency on pair X11 libraries (to access clipboard and to get state of
-all keyboard modifiers), almost perfect UX;
+- **TTY|Xi**: works in terminal mode, requires a dependency on pair X11 libraries
+(to access clipboard and to get state of all keyboard modifiers), **almost perfect UX**;
- **TTY|X**: works in terminal mode, uses X11 to access clipboard, all keyboard works via terminal;
-- **TTY**: plain terminal mode, no X11 dependencies, UX with some restrictions (works fully when running in the [terminal
-emulators](#terminals), which provide clipboard access and has their advanced keyboard-protocols).
-
+- **TTY**: plain terminal mode, no X11 dependencies, **UX with some restrictions** (works fully when running in the
+[terminal emulators](#terminals), which provide clipboard access and has their advanced keyboard-protocols).
| Mode (UI Backends) | TTY (plain far2l) | TTY\|X | TTY\|Xi | GUI |
| ---: | --- | --- | --- | --- |
-| **Works:** | in terminal | in terminal | in terminal | in Desktop environment (X11 or Wayland or macOS) via wxWidgets |
+| **Works:** | in **console** and in any **terminal** | in **terminal window** under graphic X11 session | in **terminal window** under graphic X11 session | in **Desktop environment** (X11 or Wayland or macOS) via wxWidgets |
| **Binaries:** | far2l | far2l far2l_ttyx.broker | far2l far2l_ttyx.broker | far2l far2l_gui.so |
| **[Dependencies](#required-dependencies):** | minimal | + libx11 | + libx11, libxi | + wxWidgets, GTK |
| **Keyboard:** | _Typical terminals_: **only essential key combinations**
_KiTTY_ (putty fork), _kitty_ (*nix one), _iTerm2_, _Windows Terminal_, far2l’s VT: **full support** | _Typical terminals_: **most of key combinations under x11**; **only essential key combinations under Wayland**
_KiTTY_ (putty fork), _kitty_ (*nix one), _iTerm2_, _Windows Terminal_, far2l’s VT: **full support** | **All key combinations** |
| **Clipboard access:** | _Typical terminals_: via command line tools like xclip
_kitty_ (*nix one), _iTerm2_: via **OSC52**
_Windows Terminal_: via **OSC52** or via **command line tools under WSL**
_KiTTY_ (putty fork), far2l’s VT: via **far2l extensions** | _Typical terminals_, _kitty_ (*nix one): via **x11 interaction**
_iTerm2_: via **OSC52**
_Windows Terminal_: via **OSC52** or via **command line tools under WSL**
_KiTTY_ (putty fork), far2l’s VT: via **far2l extensions** | _Typical terminals_, _kitty_ (*nix one): via **x11 interaction**
_iTerm2_: via **OSC52**
_Windows Terminal_: via **OSC52** or via **command line tools under WSL**
_KiTTY_ (putty fork), far2l’s VT: via **far2l extensions** | via **wxWidgets API**
via command line tools under WSL |
-| **Typical use case:** | **Servers**, embedded | Run far2l in favorite terminal but with **better UX** | Run far2l in favorite terminal but with **best UX** | **Desktop** |
-| **Mandatory:** | yes | no | no | no |
+| **Typical use case:** | **Servers**, embedded (*wrt, etc) | Run far2l in favorite terminal but with **better UX** | Run far2l in favorite terminal but with **best UX** | **Desktop** |
+| [Debian](https://packages.debian.org/search?keywords=far2l) packages: | _none_ (use `far2l` due to [auto downgrade](#downgrade)) | `far2l` | `far2l` | `far2l-wx` (since _2.6.4_) |
+| [Ubuntu](https://packages.ubuntu.com/search?keywords=far2l) packages: | _none_ (use `far2l` due to [auto downgrade](#downgrade)) | `far2l` | `far2l` | _none_ |
+| Community [PPA](#community_bins): | `far2l` | `far2l-ttyx` | `far2l-ttyx` | `far2l-gui` |
-_Note_: When running far2l automatically downgrade
+_Note_: When running far2l automatically downgrade
if its components are not installed (or system libs are not available):
**GUI** ⇒ **TTY|Xi** ⇒ **TTY|X** ⇒ **TTY**.
To force run only specific backend use in command line:
@@ -67,25 +69,24 @@ OSC 52 in many terminals is implemented only for the copy mode, and paste from t
## Installing, Running
-#### Debian/Ubuntu 23.10+ binaries (with TTY X/Xi backends only)
+#### Debian/Ubuntu binaries from the official repositories
-```sh
-apt-get install far2l
-```
+* **TTY X/Xi** backends only (Debian / Ubuntu 23.10+)
+ ```sh
+ apt install far2l
+ ```
-Only under Ubuntu Desktop 23.10 with Wayland run as
-`far2l --nodetect=xi --ee`
+* **GUI** backend (Debian since far2l _2.6.4_)
+ ```sh
+ apt install far2l-wx
+ ```
-
-**Debian** has far2 in **sid-unstable** / **13 trixie-testing** / **12 bookworm-backports**; **Ubuntu** from **23.10**.
+**Debian** has far2 in **sid-unstable** / **13 trixie-testing** / **12 bookworm-backports**; **Ubuntu** since **23.10**.
Details about versions in the official repositories see in
https://packages.debian.org/search?keywords=far2l or https://packages.ubuntu.com/search?keywords=far2l
-
-Note: now far2l in official repositories Debian/Ubuntu is only TTY|Xi version with extra dependencies of pair X11-libs.
-It may be not convenient for some servers.
-For servers without X and only terminal/ssh access the plain far2l-TTY version is more suitable
-(binaries or portable see in [Community packages & binaries](#community_bins)).
+_Note_: binaries in official repositories may be very outdated,
+actual binaries or portable see in [Community packages & binaries](#community_bins).
#### OSX/MacOS binaries
@@ -309,7 +310,7 @@ You can import the project into your favourite IDE like QtCreator, CodeLite, or
* **Visual Studio Code** (required _CMake Tools extension_): open far2l root directory (by default building in subdirectory `_build`; you can change in `.vscode/settings.json`)
-### Terminals and SSH clients
+## Terminals and SSH clients
Supporting extended far2l keyboard shortcuts and clipboard access
* **kovidgoyal's kitty** (Linux, macOS, *BSD): https://github.com/kovidgoyal/kitty & https://sw.kovidgoyal.net/kitty (TTY|k backend: keys by kovidgoyal's kitty keyboard protocol; turn on OSC 52 in far2l and kitty for clipboard support)
@@ -326,7 +327,7 @@ _Note_: to full transfer extended keyboard shortcuts and the clipboard to/from t
one of the best way to initiate the connection **inside local far2l-GUI**
(see details in build-in help section **UI backends**).
-### Useful 3rd-party extras
+## Useful 3rd-party extras
* A collection of macros for far2l: https://github.com/corporateshark/far2l-macros
* Turbo Vision, TUI framework supporting far2l terminal extensions: https://github.com/magiblot/tvision
@@ -336,14 +337,14 @@ one of the best way to initiate the connection **inside local far2l-GUI**
* **Community wiki & tips** (in Russian; unofficial): https://github.com/akruphi/far2l/wiki
-### Community packages & binaries
+## Community packages & binaries
_They are mainteined by enthusiasts and may be not exact with master: sometimes has extra plugins, sometimes has tweak, etc._
* **Portable** (_with TTY X/Xi backend_) | **AppImage** (_with wx-GUI and some extra plugins_): https://github.com/spvkgn/far2l-portable/releases
* **Ubuntu** and **Mint** from PPA with fresh far2l: https://launchpad.net/~far2l-team/+archive/ubuntu/ppa
* **Fedora** and **CentOS**: https://copr.fedorainfracloud.org/coprs/polter/far2l
- * **OpenSUSE**, **Fedora**, **Ubuntu**: https://download.opensuse.org/repositories/home:/viklequick/
+ * **OpenSUSE**, **Fedora**, **Debian**, **Ubuntu**: https://download.opensuse.org/repositories/home:/viklequick/
* **OpenWrt**: https://github.com/spvkgn/far2l-openwrt
* **Termux**: https://github.com/spvkgn/far2l-termux
* **Flatpak**: https://github.com/spvkgn/far2l-flatpak (access only to part of real filesystem via sandbox)
diff --git a/WinPort/src/Backend/WX/wxMain.cpp b/WinPort/src/Backend/WX/wxMain.cpp
index 3a7dc990c..c977c96f9 100644
--- a/WinPort/src/Backend/WX/wxMain.cpp
+++ b/WinPort/src/Backend/WX/wxMain.cpp
@@ -1304,7 +1304,7 @@ void WinPortPanel::OnKeyDown( wxKeyEvent& event )
// also it didnt cause problems yet
if ( (_key_tracker.Shift() && !event.ShiftDown())
|| ((_key_tracker.LeftControl() || _key_tracker.RightControl()) && !event.ControlDown())) {
- if (_key_tracker.CheckForSuddenModifiersUp()) {
+ if ((!_key_tracker.Alt() || g_wayland) && _key_tracker.CheckForSuddenModifiersUp()) {
_exclusive_hotkeys.Reset();
}
}
@@ -1438,7 +1438,7 @@ void WinPortPanel::OnKeyUp( wxKeyEvent& event )
#endif
wxConsoleInputShim::Enqueue(&ir, 1);
}
- if (_key_tracker.CheckForSuddenModifiersUp()) {
+ if ((!_key_tracker.Alt() || g_wayland) && _key_tracker.CheckForSuddenModifiersUp()) {
_exclusive_hotkeys.Reset();
}
//event.Skip();
diff --git a/WinPort/src/Backend/WinPortMain.cpp b/WinPort/src/Backend/WinPortMain.cpp
index 2816890e2..1bc2662b9 100644
--- a/WinPort/src/Backend/WinPortMain.cpp
+++ b/WinPort/src/Backend/WinPortMain.cpp
@@ -235,22 +235,23 @@ static void ShimSigWinch(int sig)
extern "C" void WinPortHelp()
{
- printf("FAR2L backend-specific options:\n");
- printf("\t--tty - force using TTY backend only (disable GUI/TTY autodetection)\n");
- printf("\t--notty - don't fallback to TTY backend if GUI backend failed\n");
- printf("\t--nodetect or --nodetect=[x|xi][f][w][a][k] - don't detect if TTY backend supports X11/Xi input and clipboard interaction extensions and/or disable detect f=FAR2l terminal extensions, w=win32, a=apple iTerm2, k=kovidgoyal's kitty input modes\n");
- printf("\t--norgb - don't use true (24-bit) colors\n");
- printf("\t--mortal - terminate instead of going to background on getting SIGHUP (default if in Linux TTY)\n");
- printf("\t--immortal - go to background instead of terminating on getting SIGHUP (default if not in Linux TTY)\n");
- printf("\t--x11 - force GUI backend to run on X11\n");
- printf("\t--wayland - force GUI backend to run on Wayland\n");
- printf("\t--ee=N - ESC expiration in msec (default is 100, 0 to disable) to avoid need for double ESC presses (valid only in TTY mode without FAR2L extensions)\n");
- printf("\t--primary-selection - use PRIMARY selection instead of CLIPBOARD X11 selection (only for GUI backend)\n");
- printf("\t--maximize - force maximize window upon launch (only for GUI backend)\n");
- printf("\t--nomaximize - dont maximize window upon launch even if its has saved maximized state (only for GUI backend)\n");
- printf("\t--clipboard=SCRIPT - use external clipboard handler script that implements get/set text clipboard data via its stdin/stdout\n");
- printf(" Backend-specific options also can be set via the FAR2L_ARGS environment variable\n");
- printf(" (for example: export FAR2L_ARGS=\"--tty\" to start far2l in tty mode by default)\n");
+ printf("FAR2L backend-specific options:\n"
+ "\t--tty - force using TTY backend only (disable GUI/TTY autodetection)\n"
+ "\t--notty - don't fallback to TTY backend if GUI backend failed\n"
+ "\t--nodetect or --nodetect=[x|xi][f][w][a][k] - don't detect if TTY backend supports X11/Xi input and clipboard interaction extensions and/or disable detect f=FAR2l terminal extensions, w=win32, a=apple iTerm2, k=kovidgoyal's kitty input modes\n"
+ "\t--norgb - don't use true (24-bit) colors\n"
+ "\t--mortal - terminate instead of going to background on getting SIGHUP (default if in Linux TTY)\n"
+ "\t--immortal - go to background instead of terminating on getting SIGHUP (default if not in Linux TTY)\n"
+ "\t--x11 - force GUI backend to run on X11\n"
+ "\t--wayland - force GUI backend to run on Wayland\n"
+ "\t--ee=N - ESC expiration in msec (default is 100, 0 to disable) to avoid need for double ESC presses (valid only in TTY mode without FAR2L extensions)\n"
+ "\t--primary-selection - use PRIMARY selection instead of CLIPBOARD X11 selection (only for GUI backend)\n"
+ "\t--maximize - force maximize window upon launch (only for GUI backend)\n"
+ "\t--nomaximize - dont maximize window upon launch even if its has saved maximized state (only for GUI backend)\n"
+ "\t--clipboard=SCRIPT - use external clipboard handler script that implements get/set text clipboard data via its stdin/stdout\n"
+ "\n"
+ "All options (except -h and -u) also can be set via the FAR2L_ARGS environment variable\n"
+ " (for example: export FAR2L_ARGS=\"--tty\" to start far2l in tty mode by default)\n");
}
struct ArgOptions
@@ -385,7 +386,7 @@ extern "C" int WinPortMain(const char *full_exe_path, int argc, char **argv, int
}
}
- for (int i = 0; i < argc; ++i) {
+ for (int i = 1; i < argc; ++i) { // from 1 = skip self name here
arg_opts.ParseArg(argv[i], false);
}
@@ -407,6 +408,8 @@ extern "C" int WinPortMain(const char *full_exe_path, int argc, char **argv, int
}
}
+ if (argc>0)
+ arg_opts.filtered_argv.emplace(arg_opts.filtered_argv.begin(), argv[0]); // self name should be always first
if (!arg_opts.filtered_argv.empty()) {
argv = &arg_opts.filtered_argv[0];
}
diff --git a/colorer/configs/base/CHANGELOG.md b/colorer/configs/base/CHANGELOG.md
index a2a2f3523..0741331f0 100644
--- a/colorer/configs/base/CHANGELOG.md
+++ b/colorer/configs/base/CHANGELOG.md
@@ -20,6 +20,8 @@
- [smarty] fixed the work of smarty templates
- [markdown] amend emphasis with underscores
- [markdown] fix trailing spaces in em and strong
+- [smarty] fixed working with nested brackets
+- [smarty] literal block - text only
### Changed
- Simplified catalog.xml.
diff --git a/colorer/configs/base/hrc/inet/smarty.hrc b/colorer/configs/base/hrc/inet/smarty.hrc
index 2ebd08859..b09c2f0ee 100644
--- a/colorer/configs/base/hrc/inet/smarty.hrc
+++ b/colorer/configs/base/hrc/inet/smarty.hrc
@@ -232,7 +232,7 @@
-
+
@@ -292,7 +299,7 @@
- pimpl;
};
-class FileTypeException : public Exception
+class FileTypeException final : public Exception
{
public:
explicit FileTypeException(const UnicodeString& msg) noexcept
diff --git a/colorer/src/Colorer-library/src/colorer/Region.h b/colorer/src/Colorer-library/src/colorer/Region.h
index b011638f7..c6345580b 100644
--- a/colorer/src/Colorer-library/src/colorer/Region.h
+++ b/colorer/src/Colorer-library/src/colorer/Region.h
@@ -1,50 +1,53 @@
#ifndef COLORER_REGION_H
#define COLORER_REGION_H
+#include
#include "colorer/Common.h"
/**
HRC Region implementation.
- Contains information about HRC Region and it attributes:
-
-
name
-
description
-
parent
-
- @ingroup colorer
+ Contains information about HRC Region and it attributes.
*/
class Region
{
public:
/** Full Qualified region name (def:Text for example) */
- [[nodiscard]] virtual const UnicodeString& getName() const
+ [[nodiscard]]
+ virtual const UnicodeString& getName() const
{
- return *name;
+ return name;
}
+
/** Region description */
- [[nodiscard]] virtual const UnicodeString& getDescription() const
+ [[nodiscard]]
+ virtual const UnicodeString& getDescription() const
{
return *description;
}
+
/** Direct region ancestor (parent) */
- [[nodiscard]] virtual const Region* getParent() const
+ [[nodiscard]]
+ virtual const Region* getParent() const
{
return parent;
}
- /** Quick access region id (incrementable) */
- [[nodiscard]] virtual size_t getID() const
+
+ /** Quick access region id (incremental) */
+ [[nodiscard]]
+ virtual size_t getID() const
{
return id;
}
- /** Checks if region has the specified parent in all of it's ancestors.
+
+ /** Checks if region has the specified parent in all of its ancestors.
This method is useful to check if region has specified parent,
and use this information, as region type specification.
For example, def:Comment has def:Syntax parent,
- so, some syntax checking can be made with it's content.
+ so, some syntax checking can be made with its content.
*/
bool hasParent(const Region* region) const
{
- const Region* elem = this;
+ auto elem = this;
while (elem != nullptr) {
if (region == elem) {
return true;
@@ -53,32 +56,32 @@ class Region
}
return false;
}
+
/**
Basic constructor.
Used only by HrcLibrary.
*/
- Region(const UnicodeString& _name, const UnicodeString* _description, const Region* _parent,
- size_t _id)
+ Region(UnicodeString _name, const UnicodeString* _description, const Region* _parent, const size_t _id)
+ : name(std::move(_name)),parent(_parent), id(_id)
{
- name = std::make_unique(_name);
if (_description != nullptr) {
description = std::make_unique(*_description);
}
- parent = _parent;
- id = _id;
}
virtual ~Region() = default;
+
Region(Region&&) = delete;
Region(const Region&) = delete;
Region& operator=(const Region&) = delete;
Region& operator=(Region&&) = delete;
protected:
- /** Internal members */
- uUnicodeString name;
+ UnicodeString name;
uUnicodeString description;
const Region* parent;
+
+ /** unique id of Region */
size_t id;
};
diff --git a/colorer/src/Colorer-library/src/colorer/base/BaseNames.h b/colorer/src/Colorer-library/src/colorer/base/BaseNames.h
index 646b34c32..c993afd8c 100644
--- a/colorer/src/Colorer-library/src/colorer/base/BaseNames.h
+++ b/colorer/src/Colorer-library/src/colorer/base/BaseNames.h
@@ -5,4 +5,6 @@ const char16_t HrdNameDefault[] = u"default\0";
const char16_t HrdClassRgb[] = u"rgb\0";
const char16_t HrdClassText[] = u"text\0";
+inline const auto jar = UnicodeString(u"jar:");
+
#endif // COLORER_BASENAMES_H
diff --git a/colorer/src/Colorer-library/src/colorer/common/Exception.cpp b/colorer/src/Colorer-library/src/colorer/common/Exception.cpp
index b0d07b37d..65c124865 100644
--- a/colorer/src/Colorer-library/src/colorer/common/Exception.cpp
+++ b/colorer/src/Colorer-library/src/colorer/common/Exception.cpp
@@ -1,5 +1,4 @@
#include "colorer/Exception.h"
-#include "colorer/Common.h"
Exception::Exception(const char* msg) noexcept : what_str {msg} {}
diff --git a/colorer/src/Colorer-library/src/colorer/common/Features.h.in b/colorer/src/Colorer-library/src/colorer/common/Features.h.in
index f3a7dc094..16a453a34 100644
--- a/colorer/src/Colorer-library/src/colorer/common/Features.h.in
+++ b/colorer/src/Colorer-library/src/colorer/common/Features.h.in
@@ -3,7 +3,6 @@
#cmakedefine COLORER_USE_DEEPTRACE
-#cmakedefine COLORER_FEATURE_LIBXML
/**
If defined, JAR InputSource is implemented.
*/
diff --git a/colorer/src/Colorer-library/src/colorer/editor/BaseEditor.cpp b/colorer/src/Colorer-library/src/colorer/editor/BaseEditor.cpp
index 469e50d52..9b0656b4a 100644
--- a/colorer/src/Colorer-library/src/colorer/editor/BaseEditor.cpp
+++ b/colorer/src/Colorer-library/src/colorer/editor/BaseEditor.cpp
@@ -218,8 +218,9 @@ void BaseEditor::removeEditorListener(EditorListener* el)
}
}
-PairMatch* BaseEditor::getPairMatch(int lineNo, int linePos)
+PairMatch* BaseEditor::getPairMatch(int lineNo, int linePos, LineRegion** lineRegion)
{
+ *lineRegion = nullptr;
LineRegion* lrStart = getLineRegions(lineNo);
if (lrStart == nullptr) {
return nullptr;
@@ -235,6 +236,7 @@ PairMatch* BaseEditor::getPairMatch(int lineNo, int linePos)
if (pair != nullptr) {
auto* pm = new PairMatch(pair, lineNo, pair->region->hasParent(def_PairStart));
pm->setStart(pair);
+ *lineRegion = lrStart;
return pm;
}
return nullptr;
@@ -250,17 +252,16 @@ void BaseEditor::releasePairMatch(PairMatch* pm)
delete pm;
}
-PairMatch* BaseEditor::searchPair(int lineNo, int pos, int start_line, int end_line){
- int lno;
- PairMatch* pm = getPairMatch(lineNo, pos);
+PairMatch* BaseEditor::searchPair(int lineNo, int pos, int start_line, int end_line)
+{
+ LineRegion* slr = nullptr;
+ PairMatch* pm = getPairMatch(lineNo, pos, &slr);
if (pm == nullptr) {
return nullptr;
}
- lno = pm->sline;
-
+ int lno = pm->sline;
LineRegion* pair = pm->getStartRef();
- LineRegion* slr = getLineRegions(lno);
while (true) {
if (pm->pairBalance > 0) {
do {
@@ -271,6 +272,7 @@ PairMatch* BaseEditor::searchPair(int lineNo, int pos, int start_line, int end_l
return pm;
}
pair = getLineRegions(lno);
+ slr = pair;
}
} while (!pair->region);
}
diff --git a/colorer/src/Colorer-library/src/colorer/editor/BaseEditor.h b/colorer/src/Colorer-library/src/colorer/editor/BaseEditor.h
index 4b8c66d25..d3827b4c9 100644
--- a/colorer/src/Colorer-library/src/colorer/editor/BaseEditor.h
+++ b/colorer/src/Colorer-library/src/colorer/editor/BaseEditor.h
@@ -282,7 +282,7 @@ class BaseEditor : public RegionHandler
* Searches for the paired token and creates PairMatch
* object with valid initial properties filled.
*/
- PairMatch* getPairMatch(int lineNo, int pos);
+ PairMatch* getPairMatch(int lineNo, int pos, LineRegion** line_region);
};
#endif
diff --git a/colorer/src/Colorer-library/src/colorer/handlers/RegionDefine.h b/colorer/src/Colorer-library/src/colorer/handlers/RegionDefine.h
index bd398507f..aca223883 100644
--- a/colorer/src/Colorer-library/src/colorer/handlers/RegionDefine.h
+++ b/colorer/src/Colorer-library/src/colorer/handlers/RegionDefine.h
@@ -1,12 +1,10 @@
-#ifndef _COLORER_REGIONDEFINE_H_
-#define _COLORER_REGIONDEFINE_H_
+#ifndef COLORER_REGIONDEFINE_H
+#define COLORER_REGIONDEFINE_H
/**
* Object contains information about region mapping into real colors or other properties.
* This class represents abstract mapping information and declares required methods
- * to be implemented in it's subclasses.
- *
- * @ingroup colorer_handlers
+ * to be implemented in its subclasses.
*/
class RegionDefine
{
@@ -14,8 +12,6 @@ class RegionDefine
/**
* Enumeration to distinguish different types of region mapping
* Do not use RTTI because of compatibility problems
- *
- * @ingroup colorer_handlers
*/
enum class RegionDefineType {
UNKNOWN_REGION = 0,
@@ -26,12 +22,12 @@ class RegionDefine
/**
* Class type identifier
*/
- RegionDefineType type = RegionDefineType::UNKNOWN_REGION;
+ RegionDefineType type {RegionDefineType::UNKNOWN_REGION};
/**
- * Completes region define values with it's parent values.
+ * Completes region define values with its parent values.
* If region define has some incomplete information (fe some
- * transparent fields), this methods completes them with
+ * transparent fields), these methods completes them with
* passed parent's values.
*/
virtual void assignParent(const RegionDefine* parent) = 0;
@@ -56,14 +52,16 @@ class RegionDefine
}
RegionDefine(const RegionDefine& rd) = delete;
+
/**
* Clones current region and creates it's duplicate.
* To be implemented in subclasses.
*/
- [[nodiscard]] virtual RegionDefine* clone() const = 0;
+ [[nodiscard]]
+ virtual RegionDefine* clone() const = 0;
- /** Default Destructor */
virtual ~RegionDefine() = default;
+
RegionDefine(RegionDefine&&) = delete;
RegionDefine& operator=(RegionDefine&&) = delete;
diff --git a/colorer/src/Colorer-library/src/colorer/handlers/RegionMapper.cpp b/colorer/src/Colorer-library/src/colorer/handlers/RegionMapper.cpp
index 61c749e61..48eaa7708 100644
--- a/colorer/src/Colorer-library/src/colorer/handlers/RegionMapper.cpp
+++ b/colorer/src/Colorer-library/src/colorer/handlers/RegionMapper.cpp
@@ -2,49 +2,49 @@
std::vector RegionMapper::enumerateRegionDefines() const
{
- std::vector r;
- r.reserve(regionDefines.size());
+ std::vector result(regionDefines.size());
for (const auto& regionDefine : regionDefines) {
- r.push_back(regionDefine.second.get());
+ result.push_back(regionDefine.second.get());
}
- return r;
+ return result;
}
const RegionDefine* RegionMapper::getRegionDefine(const Region* region) const
{
- if (!region)
+ if (!region) {
return nullptr;
+ }
// search in cache
- const RegionDefine* rd = nullptr;
+ const RegionDefine* result = nullptr;
if (region->getID() < regionDefinesCache.size()) {
- rd = regionDefinesCache.at(region->getID());
- }
- // RegionDefine maybe not yet in cache
- if (rd != nullptr) {
- return rd;
+ result = regionDefinesCache.at(region->getID());
+ // RegionDefine maybe not yet in cache
+ if (result != nullptr) {
+ return result;
+ }
}
if (regionDefinesCache.size() < region->getID() + 1) {
regionDefinesCache.resize(region->getID() * 2);
}
- auto rd_new = regionDefines.find(region->getName());
+ const auto rd_new = regionDefines.find(region->getName());
if (rd_new != regionDefines.end()) {
regionDefinesCache.at(region->getID()) = rd_new->second.get();
return rd_new->second.get();
}
if (region->getParent()) {
- rd = getRegionDefine(region->getParent());
- regionDefinesCache.at(region->getID()) = rd;
+ result = getRegionDefine(region->getParent());
+ regionDefinesCache.at(region->getID()) = result;
}
- return rd;
+ return result;
}
const RegionDefine* RegionMapper::getRegionDefine(const UnicodeString& name) const
{
- auto tp = regionDefines.find(name);
+ const auto tp = regionDefines.find(name);
if (tp != regionDefines.end()) {
return tp->second.get();
}
diff --git a/colorer/src/Colorer-library/src/colorer/handlers/RegionMapper.h b/colorer/src/Colorer-library/src/colorer/handlers/RegionMapper.h
index 2f0bb8d06..348aac605 100644
--- a/colorer/src/Colorer-library/src/colorer/handlers/RegionMapper.h
+++ b/colorer/src/Colorer-library/src/colorer/handlers/RegionMapper.h
@@ -1,5 +1,5 @@
-#ifndef _COLORER_REGIONMAPPERIMPL_H_
-#define _COLORER_REGIONMAPPERIMPL_H_
+#ifndef COLORER_REGIONMAPPER_H
+#define COLORER_REGIONMAPPER_H
#include
#include
@@ -9,10 +9,8 @@
#include "colorer/xml/XmlInputSource.h"
/** Abstract RegionMapper.
- Stores all region mappings in hashtable and sequental vector for Region -> RegionDefine
- mappings.
- @ingroup colorer_handlers
-*/
+ * Stores all region mappings in hashtable and sequential vector for Region -> RegionDefine mappings.
+ */
class RegionMapper
{
public:
@@ -24,33 +22,32 @@ class RegionMapper
virtual void loadRegionMappings(XmlInputSource& is) = 0;
/** Saves all loaded region defines into @c writer.
- Note, that result document would not be equal
- to input one, because there could be multiple input
- documents.
- */
+ * Note, that result document would not be equal
+ * to input one, because there could be multiple input documents.
+ */
virtual void saveRegionMappings(Writer* writer) const = 0;
/** Changes specified region definition to @c rdnew
- @param region Region full qualified name.
- @param rdnew New region definition to replace old one
- */
+ * @param region Region full qualified name.
+ * @param rdnew New region definition to replace old one
+ */
virtual void setRegionDefine(const UnicodeString& region, const RegionDefine* rdnew) = 0;
/** Enumerates all loaded region defines.
- @return RegionDefine with specified internal index, or null if @c idx is too big
- */
+ * @return std::vector of RegionDefine
+ */
std::vector enumerateRegionDefines() const;
/**
* Searches mapped region define value.
- * @return Region define, associated with passed @c region
- * parameter, or null if nothing found
+ * @return Region define, associated with passed @c region parameter, or null if nothing found
*/
const RegionDefine* getRegionDefine(const Region* region) const;
/**
- * Searches mapped region define value with qualified name @c name.
+ * Searches mapped region define value with qualified name, or null if nothing found
+ * @param name
*/
const RegionDefine* getRegionDefine(const UnicodeString& name) const;
diff --git a/colorer/src/Colorer-library/src/colorer/handlers/StyledHRDMapper.cpp b/colorer/src/Colorer-library/src/colorer/handlers/StyledHRDMapper.cpp
index 9a0ca25de..4e9ca5861 100644
--- a/colorer/src/Colorer-library/src/colorer/handlers/StyledHRDMapper.cpp
+++ b/colorer/src/Colorer-library/src/colorer/handlers/StyledHRDMapper.cpp
@@ -3,11 +3,6 @@
#include "colorer/base/XmlTagDefs.h"
#include "colorer/xml/XmlReader.h"
-StyledHRDMapper::~StyledHRDMapper()
-{
- regionDefines.clear();
-}
-
void StyledHRDMapper::loadRegionMappings(XmlInputSource& is)
{
XmlReader xml(is);
@@ -60,18 +55,15 @@ void StyledHRDMapper::loadRegionMappings(XmlInputSource& is)
}
}
-/** Writes all currently loaded region definitions into
- XML file. Note, that this method writes all loaded
- defines from all loaded HRD files.
-*/
void StyledHRDMapper::saveRegionMappings(Writer* writer) const
{
- writer->write("\n");
+ writer->write(u"\n");
+
for (const auto& regionDefine : regionDefines) {
const StyledRegion* rdef = StyledRegion::cast(regionDefine.second.get());
- char temporary[256];
- constexpr auto size_temporary = std::size(temporary);
- writer->write(" write(u"\tisForeSet) {
snprintf(temporary, size_temporary, " fore=\"#%06x\"", rdef->fore);
writer->write(temporary);
@@ -84,23 +76,24 @@ void StyledHRDMapper::saveRegionMappings(Writer* writer) const
snprintf(temporary, size_temporary, " style=\"%u\"", rdef->style);
writer->write(temporary);
}
- writer->write("/>\n");
+ writer->write(u"/>\n");
}
- writer->write("\n\n");
+
+ writer->write(u"\n");
}
-/** Adds or replaces region definition */
-void StyledHRDMapper::setRegionDefine(const UnicodeString& name, const RegionDefine* rd)
+void StyledHRDMapper::setRegionDefine(const UnicodeString& region_name, const RegionDefine* rd)
{
- if (!rd)
+ if (!rd) {
return;
+ }
const StyledRegion* new_region = StyledRegion::cast(rd);
auto rd_new = std::make_unique(*new_region);
- auto rd_old_it = regionDefines.find(name);
+ const auto rd_old_it = regionDefines.find(region_name);
if (rd_old_it == regionDefines.end()) {
- regionDefines.emplace(name, std::move(rd_new));
+ regionDefines.emplace(region_name, std::move(rd_new));
}
else {
rd_old_it->second = std::move(rd_new);
diff --git a/colorer/src/Colorer-library/src/colorer/handlers/StyledHRDMapper.h b/colorer/src/Colorer-library/src/colorer/handlers/StyledHRDMapper.h
index fa5ae2892..6990a0a83 100644
--- a/colorer/src/Colorer-library/src/colorer/handlers/StyledHRDMapper.h
+++ b/colorer/src/Colorer-library/src/colorer/handlers/StyledHRDMapper.h
@@ -1,5 +1,5 @@
-#ifndef _COLORER_STYLEDHRDMAPPER_H_
-#define _COLORER_STYLEDHRDMAPPER_H_
+#ifndef COLORER_STYLEDHRDMAPPER_H
+#define COLORER_STYLEDHRDMAPPER_H
#include "colorer/handlers/RegionMapper.h"
#include "colorer/handlers/StyledRegion.h"
@@ -7,31 +7,31 @@
/** HRD files reader.
HRD Files format contains mappings of HRC syntax regions into
real coloring information. Each record in HRD (RegionDefine) can contain
- information about region color (@c fore, @c back) and about it's style
+ information about region color (@c fore, @c back) and about its style
(@c style).
-
- @ingroup colorer_handlers
*/
class StyledHRDMapper : public RegionMapper
{
public:
StyledHRDMapper() = default;
- ~StyledHRDMapper() override;
+ ~StyledHRDMapper() override = default;
- /** Loads region defines from @c is InputSource
- */
+ /** Loads region defines from @c is InputSource */
void loadRegionMappings(XmlInputSource& is) override;
+
/** Saves all loaded region defines into @c writer.
- Note, that result document would not be equal
- to input one, because there could be multiple input
- documents.
- */
+ * Note, that result document would not be equal to input one,
+ * because there could be multiple input documents.
+ * Note, that this method writes all loaded
+ * defines from all loaded HRD files.
+ */
void saveRegionMappings(Writer* writer) const override;
+
/** Changes specified region definition to @c rdnew
- @param region Region full qualified name.
- @param rdnew New region definition to replace old one
- */
- void setRegionDefine(const UnicodeString& region, const RegionDefine* rdnew) override;
+ * @param region Region full qualified name.
+ * @param rdnew New region definition to replace old one
+ */
+ void setRegionDefine(const UnicodeString& region_name, const RegionDefine* rdnew) override;
};
#endif
diff --git a/colorer/src/Colorer-library/src/colorer/handlers/StyledRegion.cpp b/colorer/src/Colorer-library/src/colorer/handlers/StyledRegion.cpp
index 544330228..6bf9d306f 100644
--- a/colorer/src/Colorer-library/src/colorer/handlers/StyledRegion.cpp
+++ b/colorer/src/Colorer-library/src/colorer/handlers/StyledRegion.cpp
@@ -1,9 +1,10 @@
-#include "colorer/Exception.h"
#include "colorer/handlers/StyledRegion.h"
+#include "colorer/Exception.h"
-StyledRegion::StyledRegion(bool _isForeSet, bool _isBackSet, unsigned int _fore, unsigned int _back, unsigned int _style)
+StyledRegion::StyledRegion(const bool _isForeSet, const bool _isBackSet, const unsigned int _fore,
+ const unsigned int _back, const unsigned int _style)
{
- type = RegionDefine::RegionDefineType::STYLED_REGION;
+ type = RegionDefineType::STYLED_REGION;
isForeSet = _isForeSet;
isBackSet = _isBackSet;
fore = _fore;
@@ -13,12 +14,7 @@ StyledRegion::StyledRegion(bool _isForeSet, bool _isBackSet, unsigned int _fore,
StyledRegion::StyledRegion()
{
- type = RegionDefine::RegionDefineType::STYLED_REGION;
- isForeSet = false;
- isBackSet = false;
- fore = 0;
- back = 0;
- style = RD_NONE;
+ type = RegionDefineType::STYLED_REGION;
}
StyledRegion::StyledRegion(const StyledRegion& rd) : RegionDefine()
@@ -28,27 +24,32 @@ StyledRegion::StyledRegion(const StyledRegion& rd) : RegionDefine()
StyledRegion& StyledRegion::operator=(const StyledRegion& rd)
{
- if (this == &rd)
+ if (this == &rd) {
return *this;
+ }
+
setValues(&rd);
return *this;
}
const StyledRegion* StyledRegion::cast(const RegionDefine* rd)
{
- if (rd == nullptr)
+ if (rd == nullptr) {
return nullptr;
- if (rd->type != RegionDefine::RegionDefineType::STYLED_REGION)
+ }
+ if (rd->type != RegionDefineType::STYLED_REGION) {
throw Exception("Bad type cast exception into StyledRegion");
- const auto* sr = (const StyledRegion*) (rd);
+ }
+ const auto* sr = dynamic_cast(rd);
return sr;
}
void StyledRegion::assignParent(const RegionDefine* _parent)
{
- const StyledRegion* parent = StyledRegion::cast(_parent);
- if (parent == nullptr)
+ const StyledRegion* parent = cast(_parent);
+ if (parent == nullptr) {
return;
+ }
if (!isForeSet) {
fore = parent->fore;
isForeSet = parent->isForeSet;
@@ -62,7 +63,7 @@ void StyledRegion::assignParent(const RegionDefine* _parent)
void StyledRegion::setValues(const RegionDefine* _rd)
{
- const StyledRegion* rd = StyledRegion::cast(_rd);
+ const StyledRegion* rd = cast(_rd);
if (rd) {
fore = rd->fore;
isForeSet = rd->isForeSet;
diff --git a/colorer/src/Colorer-library/src/colorer/handlers/StyledRegion.h b/colorer/src/Colorer-library/src/colorer/handlers/StyledRegion.h
index 9cf57f2aa..95faae21f 100644
--- a/colorer/src/Colorer-library/src/colorer/handlers/StyledRegion.h
+++ b/colorer/src/Colorer-library/src/colorer/handlers/StyledRegion.h
@@ -1,13 +1,11 @@
-#ifndef _COLORER_STYLEDREGION_H_
-#define _COLORER_STYLEDREGION_H_
+#ifndef COLORER_STYLEDREGION_H
+#define COLORER_STYLEDREGION_H
#include "colorer/handlers/RegionDefine.h"
/**
* Contains information about region mapping into real colors.
- * These mappings are stored in HRD files and processed
- * by StyledHRDMapper class.
- * @ingroup colorer_handlers
+ * These mappings are stored in HRD files and processed by StyledHRDMapper class.
*/
class StyledRegion : public RegionDefine
{
@@ -15,45 +13,49 @@ class StyledRegion : public RegionDefine
enum Style { RD_NONE = 0, RD_BOLD = 1, RD_ITALIC = 2, RD_UNDERLINE = 4, RD_STRIKEOUT = 8 };
/** Is foreground value assigned? */
- bool isForeSet;
+ bool isForeSet {false};
/** Is background value assigned? */
- bool isBackSet;
+ bool isBackSet {false};
/** Foreground color of region */
- unsigned int fore;
+ unsigned int fore {0};
/** Background color of region */
- unsigned int back;
+ unsigned int back {0};
/** Bit mask of region's style (bold, italic, underline) */
- unsigned int style;
+ unsigned int style {RD_NONE};
/** Common constructor */
- StyledRegion(bool _isForeSet, bool _isBackSet, unsigned int _fore, unsigned int _back, unsigned int _style);
+ StyledRegion(bool isForeSet, bool isBackSet, unsigned int fore, unsigned int back, unsigned int style);
/** Empty constructor */
StyledRegion();
/** Copy constructor.
- Clones all values including region reference. */
+ * Clones all values including region reference.
+ */
StyledRegion(const StyledRegion& rd);
-
StyledRegion& operator=(const StyledRegion& rd);
~StyledRegion() override = default;
- /** Static method, used to cast RegionDefine class into
- StyledRegion class.
- @throw Exception If casing is not available.
- */
+ /** Static method, used to cast RegionDefine class into StyledRegion class.
+ * @throw Exception If casing is not available.
+ */
static const StyledRegion* cast(const RegionDefine* rd);
- /** Completes region define with it's parent values.
- The values only replaced, are these, which are empty
- in this region define. Style is replaced using OR operation.
- */
- void assignParent(const RegionDefine* _parent) override;
+ /** Completes region define with its parent values.
+ * The values only replaced, are these, which are empty
+ * in this region define. Style is replaced using OR operation.
+ */
+ void assignParent(const RegionDefine* parent) override;
- void setValues(const RegionDefine* _rd) override;
+ /**
+ * Direct assign of all passed @c rd values.
+ * Do not assign region reference.
+ */
+ void setValues(const RegionDefine* region_define) override;
- [[nodiscard]] RegionDefine* clone() const override;
+ [[nodiscard]]
+ RegionDefine* clone() const override;
};
#endif
diff --git a/colorer/src/Colorer-library/src/colorer/handlers/TextHRDMapper.cpp b/colorer/src/Colorer-library/src/colorer/handlers/TextHRDMapper.cpp
index 0dcc5f894..f5b91191e 100644
--- a/colorer/src/Colorer-library/src/colorer/handlers/TextHRDMapper.cpp
+++ b/colorer/src/Colorer-library/src/colorer/handlers/TextHRDMapper.cpp
@@ -3,11 +3,6 @@
#include "colorer/base/XmlTagDefs.h"
#include "colorer/xml/XmlReader.h"
-TextHRDMapper::~TextHRDMapper()
-{
- regionDefines.clear();
-}
-
void TextHRDMapper::loadRegionMappings(XmlInputSource& is)
{
XmlReader xml(is);
@@ -33,26 +28,11 @@ void TextHRDMapper::loadRegionMappings(XmlInputSource& is)
COLORER_LOG_WARN("Duplicate region name '%' in file '%'. Previous value replaced.", name, is.getPath());
regionDefines.erase(tp);
}
- std::shared_ptr stext;
- std::shared_ptr etext;
- std::shared_ptr sback;
- std::shared_ptr eback;
- const auto& sval = node.getAttrValue(hrdAssignAttrSText);
- if (!sval.isEmpty()) {
- stext = std::make_unique(sval);
- }
- const auto& sval2 = node.getAttrValue(hrdAssignAttrEText);
- if (!sval2.isEmpty()) {
- etext = std::make_unique(sval2);
- }
- const auto& sval3 = node.getAttrValue(hrdAssignAttrSBack);
- if (!sval3.isEmpty()) {
- sback = std::make_unique(sval3);
- }
- const auto& sval4 = node.getAttrValue(hrdAssignAttrEBack);
- if (!sval4.isEmpty()) {
- eback = std::make_unique(sval4);
- }
+
+ const auto& stext = node.getAttrValue(hrdAssignAttrSText);
+ const auto& etext = node.getAttrValue(hrdAssignAttrEText);
+ const auto& sback = node.getAttrValue(hrdAssignAttrSBack);
+ const auto& eback = node.getAttrValue(hrdAssignAttrEBack);
auto rdef = std::make_unique(stext, etext, sback, eback);
regionDefines.emplace(name, std::move(rdef));
@@ -62,28 +42,30 @@ void TextHRDMapper::loadRegionMappings(XmlInputSource& is)
void TextHRDMapper::saveRegionMappings(Writer* writer) const
{
- writer->write("\n");
+ writer->write(u"\n");
+
for (const auto& regionDefine : regionDefines) {
const TextRegion* rdef = TextRegion::cast(regionDefine.second.get());
- writer->write(" write(u"\tstart_text != nullptr) {
- writer->write(" start_text='" + *rdef->start_text + "'");
+ writer->write(u" start_text='" + *rdef->start_text + u"'");
}
if (rdef->end_text != nullptr) {
- writer->write(" end_text='" + *rdef->end_text + "'");
+ writer->write(u" end_text='" + *rdef->end_text + u"'");
}
if (rdef->start_back != nullptr) {
- writer->write(" start_back='" + *rdef->start_back + "'");
+ writer->write(u" start_back='" + *rdef->start_back + u"'");
}
if (rdef->end_back != nullptr) {
- writer->write(" end_back='" + *rdef->end_back + "'");
+ writer->write(u" end_back='" + *rdef->end_back + u"'");
}
- writer->write("/>\n");
+ writer->write(u"/>\n");
}
- writer->write("\n\n");
+
+ writer->write(u"\n");
}
-void TextHRDMapper::setRegionDefine(const UnicodeString& name, const RegionDefine* rd)
+void TextHRDMapper::setRegionDefine(const UnicodeString& region_name, const RegionDefine* rd)
{
if (!rd)
return;
@@ -91,9 +73,9 @@ void TextHRDMapper::setRegionDefine(const UnicodeString& name, const RegionDefin
const TextRegion* rd_new = TextRegion::cast(rd);
auto new_region = std::make_unique(*rd_new);
- auto rd_old_it = regionDefines.find(name);
+ const auto rd_old_it = regionDefines.find(region_name);
if (rd_old_it == regionDefines.end()) {
- regionDefines.emplace(name, std::move(new_region));
+ regionDefines.emplace(region_name, std::move(new_region));
}
else {
rd_old_it->second = std::move(new_region);
diff --git a/colorer/src/Colorer-library/src/colorer/handlers/TextHRDMapper.h b/colorer/src/Colorer-library/src/colorer/handlers/TextHRDMapper.h
index 5d54f9ff6..15f61d204 100644
--- a/colorer/src/Colorer-library/src/colorer/handlers/TextHRDMapper.h
+++ b/colorer/src/Colorer-library/src/colorer/handlers/TextHRDMapper.h
@@ -1,5 +1,5 @@
-#ifndef _COLORER_TEXTHRDMAPPER_H_
-#define _COLORER_TEXTHRDMAPPER_H_
+#ifndef COLORER_TEXTHRDMAPPER_H
+#define COLORER_TEXTHRDMAPPER_H
#include "colorer/handlers/RegionMapper.h"
#include "colorer/handlers/TextRegion.h"
@@ -9,14 +9,12 @@
text indention information.
For example, HTML indention (@c stext, @c sback, @c etext, @c eback)
allows to create colorized HTML code.
-
- @ingroup colorer_handlers
*/
class TextHRDMapper : public RegionMapper
{
public:
TextHRDMapper() = default;
- ~TextHRDMapper() override;
+ ~TextHRDMapper() override = default;
/** Loads region definitions from HRD file.
* Multiple files could be loaded.
@@ -36,10 +34,10 @@ class TextHRDMapper : public RegionMapper
/**
* Changes specified region definition to @c rdnew
- * @param region Region full qualified name.
+ * @param region_name Region full qualified name.
* @param rdnew New region definition to replace old one
*/
- void setRegionDefine(const UnicodeString& region, const RegionDefine* rdnew) override;
+ void setRegionDefine(const UnicodeString& region_name, const RegionDefine* rdnew) override;
};
#endif
diff --git a/colorer/src/Colorer-library/src/colorer/handlers/TextRegion.cpp b/colorer/src/Colorer-library/src/colorer/handlers/TextRegion.cpp
index a1f163795..65d52384f 100644
--- a/colorer/src/Colorer-library/src/colorer/handlers/TextRegion.cpp
+++ b/colorer/src/Colorer-library/src/colorer/handlers/TextRegion.cpp
@@ -1,19 +1,28 @@
-#include "colorer/Exception.h"
#include "colorer/handlers/TextRegion.h"
+#include "colorer/Exception.h"
-TextRegion::TextRegion(std::shared_ptr& _start_text, std::shared_ptr& _end_text,
- std::shared_ptr& _start_back, std::shared_ptr& _end_back)
+TextRegion::TextRegion(const UnicodeString& _start_text, const UnicodeString& _end_text,
+ const UnicodeString& _start_back, const UnicodeString& _end_back)
{
- start_text = std::move(_start_text);
- end_text = std::move(_end_text);
- start_back = std::move(_start_back);
- end_back = std::move(_end_back);
- type = RegionDefine::RegionDefineType::TEXT_REGION;
+ type = RegionDefineType::TEXT_REGION;
+
+ if (!_start_text.isEmpty()) {
+ start_text = std::make_shared(_start_text);
+ }
+ if (!_end_text.isEmpty()) {
+ end_text = std::make_shared(_end_text);
+ }
+ if (!_start_back.isEmpty()) {
+ start_back = std::make_shared(_start_back);
+ }
+ if (!_end_back.isEmpty()) {
+ end_back = std::make_shared(_end_back);
+ }
}
TextRegion::TextRegion()
{
- type = RegionDefine::RegionDefineType::TEXT_REGION;
+ type = RegionDefineType::TEXT_REGION;
}
TextRegion::TextRegion(const TextRegion& rd) : RegionDefine()
@@ -23,28 +32,32 @@ TextRegion::TextRegion(const TextRegion& rd) : RegionDefine()
TextRegion& TextRegion::operator=(const TextRegion& rd)
{
- if (this == &rd)
+ if (this == &rd) {
return *this;
+ }
+
setValues(&rd);
return *this;
}
const TextRegion* TextRegion::cast(const RegionDefine* rd)
{
- if (rd == nullptr)
+ if (rd == nullptr) {
return nullptr;
- if (rd->type != RegionDefine::RegionDefineType::TEXT_REGION) {
+ }
+ if (rd->type != RegionDefineType::TEXT_REGION) {
throw Exception("Bad type cast exception into TextRegion");
}
- const auto* tr = (const TextRegion*) (rd);
+ const auto* tr = dynamic_cast(rd);
return tr;
}
void TextRegion::assignParent(const RegionDefine* _parent)
{
- const TextRegion* parent = TextRegion::cast(_parent);
- if (parent == nullptr)
+ const TextRegion* parent = cast(_parent);
+ if (parent == nullptr) {
return;
+ }
if (start_text == nullptr || end_text == nullptr) {
start_text = parent->start_text;
end_text = parent->end_text;
@@ -57,7 +70,7 @@ void TextRegion::assignParent(const RegionDefine* _parent)
void TextRegion::setValues(const RegionDefine* _rd)
{
- const TextRegion* rd = TextRegion::cast(_rd);
+ const TextRegion* rd = cast(_rd);
if (rd) {
start_text = rd->start_text;
end_text = rd->end_text;
diff --git a/colorer/src/Colorer-library/src/colorer/handlers/TextRegion.h b/colorer/src/Colorer-library/src/colorer/handlers/TextRegion.h
index bf8f0311c..abb8aedcb 100644
--- a/colorer/src/Colorer-library/src/colorer/handlers/TextRegion.h
+++ b/colorer/src/Colorer-library/src/colorer/handlers/TextRegion.h
@@ -1,13 +1,12 @@
-#ifndef _COLORER_TEXTREGION_H_
-#define _COLORER_TEXTREGION_H_
+#ifndef COLORER_TEXTREGION_H
+#define COLORER_TEXTREGION_H
+#include "colorer/Common.h"
#include "colorer/handlers/RegionDefine.h"
-#include
/**
* Contains information about region mapping into textual prefix/suffix.
* These mappings are stored in HRD files.
- * @ingroup colorer_handlers
*/
class TextRegion : public RegionDefine
{
@@ -21,11 +20,11 @@ class TextRegion : public RegionDefine
std::shared_ptr start_back;
std::shared_ptr end_back;
- /**
- * Initial constructor
- */
- TextRegion(std::shared_ptr& _start_text, std::shared_ptr& _end_text,
- std::shared_ptr& _start_back, std::shared_ptr& _end_back);
+ /** Common constructor */
+ TextRegion(const UnicodeString& start_text, const UnicodeString& end_text, const UnicodeString& start_back,
+ const UnicodeString& end_back);
+
+ /** Empty constructor */
TextRegion();
/**
@@ -44,17 +43,19 @@ class TextRegion : public RegionDefine
static const TextRegion* cast(const RegionDefine* rd);
/**
- * Assigns region define with it's parent values.
+ * Assigns region define with its parent values.
* All fields are to be replaced, if they are null-ed.
*/
- void assignParent(const RegionDefine* _parent) override;
+ void assignParent(const RegionDefine* parent) override;
+
/**
* Direct assign of all passed @c rd values.
* Do not assign region reference.
*/
- void setValues(const RegionDefine* _rd) override;
+ void setValues(const RegionDefine* region_define) override;
- [[nodiscard]] RegionDefine* clone() const override;
+ [[nodiscard]]
+ RegionDefine* clone() const override;
};
#endif
diff --git a/colorer/src/Colorer-library/src/colorer/parsers/CatalogParser.cpp b/colorer/src/Colorer-library/src/colorer/parsers/CatalogParser.cpp
index f3bdce869..d6fb22330 100644
--- a/colorer/src/Colorer-library/src/colorer/parsers/CatalogParser.cpp
+++ b/colorer/src/Colorer-library/src/colorer/parsers/CatalogParser.cpp
@@ -9,7 +9,7 @@ void CatalogParser::parse(const UnicodeString* path)
hrc_locations.clear();
hrd_nodes.clear();
- XmlInputSource catalogXIS(*path);
+ const XmlInputSource catalogXIS(*path);
XmlReader xml(catalogXIS);
if (!xml.parse()) {
throw CatalogParserException(*path + UnicodeString(" parse error"));
@@ -94,7 +94,7 @@ std::unique_ptr CatalogParser::parseHRDSetsChild(const XMLNode& elem)
if (!attr_value.isEmpty()) {
hrd_node->hrd_location.emplace_back(attr_value);
COLORER_LOG_DEBUG("add hrd location '%' for %:%", hrd_node->hrd_location.back(), hrd_node->hrd_class,
- hrd_node->hrd_name);
+ hrd_node->hrd_name);
}
else {
COLORER_LOG_WARN("found hrd with empty location. skip it location.");
diff --git a/colorer/src/Colorer-library/src/colorer/parsers/CatalogParser.h b/colorer/src/Colorer-library/src/colorer/parsers/CatalogParser.h
index 3f3c93ab9..3b13f12da 100644
--- a/colorer/src/Colorer-library/src/colorer/parsers/CatalogParser.h
+++ b/colorer/src/Colorer-library/src/colorer/parsers/CatalogParser.h
@@ -31,7 +31,7 @@ class CatalogParser
void parseHrdSetsBlock(const XMLNode& elem);
};
-class CatalogParserException : public Exception
+class CatalogParserException final : public Exception
{
public:
explicit CatalogParserException(const UnicodeString& msg) noexcept : Exception("[CatalogParserException] " + msg) {}
diff --git a/colorer/src/Colorer-library/src/colorer/parsers/FileType.cpp b/colorer/src/Colorer-library/src/colorer/parsers/FileType.cpp
index 75a95ecae..074d6251b 100644
--- a/colorer/src/Colorer-library/src/colorer/parsers/FileType.cpp
+++ b/colorer/src/Colorer-library/src/colorer/parsers/FileType.cpp
@@ -47,17 +47,17 @@ const UnicodeString* FileType::getParamDefaultValue(const UnicodeString& name) c
return pimpl->getParamDefaultValue(name);
}
-int FileType::getParamValueInt(const UnicodeString& name, int def_value) const
+int FileType::getParamValueInt(const UnicodeString& name, const int def_value) const
{
return pimpl->getParamValueInt(name, def_value);
}
-void FileType::addParam(const UnicodeString* name, const UnicodeString* value)
+void FileType::addParam(const UnicodeString& name, const UnicodeString* value)
{
- if (name == nullptr || value == nullptr) {
- throw FileTypeException("Parameter must have not empty name and value");
+ if (value == nullptr) {
+ throw FileTypeException("Parameter must have not empty value");
}
- pimpl->addParam(*name, *value);
+ pimpl->addParam(name, *value);
}
void FileType::addParam(const UnicodeString& name, const UnicodeString& value)
@@ -70,19 +70,19 @@ size_t FileType::getParamCount() const
return pimpl->getParamCount();
}
-const UnicodeString* FileType::getParamUserValue(const UnicodeString& name_) const
+const UnicodeString* FileType::getParamUserValue(const UnicodeString& name) const
{
- return pimpl->getParamUserValue(name_);
+ return pimpl->getParamUserValue(name);
}
-void FileType::setParamDescription(const UnicodeString& name_, const UnicodeString* value)
+void FileType::setParamDescription(const UnicodeString& name, const UnicodeString* value)
{
- pimpl->setParamDescription(name_, value);
+ pimpl->setParamDescription(name, value);
}
-void FileType::setParamDefaultValue(const UnicodeString& name_, const UnicodeString* value)
+void FileType::setParamDefaultValue(const UnicodeString& name, const UnicodeString* value)
{
- pimpl->setParamDefaultValue(name_, value);
+ pimpl->setParamDefaultValue(name, value);
}
void FileType::setParamValue(const UnicodeString& name, const UnicodeString* value)
@@ -90,17 +90,17 @@ void FileType::setParamValue(const UnicodeString& name, const UnicodeString* val
pimpl->setParamValue(name, value);
}
-void FileType::setName(const UnicodeString* name)
+void FileType::setName(const UnicodeString& name)
{
pimpl->setName(name);
}
-void FileType::setGroup(const UnicodeString* group)
+void FileType::setGroup(const UnicodeString& group)
{
pimpl->setGroup(group);
}
-void FileType::setDescription(const UnicodeString* description)
+void FileType::setDescription(const UnicodeString& description)
{
pimpl->setDescription(description);
}
diff --git a/colorer/src/Colorer-library/src/colorer/parsers/FileTypeChooser.cpp b/colorer/src/Colorer-library/src/colorer/parsers/FileTypeChooser.cpp
index e7ab09222..47ab2958c 100644
--- a/colorer/src/Colorer-library/src/colorer/parsers/FileTypeChooser.cpp
+++ b/colorer/src/Colorer-library/src/colorer/parsers/FileTypeChooser.cpp
@@ -1,6 +1,6 @@
#include "colorer/parsers/FileTypeChooser.h"
-FileTypeChooser::FileTypeChooser(ChooserType type, double priority, CRegExp* re)
+FileTypeChooser::FileTypeChooser(const ChooserType type, const double priority, CRegExp* re)
: m_type {type}, m_priority {priority}, m_reg_matcher {re}
{
}
@@ -23,4 +23,13 @@ double FileTypeChooser::getPriority() const
CRegExp* FileTypeChooser::getRE() const
{
return m_reg_matcher.get();
+}
+
+double FileTypeChooser::calcPriority(const UnicodeString* string) const
+{
+ SMatches match {};
+ if (string != nullptr && m_reg_matcher->parse(string, &match)) {
+ return m_priority;
+ }
+ return 0;
}
\ No newline at end of file
diff --git a/colorer/src/Colorer-library/src/colorer/parsers/FileTypeChooser.h b/colorer/src/Colorer-library/src/colorer/parsers/FileTypeChooser.h
index f46cd40a2..0be77ba82 100644
--- a/colorer/src/Colorer-library/src/colorer/parsers/FileTypeChooser.h
+++ b/colorer/src/Colorer-library/src/colorer/parsers/FileTypeChooser.h
@@ -14,18 +14,29 @@ class FileTypeChooser
/** Creates choose entry.
@param type If 0 - filename RE, if 1 - firstline RE
- @param prior Priority of this rule
+ @param priority Priority of this rule
@param re Associated regular expression
*/
FileTypeChooser(ChooserType type, double priority, CRegExp* re);
+
/** Returns type of chooser */
- [[nodiscard]] bool isFileName() const;
+ [[nodiscard]]
+ bool isFileName() const;
+
/** Returns type of chooser */
- [[nodiscard]] bool isFileContent() const;
+ [[nodiscard]]
+ bool isFileContent() const;
+
/** Returns chooser priority */
- [[nodiscard]] double getPriority() const;
+ [[nodiscard]]
+ double getPriority() const;
+
/** Returns associated regular expression */
- [[nodiscard]] CRegExp* getRE() const;
+ [[nodiscard]]
+ CRegExp* getRE() const;
+
+ [[nodiscard]]
+ double calcPriority(const UnicodeString* string) const;
private:
ChooserType m_type;
diff --git a/colorer/src/Colorer-library/src/colorer/parsers/FileTypeImpl.cpp b/colorer/src/Colorer-library/src/colorer/parsers/FileTypeImpl.cpp
index 4eaef26ca..fa65d4c13 100644
--- a/colorer/src/Colorer-library/src/colorer/parsers/FileTypeImpl.cpp
+++ b/colorer/src/Colorer-library/src/colorer/parsers/FileTypeImpl.cpp
@@ -1,10 +1,12 @@
#include "colorer/parsers/FileTypeImpl.h"
-
#include
-FileType::Impl::Impl(UnicodeString name, UnicodeString group, UnicodeString description)
- : name(std::move(name)), group(std::move(group)), description(std::move(description))
+FileType::Impl::Impl(UnicodeString l_name, UnicodeString l_group, UnicodeString l_description)
+ : name(std::move(l_name)), group(std::move(l_group)), description(std::move(l_description))
{
+ if (name.isEmpty()) {
+ throw FileTypeException("The file type name must not be empty");
+ }
}
const UnicodeString& FileType::Impl::getName() const
@@ -22,19 +24,22 @@ const UnicodeString& FileType::Impl::getDescription() const
return description;
}
-void FileType::Impl::setName(const UnicodeString* param_name)
+void FileType::Impl::setName(const UnicodeString& param_name)
{
- name = *param_name;
+ if (param_name.isEmpty()) {
+ throw FileTypeException("The file type name must not be empty");
+ }
+ name = param_name;
}
-void FileType::Impl::setGroup(const UnicodeString* group_name)
+void FileType::Impl::setGroup(const UnicodeString& group_name)
{
- group = *group_name;
+ group = group_name;
}
-void FileType::Impl::setDescription(const UnicodeString* description_)
+void FileType::Impl::setDescription(const UnicodeString& value)
{
- description = *description_;
+ description = value;
}
Scheme* FileType::Impl::getBaseScheme() const
@@ -54,7 +59,7 @@ std::vector FileType::Impl::enumParams() const
const UnicodeString* FileType::Impl::getParamDescription(const UnicodeString& param_name) const
{
- auto tp = paramsHash.find(param_name);
+ const auto tp = paramsHash.find(param_name);
if (tp != paramsHash.end() && tp->second.description) {
return tp->second.description.get();
}
@@ -63,7 +68,7 @@ const UnicodeString* FileType::Impl::getParamDescription(const UnicodeString& pa
const UnicodeString* FileType::Impl::getParamValue(const UnicodeString& param_name) const
{
- auto tp = paramsHash.find(param_name);
+ const auto tp = paramsHash.find(param_name);
if (tp != paramsHash.end()) {
if (tp->second.user_value) {
return tp->second.user_value.get();
@@ -73,17 +78,16 @@ const UnicodeString* FileType::Impl::getParamValue(const UnicodeString& param_na
return nullptr;
}
-int FileType::Impl::getParamValueInt(const UnicodeString& param_name, int def) const
+int FileType::Impl::getParamValueInt(const UnicodeString& param_name, const int def) const
{
int val = def;
- auto param_value = getParamValue(param_name);
+ const auto* param_value = getParamValue(param_name);
if (param_value && param_value->length() > 0) {
auto param_str = UStr::to_stdstr(param_value);
try {
val = std::stoi(param_str, nullptr);
} catch (std::exception&) {
- COLORER_LOG_ERROR("Error parse param % with value % to integer number", param_name,
- param_str);
+ COLORER_LOG_ERROR("Error parse param '%' with value '%' to integer number", param_name, param_str);
}
}
return val;
@@ -91,7 +95,7 @@ int FileType::Impl::getParamValueInt(const UnicodeString& param_name, int def) c
const UnicodeString* FileType::Impl::getParamDefaultValue(const UnicodeString& param_name) const
{
- auto tp = paramsHash.find(param_name);
+ const auto tp = paramsHash.find(param_name);
if (tp != paramsHash.end()) {
return &tp->second.value;
}
@@ -100,7 +104,7 @@ const UnicodeString* FileType::Impl::getParamDefaultValue(const UnicodeString& p
const UnicodeString* FileType::Impl::getParamUserValue(const UnicodeString& param_name) const
{
- auto tp = paramsHash.find(param_name);
+ const auto tp = paramsHash.find(param_name);
if (tp != paramsHash.end() && tp->second.user_value) {
return tp->second.user_value.get();
}
@@ -115,36 +119,31 @@ TypeParameter& FileType::Impl::addParam(const UnicodeString& param_name, const U
void FileType::Impl::setParamValue(const UnicodeString& param_name, const UnicodeString* value)
{
- auto tp = paramsHash.find(param_name);
+ const auto tp = paramsHash.find(param_name);
if (tp != paramsHash.end()) {
if (value) {
- tp->second.user_value = std::make_unique(*value);;
+ tp->second.user_value = std::make_unique(*value);
}
else {
tp->second.user_value.reset();
}
}
else {
- throw FileTypeException("Don`t set value " + *value + " for parameter \"" + param_name +
- "\". Parameter not exists.");
+ throw FileTypeException("Don`t set new value for parameter \"" + param_name + "\". Parameter not exists.");
}
}
-void FileType::Impl::setParamDefaultValue(const UnicodeString& param_name,
- const UnicodeString* value)
+void FileType::Impl::setParamDefaultValue(const UnicodeString& param_name, const UnicodeString* value)
{
- auto tp = paramsHash.find(param_name);
+ if (!value) {
+ throw FileTypeException("You can`t set the default value to null for the parameter \"" + param_name + "\"");
+ }
+ const auto tp = paramsHash.find(param_name);
if (tp != paramsHash.end()) {
- if (value) {
- tp->second.value = *value;
- }
- else {
- throw FileTypeException("Don`t set null value for parameter \"" + param_name + "\"");
- }
+ tp->second.value = *value;
}
else {
- throw FileTypeException("Don`t set value " + *value + " for parameter \"" + param_name +
- "\". Parameter not exists.");
+ throw FileTypeException("Don`t set new value for parameter \"" + param_name + "\". Parameter not exists.");
}
}
@@ -153,16 +152,19 @@ void FileType::Impl::setParamUserValue(const UnicodeString& param_name, const Un
setParamValue(param_name, value);
}
-void FileType::Impl::setParamDescription(const UnicodeString& param_name,
- const UnicodeString* t_description)
+void FileType::Impl::setParamDescription(const UnicodeString& param_name, const UnicodeString* value)
{
- auto tp = paramsHash.find(param_name);
+ const auto tp = paramsHash.find(param_name);
if (tp != paramsHash.end()) {
- tp->second.description = std::make_unique(*t_description);
+ if (value) {
+ tp->second.description = std::make_unique(*value);
+ }
+ else {
+ tp->second.description.reset();
+ }
}
else {
- throw FileTypeException("Don`t set value " + *t_description +
- " for description of parameter \"" + param_name +
+ throw FileTypeException("Don`t set value for description of parameter \"" + param_name +
"\". Parameter not exists.");
}
}
@@ -172,18 +174,15 @@ size_t FileType::Impl::getParamCount() const
return paramsHash.size();
}
-double FileType::Impl::getPriority(const UnicodeString* fileName,
- const UnicodeString* fileContent) const
+double FileType::Impl::getPriority(const UnicodeString* fileName, const UnicodeString* fileContent) const
{
- SMatches match {};
double cur_prior {0};
for (auto const& ftc : chooserVector) {
- if (ftc.isFileName() && fileName != nullptr && ftc.getRE()->parse(fileName, &match)) {
- cur_prior += ftc.getPriority();
+ if (ftc.isFileName()) {
+ cur_prior += ftc.calcPriority(fileName);
}
- else if (ftc.isFileContent() && fileContent != nullptr &&
- ftc.getRE()->parse(fileContent, &match)) {
- cur_prior += ftc.getPriority();
+ else if (ftc.isFileContent()) {
+ cur_prior += ftc.calcPriority(fileContent);
}
}
return cur_prior;
diff --git a/colorer/src/Colorer-library/src/colorer/parsers/FileTypeImpl.h b/colorer/src/Colorer-library/src/colorer/parsers/FileTypeImpl.h
index cefacca74..ccf9b75af 100644
--- a/colorer/src/Colorer-library/src/colorer/parsers/FileTypeImpl.h
+++ b/colorer/src/Colorer-library/src/colorer/parsers/FileTypeImpl.h
@@ -13,8 +13,7 @@
class TypeParameter
{
public:
- TypeParameter(UnicodeString t_name, UnicodeString t_value)
- : name(std::move(t_name)), value(std::move(t_value)) {};
+ TypeParameter(UnicodeString t_name, UnicodeString t_value) : name(std::move(t_name)), value(std::move(t_value)) {}
/* parameter name*/
UnicodeString name;
@@ -34,33 +33,44 @@ class TypeParameter
class FileType::Impl
{
public:
- Impl(UnicodeString name, UnicodeString group, UnicodeString description);
+ Impl(UnicodeString l_name, UnicodeString l_group, UnicodeString l_description);
- [[nodiscard]] const UnicodeString& getName() const;
- [[nodiscard]] const UnicodeString& getGroup() const;
- [[nodiscard]] const UnicodeString& getDescription() const;
+ [[nodiscard]]
+ const UnicodeString& getName() const;
+ [[nodiscard]]
+ const UnicodeString& getGroup() const;
+ [[nodiscard]]
+ const UnicodeString& getDescription() const;
- void setName(const UnicodeString* param_name);
- void setGroup(const UnicodeString* group_name);
- void setDescription(const UnicodeString* description);
+ void setName(const UnicodeString& param_name);
+ void setGroup(const UnicodeString& group_name);
+ void setDescription(const UnicodeString& description);
- [[nodiscard]] const UnicodeString* getParamValue(const UnicodeString& param_name) const;
- [[nodiscard]] const UnicodeString* getParamDefaultValue(const UnicodeString& param_name) const;
- [[nodiscard]] const UnicodeString* getParamUserValue(const UnicodeString& param_name) const;
- [[nodiscard]] const UnicodeString* getParamDescription(const UnicodeString& param_name) const;
- [[nodiscard]] int getParamValueInt(const UnicodeString& param_name, int def) const;
+ [[nodiscard]]
+ const UnicodeString* getParamValue(const UnicodeString& param_name) const;
+ [[nodiscard]]
+ const UnicodeString* getParamDefaultValue(const UnicodeString& param_name) const;
+ [[nodiscard]]
+ const UnicodeString* getParamUserValue(const UnicodeString& param_name) const;
+ [[nodiscard]]
+ const UnicodeString* getParamDescription(const UnicodeString& param_name) const;
+ [[nodiscard]]
+ int getParamValueInt(const UnicodeString& param_name, int def) const;
void setParamValue(const UnicodeString& param_name, const UnicodeString* value);
void setParamDefaultValue(const UnicodeString& param_name, const UnicodeString* value);
void setParamUserValue(const UnicodeString& param_name, const UnicodeString* value);
void setParamDescription(const UnicodeString& param_name, const UnicodeString* description);
- [[nodiscard]] std::vector enumParams() const;
- [[nodiscard]] size_t getParamCount() const;
+ [[nodiscard]]
+ std::vector enumParams() const;
+ [[nodiscard]]
+ size_t getParamCount() const;
TypeParameter& addParam(const UnicodeString& param_name, const UnicodeString& value);
- [[nodiscard]] Scheme* getBaseScheme() const;
+ [[nodiscard]]
+ Scheme* getBaseScheme() const;
/**
* Returns total priority, accordingly to all it's
* choosers (filename and firstline choosers).
diff --git a/colorer/src/Colorer-library/src/colorer/parsers/HrcLibraryImpl.cpp b/colorer/src/Colorer-library/src/colorer/parsers/HrcLibraryImpl.cpp
index 5571f927d..239509f0a 100644
--- a/colorer/src/Colorer-library/src/colorer/parsers/HrcLibraryImpl.cpp
+++ b/colorer/src/Colorer-library/src/colorer/parsers/HrcLibraryImpl.cpp
@@ -1,5 +1,4 @@
#include "colorer/parsers/HrcLibraryImpl.h"
-#include
#include
#include "colorer/base/XmlTagDefs.h"
#include "colorer/parsers/FileTypeImpl.h"
@@ -24,7 +23,7 @@ HrcLibrary::Impl::~Impl()
delete it.second;
}
- for (const auto *it : regionNamesVector) {
+ for (const auto* it : regionNamesVector) {
delete it;
}
@@ -84,7 +83,7 @@ void HrcLibrary::Impl::loadFileType(FileType* filetype)
thisType->pimpl->input_source_loading = true;
- auto& input_source = thisType->pimpl->inputSource;
+ const auto& input_source = thisType->pimpl->inputSource;
try {
loadSource(input_source.get());
} catch (InputSourceException& e) {
@@ -109,7 +108,7 @@ FileType* HrcLibrary::Impl::chooseFileType(const UnicodeString* fileName, const
FileType* best = nullptr;
double max_prior = 0;
const double DELTA = 1e-6;
- for (auto *ret : fileTypeVector) {
+ for (auto* ret : fileTypeVector) {
double const prior = ret->pimpl->getPriority(fileName, firstLine);
if (typeNo > 0 && (prior - max_prior < DELTA)) {
@@ -132,14 +131,14 @@ FileType* HrcLibrary::Impl::getFileType(const UnicodeString* name)
if (name == nullptr) {
return nullptr;
}
- auto filetype = fileTypeHash.find(*name);
+ const auto filetype = fileTypeHash.find(*name);
if (filetype != fileTypeHash.end()) {
return filetype->second;
}
return nullptr;
}
-FileType* HrcLibrary::Impl::enumerateFileTypes(unsigned int index)
+FileType* HrcLibrary::Impl::enumerateFileTypes(const unsigned int index) const
{
if (index < fileTypeVector.size()) {
return fileTypeVector[index];
@@ -147,17 +146,17 @@ FileType* HrcLibrary::Impl::enumerateFileTypes(unsigned int index)
return nullptr;
}
-size_t HrcLibrary::Impl::getFileTypesCount()
+size_t HrcLibrary::Impl::getFileTypesCount() const
{
return fileTypeVector.size();
}
-size_t HrcLibrary::Impl::getRegionCount()
+size_t HrcLibrary::Impl::getRegionCount() const
{
return regionNamesVector.size();
}
-const Region* HrcLibrary::Impl::getRegion(unsigned int id)
+const Region* HrcLibrary::Impl::getRegion(const unsigned int id) const
{
if (id >= regionNamesVector.size()) {
return nullptr;
@@ -170,7 +169,7 @@ const Region* HrcLibrary::Impl::getRegion(const UnicodeString* name)
if (name == nullptr) {
return nullptr;
}
- return getNCRegion(name, false); // regionNamesHash.get(name);
+ return getNCRegion(name, false);
}
// protected methods
@@ -210,7 +209,7 @@ void HrcLibrary::Impl::parseHRC(const XmlInputSource& is)
void HrcLibrary::Impl::parseHrcBlock(const XMLNode& elem)
{
- for (auto node : elem.children) {
+ for (const auto& node : elem.children) {
if (node.name == hrcTagPrototype || node.name == hrcTagPackage) {
addPrototype(node);
}
@@ -235,7 +234,7 @@ void HrcLibrary::Impl::addPrototype(const XMLNode& elem)
return;
}
- auto ft = fileTypeHash.find(typeName);
+ const auto ft = fileTypeHash.find(typeName);
if (ft != fileTypeHash.end()) {
unloadFileType(ft->second);
COLORER_LOG_WARN("Duplicate prototype '%'. First version unloaded, current is loading.", typeName);
@@ -261,7 +260,7 @@ void HrcLibrary::Impl::addPrototype(const XMLNode& elem)
void HrcLibrary::Impl::parsePrototypeBlock(const XMLNode& elem, FileType* current_parse_prototype)
{
- for (auto node : elem.children) {
+ for (const auto& node : elem.children) {
if (node.name == hrcTagLocation) {
addPrototypeLocation(node, current_parse_prototype);
}
@@ -278,7 +277,7 @@ void HrcLibrary::Impl::parsePrototypeBlock(const XMLNode& elem, FileType* curren
}
else {
COLORER_LOG_WARN("Unused element '%' in prototype '%'. Current file %.", node.name,
- current_parse_prototype->pimpl->name, current_input_source->getPath());
+ current_parse_prototype->pimpl->name, current_input_source->getPath());
}
}
}
@@ -304,7 +303,7 @@ void HrcLibrary::Impl::addPrototypeDetectParam(const XMLNode& elem, FileType* cu
matchRE->setPositionMoves(true);
if (!matchRE->isOk()) {
COLORER_LOG_WARN("Fault compiling chooser RE '%' in prototype '%'", elem.text,
- current_parse_prototype->pimpl->name);
+ current_parse_prototype->pimpl->name);
return;
}
auto ctype = elem.name == hrcTagFilename ? FileTypeChooser::ChooserType::CT_FILENAME
@@ -335,7 +334,7 @@ void HrcLibrary::Impl::addPrototypeDetectParam(const XMLNode& elem, FileType* cu
void HrcLibrary::Impl::addPrototypeParameters(const XMLNode& elem, FileType* current_parse_prototype)
{
- for (auto node : elem.children) {
+ for (const auto& node : elem.children) {
if (node.name == hrcTagParam) {
const auto& name = node.getAttrValue(hrcParamAttrName);
const auto& value = node.getAttrValue(hrcParamAttrValue);
@@ -351,7 +350,7 @@ void HrcLibrary::Impl::addPrototypeParameters(const XMLNode& elem, FileType* cur
}
else {
COLORER_LOG_WARN("Unused element '%' in prototype '%'. Current file %.", node.name,
- current_parse_prototype->pimpl->name, current_input_source->getPath());
+ current_parse_prototype->pimpl->name, current_input_source->getPath());
}
}
}
@@ -370,7 +369,7 @@ void HrcLibrary::Impl::addType(const XMLNode& elem)
COLORER_LOG_ERROR("Type '%s' without prototype", typeName);
return;
}
- auto *const type = type_ref->second;
+ auto* const type = type_ref->second;
if (type->pimpl->type_loading) {
COLORER_LOG_WARN("Type '%' is loading already. Current file %", typeName, current_input_source->getPath());
return;
@@ -435,7 +434,8 @@ void HrcLibrary::Impl::addTypeRegion(const XMLNode& elem)
const auto& regionParent = elem.getAttrValue(hrcRegionAttrParent);
const auto& regionDescr = elem.getAttrValue(hrcRegionAttrDescription);
- const auto qname2 = qualifyForeignName(regionParent.isEmpty() ? nullptr : ®ionParent, QualifyNameType::QNT_DEFINE, true);
+ const auto qname2 =
+ qualifyForeignName(regionParent.isEmpty() ? nullptr : ®ionParent, QualifyNameType::QNT_DEFINE, true);
const Region* region = new Region(*qname1, ®ionDescr, getRegion(qname2.get()), regionNamesVector.size());
regionNamesVector.push_back(region);
@@ -531,7 +531,7 @@ void HrcLibrary::Impl::addSchemeInherit(SchemeImpl* scheme, const XMLNode& elem)
auto nqSchemeName = elem.getAttrValue(hrcInheritAttrScheme);
if (nqSchemeName.isEmpty()) {
COLORER_LOG_ERROR("there is empty scheme name in inherit block of scheme '%', skip this inherit block.",
- *scheme->schemeName);
+ *scheme->schemeName);
return;
}
auto scheme_node = std::make_unique();
@@ -548,7 +548,7 @@ void HrcLibrary::Impl::addSchemeInherit(SchemeImpl* scheme, const XMLNode& elem)
const auto& x_substName = node.getAttrValue(hrcVirtualAttrSubstScheme);
if (x_schemeName.isEmpty() || x_substName.isEmpty()) {
COLORER_LOG_ERROR("there is bad virtualize attributes of scheme '%', skip this virtual block.",
- *scheme_node->schemeName);
+ *scheme_node->schemeName);
continue;
}
scheme_node->virtualEntryVector.emplace_back(new VirtualEntry(&x_schemeName, &x_substName));
@@ -567,7 +567,7 @@ void HrcLibrary::Impl::addSchemeRegexp(SchemeImpl* scheme, const XMLNode& elem)
if (matchParam.isEmpty()) {
COLORER_LOG_ERROR("there is no 'match' attribute in regexp of scheme '%', skip this regexp block.",
- *scheme->schemeName);
+ *scheme->schemeName);
return;
}
@@ -575,7 +575,7 @@ void HrcLibrary::Impl::addSchemeRegexp(SchemeImpl* scheme, const XMLNode& elem)
auto regexp = std::make_unique(entMatchParam.get());
if (!regexp->isOk()) {
COLORER_LOG_ERROR("fault compiling regexp '%' of scheme '%', skip this regexp block.", *entMatchParam,
- *scheme->schemeName);
+ *scheme->schemeName);
return;
}
@@ -601,7 +601,8 @@ void HrcLibrary::Impl::addSchemeBlock(SchemeImpl* scheme, const XMLNode& elem)
const XMLNode* element_start = nullptr;
const XMLNode* element_end = nullptr;
- if ((end_param.isEmpty() && start_param.isEmpty())) {
+ if (end_param.isEmpty() && start_param.isEmpty()) {
+ // don`t use range-based loop , we need pointer to elements
for (auto node = elem.children.begin(); node != elem.children.end(); ++node) {
if (node->name == hrcBlockAttrStart) {
element_start = &*node;
@@ -614,7 +615,7 @@ void HrcLibrary::Impl::addSchemeBlock(SchemeImpl* scheme, const XMLNode& elem)
}
else if (node->name == hrcBlockAttrEnd) {
element_end = &*node;
- if (node->isExist(hrcBlockAttrMatch) ) {
+ if (node->isExist(hrcBlockAttrMatch)) {
end_param = node->getAttrValue(hrcBlockAttrMatch);
}
else {
@@ -643,7 +644,7 @@ void HrcLibrary::Impl::addSchemeBlock(SchemeImpl* scheme, const XMLNode& elem)
start_regexp->setPositionMoves(false);
if (!start_regexp->isOk()) {
COLORER_LOG_ERROR("fault compiling start regexp '%' in block of scheme '%', skip this block.", *startParam,
- *scheme->schemeName);
+ *scheme->schemeName);
return;
}
@@ -654,7 +655,7 @@ void HrcLibrary::Impl::addSchemeBlock(SchemeImpl* scheme, const XMLNode& elem)
end_regexp->setRE(endParam.get());
if (!end_regexp->isOk()) {
COLORER_LOG_ERROR("fault compiling end regexp '%' in block of scheme '%', skip this block.", *startParam,
- *scheme->schemeName);
+ *scheme->schemeName);
return;
}
@@ -678,7 +679,7 @@ void HrcLibrary::Impl::addSchemeBlock(SchemeImpl* scheme, const XMLNode& elem)
void HrcLibrary::Impl::parseSchemeKeywords(SchemeImpl* scheme, const XMLNode& elem)
{
- auto rg_tmpl = UnicodeString(u"region");
+ const auto rg_tmpl = UnicodeString(u"region");
const Region* region = getNCRegion(&elem, rg_tmpl);
if (region == nullptr) {
COLORER_LOG_ERROR(
@@ -730,13 +731,14 @@ void HrcLibrary::Impl::loopSchemeKeywords(const XMLNode& elem, const SchemeImpl*
}
}
-void HrcLibrary::Impl::addSchemeKeyword(const XMLNode& elem, const SchemeImpl* scheme, const SchemeNodeKeywords* scheme_node,
- const Region* region, KeywordInfo::KeywordType keyword_type)
+void HrcLibrary::Impl::addSchemeKeyword(const XMLNode& elem, const SchemeImpl* scheme,
+ const SchemeNodeKeywords* scheme_node, const Region* region,
+ const KeywordInfo::KeywordType keyword_type)
{
const auto& keyword_value = elem.getAttrValue(hrcWordAttrName);
if (keyword_value.isEmpty()) {
COLORER_LOG_WARN("the 'name' attribute in the '%' element of scheme '%' is empty or missing, skip it.",
- *scheme->schemeName, keyword_type == KeywordInfo::KeywordType::KT_WORD ? "word" : "symb");
+ *scheme->schemeName, keyword_type == KeywordInfo::KeywordType::KT_WORD ? "word" : "symb");
return;
}
@@ -749,8 +751,8 @@ void HrcLibrary::Impl::addSchemeKeyword(const XMLNode& elem, const SchemeImpl* s
KeywordInfo& list = scheme_node->kwList->kwList[scheme_node->kwList->count];
list.keyword = std::make_unique(keyword_value);
list.region = rgn;
- list.isSymbol = (keyword_type == KeywordInfo::KeywordType::KT_SYMB);
- auto *first_char = scheme_node->kwList->firstChar.get();
+ list.isSymbol = keyword_type == KeywordInfo::KeywordType::KT_SYMB;
+ auto* first_char = scheme_node->kwList->firstChar.get();
first_char->add(keyword_value[0]);
if (!scheme_node->kwList->matchCase) {
first_char->add(Character::toLowerCase(keyword_value[0]));
@@ -765,7 +767,7 @@ size_t HrcLibrary::Impl::getSchemeKeywordsCount(const XMLNode& elem)
{
size_t result = 0;
for (const auto& node : elem.children) {
- if ((node.name == hrcTagWord || node.name == hrcTagSymb)) {
+ if (node.name == hrcTagWord || node.name == hrcTagSymb) {
const auto& atr = node.getAttrValue(hrcWordAttrName);
if (!atr.isEmpty()) {
result++;
@@ -793,7 +795,7 @@ void HrcLibrary::Impl::loadRegexpRegions(SchemeNodeRegexp* node, const XMLNode&
}
}
-void HrcLibrary::Impl::loadRegions(SchemeNodeBlock* node, const XMLNode* el, bool start_element)
+void HrcLibrary::Impl::loadRegions(SchemeNodeBlock* node, const XMLNode* el, const bool start_element)
{
char16_t rg_tmpl[] = u"region\0";
if (el) {
@@ -804,7 +806,7 @@ void HrcLibrary::Impl::loadRegions(SchemeNodeBlock* node, const XMLNode* el, boo
for (int i = 0; i < REGIONS_NUM; i++) {
rg_tmpl[6] = static_cast((i < 0xA ? i : i + 39) + '0');
- const auto *reg = getNCRegion(el, UnicodeString(rg_tmpl));
+ const auto* reg = getNCRegion(el, UnicodeString(rg_tmpl));
if (start_element) {
node->regions[i] = reg;
}
@@ -840,7 +842,7 @@ void HrcLibrary::Impl::loadBlockRegions(SchemeNodeBlock* node, const XMLNode& el
}
}
-void HrcLibrary::Impl::updateSchemeLink(uUnicodeString& scheme_name, SchemeImpl** scheme_impl, byte scheme_type,
+void HrcLibrary::Impl::updateSchemeLink(uUnicodeString& scheme_name, SchemeImpl** scheme_impl, const byte scheme_type,
const SchemeImpl* current_scheme)
{
static const char* message[4] = {"cannot resolve scheme name '%' of block in scheme '%'",
@@ -866,7 +868,7 @@ void HrcLibrary::Impl::updateLinks()
while (structureChanged) {
structureChanged = false;
for (auto& scheme_it : schemeHash) {
- SchemeImpl* scheme = scheme_it.second;
+ const SchemeImpl* scheme = scheme_it.second;
if (!scheme->fileType->pimpl->loadDone) {
continue;
}
@@ -874,16 +876,16 @@ void HrcLibrary::Impl::updateLinks()
current_parse_type = scheme->fileType;
for (auto& snode : scheme->nodes) {
if (snode->type == SchemeNode::SchemeNodeType::SNT_BLOCK) {
- auto *snode_block = static_cast(snode.get());
+ auto* snode_block = static_cast(snode.get());
updateSchemeLink(snode_block->schemeName, &snode_block->scheme, 0, scheme);
}
if (snode->type == SchemeNode::SchemeNodeType::SNT_INHERIT) {
- auto *snode_inherit = static_cast(snode.get());
+ auto* snode_inherit = static_cast(snode.get());
updateSchemeLink(snode_inherit->schemeName, &snode_inherit->scheme, 1, scheme);
- for (auto *vt : snode_inherit->virtualEntryVector) {
+ for (auto* vt : snode_inherit->virtualEntryVector) {
updateSchemeLink(vt->virtSchemeName, &vt->virtScheme, 2, scheme);
updateSchemeLink(vt->substSchemeName, &vt->substScheme, 3, scheme);
}
@@ -897,13 +899,13 @@ void HrcLibrary::Impl::updateLinks()
}
}
-uUnicodeString HrcLibrary::Impl::qualifyOwnName(const UnicodeString& name)
+uUnicodeString HrcLibrary::Impl::qualifyOwnName(const UnicodeString& name) const
{
- auto colon = name.indexOf(':');
+ const auto colon = name.indexOf(':');
if (colon != -1) {
if (UnicodeString(name, 0, colon).compare(current_parse_type->pimpl->name) != 0) {
COLORER_LOG_ERROR("type name qualifer in '%' doesn't match current type '%'", name,
- current_parse_type->pimpl->name);
+ current_parse_type->pimpl->name);
return nullptr;
}
return std::make_unique(name);
@@ -914,8 +916,8 @@ uUnicodeString HrcLibrary::Impl::qualifyOwnName(const UnicodeString& name)
return sbuf;
}
-bool HrcLibrary::Impl::checkNameExist(const UnicodeString* name, FileType* parseType, QualifyNameType qntype,
- bool logErrors)
+bool HrcLibrary::Impl::checkNameExist(const UnicodeString* name, FileType* parseType, const QualifyNameType qntype,
+ const bool logErrors)
{
if (qntype == QualifyNameType::QNT_DEFINE && regionNamesHash.find(*name) == regionNamesHash.end()) {
if (logErrors) {
@@ -938,15 +940,16 @@ bool HrcLibrary::Impl::checkNameExist(const UnicodeString* name, FileType* parse
return true;
}
-uUnicodeString HrcLibrary::Impl::qualifyForeignName(const UnicodeString* name, QualifyNameType qntype, bool logErrors)
+uUnicodeString HrcLibrary::Impl::qualifyForeignName(const UnicodeString* name, const QualifyNameType qntype,
+ const bool logErrors)
{
if (name == nullptr) {
return nullptr;
}
- auto colon = name->indexOf(':');
+ const auto colon = name->indexOf(':');
if (colon != -1) { // qualified name
- UnicodeString prefix(*name, 0, colon);
- auto ft = fileTypeHash.find(prefix);
+ const UnicodeString prefix(*name, 0, colon);
+ const auto ft = fileTypeHash.find(prefix);
FileType* prefType = nullptr;
if (ft != fileTypeHash.end()) {
prefType = ft->second;
@@ -986,7 +989,7 @@ uUnicodeString HrcLibrary::Impl::qualifyForeignName(const UnicodeString* name, Q
}
if (logErrors) {
COLORER_LOG_ERROR("unqualified name '%' doesn't belong to any imported type [%]", *name,
- current_input_source->getPath());
+ current_input_source->getPath());
}
}
return nullptr;
@@ -1012,7 +1015,7 @@ uUnicodeString HrcLibrary::Impl::useEntities(const UnicodeString* name)
epos++;
continue;
}
- auto elpos = name->indexOf(';', epos);
+ const auto elpos = name->indexOf(';', epos);
if (elpos == -1) {
epos = name->length();
break;
@@ -1039,17 +1042,17 @@ uUnicodeString HrcLibrary::Impl::useEntities(const UnicodeString* name)
return newname;
}
-const Region* HrcLibrary::Impl::getNCRegion(const UnicodeString* name, bool logErrors)
+const Region* HrcLibrary::Impl::getNCRegion(const UnicodeString* name, const bool logErrors)
{
if (name == nullptr || name->isEmpty()) {
return nullptr;
}
const Region* reg = nullptr;
- auto qname = qualifyForeignName(name, QualifyNameType::QNT_DEFINE, logErrors);
+ const auto qname = qualifyForeignName(name, QualifyNameType::QNT_DEFINE, logErrors);
if (qname == nullptr) {
return nullptr;
}
- auto reg_ = regionNamesHash.find(*qname);
+ const auto reg_ = regionNamesHash.find(*qname);
if (reg_ != regionNamesHash.end()) {
reg = reg_->second;
}
@@ -1058,8 +1061,8 @@ const Region* HrcLibrary::Impl::getNCRegion(const UnicodeString* name, bool logE
Regions with this name are always transparent
*/
if (reg != nullptr) {
- auto s_name = reg->getName();
- auto idx = s_name.indexOf(":default");
+ const auto s_name = reg->getName();
+ const auto idx = s_name.indexOf(":default");
if (idx != -1 && idx + 8 == s_name.length()) {
return nullptr;
}
diff --git a/colorer/src/Colorer-library/src/colorer/parsers/HrcLibraryImpl.h b/colorer/src/Colorer-library/src/colorer/parsers/HrcLibraryImpl.h
index 94e63fda1..88f0a9004 100644
--- a/colorer/src/Colorer-library/src/colorer/parsers/HrcLibraryImpl.h
+++ b/colorer/src/Colorer-library/src/colorer/parsers/HrcLibraryImpl.h
@@ -1,5 +1,5 @@
-#ifndef _COLORER_HRCLIBRARYIMPL_H_
-#define _COLORER_HRCLIBRARYIMPL_H_
+#ifndef COLORER_HRCLIBRARYIMPL_H
+#define COLORER_HRCLIBRARYIMPL_H
#include
#include "colorer/HrcLibrary.h"
@@ -25,12 +25,12 @@ class HrcLibrary::Impl
void loadSource(XmlInputSource* is);
void loadFileType(FileType* filetype);
FileType* getFileType(const UnicodeString* name);
- FileType* enumerateFileTypes(unsigned int index);
+ FileType* enumerateFileTypes(unsigned int index) const;
FileType* chooseFileType(const UnicodeString* fileName, const UnicodeString* firstLine, int typeNo = 0);
- size_t getFileTypesCount();
+ size_t getFileTypesCount() const;
- size_t getRegionCount();
- const Region* getRegion(unsigned int id);
+ size_t getRegionCount() const;
+ const Region* getRegion(unsigned int id) const;
const Region* getRegion(const UnicodeString* name);
protected:
@@ -81,7 +81,7 @@ class HrcLibrary::Impl
void loadRegions(SchemeNodeBlock* node, const XMLNode* el, bool start_element);
void loadRegexpRegions(SchemeNodeRegexp* node, const XMLNode& el);
- uUnicodeString qualifyOwnName(const UnicodeString& name);
+ uUnicodeString qualifyOwnName(const UnicodeString& name) const;
bool checkNameExist(const UnicodeString* name, FileType* parseType, QualifyNameType qntype, bool logErrors);
uUnicodeString qualifyForeignName(const UnicodeString* name, QualifyNameType qntype, bool logErrors);
@@ -95,4 +95,4 @@ class HrcLibrary::Impl
const std::unique_ptr& scheme_node, const Region* region);
};
-#endif
+#endif // COLORER_HRCLIBRARYIMPL_H
diff --git a/colorer/src/Colorer-library/src/colorer/parsers/ParserFactoryImpl.cpp b/colorer/src/Colorer-library/src/colorer/parsers/ParserFactoryImpl.cpp
index 3fc66dd5c..ce884a094 100644
--- a/colorer/src/Colorer-library/src/colorer/parsers/ParserFactoryImpl.cpp
+++ b/colorer/src/Colorer-library/src/colorer/parsers/ParserFactoryImpl.cpp
@@ -20,7 +20,7 @@ void ParserFactory::Impl::loadCatalog(const UnicodeString* catalog_path)
if (!catalog_path || catalog_path->isEmpty()) {
COLORER_LOG_DEBUG("loadCatalog for empty path");
- auto env = colorer::Environment::getOSVariable("COLORER_CATALOG");
+ auto env = colorer::Environment::getOSEnv("COLORER_CATALOG");
if (!env || env->isEmpty()) {
throw ParserFactoryException("Can't find suitable catalog.xml for parse.");
}
@@ -44,7 +44,7 @@ void ParserFactory::Impl::loadHrcPath(const UnicodeString& location)
{
try {
COLORER_LOG_DEBUG("try load '%'", location);
- if (XmlInputSource::isFileURI(*base_catalog_path, &location)) {
+ if (XmlInputSource::isFsURI(*base_catalog_path, &location)) {
auto files = colorer::Environment::getFilesFromPath(base_catalog_path.get(), &location, ".hrc");
for (auto& file : files) {
loadHrc(file, nullptr);
@@ -163,7 +163,7 @@ void ParserFactory::Impl::fillMapper(const UnicodeString& classID, const Unicode
const UnicodeString* name_id;
const UnicodeString name_default(HrdNameDefault);
if (nameID == nullptr) {
- auto hrd = colorer::Environment::getOSVariable("COLORER_HRD");
+ auto hrd = colorer::Environment::getOSEnv("COLORER_HRD");
if (hrd) {
name_id = hrd.get();
}
diff --git a/colorer/src/Colorer-library/src/colorer/parsers/SchemeNode.h b/colorer/src/Colorer-library/src/colorer/parsers/SchemeNode.h
index dff776666..d9c65738b 100644
--- a/colorer/src/Colorer-library/src/colorer/parsers/SchemeNode.h
+++ b/colorer/src/Colorer-library/src/colorer/parsers/SchemeNode.h
@@ -30,7 +30,7 @@ class SchemeNode
virtual ~SchemeNode() = default;
};
-class SchemeNodeInherit : public SchemeNode
+class SchemeNodeInherit final : public SchemeNode
{
public:
uUnicodeString schemeName = nullptr;
@@ -40,7 +40,7 @@ class SchemeNodeInherit : public SchemeNode
~SchemeNodeInherit() override;
};
-class SchemeNodeRegexp : public SchemeNode
+class SchemeNodeRegexp final : public SchemeNode
{
public:
bool lowPriority = false;
@@ -53,7 +53,7 @@ class SchemeNodeRegexp : public SchemeNode
~SchemeNodeRegexp() override = default;
};
-class SchemeNodeBlock : public SchemeNode
+class SchemeNodeBlock final : public SchemeNode
{
public:
bool innerRegion = false;
@@ -73,7 +73,7 @@ class SchemeNodeBlock : public SchemeNode
~SchemeNodeBlock() override = default;
};
-class SchemeNodeKeywords : public SchemeNode
+class SchemeNodeKeywords final : public SchemeNode
{
public:
std::unique_ptr kwList;
diff --git a/colorer/src/Colorer-library/src/colorer/strings/icu/UStr.cpp b/colorer/src/Colorer-library/src/colorer/strings/icu/UStr.cpp
index 7522336e7..ebc001856 100644
--- a/colorer/src/Colorer-library/src/colorer/strings/icu/UStr.cpp
+++ b/colorer/src/Colorer-library/src/colorer/strings/icu/UStr.cpp
@@ -241,24 +241,3 @@ int32_t UStr::indexOfIgnoreCase(const UnicodeString& str1, const UnicodeString&
auto tmp_str2 = str2;
return tmp_str1.toUpper().indexOf(tmp_str2.toUpper(), pos);
}
-
-#ifndef COLORER_FEATURE_LIBXML
-std::unique_ptr UStr::to_xmlch(const UnicodeString* str)
-{
- // XMLCh and UChar are the same size
- std::unique_ptr out_s;
- if (str) {
- auto len = str->length();
- out_s = std::make_unique(len + 1);
- str->extract(0, len, out_s.get());
- out_s[len] = 0;
- }
- return out_s;
-}
-
-std::string UStr::to_stdstr(const XMLCh* str)
-{
- std::string _string = std::string(xercesc::XMLString::transcode(str));
- return _string;
-}
-#endif
diff --git a/colorer/src/Colorer-library/src/colorer/strings/icu/UStr.h b/colorer/src/Colorer-library/src/colorer/strings/icu/UStr.h
index af80cba1f..c8f60d9f6 100644
--- a/colorer/src/Colorer-library/src/colorer/strings/icu/UStr.h
+++ b/colorer/src/Colorer-library/src/colorer/strings/icu/UStr.h
@@ -3,9 +3,6 @@
#include
#include "colorer/Common.h"
-#ifndef COLORER_FEATURE_LIBXML
-#include "xercesc/util/XMLString.hpp"
-#endif
class UStr
{
@@ -19,12 +16,6 @@ class UStr
[[nodiscard]] static std::wstring to_stdwstr(const uUnicodeString& str);
#endif
-#ifndef COLORER_FEATURE_LIBXML
- [[nodiscard]] static std::unique_ptr to_xmlch(const UnicodeString* str);
- [[nodiscard]] static std::string to_stdstr(const XMLCh* str);
- inline static bool isEmpty(const XMLCh* string) { return *string == '\0'; }
-#endif
-
static std::unique_ptr createCharClass(const UnicodeString& ccs, int pos, int* retPos,
bool ignore_case);
diff --git a/colorer/src/Colorer-library/src/colorer/strings/legacy/UStr.cpp b/colorer/src/Colorer-library/src/colorer/strings/legacy/UStr.cpp
index 967411e1b..927682a78 100644
--- a/colorer/src/Colorer-library/src/colorer/strings/legacy/UStr.cpp
+++ b/colorer/src/Colorer-library/src/colorer/strings/legacy/UStr.cpp
@@ -1,28 +1,6 @@
#include "colorer/strings/legacy/UStr.h"
#include
-#ifndef COLORER_FEATURE_LIBXML
-std::string UStr::to_stdstr(const XMLCh* str)
-{
- std::string _string = std::string(xercesc::XMLString::transcode(str));
- return _string;
-}
-
-std::unique_ptr UStr::to_xmlch(const UnicodeString* str)
-{
- // XMLCh and UChar are the same size
- std::unique_ptr out_s;
- if (str) {
- auto len = str->length();
- out_s = std::make_unique(len + 1);
- memcpy(out_s.get(),str->getW2Chars(),len*2);
- out_s[len] = 0;
- }
- return out_s;
-}
-
-#endif
-
std::string UStr::to_stdstr(const UnicodeString* str)
{
std::string out_str(str->getChars());
diff --git a/colorer/src/Colorer-library/src/colorer/strings/legacy/UStr.h b/colorer/src/Colorer-library/src/colorer/strings/legacy/UStr.h
index de7e88dab..817a2a3f7 100644
--- a/colorer/src/Colorer-library/src/colorer/strings/legacy/UStr.h
+++ b/colorer/src/Colorer-library/src/colorer/strings/legacy/UStr.h
@@ -3,9 +3,6 @@
#include
#include "colorer/Common.h"
-#ifndef COLORER_FEATURE_LIBXML
-#include
-#endif
#include "colorer/strings/legacy/CharacterClass.h"
class UStr
@@ -18,11 +15,6 @@ class UStr
[[nodiscard]] static std::wstring to_stdwstr(const UnicodeString* str);
[[nodiscard]] static std::wstring to_stdwstr(const UnicodeString& str);
-#ifndef COLORER_FEATURE_LIBXML
- [[nodiscard]] static std::string to_stdstr(const XMLCh* str);
- [[nodiscard]] static std::unique_ptr to_xmlch(const UnicodeString* str);
- inline static bool isEmpty(const XMLCh* string) { return *string == '\0'; }
-#endif
static std::unique_ptr createCharClass(const UnicodeString& ccs, int pos, int* retPos, bool ignore_case);
static int8_t caseCompare(const UnicodeString& str1, const UnicodeString& str2);
diff --git a/colorer/src/Colorer-library/src/colorer/utils/Environment.cpp b/colorer/src/Colorer-library/src/colorer/utils/Environment.cpp
index f1a68375d..7b04c4ed1 100644
--- a/colorer/src/Colorer-library/src/colorer/utils/Environment.cpp
+++ b/colorer/src/Colorer-library/src/colorer/utils/Environment.cpp
@@ -2,10 +2,11 @@
#ifdef WIN32
#include
#include
-#else
-#include
+#include
#endif
+
namespace colorer {
+
fs::path Environment::to_filepath(const UnicodeString* str)
{
#ifdef _WINDOWS
@@ -16,9 +17,9 @@ fs::path Environment::to_filepath(const UnicodeString* str)
return result;
}
-uUnicodeString Environment::getOSVariable(const UnicodeString& name)
+uUnicodeString Environment::getOSEnv(const UnicodeString& name)
{
-#ifdef WIN32
+#ifdef _WINDOWS
COLORER_LOG_DEBUG("get system environment '%'", name);
auto str_name = UStr::to_stdwstr(&name);
size_t sz = 0;
@@ -44,36 +45,18 @@ uUnicodeString Environment::getOSVariable(const UnicodeString& name)
COLORER_LOG_DEBUG("'%' not set", name);
return nullptr;
}
- else {
- COLORER_LOG_DEBUG("'%' = '%'", name, value);
- return std::make_unique(value);
- }
+
+ COLORER_LOG_DEBUG("'%' = '%'", name, value);
+ return std::make_unique(value);
#endif
}
-uUnicodeString Environment::expandEnvironment(const UnicodeString* path)
+void Environment::setOSEnv(const UnicodeString& name, const UnicodeString& value)
{
- COLORER_LOG_DEBUG("expand system environment for '%'", *path);
-#ifdef WIN32
- std::wstring path_ws = UStr::to_stdwstr(path);
- size_t i = ExpandEnvironmentStringsW(path_ws.c_str(), nullptr, 0);
- auto temp = std::make_unique(i);
- ExpandEnvironmentStringsW(path_ws.c_str(), temp.get(), static_cast(i));
- return std::make_unique(temp.get());
+#ifdef _WINDOWS
+ _putenv_s(UStr::to_stdstr(&name).c_str(), UStr::to_stdstr(&value).c_str());
#else
- std::smatch matcher;
- std::string result;
- auto text = UStr::to_stdstr(path);
- static const std::regex env_re {R"--(\$\{([^}]+)\})--"};
- while (std::regex_search(text, matcher, env_re)) {
- result += matcher.prefix().str();
- result += std::getenv(matcher[1].str().c_str());
- text = matcher.suffix().str();
- }
- result += text;
-
- COLORER_LOG_DEBUG("result of expand '%'", result);
- return std::make_unique(result.c_str());
+ setenv( UStr::to_stdstr(&name).c_str(), UStr::to_stdstr(&value).c_str(), 1);
#endif
}
@@ -84,8 +67,8 @@ uUnicodeString Environment::normalizePath(const UnicodeString* path)
fs::path Environment::normalizeFsPath(const UnicodeString* path)
{
- auto expanded_string = Environment::expandEnvironment(path);
- auto fpath = fs::path(Environment::to_filepath(expanded_string.get()));
+ auto expanded_string = expandEnvironment(*path);
+ auto fpath = fs::path(to_filepath(&expanded_string));
fpath = fpath.lexically_normal();
if (fs::is_symlink(fpath)) {
fpath = fs::read_symlink(fpath);
@@ -142,4 +125,90 @@ bool Environment::isRegularFile(const UnicodeString* basePath, const UnicodeStri
return fs::is_regular_file(clear_path);
}
+bool Environment::isRegularFile(const UnicodeString& path)
+{
+ return fs::is_regular_file(UStr::to_stdstr(&path));
+}
+
+UnicodeString Environment::getAbsolutePath(const UnicodeString& basePath, const UnicodeString& relPath)
+{
+ auto root_pos = basePath.lastIndexOf('/');
+ const auto root_pos2 = basePath.lastIndexOf('\\');
+ if (root_pos2 > root_pos) {
+ root_pos = root_pos2;
+ }
+ if (root_pos == -1) {
+ root_pos = 0;
+ }
+ else {
+ root_pos++;
+ }
+ UnicodeString newPath(basePath, 0, root_pos);
+ newPath.append(relPath);
+ return newPath;
+}
+
+UnicodeString Environment::expandSpecialEnvironment(const UnicodeString& path)
+{
+ COLORER_LOG_DEBUG("expand system environment for '%'", path);
+
+ const auto text = UStr::to_stdstr(&path);
+ auto result = expandEnvByRegexp(text, std::regex(R"--(\$([[:alpha:]]\w*)\b)--"));
+
+ COLORER_LOG_DEBUG("result of expand '%'", result);
+ return {result.c_str()};
+}
+
+UnicodeString Environment::expandEnvironment(const UnicodeString& path)
+{
+ COLORER_LOG_DEBUG("expand system environment for '%'", path);
+ if (path.isEmpty()) {
+ COLORER_LOG_DEBUG("result of expand ''");
+ return {};
+ }
+
+#ifdef _WINDOWS
+ std::wstring path_ws = UStr::to_stdwstr(&path);
+ size_t i = ExpandEnvironmentStringsW(path_ws.c_str(), nullptr, 0);
+ auto temp = std::make_unique(i);
+ ExpandEnvironmentStringsW(path_ws.c_str(), temp.get(), static_cast(i));
+ COLORER_LOG_DEBUG("result of expand '%'", temp.get());
+ return {temp.get()};
+#else
+ const auto text = UStr::to_stdstr(&path);
+ auto res = expandEnvByRegexp(text, std::regex(R"--(\$\{([[:alpha:]]\w*)\})--"));
+ res = expandEnvByRegexp(res, std::regex(R"--(\$([[:alpha:]]\w*)\b)--"));
+ COLORER_LOG_DEBUG("result of expand '%'", res);
+ return {res.c_str()};
+#endif
+}
+
+uintmax_t Environment::getFileSize(const UnicodeString& path)
+{
+ return fs::file_size(UStr::to_stdstr(&path));
+}
+
+std::string Environment::expandEnvByRegexp(const std::string& path, const std::regex& regex)
+{
+ std::smatch matcher;
+ std::string result;
+ auto text = path;
+ while (std::regex_search(text, matcher, regex)) {
+ result += matcher.prefix().str();
+ auto env_value = getOSEnv(matcher[1].str().c_str());
+ if (env_value) {
+ // add expanded value
+ result += UStr::to_stdstr(env_value);
+ }
+ else {
+ // add variable name
+ result += matcher[0].str();
+ }
+ text = matcher.suffix().str();
+ }
+ result += text;
+
+ return result;
+}
+
} // namespace colorer
\ No newline at end of file
diff --git a/colorer/src/Colorer-library/src/colorer/utils/Environment.h b/colorer/src/Colorer-library/src/colorer/utils/Environment.h
index bed3fb108..69e67360a 100644
--- a/colorer/src/Colorer-library/src/colorer/utils/Environment.h
+++ b/colorer/src/Colorer-library/src/colorer/utils/Environment.h
@@ -1,7 +1,10 @@
#ifndef COLORER_ENVIRONMENT_H
#define COLORER_ENVIRONMENT_H
+#include
+#include
#include "colorer/Common.h"
+
#ifdef COLORER_FEATURE_OLD_COMPILERS
#include "colorer/platform/filesystem.hpp"
namespace fs = ghc::filesystem;
@@ -9,14 +12,15 @@ namespace fs = ghc::filesystem;
#include
namespace fs = std::filesystem;
#endif
-#include
+
+
namespace colorer {
class Environment
{
public:
- static uUnicodeString getOSVariable(const UnicodeString& name);
- static uUnicodeString expandEnvironment(const UnicodeString* path);
+ static uUnicodeString getOSEnv(const UnicodeString& name);
+ static void setOSEnv(const UnicodeString& name, const UnicodeString& value);
static uUnicodeString normalizePath(const UnicodeString* path);
static fs::path normalizeFsPath(const UnicodeString* path);
static fs::path getClearFilePath(const UnicodeString* basePath, const UnicodeString* relPath);
@@ -25,6 +29,15 @@ class Environment
static std::vector getFilesFromPath(const UnicodeString* basePath, const UnicodeString* relPath,
const UnicodeString& extension);
static bool isRegularFile(const UnicodeString* basePath, const UnicodeString* relPath, UnicodeString& fullPath);
+ static bool isRegularFile(const UnicodeString& path);
+ static UnicodeString getAbsolutePath(const UnicodeString& basePath, const UnicodeString& relPath);
+
+ static UnicodeString expandSpecialEnvironment(const UnicodeString& path);
+ static UnicodeString expandEnvironment(const UnicodeString& path);
+
+ static uintmax_t getFileSize(const UnicodeString& path);
+private:
+ static std::string expandEnvByRegexp(const std::string& path, const std::regex& regex);
};
} // namespace colorer
diff --git a/colorer/src/Colorer-library/src/colorer/version.h b/colorer/src/Colorer-library/src/colorer/version.h
index 90e7f1b61..4cd8aa527 100644
--- a/colorer/src/Colorer-library/src/colorer/version.h
+++ b/colorer/src/Colorer-library/src/colorer/version.h
@@ -2,10 +2,10 @@
#define _COLORER_VERSION_H_
#define COLORER_VER_MAJOR 1
-#define COLORER_VER_MINOR 3
-#define COLORER_VER_PATCH 3
+#define COLORER_VER_MINOR 4
+#define COLORER_VER_PATCH 0
-#define COLORER_COPYRIGHT "(c) 1999-2009 Igor Russkih, (c) 2009-2021 Aleksey Dobrunov"
+#define COLORER_COPYRIGHT "(c) 1999-2009 Igor Russkih, (c) 2009-2024 Aleksey Dobrunov"
#ifdef _WIN64
#define CONF " x64"
diff --git a/colorer/src/Colorer-library/src/colorer/xml/XMLNode.cpp b/colorer/src/Colorer-library/src/colorer/xml/XMLNode.cpp
new file mode 100644
index 000000000..5d19d97c9
--- /dev/null
+++ b/colorer/src/Colorer-library/src/colorer/xml/XMLNode.cpp
@@ -0,0 +1,17 @@
+#include "colorer/xml/XMLNode.h"
+
+const UnicodeString& XMLNode::getAttrValue(const UnicodeString& key) const
+{
+ static const UnicodeString empty_string(u"");
+
+ const auto found = attributes.find(key);
+ if (found == attributes.end()) {
+ return empty_string;
+ }
+ return found->second;
+}
+
+bool XMLNode::isExist(const UnicodeString& key) const
+{
+ return attributes.find(key) != attributes.end();
+}
\ No newline at end of file
diff --git a/colorer/src/Colorer-library/src/colorer/xml/XMLNode.h b/colorer/src/Colorer-library/src/colorer/xml/XMLNode.h
index 2ace5bad1..6405ec3df 100644
--- a/colorer/src/Colorer-library/src/colorer/xml/XMLNode.h
+++ b/colorer/src/Colorer-library/src/colorer/xml/XMLNode.h
@@ -5,24 +5,14 @@
#include
#include "colorer/Common.h"
-inline const UnicodeString empty_string("");
-
class XMLNode
{
-public:
+ public:
XMLNode() = default;
- bool isExist(const UnicodeString& key) const { return attributes.find(key) != attributes.end(); }
-
- const UnicodeString& getAttrValue(const UnicodeString& key) const
- {
- const auto found = attributes.find(key);
- if (found == attributes.end()) {
- return empty_string;
- }
- return found->second;
- }
+ bool isExist(const UnicodeString& key) const;
+ const UnicodeString& getAttrValue(const UnicodeString& key) const;
UnicodeString name; // tag name
UnicodeString text; // tag value ( if is a text tag )
std::unordered_map attributes;
diff --git a/colorer/src/Colorer-library/src/colorer/xml/XmlInputSource.cpp b/colorer/src/Colorer-library/src/colorer/xml/XmlInputSource.cpp
index c64f07e67..c10197d3c 100644
--- a/colorer/src/Colorer-library/src/colorer/xml/XmlInputSource.cpp
+++ b/colorer/src/Colorer-library/src/colorer/xml/XmlInputSource.cpp
@@ -1,24 +1,11 @@
#include "colorer/xml/XmlInputSource.h"
+#include "colorer/base/BaseNames.h"
XmlInputSource::XmlInputSource(const UnicodeString& source_path) : XmlInputSource(source_path, nullptr) {}
-XmlInputSource::~XmlInputSource()
-{
-#ifndef COLORER_FEATURE_LIBXML
- //xml_input_source child of xercesc classes and need to free before xercesc
- xml_input_source.reset();
- xercesc::XMLPlatformUtils::Terminate();
-#endif
-}
-
XmlInputSource::XmlInputSource(const UnicodeString& source_path, const UnicodeString* source_base)
{
-#ifdef COLORER_FEATURE_LIBXML
- xml_input_source = std::make_unique(&source_path, source_base);
-#else
- xercesc::XMLPlatformUtils::Initialize();
- xml_input_source = XercesXmlInputSource::newInstance(&source_path, source_base);
-#endif
+ xml_input_source = std::make_unique(source_path, source_base);
}
uXmlInputSource XmlInputSource::createRelative(const UnicodeString& relPath) const
@@ -32,16 +19,9 @@ UnicodeString& XmlInputSource::getPath() const
return xml_input_source->getPath();
}
-#ifndef COLORER_FEATURE_LIBXML
-XercesXmlInputSource* XmlInputSource::getInputSource() const
-{
- return xml_input_source.get();
-}
-#endif
-
-bool XmlInputSource::isFileURI(const UnicodeString& path, const UnicodeString* base)
+bool XmlInputSource::isFsURI(const UnicodeString& path, const UnicodeString* base)
{
- if (path.startsWith(u"jar") || (base && base->startsWith(u"jar"))) {
+ if (path.startsWith(jar) || (base && base->startsWith(jar))) {
return false;
}
return true;
diff --git a/colorer/src/Colorer-library/src/colorer/xml/XmlInputSource.h b/colorer/src/Colorer-library/src/colorer/xml/XmlInputSource.h
index 1d382a587..5cd619dd0 100644
--- a/colorer/src/Colorer-library/src/colorer/xml/XmlInputSource.h
+++ b/colorer/src/Colorer-library/src/colorer/xml/XmlInputSource.h
@@ -2,12 +2,7 @@
#define COLORER_XMLINPUTSOURCE_H
#include "colorer/Common.h"
-#ifdef COLORER_FEATURE_LIBXML
#include "colorer/xml/libxml2/LibXmlInputSource.h"
-#else
-#include "colorer/xml/xercesc/XercesXmlInputSource.h"
-#endif
-
class XmlInputSource;
using uXmlInputSource = std::unique_ptr;
@@ -16,7 +11,7 @@ class XmlInputSource
{
public:
explicit XmlInputSource(const UnicodeString& source_path);
- ~XmlInputSource();
+ ~XmlInputSource() = default;
XmlInputSource(const UnicodeString& source_path, const UnicodeString* source_base);
@@ -26,19 +21,10 @@ class XmlInputSource
[[nodiscard]]
UnicodeString& getPath() const;
-#ifndef COLORER_FEATURE_LIBXML
- [[nodiscard]]
- XercesXmlInputSource* getInputSource() const;
-#endif
-
- static bool isFileURI(const UnicodeString& path, const UnicodeString* base);
+ static bool isFsURI(const UnicodeString& path, const UnicodeString* base);
private:
-#ifdef COLORER_FEATURE_LIBXML
std::unique_ptr xml_input_source;
-#else
- uXercesXmlInputSource xml_input_source;
-#endif
};
#endif // COLORER_XMLINPUTSOURCE_H
diff --git a/colorer/src/Colorer-library/src/colorer/xml/XmlReader.cpp b/colorer/src/Colorer-library/src/colorer/xml/XmlReader.cpp
index 6174e88eb..ce9fd7bd3 100644
--- a/colorer/src/Colorer-library/src/colorer/xml/XmlReader.cpp
+++ b/colorer/src/Colorer-library/src/colorer/xml/XmlReader.cpp
@@ -12,11 +12,7 @@ XmlReader::~XmlReader()
bool XmlReader::parse()
{
-#ifdef COLORER_FEATURE_LIBXML
xml_reader = new LibXmlReader(*input_source);
-#else
- xml_reader = new XercesXmlReader(*input_source);
-#endif
return xml_reader->isParsed();
}
diff --git a/colorer/src/Colorer-library/src/colorer/xml/XmlReader.h b/colorer/src/Colorer-library/src/colorer/xml/XmlReader.h
index 4e9eeafba..4dfa37619 100644
--- a/colorer/src/Colorer-library/src/colorer/xml/XmlReader.h
+++ b/colorer/src/Colorer-library/src/colorer/xml/XmlReader.h
@@ -3,11 +3,7 @@
#include "colorer/xml/XMLNode.h"
#include "colorer/xml/XmlInputSource.h"
-#ifdef COLORER_FEATURE_LIBXML
#include "libxml2/LibXmlReader.h"
-#else
-#include "colorer/xml/xercesc/XercesXmlReader.h"
-#endif
class XmlReader
{
@@ -19,11 +15,7 @@ class XmlReader
private:
const XmlInputSource* input_source;
-#ifdef COLORER_FEATURE_LIBXML
LibXmlReader* xml_reader = nullptr;
-#else
- XercesXmlReader* xml_reader = nullptr;
-#endif
};
#endif // COLORER_XMLREADER_H
diff --git a/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlInputSource.cpp b/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlInputSource.cpp
new file mode 100644
index 000000000..c238b11db
--- /dev/null
+++ b/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlInputSource.cpp
@@ -0,0 +1,98 @@
+#include "colorer/xml/libxml2/LibXmlInputSource.h"
+#include "colorer/Exception.h"
+#include "colorer/base/BaseNames.h"
+#include "colorer/utils/Environment.h"
+
+LibXmlInputSource::LibXmlInputSource(const UnicodeString& path, const UnicodeString* base)
+{
+ if (path.isEmpty()) {
+ throw InputSourceException("LibXmlInputSource: path is empty");
+ }
+ UnicodeString full_path;
+ if (path.startsWith(jar) || (base != nullptr && base->startsWith(jar))) {
+#ifdef COLORER_FEATURE_ZIPINPUTSOURCE
+ initZipSource(path, base);
+#else
+ throw InputSourceException("zip input source not supported");
+#endif
+ }
+ else if (colorer::Environment::isRegularFile(base, &path, full_path)) {
+ sourcePath = full_path;
+ }
+ else {
+ throw InputSourceException(full_path + " isn't regular file.");
+ }
+}
+
+LibXmlInputSource::~LibXmlInputSource()
+{
+#ifdef COLORER_FEATURE_ZIPINPUTSOURCE
+ if (zip_source) {
+ zip_source->delref();
+ }
+#endif
+}
+
+LibXmlInputSource LibXmlInputSource::createRelative(const UnicodeString& relPath) const
+{
+ return LibXmlInputSource(relPath, &sourcePath);
+}
+
+UnicodeString& LibXmlInputSource::getPath()
+{
+ return sourcePath;
+}
+
+#ifdef COLORER_FEATURE_ZIPINPUTSOURCE
+
+void LibXmlInputSource::initZipSource(const UnicodeString& path, const UnicodeString* base)
+{
+ const auto paths = getFullPathsToZip(path, base);
+
+ if (!colorer::Environment::isRegularFile(paths.path_to_jar)) {
+ throw InputSourceException(paths.path_to_jar + " isn't regular file.");
+ }
+
+ sourcePath = paths.full_path;
+ zip_source = SharedXmlInputSource::getSharedInputSource(paths.path_to_jar);
+}
+
+PathInJar LibXmlInputSource::getFullPathsToZip(const UnicodeString& path, const UnicodeString* base)
+{
+ if (path.startsWith(jar)) {
+ auto local_path = colorer::Environment::expandSpecialEnvironment(path);
+ const auto path_idx = local_path.lastIndexOf('!');
+ if (path_idx == -1) {
+ throw InputSourceException("Bad jar uri format: " + local_path);
+ }
+
+ UnicodeString path_to_jar;
+ if (local_path.compare(path) == 0) {
+ path_to_jar = colorer::Environment::getAbsolutePath(
+ base ? *base : u"", UnicodeString(local_path, jar.length(), path_idx - jar.length()));
+ }
+ else {
+ path_to_jar =
+ colorer::Environment::getAbsolutePath(u"", UnicodeString(local_path, jar.length(), path_idx - jar.length()));
+ }
+
+ const UnicodeString path_in_jar(local_path, path_idx + 1);
+
+ const UnicodeString full_path = jar + path_to_jar + u"!" + path_in_jar;
+ return {full_path, path_to_jar, path_in_jar};
+ }
+ if (base != nullptr && base->startsWith(jar)) {
+ const auto base_idx = base->lastIndexOf('!');
+ if (base_idx == -1) {
+ throw InputSourceException("Bad jar uri format: " + path);
+ }
+ const UnicodeString path_to_jar(*base, jar.length(), base_idx - jar.length());
+ const UnicodeString path_in_jar = colorer::Environment::getAbsolutePath(UnicodeString(*base, base_idx + 1), path);
+
+ const UnicodeString full_path = jar + path_to_jar + u"!" + path_in_jar;
+ return {full_path, path_to_jar, path_in_jar};
+ }
+ throw InputSourceException("The path to the jar was not found");
+}
+
+#endif
diff --git a/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlInputSource.h b/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlInputSource.h
index 6fb604b9d..f3fff4c7d 100644
--- a/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlInputSource.h
+++ b/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlInputSource.h
@@ -2,37 +2,40 @@
#define COLORER_LIBXMLINPUTSOURCE_H
#include "colorer/Common.h"
-#include "colorer/Exception.h"
-#include "colorer/utils/Environment.h"
+#ifdef COLORER_FEATURE_ZIPINPUTSOURCE
+#include "colorer/xml/libxml2/SharedXmlInputSource.h"
+#endif
+
+struct PathInJar
+{
+ UnicodeString full_path;
+ UnicodeString path_to_jar;
+ UnicodeString path_in_jar;
+};
class LibXmlInputSource
{
public:
- explicit LibXmlInputSource(const UnicodeString* path, const UnicodeString* base = nullptr)
- {
- UnicodeString full_path;
- if (colorer::Environment::isRegularFile(base, path, full_path)) {
- sourcePath = full_path;
- // file is not open yet, only after makeStream
- }
- else {
- throw InputSourceException(full_path + " isn't regular file.");
- }
- }
-
- LibXmlInputSource createRelative(const UnicodeString& relPath) const
- {
- return LibXmlInputSource(&relPath, &sourcePath);
- }
+ explicit LibXmlInputSource(const UnicodeString& path, const UnicodeString* base = nullptr);
+ ~LibXmlInputSource();
+
+ [[nodiscard]]
+ LibXmlInputSource createRelative(const UnicodeString& relPath) const;
[[nodiscard]]
- UnicodeString& getPath()
- {
- return sourcePath;
- }
+ UnicodeString& getPath();
private:
UnicodeString sourcePath;
+
+#ifdef COLORER_FEATURE_ZIPINPUTSOURCE
+ public:
+ static PathInJar getFullPathsToZip(const UnicodeString& path, const UnicodeString* base = nullptr);
+
+ private:
+ SharedXmlInputSource* zip_source {nullptr};
+ void initZipSource(const UnicodeString& path, const UnicodeString* base = nullptr);
+#endif
};
#endif // COLORER_LIBXMLINPUTSOURCE_H
diff --git a/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlReader.cpp b/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlReader.cpp
index 523e1d3d2..1c287e5f3 100644
--- a/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlReader.cpp
+++ b/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlReader.cpp
@@ -1,11 +1,31 @@
#include "colorer/xml/libxml2/LibXmlReader.h"
#include
#include
+#include
+#include "colorer/Exception.h"
+#include "colorer/base/BaseNames.h"
+#include "colorer/utils/Environment.h"
-LibXmlReader::LibXmlReader(const UnicodeString& source_file) : xmldoc(nullptr)
+#ifdef COLORER_FEATURE_ZIPINPUTSOURCE
+#include "colorer/zip/MemoryFile.h"
+#endif
+
+#ifdef _MSC_VER
+#define strdup(p) _strdup(p)
+#endif
+
+uUnicodeString LibXmlReader::current_file = nullptr;
+bool LibXmlReader::is_first_call = false;
+
+LibXmlReader::LibXmlReader(const UnicodeString& source_file)
{
xmlSetExternalEntityLoader(xmlMyExternalEntityLoader);
xmlSetGenericErrorFunc(nullptr, xml_error_func);
+
+ current_file = std::make_unique(source_file);
+ is_first_call = true;
+
+ // you can pass any string for the file name, it can be processed/converted into xml by MyExternalEntityLoader
xmldoc = xmlReadFile(UStr::to_stdstr(&source_file).c_str(), nullptr, XML_PARSE_NOENT | XML_PARSE_NONET);
}
@@ -16,6 +36,7 @@ LibXmlReader::~LibXmlReader()
if (xmldoc != nullptr) {
xmlFreeDoc(xmldoc);
}
+ current_file.reset();
}
void LibXmlReader::parse(std::list& nodes)
@@ -32,7 +53,7 @@ void LibXmlReader::parse(std::list& nodes)
bool LibXmlReader::populateNode(xmlNode* node, XMLNode& result)
{
if (node->type == XML_ELEMENT_NODE) {
- result.name = UnicodeString((const char*) node->name);
+ result.name = UnicodeString(reinterpret_cast(node->name));
const auto text_string = getElementText(node);
if (!text_string.isEmpty()) {
@@ -46,14 +67,14 @@ bool LibXmlReader::populateNode(xmlNode* node, XMLNode& result)
return false;
}
-UnicodeString LibXmlReader::getElementText(xmlNode* node)
+UnicodeString LibXmlReader::getElementText(const xmlNode* node)
{
for (const xmlNode* child = node->children; child != nullptr; child = child->next) {
if (child->type == XML_CDATA_SECTION_NODE) {
- return UnicodeString((const char*) child->content);
+ return {reinterpret_cast(child->content)};
}
if (child->type == XML_TEXT_NODE) {
- auto temp_string = UnicodeString((const char*) child->content);
+ auto temp_string = UnicodeString(reinterpret_cast(child->content));
temp_string.trim();
if (temp_string.isEmpty()) {
continue;
@@ -61,7 +82,7 @@ UnicodeString LibXmlReader::getElementText(xmlNode* node)
return temp_string;
}
}
- return UnicodeString("");
+ return {u""};
}
void LibXmlReader::getChildren(xmlNode* node, XMLNode& result)
@@ -85,33 +106,74 @@ void LibXmlReader::getChildren(xmlNode* node, XMLNode& result)
void LibXmlReader::getAttributes(const xmlNode* node, std::unordered_map& data)
{
for (xmlAttrPtr attr = node->properties; attr != nullptr; attr = attr->next) {
- data.emplace(std::pair((const char*) attr->name, (const char*) xmlNodeGetContent(attr->children)));
+ const auto content = xmlNodeGetContent(attr->children);
+ data.emplace(std::pair(reinterpret_cast(attr->name), reinterpret_cast(content)));
+ xmlFree(content);
}
}
+#ifdef COLORER_FEATURE_ZIPINPUTSOURCE
+xmlParserInputPtr LibXmlReader::xmlZipEntityLoader(const PathInJar& paths, xmlParserCtxtPtr ctxt)
+{
+ const auto is = SharedXmlInputSource::getSharedInputSource(paths.path_to_jar);
+ is->open();
+
+ const auto unzipped_stream = unzip(is->getSrc(), is->getSize(), paths.path_in_jar);
+
+ xmlParserInputBufferPtr buf =
+ xmlParserInputBufferCreateMem(reinterpret_cast(unzipped_stream->data()),
+ static_cast(unzipped_stream->size()), XML_CHAR_ENCODING_NONE);
+ xmlParserInputPtr pInput = xmlNewIOInputStream(ctxt, buf, XML_CHAR_ENCODING_NONE);
+
+ // filling in the filename for the external entity to work
+ const auto root_pos = paths.path_in_jar.lastIndexOf('/') + 1;
+ const auto file_name = UnicodeString(paths.path_in_jar, root_pos);
+ pInput->filename = strdup(UStr::to_stdstr(&file_name).c_str());
+ return pInput;
+}
+#endif
+
xmlParserInputPtr LibXmlReader::xmlMyExternalEntityLoader(const char* URL, const char* /*ID*/, xmlParserCtxtPtr ctxt)
{
- xmlParserInputPtr ret = nullptr;
- // тут обработка имени файла для внешнего entity
- // при этом если в entity указан нормальный путь файловой системы, без всяких переменных окружения, архивов,
- // но можно с комбинацией ./ ../
- // то в url будет указан полный путь, относительно текущего файла. libxml сама склеит путь.
- // Иначе в url будет указан путь из самого entity, и дальше с ним над самому разбираться.
- //
- // в ctxt нет информации об обрабатываемом файле.
- ret = xmlNewInputFromFile(ctxt, URL);
- /*if (ret != nullptr) {
+ /*
+ * The function is called before each opening of a file within libxml, whether it is an xmlReadFile,
+ * or opening a file for an external entity.
+ * I.e., the path to the file can be checked or modified here. If the external entity specifies a path similar
+ * to the file path, then libxml itself forms the full path to the entity file by gluing the path from the current
+ * file and the one specified in the external entity.
+ * At the same time, there is no path to the source file or to the file in the entity in the function parameters.
+ */
+
+ UnicodeString string_url(URL);
+
+ // read entity string like "env:$FAR_HOME/hrd/catalog-console.xml"
+ static const UnicodeString env(u"env:");
+ if (!is_first_call && string_url.startsWith(env)) {
+ const auto exp = colorer::Environment::expandSpecialEnvironment(string_url);
+ string_url = UnicodeString(exp, env.length());
+ }
+#ifdef COLORER_FEATURE_ZIPINPUTSOURCE
+ if (string_url.startsWith(jar) || current_file->startsWith(jar)) {
+ const auto paths = LibXmlInputSource::getFullPathsToZip(string_url, is_first_call ? nullptr : current_file.get());
+ is_first_call = false;
+ xmlParserInputPtr ret = nullptr;
+ try {
+ ret = xmlZipEntityLoader(paths, ctxt);
+ } catch (...) {
+ }
return ret;
}
- if (defaultLoader != nullptr) {
- ret = defaultLoader(URL, ID, ctxt);
- }*/
+#endif
+ is_first_call = false;
+ // read it as a regular file
+ xmlParserInputPtr ret = xmlNewInputFromFile(ctxt, UStr::to_stdstr(&string_url).c_str());
+
return ret;
}
void LibXmlReader::xml_error_func(void* /*ctx*/, const char* msg, ...)
{
- static char buf[PATH_MAX];
+ static char buf[4096];
static int slen = 0;
va_list args;
@@ -121,7 +183,7 @@ void LibXmlReader::xml_error_func(void* /*ctx*/, const char* msg, ...)
* the line break. My enthusiasm about this is indescribable.
*/
va_start(args, msg);
- int rc = vsnprintf(&buf[slen], sizeof(buf) - slen, msg, args);
+ const int rc = vsnprintf(&buf[slen], sizeof(buf) - slen, msg, args);
va_end(args);
/* This shouldn't really happen */
@@ -133,7 +195,7 @@ void LibXmlReader::xml_error_func(void* /*ctx*/, const char* msg, ...)
}
slen += rc;
- if (slen >= (int) sizeof(buf)) {
+ if (slen >= static_cast(sizeof(buf))) {
/* truncated, let's flush this */
buf[sizeof(buf) - 1] = '\n';
slen = sizeof(buf);
diff --git a/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlReader.h b/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlReader.h
index d93a97a73..21a83c82a 100644
--- a/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlReader.h
+++ b/colorer/src/Colorer-library/src/colorer/xml/libxml2/LibXmlReader.h
@@ -10,28 +10,38 @@
class LibXmlReader
{
public:
- explicit LibXmlReader(const UnicodeString& source_file);
- LibXmlReader(const XmlInputSource& source);
+ explicit LibXmlReader(const XmlInputSource& source);
~LibXmlReader();
void parse(std::list& nodes);
- [[nodiscard]] bool isParsed() const
+ [[nodiscard]]
+ bool isParsed() const
{
return xmldoc != nullptr;
}
private:
- xmlDocPtr xmldoc;
- void getAttributes(const xmlNode* node, std::unordered_map& data);
+ xmlDocPtr xmldoc {nullptr};
+
+ explicit LibXmlReader(const UnicodeString& source_file);
+ static void getAttributes(const xmlNode* node, std::unordered_map& data);
void getChildren(xmlNode* node, XMLNode& result);
bool populateNode(xmlNode* node, XMLNode& result);
- UnicodeString getElementText(xmlNode* node);
+ static UnicodeString getElementText(const xmlNode* node);
+ /* the name of the file that is being processed */
+ static uUnicodeString current_file;
+ /* is this the first xmlMyExternalEntityLoader call for current file*/
+ static bool is_first_call;
static xmlParserInputPtr xmlMyExternalEntityLoader(const char* URL, const char* ID, xmlParserCtxtPtr ctxt);
static void xml_error_func(void* ctx, const char* msg, ...);
+
+#ifdef COLORER_FEATURE_ZIPINPUTSOURCE
+ static xmlParserInputPtr xmlZipEntityLoader(const PathInJar& paths, xmlParserCtxtPtr ctxt);
+#endif
};
#endif // COLORER_LIBXMLREADER_H
diff --git a/colorer/src/Colorer-library/src/colorer/xml/libxml2/SharedXmlInputSource.cpp b/colorer/src/Colorer-library/src/colorer/xml/libxml2/SharedXmlInputSource.cpp
new file mode 100644
index 000000000..68f6f602c
--- /dev/null
+++ b/colorer/src/Colorer-library/src/colorer/xml/libxml2/SharedXmlInputSource.cpp
@@ -0,0 +1,81 @@
+#include "colorer/xml/libxml2/SharedXmlInputSource.h"
+#include
+#include "colorer/Exception.h"
+#include "colorer/utils/Environment.h"
+
+std::unordered_map* SharedXmlInputSource::isHash = nullptr;
+
+int SharedXmlInputSource::addref()
+{
+ return ++ref_count;
+}
+
+int SharedXmlInputSource::delref()
+{
+ ref_count--;
+ if (ref_count <= 0) {
+ delete this;
+ return -1;
+ }
+ return ref_count;
+}
+
+SharedXmlInputSource* SharedXmlInputSource::getSharedInputSource(const UnicodeString& path)
+{
+ if (isHash == nullptr) {
+ isHash = new std::unordered_map();
+ }
+
+ const auto s = isHash->find(path);
+ if (s != isHash->end()) {
+ SharedXmlInputSource* sis = s->second;
+ sis->addref();
+ return sis;
+ }
+
+ auto* sis = new SharedXmlInputSource(path);
+ isHash->emplace(path, sis);
+ return sis;
+}
+
+SharedXmlInputSource::SharedXmlInputSource(const UnicodeString& path): source_path(path)
+{
+
+ is_open = false;
+}
+
+SharedXmlInputSource::~SharedXmlInputSource()
+{
+ // You don't need to delete an object that has been deleted from the array. We are already in the destructor.
+ isHash->erase(source_path);
+ if (isHash->empty()) {
+ delete isHash;
+ isHash = nullptr;
+ }
+}
+
+int SharedXmlInputSource::getSize() const
+{
+ return mSize;
+}
+
+byte* SharedXmlInputSource::getSrc() const
+{
+ return mSrc.get();
+}
+
+void SharedXmlInputSource::open()
+{
+ if (!is_open) {
+ std::ifstream f(UStr::to_stdstr(&source_path), std::ios::in | std::ios::binary);
+ if (!f.is_open()) {
+ COLORER_LOG_ERROR("failed to open %", source_path);
+ throw InputSourceException("failed to open " + source_path);
+ }
+ mSize = static_cast(colorer::Environment::getFileSize(source_path));
+ mSrc.reset(new byte[mSize]);
+ f.read(reinterpret_cast(mSrc.get()), mSize);
+ f.close();
+ is_open = true;
+ }
+}
\ No newline at end of file
diff --git a/colorer/src/Colorer-library/src/colorer/xml/libxml2/SharedXmlInputSource.h b/colorer/src/Colorer-library/src/colorer/xml/libxml2/SharedXmlInputSource.h
new file mode 100644
index 000000000..430dcab96
--- /dev/null
+++ b/colorer/src/Colorer-library/src/colorer/xml/libxml2/SharedXmlInputSource.h
@@ -0,0 +1,42 @@
+#ifndef SHAREDXMLINPUTSOURCE_H
+#define SHAREDXMLINPUTSOURCE_H
+
+#include
+#include "colorer/Common.h"
+
+class SharedXmlInputSource
+{
+ public:
+ static SharedXmlInputSource* getSharedInputSource(const UnicodeString& path);
+
+ /** Increments reference counter */
+ int addref();
+ /** Decrements reference counter */
+ int delref();
+
+ [[nodiscard]]
+ int getSize() const;
+ [[nodiscard]]
+ byte* getSrc() const;
+
+ void open();
+
+ SharedXmlInputSource(SharedXmlInputSource const&) = delete;
+ SharedXmlInputSource& operator=(SharedXmlInputSource const&) = delete;
+ SharedXmlInputSource(SharedXmlInputSource&&) = delete;
+ SharedXmlInputSource& operator=(SharedXmlInputSource&&) = delete;
+
+ private:
+ explicit SharedXmlInputSource(const UnicodeString& path);
+ ~SharedXmlInputSource();
+
+ static std::unordered_map* isHash;
+
+ int ref_count {1};
+ bool is_open {false};
+ UnicodeString source_path;
+ std::unique_ptr mSrc;
+ int mSize {0};
+};
+
+#endif // SHAREDXMLINPUTSOURCE_H
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/BaseEntityResolver.cpp b/colorer/src/Colorer-library/src/colorer/xml/xercesc/BaseEntityResolver.cpp
deleted file mode 100644
index f7def7bb6..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/BaseEntityResolver.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "colorer/xml/xercesc/BaseEntityResolver.h"
-#include
-#include "colorer/Exception.h"
-#include "colorer/xml/xercesc/XercesXmlInputSource.h"
-
-xercesc::InputSource* BaseEntityResolver::resolveEntity(xercesc::XMLResourceIdentifier* resourceIdentifier)
-{
- try {
- auto input_source =
- XercesXmlInputSource::newInstance(resourceIdentifier->getSystemId(), resourceIdentifier->getBaseURI());
- return input_source.release();
- } catch (InputSourceException& e) {
- COLORER_LOG_WARN(e.what());
- // Если не можем открыть external entity, то отдаем пустой файл.
- // Тем самым гасим ошибку загрузки схемы. Работа продолжится, но раскраска будет не до конца верной.
- auto empty_buf = new xercesc::MemBufInputSource((const XMLByte*) "", 0, "dummy");
- return empty_buf;
- }
-}
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/BaseEntityResolver.h b/colorer/src/Colorer-library/src/colorer/xml/xercesc/BaseEntityResolver.h
deleted file mode 100644
index 2fbeab859..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/BaseEntityResolver.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef COLORER_BASE_ENTITY_RESOLVER_H
-#define COLORER_BASE_ENTITY_RESOLVER_H
-
-#include
-
-class BaseEntityResolver : public xercesc::XMLEntityResolver
-{
- public:
- xercesc::InputSource* resolveEntity(xercesc::XMLResourceIdentifier* resourceIdentifier) override;
-};
-
-#endif // COLORER_BASE_ENTITY_RESOLVER_H
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/LocalFileXmlInputSource.cpp b/colorer/src/Colorer-library/src/colorer/xml/xercesc/LocalFileXmlInputSource.cpp
deleted file mode 100644
index cb9154bfe..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/LocalFileXmlInputSource.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "colorer/xml/xercesc/LocalFileXmlInputSource.h"
-#include
-#include
-#include "colorer/Exception.h"
-#include "colorer/utils/Environment.h"
-
-LocalFileXmlInputSource::LocalFileXmlInputSource(const XMLCh* path, const XMLCh* base)
-{
- auto upath = UnicodeString(path);
- auto ubase = UnicodeString(base);
-
- UnicodeString full_path;
- if (colorer::Environment::isRegularFile(&ubase, &upath, full_path)) {
- source_path = std::make_unique(full_path);
- setSystemId(UStr::to_xmlch(&full_path).get());
- // file is not open yet, only after makeStream
- }
- else {
- throw InputSourceException(full_path + " isn't regular file.");
- }
-}
-
-xercesc::BinInputStream* LocalFileXmlInputSource::makeStream() const
-{
- auto stream = std::make_unique(UStr::to_xmlch(source_path.get()).get());
- if (!stream->getIsOpen()) {
- throw InputSourceException("Can't open file '" + this->getPath() + "'");
- }
- return stream.release();
-}
-
-xercesc::InputSource* LocalFileXmlInputSource::getInputSource() const
-{
- return (xercesc::InputSource*) this;
-}
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/LocalFileXmlInputSource.h b/colorer/src/Colorer-library/src/colorer/xml/xercesc/LocalFileXmlInputSource.h
deleted file mode 100644
index c4456f605..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/LocalFileXmlInputSource.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#ifndef _COLORER_LOCALFILEINPUTSOURCE_H_
-#define _COLORER_LOCALFILEINPUTSOURCE_H_
-
-#include "colorer/xml/xercesc/XercesXmlInputSource.h"
-#include
-
-/**
- * LocalFileXmlInputSource класс для работы с InputSource - локальными файлами
- */
-class LocalFileXmlInputSource : public XercesXmlInputSource
-{
- public:
- LocalFileXmlInputSource(const XMLCh* path, const XMLCh* base);
- ~LocalFileXmlInputSource() override = default;
- [[nodiscard]] xercesc::BinInputStream* makeStream() const override;
- xercesc::InputSource* getInputSource() const override;
-
- LocalFileXmlInputSource(LocalFileXmlInputSource const&) = delete;
- LocalFileXmlInputSource& operator=(LocalFileXmlInputSource const&) = delete;
- LocalFileXmlInputSource(LocalFileXmlInputSource&&) = delete;
- LocalFileXmlInputSource& operator=(LocalFileXmlInputSource&&) = delete;
-
-};
-
-#endif //_COLORER_LOCALFILEINPUTSOURCE_H_
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/MemoryFile.h b/colorer/src/Colorer-library/src/colorer/xml/xercesc/MemoryFile.h
deleted file mode 100644
index 5d91ea483..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/MemoryFile.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef _COLORER_MEMORYFILE_H_
-#define _COLORER_MEMORYFILE_H_
-
-#include
-
-typedef struct{
- const unsigned char *stream;
- int length;
- int pointer;
- int error;
-} MemoryFile;
-
-voidpf ZCALLBACK mem_open_file_func (voidpf opaque, const char *filename, int mode);
-uLong ZCALLBACK mem_read_file_func (voidpf opaque, voidpf stream, void *buf, uLong size);
-uLong ZCALLBACK mem_write_file_func (voidpf opaque, voidpf stream, const void *buf, uLong size);
-long ZCALLBACK mem_tell_file_func (voidpf opaque, voidpf stream);
-long ZCALLBACK mem_seek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin);
-int ZCALLBACK mem_close_file_func (voidpf opaque, voidpf stream);
-int ZCALLBACK mem_error_file_func (voidpf opaque, voidpf stream);
-void fill_mem_filefunc (zlib_filefunc_def* pzlib_filefunc_def, MemoryFile *source);
-#endif
-
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/SharedXmlInputSource.cpp b/colorer/src/Colorer-library/src/colorer/xml/xercesc/SharedXmlInputSource.cpp
deleted file mode 100644
index 8730b8a4c..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/SharedXmlInputSource.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-#include "colorer/xml/xercesc/SharedXmlInputSource.h"
-#include
-#include "colorer/Exception.h"
-
-std::unordered_map* SharedXmlInputSource::isHash = nullptr;
-
-int SharedXmlInputSource::addref()
-{
- return ++ref_count;
-}
-
-int SharedXmlInputSource::delref()
-{
- ref_count--;
- if (ref_count <= 0) {
- delete this;
- return -1;
- }
- return ref_count;
-}
-
-SharedXmlInputSource::SharedXmlInputSource(uXercesXmlInputSource source)
-{
- ref_count = 1;
- input_source = std::move(source);
- auto pStream = input_source->makeStream();
- // don`t use dynamic_cast, see https://github.com/colorer/Colorer-library/issues/32
- std::unique_ptr bfis(
- static_cast(pStream));
- if (bfis == nullptr) {
- throw InputSourceException("can`t read " + input_source->getPath());
- }
- mSize = static_cast(bfis->getSize());
- mSrc.reset(new XMLByte[mSize]);
- bfis->readBytes(mSrc.get(), mSize);
-}
-
-SharedXmlInputSource::~SharedXmlInputSource()
-{
- // не нужно удалять объект, удаляемый из массива. мы и так уже в деструкторе
- isHash->erase(input_source->getPath());
- if (isHash->empty()) {
- delete isHash;
- isHash = nullptr;
- }
-}
-
-SharedXmlInputSource* SharedXmlInputSource::getSharedInputSource(const XMLCh* path,
- const XMLCh* base)
-{
- uXercesXmlInputSource tempis = XercesXmlInputSource::newInstance(path, base);
-
- if (isHash == nullptr) {
- isHash = new std::unordered_map();
- }
-
- UnicodeString d_id = UnicodeString(tempis->getInputSource()->getSystemId());
- auto s = isHash->find(d_id);
- if (s != isHash->end()) {
- SharedXmlInputSource* sis = s->second;
- sis->addref();
- return sis;
- }
- else {
- auto* sis = new SharedXmlInputSource(std::move(tempis));
- isHash->emplace(std::make_pair(d_id, sis));
- return sis;
- }
-}
-
-xercesc::InputSource* SharedXmlInputSource::getInputSource() const
-{
- return input_source->getInputSource();
-}
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/SharedXmlInputSource.h b/colorer/src/Colorer-library/src/colorer/xml/xercesc/SharedXmlInputSource.h
deleted file mode 100644
index 694132f6d..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/SharedXmlInputSource.h
+++ /dev/null
@@ -1,50 +0,0 @@
-#ifndef _COLORER_SHAREDXMLINPUTSOURCE_H_
-#define _COLORER_SHAREDXMLINPUTSOURCE_H_
-
-#include
-#include "colorer/Common.h"
-#include "colorer/xml/xercesc/XercesXmlInputSource.h"
-#include
-
-class SharedXmlInputSource
-{
- public:
- static SharedXmlInputSource* getSharedInputSource(const XMLCh* path, const XMLCh* base);
- [[nodiscard]] xercesc::InputSource* getInputSource() const;
-
- /** Increments reference counter */
- int addref();
- /** Decrements reference counter */
- int delref();
-
- [[nodiscard]] XMLSize_t getSize() const;
- [[nodiscard]] XMLByte* getSrc() const;
-
- SharedXmlInputSource(SharedXmlInputSource const&) = delete;
- SharedXmlInputSource& operator=(SharedXmlInputSource const&) = delete;
- SharedXmlInputSource(SharedXmlInputSource&&) = delete;
- SharedXmlInputSource& operator=(SharedXmlInputSource&&) = delete;
-
- private:
- explicit SharedXmlInputSource(uXercesXmlInputSource source);
- ~SharedXmlInputSource();
-
- static std::unordered_map* isHash;
-
- uXercesXmlInputSource input_source;
- int ref_count;
- std::unique_ptr mSrc;
- XMLSize_t mSize;
-};
-
-inline XMLSize_t SharedXmlInputSource::getSize() const
-{
- return mSize;
-}
-
-inline XMLByte* SharedXmlInputSource::getSrc() const
-{
- return mSrc.get();
-}
-
-#endif //_COLORER_SHAREDXMLINPUTSOURCE_H_
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/XercesXmlInputSource.cpp b/colorer/src/Colorer-library/src/colorer/xml/xercesc/XercesXmlInputSource.cpp
deleted file mode 100644
index 35fb4c80e..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/XercesXmlInputSource.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-#include "colorer/xml/xercesc/XercesXmlInputSource.h"
-#include "colorer/Exception.h"
-#include "colorer/xml/xercesc/LocalFileXmlInputSource.h"
-#ifdef COLORER_FEATURE_ZIPINPUTSOURCE
-#include "colorer/xml/xercesc/ZipXmlInputSource.h"
-#endif
-
-uXercesXmlInputSource XercesXmlInputSource::newInstance(const UnicodeString* path, const UnicodeString* base)
-{
- return newInstance(UStr::to_xmlch(path).get(), UStr::to_xmlch(base).get());
-}
-
-uXercesXmlInputSource XercesXmlInputSource::newInstance(const XMLCh* path, const XMLCh* base)
-{
- if (!path || (*path == '\0')) {
- throw InputSourceException("XmlInputSource::newInstance: path is empty");
- }
- if (xercesc::XMLString::startsWith(path, kJar) || (base != nullptr && xercesc::XMLString::startsWith(base, kJar))) {
-#ifdef COLORER_FEATURE_ZIPINPUTSOURCE
- return std::make_unique(path, base);
-#else
- throw InputSourceException("ZipXmlInputSource not supported");
-#endif
- }
- return std::make_unique(path, base);
-}
-
-bool XercesXmlInputSource::isUriFile(const UnicodeString& path, const UnicodeString* base)
-{
- if ((path.startsWith(kJar)) || (base && base->startsWith(kJar))) {
- return false;
- }
- return true;
-}
-
-uXercesXmlInputSource XercesXmlInputSource::createRelative(const UnicodeString& relPath)
-{
- return newInstance(UStr::to_xmlch(&relPath).get(), this->getInputSource()->getSystemId());
-}
-
-UnicodeString& XercesXmlInputSource::getPath() const
-{
- return *source_path;
-}
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/XercesXmlInputSource.h b/colorer/src/Colorer-library/src/colorer/xml/xercesc/XercesXmlInputSource.h
deleted file mode 100644
index 6d2488e5a..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/XercesXmlInputSource.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#ifndef COLORER_XERCESXMLINPUTSOURCE_H
-#define COLORER_XERCESXMLINPUTSOURCE_H
-
-#include
-#include "colorer/Common.h"
-
-inline const auto kJar = (const XMLCh *) u"jar:\0";
-
-class XercesXmlInputSource;
-
-typedef std::unique_ptr uXercesXmlInputSource;
-
-/**
- * @brief Class to creat xercesc::InputSource
- */
-class XercesXmlInputSource : public xercesc::InputSource
-{
- public:
- /**
- * @brief Tries statically create instance of InputSource object,
- * according to passed path string.
- * @param path Could be relative file location, absolute file
- */
- static uXercesXmlInputSource newInstance(const XMLCh* path, const XMLCh* base);
- static uXercesXmlInputSource newInstance(const UnicodeString* path,
- const UnicodeString* base = nullptr);
-
- /**
- * @brief Creates inherited InputSource with the same type
- * relatively to the current.
- * @param relPath Relative URI part.
- */
- virtual uXercesXmlInputSource createRelative(const UnicodeString& relPath);
-
- [[nodiscard]] virtual xercesc::InputSource* getInputSource() const = 0;
-
- ~XercesXmlInputSource() override = default;
-
- static bool isUriFile(const UnicodeString& path, const UnicodeString* base = nullptr);
-
- [[nodiscard]] UnicodeString& getPath() const;
-
- XercesXmlInputSource(XercesXmlInputSource const&) = delete;
- XercesXmlInputSource& operator=(XercesXmlInputSource const&) = delete;
- XercesXmlInputSource(XercesXmlInputSource&&) = delete;
- XercesXmlInputSource& operator=(XercesXmlInputSource&&) = delete;
-
- protected:
- XercesXmlInputSource() = default;
- uUnicodeString source_path;
-};
-
-#endif // COLORER_XERCESXMLINPUTSOURCE_H
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/XercesXmlReader.cpp b/colorer/src/Colorer-library/src/colorer/xml/xercesc/XercesXmlReader.cpp
deleted file mode 100644
index d0966cf44..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/XercesXmlReader.cpp
+++ /dev/null
@@ -1,112 +0,0 @@
-#include "colorer/xml/xercesc/XercesXmlReader.h"
-#include "colorer/xml/xercesc/BaseEntityResolver.h"
-#include "colorer/xml/xercesc/XmlParserErrorHandler.h"
-
-XercesXmlReader::XercesXmlReader(const XmlInputSource& source) : XercesXmlReader(source.getInputSource()) {}
-
-XercesXmlReader::XercesXmlReader(const xercesc::InputSource* in)
-{
- xercesc::XMLPlatformUtils::Initialize();
-
- xml_parser = new xercesc::XercesDOMParser();
- XmlParserErrorHandler error_handler;
- BaseEntityResolver resolver;
- xml_parser->setErrorHandler(&error_handler);
- xml_parser->setXMLEntityResolver(&resolver);
- xml_parser->setLoadExternalDTD(false);
- xml_parser->setSkipDTDValidation(true);
- xml_parser->setDisableDefaultEntityResolution(true);
-
- xml_parser->parse(*in);
- saw_error = error_handler.getSawErrors();
-}
-
-XercesXmlReader::~XercesXmlReader()
-{
- delete xml_parser;
- xercesc::XMLPlatformUtils::Terminate();
-}
-
-void XercesXmlReader::parse(std::list& nodes)
-{
- const xercesc::DOMDocument* doc = xml_parser->getDocument();
- const xercesc::DOMElement* root = doc->getDocumentElement();
-
- XMLNode result;
- populateNode(root, result);
- nodes.push_back(result);
-}
-
-bool XercesXmlReader::populateNode(const xercesc::DOMNode* node, XMLNode& result)
-{
- if (node->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) {
- return false;
- }
-
- // don`t use dynamic_cast, see https://github.com/colorer/Colorer-library/issues/32
- const auto* elem = static_cast(node);
- result.name = UnicodeString(elem->getNodeName());
- const auto* t = getElementText(elem);
- if (t != nullptr) {
- result.text = UnicodeString(t);
- }
-
- getChildren(elem, result);
-
- getAttributes(elem, result.attributes);
-
- return true;
-}
-
-void XercesXmlReader::getAttributes(const xercesc::DOMElement* node,
- std::unordered_map& data)
-{
- const auto* attrs = node->getAttributes();
- for (size_t i = 0; i < attrs->getLength(); i++) {
- const auto* attr = attrs->item(i);
- data.insert(std::pair(UnicodeString(attr->getNodeName()), UnicodeString(attr->getNodeValue())));
- }
-}
-
-void XercesXmlReader::getChildren(const xercesc::DOMNode* node, XMLNode& result)
-{
- for (const auto* elem = node->getFirstChild(); elem != nullptr; elem = elem->getNextSibling()) {
- if (elem->getNodeType() == xercesc::DOMNode::ENTITY_REFERENCE_NODE) {
- getChildren(elem, result);
- }
- else {
- if (XMLNode child; populateNode(elem, child)) {
- result.children.push_back(child);
- }
- }
- }
-}
-
-const XMLCh* XercesXmlReader::getElementText(const xercesc::DOMElement* blkel) const
-{
- const XMLCh* p = nullptr;
- // возможно текст указан как ...
- for (xercesc::DOMNode* child = blkel->getFirstChild(); child != nullptr; child = child->getNextSibling()) {
- if (child->getNodeType() == xercesc::DOMNode::CDATA_SECTION_NODE) {
- // ... блок CDATA: например ![CDATA[ match_regexp ]]
- const auto* cdata = static_cast(child);
- p = cdata->getData();
- break;
- }
- if (child->getNodeType() == xercesc::DOMNode::TEXT_NODE) {
- // ... текстовый блок match_regexp
- const auto* text = static_cast(child);
- const XMLCh* p1 = text->getData();
- auto* temp_string = xercesc::XMLString::replicate(p1);
- // перед блоком CDATA могут быть пустые строки, учитываем это
- xercesc::XMLString::trim(temp_string);
- if (*temp_string != '\0') {
- p = p1;
- xercesc::XMLString::release(&temp_string);
- break;
- }
- xercesc::XMLString::release(&temp_string);
- }
- }
- return p;
-}
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/XercesXmlReader.h b/colorer/src/Colorer-library/src/colorer/xml/xercesc/XercesXmlReader.h
deleted file mode 100644
index 3aab00aaa..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/XercesXmlReader.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef COLORER_XERCESXML_H
-#define COLORER_XERCESXML_H
-
-#include
-#include
-#include
-#include
-#include "colorer/Common.h"
-#include "colorer/xml/XMLNode.h"
-#include "colorer/xml/XmlInputSource.h"
-
-class XercesXmlReader
-{
- public:
-
- explicit XercesXmlReader(const xercesc::InputSource* in);
- explicit XercesXmlReader(const XmlInputSource& source);
-
- void parse(std::list& nodes);
-
- ~XercesXmlReader();
-
- [[nodiscard]] bool isParsed() const
- {
- return !saw_error;
- }
-
- private:
- bool saw_error = false;
- bool populateNode(const xercesc::DOMNode* node, XMLNode& result);
- void getAttributes(const xercesc::DOMElement* node, std::unordered_map& data);
- void getChildren(const xercesc::DOMNode* node, XMLNode& result);
- const XMLCh* getElementText(const xercesc::DOMElement* blkel) const;
-
- xercesc::XercesDOMParser* xml_parser;
-};
-#endif // COLORER_XERCESXML_H
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/XmlParserErrorHandler.cpp b/colorer/src/Colorer-library/src/colorer/xml/xercesc/XmlParserErrorHandler.cpp
deleted file mode 100644
index 8fec67500..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/XmlParserErrorHandler.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "colorer/xml/xercesc/XmlParserErrorHandler.h"
-#include "colorer/Common.h"
-
-void XmlParserErrorHandler::warning(const xercesc::SAXParseException& toCatch)
-{
- COLORER_LOG_WARN("Warning at file %, line %, column %. Message: %",
- UStr::to_stdstr(toCatch.getSystemId()), toCatch.getLineNumber(),
- toCatch.getColumnNumber(), UStr::to_stdstr(toCatch.getMessage()));
-}
-
-void XmlParserErrorHandler::error(const xercesc::SAXParseException& toCatch)
-{
- fSawErrors = true;
- COLORER_LOG_ERROR("Error at file %, line %, column %. Message: %",
- UStr::to_stdstr(toCatch.getSystemId()), toCatch.getLineNumber(),
- toCatch.getColumnNumber(), UStr::to_stdstr(toCatch.getMessage()));
-}
-
-void XmlParserErrorHandler::fatalError(const xercesc::SAXParseException& toCatch)
-{
- fSawErrors = true;
- COLORER_LOG_ERROR("Fatal error at file %, line %, column %. Message: %",
- UStr::to_stdstr(toCatch.getSystemId()), toCatch.getLineNumber(),
- toCatch.getColumnNumber(), UStr::to_stdstr(toCatch.getMessage()));
-}
-
-bool XmlParserErrorHandler::getSawErrors() const
-{
- return fSawErrors;
-}
-
-void XmlParserErrorHandler::resetErrors()
-{
- fSawErrors = false;
-}
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/XmlParserErrorHandler.h b/colorer/src/Colorer-library/src/colorer/xml/xercesc/XmlParserErrorHandler.h
deleted file mode 100644
index 51e6e2aae..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/XmlParserErrorHandler.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef COLORER_XML_PARSER_ERROR_HANDLER_H
-#define COLORER_XML_PARSER_ERROR_HANDLER_H
-
-#include
-#include
-
-/* XmlParserErrorHandler - class to catch errors and warnings from the XML Parser*/
-class XmlParserErrorHandler : public xercesc::ErrorHandler
-{
- public:
- XmlParserErrorHandler() : fSawErrors {false} {}
-
- void warning(const xercesc::SAXParseException& toCatch) override;
- void error(const xercesc::SAXParseException& toCatch) override;
- void fatalError(const xercesc::SAXParseException& toCatch) override;
- void resetErrors() override;
- [[nodiscard]] bool getSawErrors() const;
-
- private:
- /* fSawErrors
- This is set if we get any errors, and is queryable via a getter
- method. Its used by the main code to suppress output if there are
- errors. */
- bool fSawErrors;
-};
-
-#endif // COLORER_XML_PARSER_ERROR_HANDLER_H
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/ZipXmlInputSource.cpp b/colorer/src/Colorer-library/src/colorer/xml/xercesc/ZipXmlInputSource.cpp
deleted file mode 100644
index 7b91665bc..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/ZipXmlInputSource.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
-#include "colorer/xml/xercesc/ZipXmlInputSource.h"
-#include "colorer/Exception.h"
-#include "colorer/xml/xercesc/MemoryFile.h"
-
-ZipXmlInputSource::ZipXmlInputSource(const XMLCh* path, const XMLCh* base)
-{
- create(path, base);
-}
-
-void ZipXmlInputSource::create(const XMLCh* path, const XMLCh* base)
-{
- const auto kJar_len = xercesc::XMLString::stringLen(kJar);
- if (xercesc::XMLString::startsWith(path, kJar)) {
- int path_idx = xercesc::XMLString::lastIndexOf(path, '!');
- if (path_idx == -1) {
- throw InputSourceException("Bad jar uri format: " + UnicodeString(path));
- }
-
- auto bpath = std::make_unique(path_idx - kJar_len + 1);
- xercesc::XMLString::subString(bpath.get(), path, kJar_len, path_idx);
- jar_input_source = SharedXmlInputSource::getSharedInputSource(bpath.get(), base);
-
- in_jar_location = std::make_unique(UnicodeString(path), path_idx + 1);
-
- } else if (base != nullptr && xercesc::XMLString::startsWith(base, kJar)) {
- int base_idx = xercesc::XMLString::lastIndexOf(base, '!');
- if (base_idx == -1) {
- throw InputSourceException("Bad jar uri format: " + UnicodeString(path));
- }
-
- auto bpath = std::make_unique(base_idx - kJar_len + 1);
- xercesc::XMLString::subString(bpath.get(), base, kJar_len, base_idx);
- jar_input_source = SharedXmlInputSource::getSharedInputSource(bpath.get(), nullptr);
-
- auto in_base = std::make_unique(UnicodeString(base), base_idx + 1);
- UnicodeString d_path = UnicodeString(path);
- in_jar_location = getAbsolutePath(in_base.get(), &d_path);
-
- } else {
- throw InputSourceException("Can't create jar source");
- }
-
- UnicodeString str("jar:");
- str.append(UnicodeString(jar_input_source->getInputSource()->getSystemId()));
- str.append("!");
- str.append(*in_jar_location);
- setSystemId(UStr::to_xmlch(&str).get());
- source_path = std::make_unique(str);
-}
-
-ZipXmlInputSource::~ZipXmlInputSource()
-{
- jar_input_source->delref();
-}
-
-xercesc::InputSource* ZipXmlInputSource::getInputSource() const
-{
- return (xercesc::InputSource*) this;
-}
-
-xercesc::BinInputStream* ZipXmlInputSource::makeStream() const
-{
- return new UnZip(jar_input_source->getSrc(), jar_input_source->getSize(), in_jar_location.get());
-}
-
-uUnicodeString ZipXmlInputSource::getAbsolutePath(const UnicodeString* basePath, const UnicodeString* relPath)
-{
- auto root_pos = basePath->lastIndexOf('/');
- auto root_pos2 = basePath->lastIndexOf('\\');
- if (root_pos2 > root_pos) {
- root_pos = root_pos2;
- }
- if (root_pos == -1) {
- root_pos = 0;
- } else {
- root_pos++;
- }
- auto newPath = std::make_unique();
- newPath->append(UnicodeString(*basePath, 0, root_pos)).append(*relPath);
- return newPath;
-}
-
-UnZip::UnZip(const XMLByte* src, XMLSize_t size, const UnicodeString* path) : mPos(0), mBoundary(0), stream(nullptr), len(0)
-{
- MemoryFile mf;
- mf.stream = src;
- mf.length = (int) size;
- zlib_filefunc_def zlib_ff;
- fill_mem_filefunc(&zlib_ff, &mf);
-
- unzFile fid = unzOpen2(nullptr, &zlib_ff);
-
- if (!fid) {
- unzClose(fid);
- throw InputSourceException("Can't locate file in JAR content: '" + *path + "'");
- }
- int ret = unzLocateFile(fid, UStr::to_stdstr(path).c_str(), 0);
- if (ret != UNZ_OK) {
- unzClose(fid);
- throw InputSourceException("Can't locate file in JAR content: '" + *path + "'");
- }
- unz_file_info file_info;
- ret = unzGetCurrentFileInfo(fid, &file_info, nullptr, 0, nullptr, 0, nullptr, 0);
- if (ret != UNZ_OK) {
- unzClose(fid);
- throw InputSourceException("Can't retrieve current file in JAR content: '" + *path + "'");
- }
-
- len = file_info.uncompressed_size;
- stream.reset(new byte[len]);
- ret = unzOpenCurrentFile(fid);
- if (ret != UNZ_OK) {
- unzClose(fid);
- throw InputSourceException("Can't open current file in JAR content: '" + *path + "'");
- }
- ret = unzReadCurrentFile(fid, stream.get(), len);
- if (ret <= 0) {
- unzClose(fid);
- throw InputSourceException("Can't read current file in JAR content: '" + *path + "' (" + ret + ")");
- }
- ret = unzCloseCurrentFile(fid);
- if (ret == UNZ_CRCERROR) {
- unzClose(fid);
- throw InputSourceException("Bad JAR file CRC");
- }
- unzClose(fid);
-}
-
-XMLFilePos UnZip::curPos() const
-{
- return mPos;
-}
-
-XMLSize_t UnZip::readBytes(XMLByte* const toFill, const XMLSize_t maxToRead)
-{
- mBoundary = len;
- XMLSize_t remain = mBoundary - mPos;
- XMLSize_t toRead = (maxToRead < remain) ? maxToRead : remain;
- memcpy(toFill, stream.get() + mPos, toRead);
- mPos += toRead;
- return toRead;
-}
-
-const XMLCh* UnZip::getContentType() const
-{
- return nullptr;
-}
-
-UnZip::~UnZip() = default;
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/ZipXmlInputSource.h b/colorer/src/Colorer-library/src/colorer/xml/xercesc/ZipXmlInputSource.h
deleted file mode 100644
index 2450534ed..000000000
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/ZipXmlInputSource.h
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef _COLORER_ZIPINPUTSOURCE_H_
-#define _COLORER_ZIPINPUTSOURCE_H_
-
-#include "colorer/xml/xercesc/SharedXmlInputSource.h"
-#include "colorer/xml/xercesc/XercesXmlInputSource.h"
-#include
-
-class ZipXmlInputSource : public XercesXmlInputSource
-{
- public:
- ZipXmlInputSource(const XMLCh* path, const XMLCh* base);
- ~ZipXmlInputSource() override;
- [[nodiscard]] xercesc::BinInputStream* makeStream() const override;
- xercesc::InputSource* getInputSource() const override;
-
- static uUnicodeString getAbsolutePath(const UnicodeString* basePath, const UnicodeString* relPath);
-
- ZipXmlInputSource(ZipXmlInputSource const&) = delete;
- ZipXmlInputSource& operator=(ZipXmlInputSource const&) = delete;
- ZipXmlInputSource(ZipXmlInputSource&&) = delete;
- ZipXmlInputSource& operator=(ZipXmlInputSource&&) = delete;
-
- private:
- void create(const XMLCh* path, const XMLCh* base);
- uUnicodeString in_jar_location;
- SharedXmlInputSource* jar_input_source = nullptr;
-};
-
-class UnZip : public xercesc::BinInputStream
-{
- public:
- UnZip(const XMLByte* src, XMLSize_t size, const UnicodeString* path);
- ~UnZip() override;
-
- [[nodiscard]] XMLFilePos curPos() const override;
- XMLSize_t readBytes(XMLByte* toFill, XMLSize_t maxToRead) override;
- [[nodiscard]] const XMLCh* getContentType() const override;
-
- UnZip(UnZip const&) = delete;
- UnZip& operator=(UnZip const&) = delete;
- UnZip(UnZip&&) = delete;
- UnZip& operator=(UnZip&&) = delete;
-
- private:
- XMLSize_t mPos;
- XMLSize_t mBoundary;
- std::unique_ptr stream;
- int len;
-};
-
-#endif //_COLORER_ZIPINPUTSOURCE_H_
diff --git a/colorer/src/Colorer-library/src/colorer/xml/xercesc/MemoryFile.cpp b/colorer/src/Colorer-library/src/colorer/zip/MemoryFile.cpp
similarity index 58%
rename from colorer/src/Colorer-library/src/colorer/xml/xercesc/MemoryFile.cpp
rename to colorer/src/Colorer-library/src/colorer/zip/MemoryFile.cpp
index b8028d1b2..2632af9ec 100644
--- a/colorer/src/Colorer-library/src/colorer/xml/xercesc/MemoryFile.cpp
+++ b/colorer/src/Colorer-library/src/colorer/zip/MemoryFile.cpp
@@ -1,12 +1,60 @@
-#include "colorer/xml/xercesc/MemoryFile.h"
+#include "colorer/zip/MemoryFile.h"
#include
+#include "colorer/Exception.h"
+
+std::unique_ptr> unzip(const byte* src, int size, const UnicodeString& path_in_zip)
+{
+ MemoryFile mf;
+ mf.stream = src;
+ mf.length = size;
+ zlib_filefunc_def zlib_ff;
+ fill_mem_filefunc(&zlib_ff, &mf);
+
+ unzFile fid = unzOpen2(nullptr, &zlib_ff);
+
+ if (!fid) {
+ unzClose(fid);
+ throw InputSourceException("Can't locate file in JAR content: '" + path_in_zip + "'");
+ }
+ int ret = unzLocateFile(fid, UStr::to_stdstr(&path_in_zip).c_str(), 0);
+ if (ret != UNZ_OK) {
+ unzClose(fid);
+ throw InputSourceException("Can't locate file in JAR content: '" + path_in_zip + "'");
+ }
+ unz_file_info file_info;
+ ret = unzGetCurrentFileInfo(fid, &file_info, nullptr, 0, nullptr, 0, nullptr, 0);
+ if (ret != UNZ_OK) {
+ unzClose(fid);
+ throw InputSourceException("Can't retrieve current file in JAR content: '" + path_in_zip + "'");
+ }
+
+ const auto len = file_info.uncompressed_size;
+ auto stream = std::make_unique>(len);
+ ret = unzOpenCurrentFile(fid);
+ if (ret != UNZ_OK) {
+ unzClose(fid);
+ throw InputSourceException("Can't open current file in JAR content: '" + path_in_zip + "'");
+ }
+ ret = unzReadCurrentFile(fid, stream->data(), len);
+ if (ret <= 0) {
+ unzClose(fid);
+ throw InputSourceException("Can't read current file in JAR content: '" + path_in_zip + "' (" + ret + ")");
+ }
+ ret = unzCloseCurrentFile(fid);
+ if (ret == UNZ_CRCERROR) {
+ unzClose(fid);
+ throw InputSourceException("Bad JAR file CRC");
+ }
+ unzClose(fid);
+ return stream;
+}
voidpf ZCALLBACK mem_open_file_func(voidpf opaque, const char* /*filename*/, int /*mode*/)
{
MemoryFile* mf = (MemoryFile*) opaque;
mf->error = 0;
mf->pointer = 0;
- return (voidpf) 0x666888; //-V566
+ return (voidpf) 0x666888; //-V566
}
uLong ZCALLBACK mem_read_file_func(voidpf opaque, voidpf /*stream*/, void* buf, uLong size)
diff --git a/colorer/src/Colorer-library/src/colorer/zip/MemoryFile.h b/colorer/src/Colorer-library/src/colorer/zip/MemoryFile.h
new file mode 100644
index 000000000..5f6418100
--- /dev/null
+++ b/colorer/src/Colorer-library/src/colorer/zip/MemoryFile.h
@@ -0,0 +1,26 @@
+#ifndef COLORER_MEMORYFILE_H
+#define COLORER_MEMORYFILE_H
+
+#include
+#include
+#include "colorer/Common.h"
+
+typedef struct
+{
+ const unsigned char* stream;
+ int length;
+ int pointer;
+ int error;
+} MemoryFile;
+
+std::unique_ptr> unzip(const byte* src, int size, const UnicodeString& path_in_zip);
+voidpf ZCALLBACK mem_open_file_func(voidpf opaque, const char* filename, int mode);
+uLong ZCALLBACK mem_read_file_func(voidpf opaque, voidpf stream, void* buf, uLong size);
+uLong ZCALLBACK mem_write_file_func(voidpf opaque, voidpf stream, const void* buf, uLong size);
+long ZCALLBACK mem_tell_file_func(voidpf opaque, voidpf stream);
+long ZCALLBACK mem_seek_file_func(voidpf opaque, voidpf stream, uLong offset, int origin);
+int ZCALLBACK mem_close_file_func(voidpf opaque, voidpf stream);
+int ZCALLBACK mem_error_file_func(voidpf opaque, voidpf stream);
+void fill_mem_filefunc(zlib_filefunc_def* pzlib_filefunc_def, MemoryFile* source);
+
+#endif
diff --git a/far2l/CMakeLists.txt b/far2l/CMakeLists.txt
index 4277ee40a..070b9e0be 100644
--- a/far2l/CMakeLists.txt
+++ b/far2l/CMakeLists.txt
@@ -280,11 +280,14 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
#TODO
else()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/DE/far2l.desktop" "${CMAKE_CURRENT_BINARY_DIR}/DE/far2l.desktop")
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/DE/far2ledit.desktop" "${CMAKE_CURRENT_BINARY_DIR}/DE/far2ledit.desktop")
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/DE/icons" DESTINATION "share" USE_SOURCE_PERMISSIONS COMPONENT desktop FILES_MATCHING PATTERN "*")
- # Have to make desktop file executable, see:
+ # Have to make desktop files executable, see:
# https://wiki.ubuntu.com/SecurityTeam/Policies#Execute-Permission_Bit_Required
- install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DE/far2l.desktop" DESTINATION "share/applications" COMPONENT desktop
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DE/far2l.desktop" "${CMAKE_CURRENT_BINARY_DIR}/DE/far2ledit.desktop"
+ DESTINATION "share/applications"
+ COMPONENT desktop
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)
endif()
diff --git a/far2l/DE/far2ledit.desktop b/far2l/DE/far2ledit.desktop
new file mode 100644
index 000000000..64c4d0eba
--- /dev/null
+++ b/far2l/DE/far2ledit.desktop
@@ -0,0 +1,13 @@
+[Desktop Entry]
+Type=Application
+Name=Far2l Editor
+Name[ru]=Редактор Far2l
+Comment=Edit text files
+Comment[ru]=Редактирование текстовых файлов
+Exec=far2ledit %f
+TryExec=far2ledit
+Terminal=true
+MimeType=text/plain;
+Categories=Utility;TextEditor;
+Icon=far2ledit
+Keywords=editor;console;text;
diff --git a/far2l/DE/icons/far2ledit.svg b/far2l/DE/icons/far2ledit.svg
new file mode 100644
index 000000000..ba513ca22
--- /dev/null
+++ b/far2l/DE/icons/far2ledit.svg
@@ -0,0 +1,22 @@
+
diff --git a/far2l/DE/icons/hicolor/1024x1024/apps/far2ledit.svg b/far2l/DE/icons/hicolor/1024x1024/apps/far2ledit.svg
new file mode 100644
index 000000000..7107aa215
--- /dev/null
+++ b/far2l/DE/icons/hicolor/1024x1024/apps/far2ledit.svg
@@ -0,0 +1,22 @@
+
diff --git a/far2l/DE/icons/hicolor/128x128/apps/far2ledit.svg b/far2l/DE/icons/hicolor/128x128/apps/far2ledit.svg
new file mode 100644
index 000000000..ba513ca22
--- /dev/null
+++ b/far2l/DE/icons/hicolor/128x128/apps/far2ledit.svg
@@ -0,0 +1,22 @@
+
diff --git a/far2l/DE/icons/hicolor/16x16/apps/far2ledit.svg b/far2l/DE/icons/hicolor/16x16/apps/far2ledit.svg
new file mode 100644
index 000000000..66a815349
--- /dev/null
+++ b/far2l/DE/icons/hicolor/16x16/apps/far2ledit.svg
@@ -0,0 +1,22 @@
+
diff --git a/far2l/DE/icons/hicolor/192x192/apps/far2ledit.svg b/far2l/DE/icons/hicolor/192x192/apps/far2ledit.svg
new file mode 100644
index 000000000..7a9b7da03
--- /dev/null
+++ b/far2l/DE/icons/hicolor/192x192/apps/far2ledit.svg
@@ -0,0 +1,22 @@
+
diff --git a/far2l/DE/icons/hicolor/24x24/apps/far2ledit.svg b/far2l/DE/icons/hicolor/24x24/apps/far2ledit.svg
new file mode 100644
index 000000000..0338521cc
--- /dev/null
+++ b/far2l/DE/icons/hicolor/24x24/apps/far2ledit.svg
@@ -0,0 +1,22 @@
+
diff --git a/far2l/DE/icons/hicolor/256x256/apps/far2ledit.svg b/far2l/DE/icons/hicolor/256x256/apps/far2ledit.svg
new file mode 100644
index 000000000..1a3b49651
--- /dev/null
+++ b/far2l/DE/icons/hicolor/256x256/apps/far2ledit.svg
@@ -0,0 +1,22 @@
+
diff --git a/far2l/DE/icons/hicolor/32x32/apps/far2ledit.svg b/far2l/DE/icons/hicolor/32x32/apps/far2ledit.svg
new file mode 100644
index 000000000..1225d5d0f
--- /dev/null
+++ b/far2l/DE/icons/hicolor/32x32/apps/far2ledit.svg
@@ -0,0 +1,22 @@
+
diff --git a/far2l/DE/icons/hicolor/48x48/apps/far2ledit.svg b/far2l/DE/icons/hicolor/48x48/apps/far2ledit.svg
new file mode 100644
index 000000000..2b07e727d
--- /dev/null
+++ b/far2l/DE/icons/hicolor/48x48/apps/far2ledit.svg
@@ -0,0 +1,22 @@
+
diff --git a/far2l/DE/icons/hicolor/512x512/apps/far2ledit.svg b/far2l/DE/icons/hicolor/512x512/apps/far2ledit.svg
new file mode 100644
index 000000000..822b443ee
--- /dev/null
+++ b/far2l/DE/icons/hicolor/512x512/apps/far2ledit.svg
@@ -0,0 +1,22 @@
+
diff --git a/far2l/DE/icons/hicolor/64x64/apps/far2ledit.svg b/far2l/DE/icons/hicolor/64x64/apps/far2ledit.svg
new file mode 100644
index 000000000..db1fa4138
--- /dev/null
+++ b/far2l/DE/icons/hicolor/64x64/apps/far2ledit.svg
@@ -0,0 +1,22 @@
+
diff --git a/far2l/DE/icons/hicolor/72x72/apps/far2ledit.svg b/far2l/DE/icons/hicolor/72x72/apps/far2ledit.svg
new file mode 100644
index 000000000..24b654af8
--- /dev/null
+++ b/far2l/DE/icons/hicolor/72x72/apps/far2ledit.svg
@@ -0,0 +1,22 @@
+
diff --git a/far2l/DE/icons/hicolor/96x96/apps/far2ledit.svg b/far2l/DE/icons/hicolor/96x96/apps/far2ledit.svg
new file mode 100644
index 000000000..1c2caa278
--- /dev/null
+++ b/far2l/DE/icons/hicolor/96x96/apps/far2ledit.svg
@@ -0,0 +1,22 @@
+
diff --git a/far2l/bootstrap/scripts/FarEng.hlf.m4 b/far2l/bootstrap/scripts/FarEng.hlf.m4
index 3e0219093..197cb433b 100644
--- a/far2l/bootstrap/scripts/FarEng.hlf.m4
+++ b/far2l/bootstrap/scripts/FarEng.hlf.m4
@@ -130,11 +130,12 @@ $ # FAR2L features - Getting Started#
#UI Backends#
FAR2L has 3 base UI Backends (see details in ~UI backends~@UIBackends@):
- - #GUI#: uses wxWidgets, works in graphics mode, ideal UX, requires a lot of X11 dependencies;
+ - #GUI#: uses wxWidgets, works in graphics mode, #ideal UX#
+(might add dependencies to your desktop environment, e.g. wxWidgets toolkit and related packages);
- #TTY|Xi#: works in terminal mode, requires a dependency on pair X11 libraries
-(to access clipboard and to get state of all keyboard modifiers), almost perfect UX;
+(to access clipboard and to get state of all keyboard modifiers), #almost perfect UX#;
- #TTY|X#: works in terminal mode, uses X11 to access clipboard, all keyboard works via terminal;
- - #TTY#: plain terminal mode, no X11 dependencies, UX with some restrictions
+ - #TTY#: plain terminal mode, no X11 dependencies, #UX with some restrictions#
(works fully when running in the terminal emulators,
which provide clipboard access and has their advanced keyboard-protocols, see list below).
You can see FAR2L version and currently used backend in window title or by ~pseudo-command~@SpecCmd@ #far:about#.
@@ -300,9 +301,6 @@ runs inside.
Use PRIMARY selection instead of CLIPBOARD X11 selection. This argument applies only to far2l
that runs with WX backend.
- Backend-specific options also can be set via the #FAR2L_ARGS# environment variable
-(for example: #export FAR2L_ARGS="--tty --nodetect --ee"# and then simple #far2l# to force start only TTY backend).
-
#FAR2L command-line options:#
#-a#
@@ -347,7 +345,7 @@ and from the path given at the "~Path for personal plugins~@PluginsManagerSettin
Macros with the "Run after FAR2L start" option set will not be run when FAR2L is started.
#-u # or #-u #
- Allows to specify separate settings identity or FS location.
+ Allows to specify separate settings identity or FS location (it override #FARSETTINGS# environment variable value).
#-u #: in path/.config/ (if path is full path)
#-u #: in ~~/.config/far2l/custom/identity/ or in $XDG_CONFIG_HOME/far2l/custom/identity/
@@ -380,6 +378,10 @@ passive command executes first (passive panel activates temporary). Односи
Example: far ma:Far20.7z "macro:post MsgBox(\\"FAR2L\\",\\"Successfully started\\")"
+ All options (except #-h# and #-u#) also can be set via the #FAR2L_ARGS# environment variable
+(for example: #export FAR2L_ARGS="--tty --nodetect --ee"# and then simple #far2l# to force start only TTY backend).
+
+
@KeyRef
$ #Keyboard reference#
diff --git a/far2l/bootstrap/scripts/FarRus.hlf.m4 b/far2l/bootstrap/scripts/FarRus.hlf.m4
index 5d2370d53..cadc1270a 100644
--- a/far2l/bootstrap/scripts/FarRus.hlf.m4
+++ b/far2l/bootstrap/scripts/FarRus.hlf.m4
@@ -134,11 +134,12 @@ $ # Особенности FAR2L - начало работы#
#Режимы интерфейса#
У FAR2L три основных бекенда отрисовки (подробности в ~Режимы интерфейса~@UIBackends@):
- - #GUI# - на базе wxWidgets, работает в графическом режиме, идеальный UX, куча X11 зависимостей;
+ - #GUI# - на базе wxWidgets, работает в графическом режиме, #идеальный UX#
+(возможны дополнительные зависимости к вашей desktop environment: wxWidgets toolkit и соответствующие пакеты);
- #TTY|Xi# - работает в терминальном режиме, зависимости буквально от пары иксовых либ
-(для поддержки буфера обмена и всех-всех сочетаний клавиш в окружениях X11), почти идеальный UX;
+(для поддержки буфера обмена и всех-всех сочетаний клавиш в окружениях X11), #почти идеальный UX#;
- #TTY|X# - работает в терминальном режиме, через X11 поддержка буфера обмена, клавиатура через возможности терминала;
- - #TTY# - чистый терминальный режим, никаких иксовых зависимостей, UX с некоторыми ограничениями
+ - #TTY# - чистый терминальный режим, никаких иксовых зависимостей, #UX с некоторыми ограничениями#
(полноценно работает при запуске в эмуляторах терминалов,
предоставляющих возможность доступа к буферу обмена и расширенную информацию о клавиатурных событиях, см. список ниже).
Версию FAR2L и используемый бекенд можно увидеть в заголовке окна или через ~псевдо-команду~@SpecCmd@ #far:about#.
@@ -306,9 +307,6 @@ far2l. В этом случае far2l автоматически использ
Использовать PRIMARY selection вместо CLIPBOARD X11 selection. Этот аргумент применим только для
far2l, который работает в режиме WX.
- Параметры режимов интерфейса также могут быть установлены через переменную окружения #FAR2L_ARGS#
-(например: #export FAR2L_ARGS="--tty --nodetect --ee"# и затем просто #far2l# для принудительного запуска только режима TTY).
-
#FAR2L command-line options:#
#-a#
@@ -356,7 +354,7 @@ far2l, который работает в режиме WX.
#-u # or #-u #
Позволяет использовать раздельные настройки для различных пользователей
-или указать расположение настроек в файловой системе.
+или указать расположение настроек в файловой системе (перекрывает значение переменной среды #FARSETTINGS#).
#-u #: in path/.config/ (если path полный путь)
#-u #: в ~~/.config/far2l/custom/identity/ или в $XDG_CONFIG_HOME/far2l/custom/identity/
@@ -387,6 +385,10 @@ far2l, который работает в режиме WX.
Пример: far ma:Far20.7z "macro:post MsgBox(\\"FAR2L\\",\\"Successfully started\\")"
+ Все параметры (кроме #-h# и #-u#) также могут быть установлены через переменную окружения #FAR2L_ARGS#
+(например: #export FAR2L_ARGS="--tty --nodetect --ee"# и затем просто #far2l# для принудительного запуска только режима TTY).
+
+
@KeyRef
$ #Клавиатурные команды#
diff --git a/far2l/bootstrap/scripts/FarUkr.hlf.m4 b/far2l/bootstrap/scripts/FarUkr.hlf.m4
index bf35577af..6d06eb96a 100644
--- a/far2l/bootstrap/scripts/FarUkr.hlf.m4
+++ b/far2l/bootstrap/scripts/FarUkr.hlf.m4
@@ -161,8 +161,6 @@ far2l. У цьому випадку far2l автоматично викорис
Використовувати PRIMARY selection замість CLIPBOARD X11 selection. Цей аргумент застосовний тільки для
far2l, який працює у режимі WX.
- Backend-specific options also can be set via the #FAR2L_ARGS# environment variable
-(for example: #export FAR2L_ARGS="--tty --nodetect --ee"# and then simple #far2l# to force start only TTY backend).
#FAR2L command-line options:#
#-a#
@@ -209,7 +207,7 @@ far2l, який працює у режимі WX.
При старті FAR2L не виконуватиме макрокоманди з опцією "Виконувати після запуску FAR2L".
#-u #
- Дозволяє використовувати різні настройки для різних користувачів.
+ Дозволяє використовувати різні настройки для різних користувачів (it override #FARSETTINGS# environment variable value).
Наприклад: far -u guest
#-v #
@@ -243,6 +241,10 @@ far2l, який працює у режимі WX.
Приклад: far ma:c:\\Far20.7z "macro:post MsgBox(\"FAR2L\",\"Successfully started\")"
+ All options (except #-h# and #-u#) also can be set via the #FAR2L_ARGS# environment variable
+(for example: #export FAR2L_ARGS="--tty --nodetect --ee"# and then simple #far2l# to force start only TTY backend).
+
+
@KeyRef
$ #Клавіатурні команди#
diff --git a/far2l/far2sdk/farplug-mb.h b/far2l/far2sdk/farplug-mb.h
index f433aa531..efba3f8de 100644
--- a/far2l/far2sdk/farplug-mb.h
+++ b/far2l/far2sdk/farplug-mb.h
@@ -282,6 +282,7 @@ namespace oldfar
enum FARLISTFINDFLAGS
{
LIFIND_EXACTMATCH = 0x00000001,
+ LIFIND_KEEPAMPERSAND = 0x00000002,
};
struct FarListFind
diff --git a/far2l/far2sdk/farplug-wide.h b/far2l/far2sdk/farplug-wide.h
index b59cd3ba8..e938d32c4 100644
--- a/far2l/far2sdk/farplug-wide.h
+++ b/far2l/far2sdk/farplug-wide.h
@@ -459,6 +459,7 @@ struct FarListPos
enum FARLISTFINDFLAGS
{
LIFIND_EXACTMATCH = 0x00000001,
+ LIFIND_KEEPAMPERSAND = 0x00000002,
};
struct FarListFind
diff --git a/far2l/src/cmdline.cpp b/far2l/src/cmdline.cpp
index d6e08ccbd..8292f7ad1 100644
--- a/far2l/src/cmdline.cpp
+++ b/far2l/src/cmdline.cpp
@@ -986,6 +986,7 @@ void FarAbout(PluginManager &Plugins)
static const char * const env_vars[] = {
"HOSTNAME", "USER",
+ "FARSETTINGS", "FAR2L_ARGS",
"XDG_SESSION_TYPE",
"TERM", "COLORTERM",
"GDK_BACKEND", "DESKTOP_SESSION",
diff --git a/far2l/src/filepanels.cpp b/far2l/src/filepanels.cpp
index 86151a923..6e85f6b00 100644
--- a/far2l/src/filepanels.cpp
+++ b/far2l/src/filepanels.cpp
@@ -237,24 +237,24 @@ void FilePanels::UpdateCmdLineVisibility(bool repos)
new_cl_x2 = left_x2 - 1;
}
}
- if (new_cl_x1 != cl_x1 || new_cl_x2 != cl_x2 || new_cl_y != cl_y) {
- repos = true;
- }
+ bool cl_repos = (new_cl_x1 != cl_x1 || new_cl_x2 != cl_x2 || new_cl_y != cl_y);
if (cl_visible != new_cl_visible) {
CtrlObject->CmdLine->SetVisible(new_cl_visible);
}
- if (repos) {
+ if (cl_repos || repos) {
CtrlObject->CmdLine->SetPosition(new_cl_x1, new_cl_y, new_cl_x2, new_cl_y);
}
- if (cl_visible != new_cl_visible || repos) {
+ if (cl_visible != new_cl_visible || cl_repos || repos) {
if (new_cl_visible) {
CtrlObject->CmdLine->Redraw();
}
- if (LeftPanel->IsVisible()) {
- LeftPanel->Redraw();
- }
- if (RightPanel->IsVisible()) {
- RightPanel->Redraw();
+ if (cl_visible != new_cl_visible || cl_repos) {
+ if (LeftPanel->IsVisible()) {
+ LeftPanel->Redraw();
+ }
+ if (RightPanel->IsVisible()) {
+ RightPanel->Redraw();
+ }
}
}
}
diff --git a/far2l/src/hist/history.cpp b/far2l/src/hist/history.cpp
index f5c4b820d..3a01b56a0 100644
--- a/far2l/src/hist/history.cpp
+++ b/far2l/src/hist/history.cpp
@@ -1038,7 +1038,7 @@ bool History::GetAllSimilar(VMenu &HistoryMenu, const wchar_t *Str)
HistoryItem = HistoryList.Prev(HistoryItem)) {
if (!StrCmpNI(Str, HistoryItem->strName, Length) && StrCmp(Str, HistoryItem->strName)
&& IsAllowedForHistory(HistoryItem->strName.CPtr())
- && HistoryMenu.FindItem(0, HistoryItem->strName.CPtr()) < 0) { // after #2241 history may have duplicate names
+ && HistoryMenu.FindItem(0, HistoryItem->strName.CPtr(), LIFIND_EXACTMATCH | LIFIND_KEEPAMPERSAND) < 0) { // after #2241 history may have duplicate names
HistoryMenu.AddItem(HistoryItem->strName);
}
}
diff --git a/far2l/src/main.cpp b/far2l/src/main.cpp
index 8340a947f..80468acd1 100644
--- a/far2l/src/main.cpp
+++ b/far2l/src/main.cpp
@@ -75,6 +75,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "ConfigRW.hpp"
#include "ConfigOptSaveLoad.hpp"
#include "help.hpp"
+#include "farversion.h"
#ifdef DIRECT_RT
int DirectRT = 0;
@@ -83,7 +84,8 @@ int DirectRT = 0;
static void print_help(const char *self)
{
bool is_far2ledit = strstr(self, "far2ledit") != NULL;
- printf("FAR2L - two-panel file manager, with built-in terminal and other usefulness'es\n"
+ printf("FAR2L Version: %s\n"
+ "FAR2L - two-panel file manager, with built-in terminal and other usefulness'es\n"
"Usage: %s [switches] [-cd apath [-cd ppath]]\n"
" or: far2ledit [switches] [filename]\n\n"
"where\n"
@@ -103,7 +105,8 @@ static void print_help(const char *self)
// " -p[]\n"
// " Search for \"common\" plugins in the directory, specified by .\n"
" -u OR \n"
- " Allows to specify separate settings identity or FS location.\n"
+ " Allows to specify separate settings identity or FS location\n"
+ " (it override FARSETTINGS environment variable value).\n"
" -v \n"
" View the specified file.\n"
" -v - \n"
@@ -117,7 +120,7 @@ static void print_help(const char *self)
" Example: far2l -set:Language.Main=English -set:Screen.Clock=0 -set:XLat.Flags=0xff -set:System.FindFolders=false\n"
"Switches -cd, -v and -e are not applicable if far2ledit.\n"
"\n",
- is_far2ledit ? "far2l" : self);
+ FAR_BUILD, is_far2ledit ? "far2l" : self);
WinPortHelp();
// Console.Write(HelpMsg, ARRAYSIZE(HelpMsg)-1);
}
@@ -287,6 +290,10 @@ static int MainProcess(FARString strEditViewArg, FARString strDestName1, FARStri
}
} */
+ // Update pointers as the above prefixed plugin calls could recreate one or both panels
+ ActivePanel=CtrlObject->Cp()->ActivePanel;
+ AnotherPanel=CtrlObject->Cp()->GetAnotherPanel(ActivePanel);
+
// !!! ВНИМАНИЕ !!!
// Сначала редравим пассивную панель, а потом активную!
AnotherPanel->Redraw();
@@ -681,7 +688,7 @@ static int libexec(const char *lib, const char *cd, const char *symbol, int argc
static void SetCustomSettings(const char *arg)
{
std::string refined;
- if (arg[0] == '/') {
+ if (arg[0] == GOOD_SLASH) {
refined = arg;
} else if (arg[0] == '.' && arg[1] == GOOD_SLASH) {
diff --git a/far2l/src/vmenu.cpp b/far2l/src/vmenu.cpp
index dee202583..37205f690 100644
--- a/far2l/src/vmenu.cpp
+++ b/far2l/src/vmenu.cpp
@@ -2678,7 +2678,9 @@ int VMenu::FindItem(int StartIndex, const wchar_t *Pattern, DWORD Flags)
for (int I = StartIndex; I < ItemCount; I++) {
FARString strTmpBuf(Item[I]->strName);
int LenNamePtr = (int)strTmpBuf.GetLength();
- RemoveChar(strTmpBuf, L'&');
+ if ( (Flags & LIFIND_KEEPAMPERSAND) == 0) {
+ RemoveChar(strTmpBuf, L'&');
+ }
if (Flags & LIFIND_EXACTMATCH) {
if (!StrCmpNI(strTmpBuf, Pattern, Max(LenPattern, LenNamePtr)))
diff --git a/man/far2l.1 b/man/far2l.1
index 6a5c8460a..3e0a8d2d6 100644
--- a/man/far2l.1
+++ b/man/far2l.1
@@ -1,6 +1,6 @@
.\" -*- mode: troff; coding: UTF-8 -*-
.\"TOPICS "Topics:"
-.TH FAR2L 1 "30-08-24" "FAR2L Version 2.6.3" "Linux fork of FAR Manager v2"
+.TH FAR2L 1 "October 2024" "FAR2L Version 2.6.4" "Linux fork of FAR Manager v2"
.\"SKIP_SECTION"
.SH "NAME"
far2l \- Two-panel file manager, with built\-in terminal and other usefulness\'es.
@@ -49,7 +49,7 @@ Do not load macros.
Do not execute auto run macros.
.TP
\fB\-u\fR \fI\,IDENTITY\/\fR OR \fI\,/PATH/NAME\/\fR
-Allows to specify separate settings \fI\,IDENTITY\/\fR or FS location.
+Allows to specify separate settings \fI\,IDENTITY\/\fR or FS location (it override \fB\,FARSETTINGS\/\fR environment variable value).
.TP
\fB\-v\fR \fI\,FILENAME\/\fR
View the specified file.
@@ -111,7 +111,7 @@ dont maximize window upon launch even if its has saved maximized state (only for
\fB\-\-clipboard=\fI\,SCRIPT\/\fR\fP
use external clipboard handler script that implements get/set text clipboard data via its stdin/stdout
.P
-Backend-specific options also can be set via the \fB\,FAR2L_ARGS\/\fR environment variable
+All options (except \fB\-h\fR and \fB\-u\fR) also can be set via the \fB\,FAR2L_ARGS\/\fR environment variable
.EX
(for example: export FAR2L_ARGS="--tty --nodetect --ee" and then simple far2l to force start only TTY backend).
.EE
diff --git a/man/ru/far2l.1 b/man/ru/far2l.1
index 2eb4af875..f6f0eea78 100644
--- a/man/ru/far2l.1
+++ b/man/ru/far2l.1
@@ -1,6 +1,6 @@
.\" -*- mode: troff; coding: UTF-8 -*-
.\"TOPICS "Topics:"
-.TH FAR2L 1 "30-08-24" "FAR2L Version 2.6.3" "Linux fork of FAR Manager v2"
+.TH FAR2L 1 "October 2024" "FAR2L Version 2.6.4" "Linux fork of FAR Manager v2"
.\"SKIP_SECTION"
.SH "НАИМЕНОВАНИЕ"
far2l \- Двухпанельный файловый менеджер, работающий в текстовом режиме, со встроенным терминалом и другими полезными функциями.
@@ -46,7 +46,9 @@ far2l \- Двухпанельный файловый менеджер, рабо
Не выполнять макросы автозапуска.
.TP
\fB\-u\fR \fI\,ПОЛЬЗОВАТЕЛЬ\/\fR OR \fI\,/ПОЛНЫЙ/ПУТЬ\/\fR
-Позволяет использовать раздельные настройки для различных \fI\,ПОЛЬЗОВАТЕЛей\/\fR или расположений в файловой системе по \fI\,/ПОЛНОМУ/ПУТИ\/\fR.
+Позволяет использовать раздельные настройки для различных \fI\,ПОЛЬЗОВАТЕЛей\/\fR
+или расположений в файловой системе по \fI\,/ПОЛНОМУ/ПУТИ\/\fR
+(перекрывает значение переменной среды \fB\,FARSETTINGS\/\fR).
.TP
\fB\-v\fR \fI\,ФАЙЛ\/\fR
Просмотреть указанный \fI\,ФАЙЛ\/\fR.
@@ -112,9 +114,9 @@ dont maximize window upon launch even if its has saved maximized state (only for
\fB\-\-clipboard=\fI\,SCRIPT\/\fR\fP
use external clipboard handler script that implements get/set text clipboard data via its stdin/stdout
.P
-Параметры режимой интерфейса также могут быть установлены через переменную окружения \fB\,FAR2L_ARGS\/\fR
+Все параметры (кроме \fB\-h\fR и \fB\-u\fR) также могут быть установлены через переменную окружения \fB\,FAR2L_ARGS\/\fR
.EX
-(например: #export FAR2L_ARGS="--tty --nodetect --ee"# и затем просто far2l для принудительного запуска только режима TTY).
+(например: export FAR2L_ARGS="--tty --nodetect --ee" и затем просто far2l для принудительного запуска только режима TTY).
.EE
.\"NODE "FULL HELP"
.SH "ПОЛНАЯ СПРАВКА"
diff --git a/python/configs/plug/plugins/ugtkhello.py b/python/configs/plug/plugins/ugtkhello.py
new file mode 100644
index 000000000..d5d49b765
--- /dev/null
+++ b/python/configs/plug/plugins/ugtkhello.py
@@ -0,0 +1,38 @@
+from far2l.plugin import PluginBase
+
+import gi
+
+gi.require_version("Gtk", "3.0")
+from gi.repository import Gtk
+
+
+import logging
+log = logging.getLogger(__name__)
+
+class MyWindow(Gtk.Window):
+ def __init__(self):
+ super().__init__(title="Hello World")
+
+ self.button = Gtk.Button(label="Click Here")
+ self.button.connect("clicked", self.on_button_clicked)
+ self.add(self.button)
+
+ self.connect("destroy", self.onQuit)
+ self.show_all()
+
+ def on_button_clicked(self, widget):
+ log.debug("Hello World")
+
+ def onQuit(self, window):
+ Gtk.main_quit()
+
+class Plugin(PluginBase):
+ label = "Python GTK"
+ openFrom = ["PLUGINSMENU", "EDITOR"]
+
+ def OpenPlugin(self, OpenFrom):
+ if OpenFrom == 5:
+ # EDITOR
+ win = MyWindow()
+ Gtk.main()
+ return -1
diff --git a/python/src/python.cpp b/python/src/python.cpp
index 79ab9a127..109267795 100644
--- a/python/src/python.cpp
+++ b/python/src/python.cpp
@@ -200,12 +200,18 @@ PYTHON_LOG("initial sys.path=%s\n", syspath.c_str());
pluginPath.resize(pos);
}
- PYTHON_LOG("pluginpath: %s, python library used:%s\n", pluginPath.c_str(), PYTHON_LIBRARY);
- soPythonInterpreter = dlopen(PYTHON_LIBRARY, RTLD_NOW | RTLD_GLOBAL);
+ std::string pythonso = PYTHON_LIBRARY;
+ PYTHON_LOG("pluginpath: %s, python library used:%s\n", pluginPath.c_str(), pythonso.c_str());
+ soPythonInterpreter = dlopen(pythonso.c_str(), RTLD_NOW | RTLD_GLOBAL);
if( !soPythonInterpreter ){
- PYTHON_LOG("error %u from dlopen('%s')\n", errno, PYTHON_LIBRARY);
- initok = false;
- return;
+ PYTHON_LOG("error %u from dlopen('%s'): %s\n", errno, pythonso.c_str(), dlerror());
+ pythonso += ".1";
+ soPythonInterpreter = dlopen(pythonso.c_str(), RTLD_NOW | RTLD_GLOBAL);
+ if( !soPythonInterpreter ){
+ PYTHON_LOG("error %u from dlopen('%s'): %s\n", errno, pythonso.c_str(), dlerror());
+ initok = false;
+ return;
+ }
}
initok = init_python();