1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997-2000 Thingamahoochie Software
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /////////////////////////////////////////////////////////////////////////////
22 * @file FileTransform.h
24 * @brief Declaration of file transformations
29 #include "UnicodeString.h"
32 namespace FileTransform
34 extern int g_bUnpackerMode;
35 extern int g_bPredifferMode;
41 * @brief Modes for plugin (Modes for prediffing included)
45 // Modes for unpacking
49 // Modes for prediffing
50 PREDIFF_MANUAL = PLUGIN_MANUAL,
51 PREDIFF_AUTO = PLUGIN_AUTO,
55 * @brief Plugin information for a given file
57 * @note Can be be passed/copied between threads
62 void Initialize(int bMode)
64 // TODO: Convert bMode to PLUGIN_MODE and fix compile errors
65 // init functions as a valid "do nothing" unpacker
67 // and init bAutomatic flag and name according to global variable
68 if (bMode != PLUGIN_AUTO)
74 pluginName = _("<Automatic>");
78 explicit PluginForFile(PLUGIN_MODE bMode)
83 /// TRUE if the plugin will be defined during the first use (through scan of all available plugins)
84 int bToBeScanned; // TODO: Convert to PLUGIN_MODE and fix compile errors
85 /// plugin name when it is defined
87 /// TRUE is the plugins exchange data through a file, false is the data is passed as parameter (BSTR/ARRAY)
92 * @brief Unpacking/packing information for a given file
94 * @note Can be be copied between threads
95 * Each thread really needs its own instance so that subcode is really defined
96 * during the unpacking (open file) of the thread
98 class PackingInfo : public PluginForFile
101 explicit PackingInfo(PLUGIN_MODE bMode = (PLUGIN_MODE)FileTransform::g_bUnpackerMode)
102 : PluginForFile(bMode)
105 , disallowMixedEOL(false)
109 /// keep some info from unpacking for packing
111 /// text type to override syntax highlighting
115 bool disallowMixedEOL;
119 * @brief Prediffing information for a given file
121 * @note Can be be passed/copied between threads
123 class PrediffingInfo : public PluginForFile
126 explicit PrediffingInfo(PLUGIN_MODE bMode = (PLUGIN_MODE)FileTransform::g_bPredifferMode)
127 : PluginForFile(bMode)
132 namespace FileTransform
136 // WinMerge uses one of these entry points to call a plugin
138 // bMayOverwrite : tells if we can overwrite the source file
139 // if we don't, don't forget do delete the temp file after use
142 * @brief Prepare one file for loading, scan all available plugins (events+filename filtering)
144 * @param filepath : [in, out] Most plugins change this filename
145 * @param handler : unpacking handler, to keep to pack again
147 * @return Tells if WinMerge handles this file
149 * @note Event FILE_UNPACK
150 * Apply only the first correct handler
152 bool Unpacking(String & filepath, const String& filteredText, PackingInfo * handler, int * handlerSubcode);
154 * @brief Prepare one file for loading, known handler
156 * @param filepath : [in, out] Most plugins change this filename
158 bool Unpacking(String & filepath, const PackingInfo * handler, int * handlerSubcode);
160 bool Unpacking(PackingInfo * handler, String & filepath, const String& filteredText);
163 * @brief Prepare one file for saving, known handler
165 * @return Tells if we can save the file (really hope we can)
167 * @param filepath : [in, out] Most plugins change this filename
169 * @note Event FILE_PACK
170 * Never do Unicode conversion, it was done in SaveFromFile
172 bool Packing(String & filepath, PackingInfo handler);
175 * @brief Prepare one file for diffing, scan all available plugins (events+filename filtering)
177 * @param filepath : [in, out] Most plugins change this filename
178 * @param handler : unpacking handler, to keep to pack again
180 * @return Tells if WinMerge handles this file
182 * @note Event FILE_PREDIFF BUFFER_PREDIFF
183 * Apply only the first correct handler
185 bool Prediffing(String & filepath, const String& filteredText, PrediffingInfo * handler, bool bMayOverwrite);
187 * @brief Prepare one file for diffing, known handler
189 * @param filepath : [in, out] Most plugins change this filename
191 bool Prediffing(String & filepath, PrediffingInfo handler, bool bMayOverwrite);
193 bool Prediffing(PrediffingInfo * handler, String & filepath, const String& filteredText, bool bMayOverwrite);
196 * @brief Transform all files to UTF8 aslong possible
198 * @param codepage : [in] codepage of source file
199 * @param filepath : [in,out] path of file to be prepared. This filename is updated if bMayOverwrite is false
200 * @param bMayOverwrite : [in] True only if the filepath points out a temp file
202 * @return Tells if we can go on with diffutils
203 * convert all Ansi or unicode-files to UTF8
204 * if other file is unicode or uses a different codepage
206 bool AnyCodepageToUTF8(int codepage, String & filepath, bool bMayOverwrite);
210 * @brief Get the list of all the free functions in all the scripts for this event :
212 * @note the order is :
213 * 1st script file, 1st function name
214 * 1st script file, 2nd function name
215 * 1st script file, ...
216 * 1st script file, last function name
217 * 2nd script file, 1st function name
218 * 2nd script file, 2nd function name
219 * 2nd script file, ...
220 * 2nd script file, last function name
222 * last script file, 1st function name
223 * last script file, 2nd function name
224 * last script file, ...
225 * last script file, last function name
227 void GetFreeFunctionsInScripts(std::vector<String> & sNamesArray, const wchar_t *TransformationEvent);
230 * @brief : Execute one free function from one script
232 * @param iFncChosen : index of the function in the list returned by GetFreeFunctionsInScripts
234 * @return Tells if the text has been changed
236 * @note Event EDITOR_SCRIPT, ?
238 bool Interactive(String & text, const wchar_t *TransformationEvent, int iFncChosen);