*****************************************************************
*              NewTextReplace NSIS plugin v0.5                  *
*                  by Gringoloco023, 2010                       *
*                                                               *
*                          Based on:                            *
*                TextReplace NSIS plugin v1.5                   *
*                                                               *
* 2006 Shengalts Aleksander aka Instructor (Shengalts@mail.ru)  *
*****************************************************************

Features:
- support for utf-8, utf-16LE/BE and all ansi code-pages
- Fast search/replacement in text file
- Case sensitive/insensitive replacement
- Supports strings and pointers to the buffer
- If no changes possible, output file will be untouched

Code-pages are specified as:  (utf-7 is not supported)
- ${CP_UTF8}    = Utf-8
- ${CP_UTF16LE} = Utf-16LE
- ${CP_UTF16BE} = Utf-16LE
- ${CP_ACP}     = Default ansi
- 1251          = Cyrilic, or any other ansi code-page identifier as specified at: 
                           http://msdn.microsoft.com/en-us/library/dd317756%28v=VS.85%29.aspx

**** Search in file ****

${textreplace::FindInFile} "[InputFile]" "[FindIt]" "[Options]" $var

"[InputFile]"   - Input file

"[FindIt]"      - String to find or pointer to the buffer if used option /PI=1

"[Options]"     - Search options

	/S=[0|1]
		/S=0   - Case insensitive (default) (only for latin characters!!!)
		/S=1   - Case sensitive (faster)
	/PI=[0|1]
		/PI=0  - FindIt is a string (default)
		/PI=1  - FindIt is a pointer to the text buffer
	/U=[CodePage]
		       - InputFile code-page overide, if not specified the plug-in depends on the BOM
                         (Mainly needed for additional ansi code-pages, e.g. Cyrilic = 1251)
	/UI=[CodePage]
		       - FindIt code-page overide, if not specified the plug-in depends either on
                         the encoding of the passed string or on the BOM in the text buffer
                         (Mainly needed for additional ansi code-pages, e.g. Cyrilic = 1251)

$var   number of founded strings
       -3   ReplaceIt string is empty
       -4   can't open input file for reading
       -5   can't get file size of the input file
       -6   can't allocate buffer for input file text
       -7   can't read input file
       -12  code-page is not supported, (e.g. Utf-7)


**** Replace in file ****

${textreplace::ReplaceInFile} "[InputFile]" "[OuputFile]" "[ReplaceIt]" "[ReplaceWith]" "[Options]" $var

"[InputFile]"   - Input file

"[OutputFile]"  - Output file, can be equal to InputFile

"[ReplaceIt]"   - String to replace or pointer to the buffer if used option /PI=1

"[ReplaceWith]" - Replace with this string or pointer to the buffer if used option /PO=1

"[Options]"     - Replace options

	/S=[0|1]
		/S=0   - Case insensitive (default) (only for latin characters!!!)
		/S=1   - Case sensitive (faster)
	/C=[1|0]
		/C=1   - Copy the file if no changes made (default)
		/C=0   - Don't copy the file if no changes made
	/AI=[1|0]
		/AI=1  - Copy attributes from the InputFile to OutputFile (default)
		/AI=0  - Don't copy attributes
	/AO=[0|1]
		/AO=0  - Don't change OutputFile attributes (error "-9" possible) (default)
		/AO=1  - Change OutputFile attributes to normal before writting
	/PI=[0|1]
		/PI=0  - ReplaceIt is a string (default)
		/PI=1  - ReplaceIt is a pointer to the text buffer
	/PO=[0|1]
		/PO=0  - ReplaceWith is a string (default)
		/PO=1  - ReplaceWith is a pointer to the text buffer
	/U=[CodePage]
		       - InputFile code-page overide, if not specified the plug-in depends on the BOM
                         (Mainly needed for additional ansi code-pages, e.g. Cyrilic = 1251)
	/UI=[CodePage]
		       - ReplaceIt code-page overide, if not specified the plug-in depends either on
                         the encoding of the passed string or on the BOM in the text buffer
                         (Mainly needed for additional ansi code-pages, e.g. Cyrilic = 1251)
	/UO=[CodePage]
		       - ReplaceWith code-page overide, if not specified the plug-in depends either on
                         the encoding of the passed string or on the BOM in the text buffer
                         (Mainly needed for additional ansi code-pages, e.g. Cyrilic = 1251)

$var   number of replacements
       -1   ReplaceIt pointer is incorrect
       -2   ReplaceWith pointer is incorrect
       -3   ReplaceIt string is empty
       -4   can't open input file for reading
       -5   can't get file size of the input file
       -6   can't allocate buffer for input file text
       -7   can't read input file
       -9   can't open output file for writting
       -10  can't allocate buffer for output file text
       -11  can't write to the output file
       -12  code-page is not supported, (e.g. Utf-7)


**** Put text file contents to the buffer ****

${textreplace::FillReadBuffer} "[File]" $var

"[File]"   - Input file

$var   pointer to the buffer
       -4   can't open input file for reading
       -5   can't get file size of the input file
       -6   can't allocate buffer for input file text
       -7   can't read input file


**** Free buffer ****

${textreplace::FreeReadBuffer} "[Pointer]"

"[Pointer]"  - Pointer to the buffer


**** Recode file ****

${textreplace::Recode} "[InputFile]" "[OuputFile]" "[InputCodePage]" "[OuputCodePage]" $var

"[InputFile]"     - Input file

"[OutputFile]"    - Output file, can be equal to InputFile

"[InputCodePage]" - InputFile code-page overide, if not specified the plug-in depends on the BOM
                    (Mainly needed for additional ansi code-pages, e.g. Cyrilic = 1251)

"[OuputCodePage]" - OutputFile code-page

$var   pointer to the buffer
        1   success
       -2   can't open input file for reading
       -9   can't open output file for writting
       -10  can't allocate buffer for output file text
       -11  can't write to the output file
       -12  code-page is not supported, (e.g. Utf-7)


**** Unload plugin ****

${textreplace::Unload}
