--------------------------------------------------------------------------------
                                   Textedit 2.5
                                created by WhiteShadow
                         updated by Phil Stopford and ilmcuts
                             Last Modified: 2003-05-27
--------------------------------------------------------------------------------


Overview
--------

Textedit2.dll is a Litestep module that can be used to edit text files. For
example it could be useful in allowing you to edit your step.rc file on the fly.
However, it could also be very dangerous if used on the wrong file.


General Note
------------

Textedit v2.x is a complete rewrite of Textedit 1.x and many features have been
removed or changed.


Installation
------------

Put textedit2.dll in a directory of your choice, e.g. C:\Litestep\Modules\.
Open your step.rc and add a LoadModule line pointing to the dll, for example:

LoadModule "C:\Litestep\Modules\textedit2.dll"

Save the file and recycle. You can use the step.rc and !bang commands described
below to control textedit2.


Step.rc Commands
----------------

TextEditDebug
    If you have this line in your step.rc, lots of message boxes will pop up and
    help you debug problems using the module.

TextEditNewSyntax
    Makes textedit use an alternative syntax. @ is used as the quote character
    instead of ".
    Example: !TextReplace @file.txt@ @search string@ @replace string@



Bang Commands
-------------

!textappend "filename" "text to be added"
    Appends "text to be added" (minus the quotes) to filename.
	Look below for various escape codes.

!textdel "filename" "regular expression"
    This will delete every line in "filename" that matches the regular
	expression in quotes. Regular expressions and escape codes are described
	below.

!textreplace "filename" "regular expression" "replace string"
    Replaces lines in "filename" that match the regular expression with "replace
	string". Regular expressions and escape codes are described below. Special
	notes about !textreplace can be found towards the end of this file.


Escape Codes
------------

The backslash (\) character is used to mark an escape code. The	following are
valid escape sequences:

	\=	Double quote (")
	\^	Replaces with a bang (!)
	\#	Replaces with a dollar sign ($) (Useful for evars.
		  for example \#litestepdir\# will become $litestepdir$)
	\~  Semicolon (;)
	\1	Ignored and used in !textreplace for () matches
		  (explained below)
	\c  Text in clipboard

Any other use of backslash will give you an error message if TextEditDebug is in
your step.rc, and will be ignored unless it is used for a character used in
regexps, such as * or \.


Regular Expressions
-------------------

Even if you know what regular expressions are, you should still read this
because only a handful of regex features are implemented. I'm using a patched
relib, a slightly modified REGEXP library by Henry Spencer to handle the regular
expressions. Read the included relib-readme.txt for more details.
The quick run down of supported features is the use of the following special
characters:

	.  ?  *  +  [  ]  _  ^  (  )  |  \

Ok, now to explain what all these are and what regular expressions are in
general.

The simplest regular expression is just a string.  For example, "a" would match
all strings with the character a in it, "abc" would match all strings with abc
in it.

Now, the first special character is a period. This is the wild card character. 
So "a.b" would match any string that contained an 'a' followed by any character
followed by a 'b'. It would match "abb", "a1b", "ajhdakjs a b aslkjf", "a b",
"extra a_b extra", and so forth.

The next special character is a ?.  This means that the previous character
occurs zero or one time.  So "a.?b" would match everything that "a.b" matched
and everything that "ab" would match.

* means that the previous character is repeated zero or more times. This is
pretty much a catch all. So ".*" would match any string.

+ matches the previous character one or more times.

[]'s are used to enclose a group of characters to match.
For example, "A[a-z]+Z" would match "AanczZ", "AaZ", or any set of lowercase
letters enclosed by an 'A' and a 'Z'.  Note that because a + is used, "AZ" would
not match while "A[a-z]*Z]"	would match "AZ".  You can also negate what is
encosed in brackets with the ^ character (so [^a-z] would mean not a lower case
letter).

_ and ^ are anchor characters. _ means that the match has to occur at the end of
the string and ^ means that the match has to occur and the beginning of the
string. For example, "test_" would match "this is a test" but would not match
"test is a this".

()'s are used to enclose a group.  For example, (AB)+ would match "AB", "ABAB",
"ABABAB", etc. This gives more flexibility for patterns.

The pipe | is used as an "or" operator. So "A|B" would match all strings with an
upper case A or an upper case B. Combine this with parenthesis and do things
like "Z(A|B)+Z" to match "ZABABABZ".

And finally the \ is used as an escape code so you can use the special
characters in your matches. For example, \* would match an asterisk, \. would
match a period, and \\ would match a backslash.

If that didn't completely confuse you, try searching for some regular expression
tutorials online. Note that relib doesn't support all the neat regex stuff that
perl does.


TextReplace
-----------

A couple notes about TextReplace. In the replace field,	you can use a few of
special characters.  For example, & is replaced by the whole string. So

!textreplace "file" "find" "&-found"

would convert "find" to "find-found". Or better yet,

!textreplace "file" "^*Shortcut" "\~ &"

would comment all *Shortcuts definied in file (\~ is the escape code for
semicolons).
Also, \1 matches with the inner-most, left-most parenthesis, \2 matches the
second inner-most, left-most parenthesis, etc. So

!textreplace "file" "(hello)(.*)(there)" "\3\2\1"

would convert "hello test there" to "there test hello". Here's another example:

!textreplace "file" "~; *(*Shortcut.*)" "\1"

This would uncomment all shortcuts.


Version History
---------------

2.51, 2003-09-01 (doy)
- disabled escape code replacement in the filename
- removed escape code \^, use \* instead
- made textedit stop parsing \\ since regex does it and it used to require 4 \s to work
- compiled in dev-c++, which is why the filesize is so big

2.5,  2003-05-27 (ilmcuts)
- Added escape code \c which expands to the text currently in the clipboard
- !textappend now creates the file if it doesn't already exist.
- Restructured and updated readme.txt.

2.4l, 2002-03-12 (Phil Stopford)
- Partial rewrite.
- Now reports RevID.
- End-of-line (EOL) marker changed from $ to _
- Added TextEditNewSyntax step.rc setting to restore backwards compatibility.
- Removed escape codes \[ and \@.

2.3l, 2001-10-23 (Phil Stopford)
- Changed escape code \& to \>
- Using multithreaded DLL runtime library.

2.2l, 2001-07-26 (Phil Stopford)
- Added version resource.
- Added escape code \[ for current version
- Changed syntax: @ used as quote character instead of ".
  Example: !TextReplace @file.txt@ @search string@ @replace string@
- Added escape code \@.
- Changed escape code \" to \=
- Added escape code \&.

2.1l, 2001-04-10 (Phil Stopford)
- Added escape code \~ to work around new lsapi parser behavior.

2.0,  09-30-00 (WhiteShadow from here down)
- Complete rewite.

1.41, 2000-07-08
- Fixed the error using ^" in textreplace.

1.4,  2000-07-03
- Added !textcopyfile
- Added TextCalculate

1.3,  2000-04-30
- Changed !textadd to !textappend
- Added !textinsert
- Added !textreplace
- Added !textcomment and !textsetcommentchar
- Added TextNotCaseSensitive

1.2,  2000-04-10
- Added * at end of strings
- Added !textdelsingle

1.1,  2000-04-04
- Added TextSubst

1.0   2000-04-02
- Initial release


Contact
-------

WhiteShadow
Phil Stopford

ilmcuts:
ilmcuts_AT_gmx_DOT_net
#lsdev, #litestep on irc.freenode.net