home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / fwe225.zip / Split.Mac < prev    next >
Text File  |  2000-01-06  |  10KB  |  302 lines

  1. /* ************************************************************************* */
  2. /*              Future Wave Editor  Sample Macro program.                    */
  3. /*                                                                           */
  4. /*                    ÄwÆΦîàé┼é╠âeâLâXâgÉ«î`â}âNâì                           */
  5. /* ------------------------------------------------------------------------- */
  6. /* ê°Éö  :  æ╡éªéΘì┼æσîàÉö                                                   */
  7. /*          âÅü[âhüEâëâbâv   0   : ïûë┬                                      */
  8. /*                          ê╚èO : ï╓Ä~                                      */
  9. /* ------------------------------------------------------------------------- */
  10. /*                                                                           */
  11. /* 1).ê°Éöé╠ÄwÆΦé¬û│éóé⌐Ælé¬òsôKÉ╪é╚ÅΩìçé═üCæ╡éªéΘì┼æσîàÉöé≡âåü[âUü[é⌐éτ     */
  12. /*    ôⁿù═é╡é─éαéτéñ                                                         */
  13. /*                                                                           */
  14. /* 2).âÅü[âhüEâëâbâvé╠ÄwÆΦé¬é╚é»éΩé╬üCâåü[âUü[é⌐éτæIæ≡é╡é─éαéτéñüD           */
  15. /*    âÅü[âhüEâëâbâvé¬ùLî°é┼üCÆPîΩôrÆåé╠É▄éΦò╘é╡é≡ï╓Ä~é╖éΘüD                 */
  16. /*                                                                           */
  17. /* 3).âJü[â\âïé≡ɵô¬ìsé╠ɵô¬îàé╔ê┌ô«                                         */
  18. /*                                                                           */
  19. /* 4).ì┼ÅIìsé▄é┼üAÄwÆΦîàÉöê╚ÅπéáéΘìsé≡ÄwÆΦîàÉöé┼ò¬èäé╖éΘ                     */
  20. /*                                                                           */
  21. /* ------------------------------------------------------------------------- */
  22. /*    (C) Copyright Future Wave Limited.  1997-1999 All right reserved.      */
  23. /* ************************************************************************* */
  24. arg     nSplitPos fWordWrap
  25.  
  26. trace off
  27.  
  28. MAX_TAB_SIZE = 8;                       /* Max TAB size                      */
  29.  
  30.         /* ----------------------------------------------------------- */
  31.         /*          C  o  n  s  t      M  e  s  s  a  g  e  s          */
  32.         /* ----------------------------------------------------------- */
  33. szTitle      = "ÄwÆΦîàÉ«î`â}âNâì";
  34. szMsgMax     = "ì┼æσîàÉöé≡ôⁿù═é╡é─ë║é│éóüB";
  35. szMsgMin     = "ôⁿù═îàÉöé═ 8 ê╚Åπé┼é╖üB";
  36. szMsgWay     = " É▄éΦò╘é╡ê╩Æué¬ÆPîΩôrÆåé┼éαüC" x2c(0a) "É▄éΦò╘é╡é≡Ä└ìsé╡é▄é╖é⌐üH";
  37. szMsgExec1   = " æ╡éªéΘì┼æσîàÉöé═";
  38. szMsgExec2   = "îàé┼üC" x2c(0a)
  39. szMsgWrap    = "É▄ò╘ê╩Æué¬ÆPîΩôrÆåé┼éαÉ▄ò╘é╡é▄é╖üD";
  40. szMsgNoWrap  = "ÆPîΩôrÆåé┼é═É▄ò╘é╡é▄é╣é±üD";
  41. szMsgExec3   = x2c(0a) "Åêù¥é≡èJÄné╡é▄é╖üB";
  42. szMsgAbort   = "ò╥ÅWï╓Ä~Å≤æ╘é╠é╜é▀Åêù¥ÆåÆfüIüI";
  43.  
  44.         /* ----------------------------------------------------------- */
  45.         /*                       M    a    i    n                      */
  46.         /* ----------------------------------------------------------- */
  47. main:
  48.         count    = 0;
  49.         wordwrap = 0;
  50.  
  51.         /* Can I edit (FWE is not disabled) ? */
  52.         if FweQueryEditMode() = 0 then do
  53.  
  54.            /* ------------------------------- */
  55.            /*  check and set split position.  */
  56.            /* ------------------------------- */
  57.            if datatype(nSplitPos,'N') = 1 then
  58.               count = nSplitPos;
  59.  
  60.            do while count < MAX_TAB_SIZE
  61.               do Forever until datatype(count,'N') = 1
  62.                  say szMsgMax;
  63.                  say szMsgMin;
  64.                  pull count;
  65.               end;
  66.            end;
  67.  
  68.            /* ------------------------------- */
  69.            /*     check and set word-wrap.    */
  70.            /* ------------------------------- */
  71.            if datatype(fWordWrap,'N') = 1 then do
  72.               wordwrap = fWordWrap;
  73.            end
  74.            else do
  75.               if fWordWrap = "" then do
  76.                  if RxMessageBox( szMsgWay, szTitle, "YESNO", "QUESTION" ) = 6 then do
  77.                     wordwrap = 0;
  78.                  end
  79.                  else do
  80.                     wordwrap = 1;
  81.                  end;
  82.               end;
  83.            end;
  84.  
  85.            /* ------------------------------- */
  86.            /*       confirm and execute.      */
  87.            /* ------------------------------- */
  88.            szMsg = szMsgExec1 count szMsgExec2
  89.  
  90.            if wordwrap = 0 then do
  91.               szMsg = szMsg szMsgWrap
  92.            end
  93.            else do
  94.               szMsg = szMsg szMsgNoWrap
  95.            end;
  96.  
  97.            szMsg = szMsg szMsgExec3
  98.  
  99.            if RxMessageBox( szMsg, szTitle, "OKCANCEL", "QUESTION" ) = 1 then do
  100.               rc = FweJump( 1, 1 );
  101.  
  102.               do Forever until FweDown() <> 0
  103.                  if split( count, wordwrap ) <> 0 then
  104.                     leave;
  105.               end;
  106.            end;
  107.         end
  108.         else do
  109.            rc = RxMessageBox( szMsgAbort, szTitle, "OK", "INFORMATION" );
  110.         end;
  111.  
  112.         /* delete macro-executing log. */
  113.         rc = FweClearLog();
  114.  
  115.         exit;
  116.  
  117.         /* ----------------------------------------------------------- */
  118.         /*                     S    p    l    i    t                   */
  119.         /* ----------------------------------------------------------- */
  120. split: procedure
  121.         maxColumns = arg( 1 );
  122.         flWordWrap = arg( 2 );
  123.         nRetcode   = 0;
  124.  
  125.         do while FweQueryTextLength(0) > maxColumns
  126.            /* doing word-wrap ? */
  127.            select
  128.               /* word-wrap */
  129.               when flWordWrap <> 0 then do
  130.                  nRetcode = wrap_prev( maxColumns );
  131.  
  132.                  if nRetcode = 0 then do
  133.                     nRetcode = wrap_next( maxColumns );
  134.                  end;
  135.               end;
  136.  
  137.               /* no word-wrap */
  138.               when flWordWrap = 0 then do
  139.                  rc = FweJump( FweQueryY(), maxColumns, 1 );
  140.                  nRetcode = 1;
  141.               end;
  142.            end;
  143.  
  144.            /* split text */
  145.            if nRetcode <> 0 then do
  146.               nRetcode = FweInputReturn();
  147.  
  148.               if nRetcode <> 0 then
  149.                  leave;
  150.            end
  151.            else do
  152.               leave;
  153.            end;
  154.         end;
  155.  
  156.         return( nRetcode );
  157.  
  158.         /* ----------------------------------------------------------- */
  159.         /*              W   o   r   d        w   r   a   p             */
  160.         /* ----------------------------------------------------------- */
  161. wrap_prev: procedure
  162.         cursor = arg( 1 );
  163.         result = 1;
  164.  
  165.         rc        = FweJump( FweQueryY(), cursor, 1 );
  166.         charOnCur = FweQueryChar();
  167.  
  168.         do while Length(charOnCur) = 1
  169.            if is_separator_prev(charOnCur) = 1 then do
  170.               if cursor <> arg(1) then do
  171.                  cursor = cursor + 1;
  172.                  rc     = FweJump( FweQueryY(), cursor, 1 );
  173.               end;
  174.  
  175.               leave;
  176.            end;
  177.  
  178.            if cursor = 2 then do
  179.               result = 0;
  180.               leave;
  181.            end;
  182.  
  183.            cursor    = cursor - 1;
  184.            rc        = FweJump( FweQueryY(), cursor, 1 );
  185.            charOnCur = FweQueryChar();
  186.         end;
  187.  
  188.         return( result );
  189.  
  190.  
  191. wrap_next: procedure
  192.         cursor = arg( 1 );
  193.         result = 1;
  194.         maxlen = FweQueryTextLength(0);
  195.  
  196.         rc        = FweJump( FweQueryY(), cursor, 1 );
  197.         charOnCur = FweQueryChar();
  198.  
  199.         do while Length(charOnCur) = 1
  200.            if is_separator_next(charOnCur) = 1 then do
  201.               if charOnCur <> ' ' then do
  202.                  cursor = cursor + 1;
  203.  
  204.                  if maxlen <= cursor then do
  205.                     result = 0;
  206.                  else
  207.                     rc = FweJump( FweQueryY(), cursor, 1 );
  208.               end;
  209.  
  210.               leave;
  211.            end;
  212.  
  213.            if maxlen <= cursor then do
  214.               result = 0;
  215.               leave;
  216.            end;
  217.  
  218.            cursor    = cursor + 1;
  219.            rc        = FweJump( FweQueryY(), cursor, 1 );
  220.            charOnCur = FweQueryChar();
  221.         end;
  222.  
  223.         return( result );
  224.  
  225.  
  226. is_separator_prev: procedure
  227.         chkchr = arg( 1 );
  228.         result = is_separator( chkchr );
  229.  
  230. /* -----------------------------------------
  231.         if result = 0 then do
  232.            select
  233.               when chkchr = ')' then do
  234.                  result = 1;
  235.               end
  236.  
  237.               when chkchr = ']' then do
  238.                  result = 1;
  239.               end
  240.  
  241.               otherwise
  242.                  result = 0;
  243.            end;
  244.         end;
  245.    ----------------------------------------- */
  246.  
  247.         return( result );
  248.  
  249.  
  250. is_separator_next: procedure
  251.         chkchr = arg( 1 );
  252.         result = is_separator( chkchr );
  253.  
  254. /* -----------------------------------------
  255.         if result = 0 then do
  256.            select
  257.               when chkchr = '(' then do
  258.                  result = 1;
  259.               end
  260.  
  261.               when chkchr = '[' then do
  262.                  result = 1;
  263.               end
  264.  
  265.               otherwise
  266.                  result = 0;
  267.            end;
  268.         end;
  269.    ----------------------------------------- */
  270.  
  271.         return( result );
  272.  
  273.  
  274. is_separator: procedure
  275.         chkchr = arg( 1 );
  276.         result = 0;
  277.  
  278.         select
  279.            when chkchr = ' ' then do
  280.               result = 1;
  281.            end
  282.  
  283. /* -----------------------------------------
  284.            when chkchr = ',' then do
  285.               result = 1;
  286.            end
  287.  
  288.            when chkchr = '-' then do
  289.               result = 1;
  290.            end
  291.  
  292.            when chkchr = ';' then do
  293.               result = 1;
  294.            end
  295.    ----------------------------------------- */
  296.  
  297.            otherwise
  298.               result = 0;
  299.         end;
  300.  
  301.         return( result );
  302.