1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997-2000 Thingamahoochie Software
5 // SPDX-License-Identifier: GPL-2.0-or-later
6 /////////////////////////////////////////////////////////////////////////////
8 * @file FileTransform.h
10 * @brief Declaration of file transformations
15 #include "UnicodeString.h"
19 * @brief Modes for plugin (Modes for prediffing included)
21 enum class PLUGIN_MODE
23 // Modes for "unpacking"
28 // Modes for "prediffing"
29 PREDIFF_MANUAL = PLUGIN_MANUAL,
30 PREDIFF_AUTO = PLUGIN_AUTO,
33 namespace FileTransform
35 extern PLUGIN_MODE g_UnpackerMode;
36 extern PLUGIN_MODE g_PredifferMode;
42 * @brief Plugin information for a given file
44 * @note Can be be passed/copied between threads
49 void Initialize(PLUGIN_MODE Mode)
51 // and init Plugin/Prediffer mode and Plugin name accordingly
52 m_PluginOrPredifferMode = Mode;
53 if (Mode != PLUGIN_MODE::PLUGIN_AUTO)
59 m_PluginName = _("<Automatic>");
62 explicit PluginForFile(PLUGIN_MODE Mode)
67 /// PLUGIN_AUTO if the plugin will be defined during the first use (via scan of all available plugins)
68 PLUGIN_MODE m_PluginOrPredifferMode;
70 /// plugin name when it is defined
75 * @brief Unpacking/packing information for a given file
77 * @note Can be be copied between threads
78 * Each thread really needs its own instance so that subcode is really defined
79 * during the unpacking (open file) of the thread
81 class PackingInfo : public PluginForFile
84 explicit PackingInfo(PLUGIN_MODE Mode = FileTransform::g_UnpackerMode)
88 , m_bDisallowMixedEOL(false)
92 /// keep some info from unpacking for packing
94 /// text type to override syntax highlighting
98 bool m_bDisallowMixedEOL;
102 * @brief Prediffing information for a given file
104 * @note Can be be passed/copied between threads
106 class PrediffingInfo : public PluginForFile
109 explicit PrediffingInfo(PLUGIN_MODE Mode = FileTransform::g_PredifferMode)
110 : PluginForFile(Mode)
115 namespace FileTransform
119 // WinMerge uses one of these entry points to call a plugin
121 // bMayOverwrite : tells if we can overwrite the source file
122 // if we don't, don't forget do delete the temp file after use
125 * @brief Prepare one file for loading, scan all available plugins (events+filename filtering)
127 * @param filepath : [in, out] Most plugins change this filename
128 * @param handler : unpacking handler, to keep to pack again
130 * @return Tells if WinMerge handles this file
132 * @note Event FILE_UNPACK
133 * Apply only the first correct handler
135 bool Unpacking(String & filepath, const String& filteredText, PackingInfo * handler, int * handlerSubcode);
137 * @brief Prepare one file for loading, known handler
139 * @param filepath : [in, out] Most plugins change this filename
141 bool Unpacking(String & filepath, const PackingInfo * handler, int * handlerSubcode);
143 bool Unpacking(PackingInfo * handler, String & filepath, const String& filteredText);
146 * @brief Prepare one file for saving, known handler
148 * @return Tells if we can save the file (really hope we can)
150 * @param filepath : [in, out] Most plugins change this filename
152 * @note Event FILE_PACK
153 * Never do Unicode conversion, it was done in SaveFromFile
155 bool Packing(String & filepath, PackingInfo handler);
158 * @brief Prepare one file for diffing, scan all available plugins (events+filename filtering)
160 * @param filepath : [in, out] Most plugins change this filename
161 * @param handler : unpacking handler, to keep to pack again
163 * @return Tells if WinMerge handles this file
165 * @note Event FILE_PREDIFF BUFFER_PREDIFF
166 * Apply only the first correct handler
168 bool Prediffing(String & filepath, const String& filteredText, PrediffingInfo * handler, bool bMayOverwrite);
170 * @brief Prepare one file for diffing, known handler
172 * @param filepath : [in, out] Most plugins change this filename
174 bool Prediffing(String & filepath, PrediffingInfo handler, bool bMayOverwrite);
176 bool Prediffing(PrediffingInfo * handler, String & filepath, const String& filteredText, bool bMayOverwrite);
179 * @brief Transform all files to UTF8 aslong possible
181 * @param codepage : [in] codepage of source file
182 * @param filepath : [in,out] path of file to be prepared. This filename is updated if bMayOverwrite is false
183 * @param bMayOverwrite : [in] True only if the filepath points out a temp file
185 * @return Tells if we can go on with diffutils
186 * convert all Ansi or unicode-files to UTF8
187 * if other file is unicode or uses a different codepage
189 bool AnyCodepageToUTF8(int codepage, String & filepath, bool bMayOverwrite);
193 * @brief Get the list of all the free functions in all the scripts for this event :
195 * @note the order is :
196 * 1st script file, 1st function name
197 * 1st script file, 2nd function name
198 * 1st script file, ...
199 * 1st script file, last function name
200 * 2nd script file, 1st function name
201 * 2nd script file, 2nd function name
202 * 2nd script file, ...
203 * 2nd script file, last function name
205 * last script file, 1st function name
206 * last script file, 2nd function name
207 * last script file, ...
208 * last script file, last function name
210 std::vector<String> GetFreeFunctionsInScripts(const wchar_t* TransformationEvent);
213 * @brief : Execute one free function from one script
215 * @param iFncChosen : index of the function in the list returned by GetFreeFunctionsInScripts
217 * @return Tells if the text has been changed
219 * @note Event EDITOR_SCRIPT, ?
221 bool Interactive(String & text, const wchar_t *TransformationEvent, int iFncChosen);