home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
fwe225.zip
/
Split.Mac
< prev
next >
Wrap
Text File
|
2000-01-06
|
10KB
|
302 lines
/* ************************************************************************* */
/* Future Wave Editor Sample Macro program. */
/* */
/* ÄwÆΦîàé┼é╠âeâLâXâgÉ«î`â}âNâì */
/* ------------------------------------------------------------------------- */
/* ê°Éö : æ╡éªéΘì┼æσîàÉö */
/* âÅü[âhüEâëâbâv 0 : ïûë┬ */
/* ê╚èO : ï╓Ä~ */
/* ------------------------------------------------------------------------- */
/* */
/* 1).ê°Éöé╠ÄwÆΦé¬û│éóé⌐Ælé¬òsôKÉ╪é╚ÅΩìçé═üCæ╡éªéΘì┼æσîàÉöé≡âåü[âUü[é⌐éτ */
/* ôⁿù═é╡é─éαéτéñ */
/* */
/* 2).âÅü[âhüEâëâbâvé╠ÄwÆΦé¬é╚é»éΩé╬üCâåü[âUü[é⌐éτæIæ≡é╡é─éαéτéñüD */
/* âÅü[âhüEâëâbâvé¬ùLî°é┼üCÆPîΩôrÆåé╠É▄éΦò╘é╡é≡ï╓Ä~é╖éΘüD */
/* */
/* 3).âJü[â\âïé≡ɵô¬ìsé╠ɵô¬îàé╔ê┌ô« */
/* */
/* 4).ì┼ÅIìsé▄é┼üAÄwÆΦîàÉöê╚ÅπéáéΘìsé≡ÄwÆΦîàÉöé┼ò¬èäé╖éΘ */
/* */
/* ------------------------------------------------------------------------- */
/* (C) Copyright Future Wave Limited. 1997-1999 All right reserved. */
/* ************************************************************************* */
arg nSplitPos fWordWrap
trace off
MAX_TAB_SIZE = 8; /* Max TAB size */
/* ----------------------------------------------------------- */
/* C o n s t M e s s a g e s */
/* ----------------------------------------------------------- */
szTitle = "ÄwÆΦîàÉ«î`â}âNâì";
szMsgMax = "ì┼æσîàÉöé≡ôⁿù═é╡é─ë║é│éóüB";
szMsgMin = "ôⁿù═îàÉöé═ 8 ê╚Åπé┼é╖üB";
szMsgWay = " É▄éΦò╘é╡ê╩Æué¬ÆPîΩôrÆåé┼éαüC" x2c(0a) "É▄éΦò╘é╡é≡Ä└ìsé╡é▄é╖é⌐üH";
szMsgExec1 = " æ╡éªéΘì┼æσîàÉöé═";
szMsgExec2 = "îàé┼üC" x2c(0a)
szMsgWrap = "É▄ò╘ê╩Æué¬ÆPîΩôrÆåé┼éαÉ▄ò╘é╡é▄é╖üD";
szMsgNoWrap = "ÆPîΩôrÆåé┼é═É▄ò╘é╡é▄é╣é±üD";
szMsgExec3 = x2c(0a) "Åêù¥é≡èJÄné╡é▄é╖üB";
szMsgAbort = "ò╥ÅWï╓Ä~Å≤æ╘é╠é╜é▀Åêù¥ÆåÆfüIüI";
/* ----------------------------------------------------------- */
/* M a i n */
/* ----------------------------------------------------------- */
main:
count = 0;
wordwrap = 0;
/* Can I edit (FWE is not disabled) ? */
if FweQueryEditMode() = 0 then do
/* ------------------------------- */
/* check and set split position. */
/* ------------------------------- */
if datatype(nSplitPos,'N') = 1 then
count = nSplitPos;
do while count < MAX_TAB_SIZE
do Forever until datatype(count,'N') = 1
say szMsgMax;
say szMsgMin;
pull count;
end;
end;
/* ------------------------------- */
/* check and set word-wrap. */
/* ------------------------------- */
if datatype(fWordWrap,'N') = 1 then do
wordwrap = fWordWrap;
end
else do
if fWordWrap = "" then do
if RxMessageBox( szMsgWay, szTitle, "YESNO", "QUESTION" ) = 6 then do
wordwrap = 0;
end
else do
wordwrap = 1;
end;
end;
end;
/* ------------------------------- */
/* confirm and execute. */
/* ------------------------------- */
szMsg = szMsgExec1 count szMsgExec2
if wordwrap = 0 then do
szMsg = szMsg szMsgWrap
end
else do
szMsg = szMsg szMsgNoWrap
end;
szMsg = szMsg szMsgExec3
if RxMessageBox( szMsg, szTitle, "OKCANCEL", "QUESTION" ) = 1 then do
rc = FweJump( 1, 1 );
do Forever until FweDown() <> 0
if split( count, wordwrap ) <> 0 then
leave;
end;
end;
end
else do
rc = RxMessageBox( szMsgAbort, szTitle, "OK", "INFORMATION" );
end;
/* delete macro-executing log. */
rc = FweClearLog();
exit;
/* ----------------------------------------------------------- */
/* S p l i t */
/* ----------------------------------------------------------- */
split: procedure
maxColumns = arg( 1 );
flWordWrap = arg( 2 );
nRetcode = 0;
do while FweQueryTextLength(0) > maxColumns
/* doing word-wrap ? */
select
/* word-wrap */
when flWordWrap <> 0 then do
nRetcode = wrap_prev( maxColumns );
if nRetcode = 0 then do
nRetcode = wrap_next( maxColumns );
end;
end;
/* no word-wrap */
when flWordWrap = 0 then do
rc = FweJump( FweQueryY(), maxColumns, 1 );
nRetcode = 1;
end;
end;
/* split text */
if nRetcode <> 0 then do
nRetcode = FweInputReturn();
if nRetcode <> 0 then
leave;
end
else do
leave;
end;
end;
return( nRetcode );
/* ----------------------------------------------------------- */
/* W o r d w r a p */
/* ----------------------------------------------------------- */
wrap_prev: procedure
cursor = arg( 1 );
result = 1;
rc = FweJump( FweQueryY(), cursor, 1 );
charOnCur = FweQueryChar();
do while Length(charOnCur) = 1
if is_separator_prev(charOnCur) = 1 then do
if cursor <> arg(1) then do
cursor = cursor + 1;
rc = FweJump( FweQueryY(), cursor, 1 );
end;
leave;
end;
if cursor = 2 then do
result = 0;
leave;
end;
cursor = cursor - 1;
rc = FweJump( FweQueryY(), cursor, 1 );
charOnCur = FweQueryChar();
end;
return( result );
wrap_next: procedure
cursor = arg( 1 );
result = 1;
maxlen = FweQueryTextLength(0);
rc = FweJump( FweQueryY(), cursor, 1 );
charOnCur = FweQueryChar();
do while Length(charOnCur) = 1
if is_separator_next(charOnCur) = 1 then do
if charOnCur <> ' ' then do
cursor = cursor + 1;
if maxlen <= cursor then do
result = 0;
else
rc = FweJump( FweQueryY(), cursor, 1 );
end;
leave;
end;
if maxlen <= cursor then do
result = 0;
leave;
end;
cursor = cursor + 1;
rc = FweJump( FweQueryY(), cursor, 1 );
charOnCur = FweQueryChar();
end;
return( result );
is_separator_prev: procedure
chkchr = arg( 1 );
result = is_separator( chkchr );
/* -----------------------------------------
if result = 0 then do
select
when chkchr = ')' then do
result = 1;
end
when chkchr = ']' then do
result = 1;
end
otherwise
result = 0;
end;
end;
----------------------------------------- */
return( result );
is_separator_next: procedure
chkchr = arg( 1 );
result = is_separator( chkchr );
/* -----------------------------------------
if result = 0 then do
select
when chkchr = '(' then do
result = 1;
end
when chkchr = '[' then do
result = 1;
end
otherwise
result = 0;
end;
end;
----------------------------------------- */
return( result );
is_separator: procedure
chkchr = arg( 1 );
result = 0;
select
when chkchr = ' ' then do
result = 1;
end
/* -----------------------------------------
when chkchr = ',' then do
result = 1;
end
when chkchr = '-' then do
result = 1;
end
when chkchr = ';' then do
result = 1;
end
----------------------------------------- */
otherwise
result = 0;
end;
return( result );