home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / amigae / e_v3.2a / tools / ee / rexx / justify.rexx < prev    next >
OS/2 REXX Batch file  |  1977-12-31  |  2KB  |  70 lines

  1. /* Justify.rexx - justify selected-block or current line in EE at column 80,
  2.    or column supplied on command line.
  3. */
  4.  
  5. ADDRESS 'EE.0'
  6. OPTIONS RESULTS
  7.  
  8. PARSE ARG rightMargin .
  9. IF rightMargin<=0 THEN rightMargin=80
  10.  
  11. LockWindow
  12.  
  13. /* Get block-dimensions; if no block selected, use current line only. */
  14. ?BlockDimensions; blockDimensions=RESULT
  15. PARSE VALUE blockDimensions WITH line dummy lastLine dummy .
  16. IF line=0 THEN DO
  17.   ?line; line=RESULT; lastLine=RESULT
  18. END
  19. CancelBlock
  20.  
  21. beginLine=line
  22. endLine=lastLine
  23. GotoLine beginLine
  24.  
  25. /* Save settings for restoral, then turn on Insert and turn off Justify. */
  26. ?InsertMode;  insertState =RESULT;  IF insertState =0 THEN InsertMode
  27. ?Justify;     justifyState=RESULT;  IF justifyState=1 THEN Justify
  28.  
  29. DO endLine-beginLine+1
  30.   /* While line is longer than right margin... */
  31.   ?Length; length=RESULT
  32.   DO WHILE length>rightMargin
  33.     /* Look for a space to break line... */
  34.     GotoColumn rightMargin+1
  35.     column=rightMargin+1
  36.     DO WHILE column>1
  37.       GetChar; char=RESULT
  38.       IF char=' ' THEN DO
  39.         /* Eat spaces, split line, then continue. */
  40.         DO WHILE char=' ' & column<=length
  41.           DeleteChar
  42.           GetChar; char=RESULT
  43.           ?Length; length=RESULT
  44.         END
  45.         IF column<length THEN SplitLine
  46.         ?Length; length=RESULT
  47.         LEAVE
  48.        END
  49.       ELSE DO
  50.         CursorLeft
  51.         column=column-1
  52.       END
  53.     END
  54.     /* If no spaces found, split line at right margin. */
  55.     IF column=1 THEN DO
  56.       GotoColumn rightMargin+1
  57.       SplitLine
  58.       ?Length; length=RESULT
  59.     END
  60.   END
  61.   CursorDown
  62. END
  63.  
  64.  
  65. /* Restore window settings and exit. */
  66. IF insertState =0 THEN InsertMode
  67. IF justifyState=0 THEN Justify
  68. UnlockWindow
  69. EXIT 0
  70.