home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
579a.lha
/
Textra_v1.11
/
Scripts
/
WrapAt.textra
< prev
Wrap
Text File
|
1991-10-23
|
5KB
|
176 lines
/*******************************************************************
* TEXTRA AREXX script -- Mike Haas, 1991, All Rights Reserved. *
* Freely distributable ONLY as a component of the TEXTRA package. *
* This banner may not be removed or altered (improvements to the *
* actual program welcome). Please document and send to me. *
* !!! PLACE THIS FILE IN YOUR REXX: DIRECTORY !!! *
*******************************************************************/
/* WrapAt <num>
*
* This routine takes all lines of text that the selection falls on
* and word-wraps the text at column <num>, 0-based. This script
* also left-justifies the text, except for the first line.
*
* When lines are joined, they are separated by a space, unless the
* last character of the topmost of the pair being joined is a period
* (assumed to mark the end of a sentence). If this is the case,
* two spaces follow the period.
*
* The <num> argument is limited between 20 and 120 because of the
* quick & dirty way this scripts checks for stuff. For example,
* this script often "joins" lines, and their combined length cannot
* exceed 255 (TEXTRA limitation), so keeping things under 120 keeps
* this from happening.
*
* Enjoy, Mike Haas
*/
options results
parse arg maxcolumn
/* make sure maxcolumn is legal */
if (maxcolumn == "") then
do
notify "Usage: WrapAt <maxcolumn>"
exit
end
if ((maxcolumn > 120) | (maxcolumn < 20)) then
do
notify "WrapAt parameter must be between 20 and 120"
exit
end
get select position
if (result == "NO SELECT") then /* is nothing selected? */
do
notify "There MUST be a select range to use the WrapAt script."
exit
end
/* yes, there is a selection, get it's boundaries */
parse var result startx ' ' starty ' ' endx ' ' endy
currx = startx
curry = starty
nomore = 0
bsto = -1
/* temporarily make sure auto indent is off */
prefs autoindent read; autoistate = result
prefs autoindent off
/* if nothing on the endline is actually selected, don't include it */
if (endx == 0) then endy = endy - 1
do while ((curry <= endy) & (nomore == 0))
do
if (bsto == -1) then do
gotoxy 0 curry
currx = 0; nowony = curry
end
else do
currx = bsto; bsto = -1
end
do while ((currx <= maxcolumn) & (nowony == curry) & (nomore == 0))
hopselect next word
if (result == "NOT FOUND") then do
nomore = 1
gotoxy 1000 curry
end
else do
get select position
parse var result dummy' 'dummy' 'currx' 'nowony
gotoxy currx nowony
end
end
inbetween = (nowony - 1) - curry
/* delete any blank lines between
notify "deleting"
todelete = (nowony - 1) - curry
if (todelete > 0) then do
tmp = todelete
do while (tmp > 0)
selectline curry+1; del
tmp = tmp - 1
end
endy = endy - todelete
nowony = nowony - todelete
gotoxy currx nowony
end
*/
if (currx > maxcolumn) then do
/* line is too long */
hopto prev word;
get cursor position; parse var result PrevEndsAt' 'dummy
if (PrevEndsAt > maxcolumn) then
hopto prev word
hopto next word
newline
endy = endy + 1 /* cause we inserted a newline */
curry = curry + 1
nomore = 0
end
else if (nomore == 0) then do
/* curry is not long enough */
gotoxy 0 nowony
get cursor char; firstchar = result
if ((curry < endy) & (inbetween == 0)) then do
backspace
thechar = " "
do while ((thechar == " ") | (thechar == " ") /*TAB*/)
do
left 1
get cursor char; thechar = result
end
end
right 1
get cursor char
do while ((result == " ") | (result == " ") /*TAB*/)
do
del
get cursor char
end
end
if (thechar == ".") then
text '" "'
else
text '" "'
get cursor position; parse var result bsto' 'nowony
endy = endy - 1
end
else
curry = nowony
end
/*
ask "Do it again?"
if (result == "NO") then exit
*/
end
end
/* restore autoindent */
prefs autoindent autoistate