Old 5th January 2006, 21:05   #1
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
TextReplace plugin

Features:
- Fast replacement in text file
- Case sensitive/insensitive replacement
- Supports strings and pointers to the buffer
- If no changes possible, output file will be untouched
- Checks before replacement, if input file is a binary file

Rough estimate perfomance info:
50 Mb text file with 4.000.000 strings to replace processed
with option "/S=1" 4 sec, with option "/S=0" 37 sec


"TextReplace" plugin v1.0

Removed attachment 18 July 2006 - Afrow UK. See last post for latest version.
Instructor is offline   Reply With Quote
Old 6th January 2006, 10:29   #2
zeeh3
Senior Member
 
Join Date: Aug 2005
Posts: 121
Great and useful plugin, thanks a lot Instructor
zeeh3 is offline   Reply With Quote
Old 6th January 2006, 11:00   #3
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
You are welcome
Instructor is offline   Reply With Quote
Old 14th January 2006, 09:45   #4
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
New: "FindInFile" only search in file without replacements
New: "ReplaceInFile" options:
    /AI=[1|0] -Copy attributes from the InputFile to OutputFile or not
    /AO=[0|1] -Change OutputFile attributes to normal before writting or not


"TextReplace" plugin v1.1
Attached Files
File Type: zip textreplace.zip (17.4 KB, 1503 views)
Instructor is offline   Reply With Quote
Old 26th January 2006, 10:55   #5
whaccybanany
Junior Member
 
Join Date: Jan 2006
Posts: 9
Thanks for the great plugin Instructor!

I'm a bit confused to what the options are.

If AI is true, does that mean read/write/execute/other attributes of the InputFile will be kept the same when written out?

If AO is true, does it mean change attributes to some standard?
whaccybanany is offline   Reply With Quote
Old 26th January 2006, 11:24   #6
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
Quote:
If AI is true, does that mean read/write/execute/other attributes of the InputFile will be kept the same when written out?
Yes

Quote:
If AO is true, does it mean change attributes to some standard?
/AO=0 - Don't change OutputFile attributes (error "-9" possible)
-9 can't open output file for writting

For example:
If "/AO=0" and OutputFile has read-only attribute, then error -9 will be returned.
If "/AO=1" and OutputFile has read-only attribute, then no error will be returned.
Instructor is offline   Reply With Quote
Old 26th January 2006, 11:56   #7
whaccybanany
Junior Member
 
Join Date: Jan 2006
Posts: 9
Thanks for the quick reply.

That clears things up!
whaccybanany is offline   Reply With Quote
Old 28th January 2006, 16:14   #8
NHOCSUNG
Guest
 
Posts: n/a
Hi Instructor can i get the source code please

I'm taking C++ now. Actually this is first course, so i need something to practice, you know.
  Reply With Quote
Old 28th January 2006, 17:09   #9
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
Quote:
Hi Instructor can i get the source code please
Archive contains binary and source code.
Instructor is offline   Reply With Quote
Old 28th January 2006, 20:20   #10
NHOCSUNG
Guest
 
Posts: n/a
Talking

I didn't see it before....
  Reply With Quote
Old 27th May 2006, 11:53   #11
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
Fixed: Now plugin doesn't read all file if it is binary.
Updated: "StrFunc.h" to v1.7
Updated: "ConvFunc.h" to v1.7

Update from previous versions:
         - Insert line in script:
            !include "TextReplace.nsh"
         - Replace:
            textreplace::FindInFile -> ${textreplace::FindInFile} ...
         - Replace:
            .r0 -> $0, .r1 -> $1 ... .R0 -> $R0, .R1 -> $R1 ...

"TextReplace" plugin v1.2
Attached Files
File Type: zip textreplace.zip (29.3 KB, 993 views)
Instructor is offline   Reply With Quote
Old 30th June 2006, 20:32   #12
zeeh3
Senior Member
 
Join Date: Aug 2005
Posts: 121
Instructor, there is a bug in the plugin that makes files bigger than 128 bytes readonly|hidden|system|archive|temporary|offline|not_content_indexed.
zeeh3 is offline   Reply With Quote
Old 1st July 2006, 05:13   #13
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
Don't understand. If file size equal to 128 then after processing it attributes changed to readonly|hidden|system|archive|temporary|offline|not_content_indexed? And what plugin parameters you use?
Instructor is offline   Reply With Quote
Old 1st July 2006, 10:55   #14
zeeh3
Senior Member
 
Join Date: Aug 2005
Posts: 121
Yes, I am just using TextReplaceTest.nsi that comes with the plugin. Attached are the input.txt and output.txt files and the exe.
Attached Files
File Type: zip textreplace.zip (25.2 KB, 736 views)
zeeh3 is offline   Reply With Quote
Old 1st July 2006, 12:53   #15
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
Fixed: Buffer overflow (thanks zeeh3)


"TextReplace" plugin v1.3
Attached Files
File Type: zip textreplace.zip (31.7 KB, 789 views)
Instructor is offline   Reply With Quote
Old 14th July 2006, 05:57   #16
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
Fixed: crash when using long string (> 1024) with 8192 special build (thanks zeeh3)


"TextReplace" plugin v1.4
Attached Files
File Type: zip textreplace.zip (31.8 KB, 736 views)
Instructor is offline   Reply With Quote
Old 14th July 2006, 16:56   #17
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
Forgot to remove debug MessageBox in release.


"TextReplace" plugin v1.4
Attached Files
File Type: zip textreplace.zip (31.7 KB, 783 views)
Instructor is offline   Reply With Quote
Old 17th October 2006, 19:10   #18
tinjaw
Junior Member
 
Join Date: Oct 2006
Posts: 1
Thank you very much. You plugin just saved me much valuable time.
tinjaw is offline   Reply With Quote
Old 29th October 2006, 00:12   #19
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
Changed: algorithm optimized - replacement speed increased.


"TextReplace" plugin v1.5
Attached Files
File Type: zip textreplace.zip (33.4 KB, 960 views)
Instructor is offline   Reply With Quote
Old 8th April 2008, 17:59   #20
Chunkster
Junior Member
 
Join Date: Apr 2008
Posts: 1
Replace one line with two lines

I am trying to replace one line of a text file with two lines, using TextReplace. The arrangement of info in the file looks something like this -


Line 1
Line 2
Line 3
Line 4

I am searching for "Line 3" and want to replace it with

Line 3a
Line 3b

for a final file arrangement that looks like -

Line 1
Line 2
Line 3a
Line 3b
Line 4

Here is the actual TextReplace line

${textreplace::ReplaceInFile} "$PROGRAMFILES\OpenOffice.org 2.4\share\dict\ooo\dictionary.lst" "$PROGRAMFILES\OpenOffice.org 2.4\share\dict\ooo\dictionary.lst" "THES en US th_en_US_v2" "THES en US th_en_US_v2 \r DICT en US en_US_OpenMedSpel \r" "/S=1" $0

This of course, does not produce the desired output. It looks like this

Line 1
Line 2
Line 3a \r Line 3b \r
Line 4

Any help with this problem would be appreciated. Thanks.
Chunkster is offline   Reply With Quote
Old 9th April 2008, 07:44   #21
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
\r -> $\r$\n
Instructor is offline   Reply With Quote
Old 12th May 2009, 15:17   #22
nduboc
Junior Member
 
Join Date: Jun 2004
Posts: 6
Hi,

What license the TextReplace v1.5 plugin is distributed under ? I can't find any license notice in the zip file or
the home page (http://nsis.sourceforge.net/TextReplace_plugin).

Thanks.
nduboc is offline   Reply With Quote
Old 12th May 2009, 16:59   #23
Instructor
Major Dude
 
Join Date: Jul 2004
Posts: 671
nduboc
NSIS license.
Instructor is offline   Reply With Quote
Old 13th May 2009, 15:11   #24
nduboc
Junior Member
 
Join Date: Jun 2004
Posts: 6
Quote:
Originally posted by Instructor
nduboc
NSIS license.
You mean the zlib/libpng license as stated on the License
page of the NSIS web site, right ?
nduboc is offline   Reply With Quote
Old 13th October 2011, 13:23   #25
Yathosho
Forum King
 
Yathosho's Avatar
 
Join Date: Jan 2002
Location: AT-DE
Posts: 3,353
saw your update of the locate plugin, so i was wondering if there are plans for a unicode version of textreplace
Yathosho is offline   Reply With Quote
Old 21st January 2012, 08:17   #26
threexk
Junior Member
 
Join Date: Jan 2012
Posts: 2
I get "Invalid command: ${textreplace::ReplaceInFile}" when trying to call TextReplace commands. The only way I could get it to work was to use "TextReplace::_ReplaceInFile", but you're probably not supposed to call the commands like that. What is the proper way to call TextReplace commands?
threexk is offline   Reply With Quote
Old 21st January 2012, 09:02   #27
threexk
Junior Member
 
Join Date: Jan 2012
Posts: 2
Quote:
Originally Posted by threexk View Post
I get "Invalid command: ${textreplace::ReplaceInFile}" when trying to call TextReplace commands. The only way I could get it to work was to use "TextReplace::_ReplaceInFile", but you're probably not supposed to call the commands like that. What is the proper way to call TextReplace commands?
The problem was I needed to have "!include "TextReplace.nsh".

${textreplace::ReplaceInFile} has the disadvantage of requiring all six parameters, whereas TextReplace::_ReplaceInFile lets you provide less than six with the unspecified parameters taking default values, so I am sticking with the latter.
threexk is offline   Reply With Quote
Old 20th February 2015, 16:27   #28
ggroup
Junior Member
 
Join Date: Oct 2013
Posts: 14
Hi there
When I use the plug-in, the message "Invalid command: ${textreplace::ReplaceInFile}" appears after the command "!Include" TextReplace.nsh "wrote!
ggroup is offline   Reply With Quote
Old 10th July 2017, 21:29   #29
taa1
Junior Member
 
Join Date: Jul 2017
Posts: 1
Hi,

I installed NSIS 3.01 and then ran install.exe after extracting textreplace.zip v1.5. When I go to compile a script, I get:

!insertmacro: textreplace::ReplaceInFile
Plugin not found, cannot call textreplace::_ReplaceInFile
Error in macro textreplace::ReplaceInFile on macroline 1

The plugin appears to have installed correctly into Plugins and Include:

C:\Program Files (x86)\NSIS>dir plugins\Text*

Directory of C:\Program Files (x86)\NSIS\plugins

07/09/2017 07:42 PM 5,120 TextReplace.dll
1 File(s) 5,120 bytes

C:\Program Files (x86)\NSIS>dir include\Text*

Directory of C:\Program Files (x86)\NSIS\include

09/06/2013 04:48 PM 24,348 TextFunc.nsh
07/09/2017 07:42 PM 1,125 TextReplace.nsh
2 File(s) 25,473 bytes

When I start compiling a script and NSIS is listing the plugins, textreplace isn't one of them.

I also tried manually copying TextReplace.dll and TextReplace.nsh from the extracted zip file to the Plugins and Include directories respectively. Same result.

How do I get NSIS to recognize the plugin?
taa1 is offline   Reply With Quote
Old 10th July 2017, 22:53   #30
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,608
It tells you what the problem is "Plugin not found". Just take a look in your C:\Program Files (x86)\NSIS\plugins directory and you should be able to figure out why it is not working...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump