/* * ----------------------------------------------------------------- * Execution of this macro requires a license for uni-XEDIT Extended * for each concurrent user of the macro. * ----------------------------------------------------------------- * * * * FLOW.XEDIT * * FLOW.XEDIT is a macro that aligns two or more lines of a text-type * file being edited (such as a NOTE). It attempts to place as many * words as possible on a single line, within the right margin defined * by the uni-XEDIT 'set trunc' setting. * * Execute the FLOW.XEDIT macro by typing * * flow * * where is a standard uni-XEDIT target defining the first * line not to be flowed. Typically, the alignment process will result * in there being fewer lines in the block than prior to alignment. * This, however, will not always be the case. * * UNIQUE CAPABILITY OF THIS PROGRAM: * * This macro can, unlike other parts of uni-XEDIT, shorten lines. * If you 'set trunc' to a value less than some of the lines in the * file, they will be handled properly by this macro. Elsewhere in * uni-XEDIT, results are unpredictable and may result in data loss. * */ /* Begin macro. */ doit: PARSE ARG targ tempfile = 'JJ.TEMP' CALL POPEN 'rm -f' tempfile 'PUTD' targ tempfile 'UP 1' 'EXTRACT /TRUNC' rotbuf = '' /* initialize rotating buffer */ DO FOREVER IF (LINES(tempfile) = 0) THEN LEAVE /* EOF? */ ibuf = LINEIN(tempfile) IF (SUBSTR(ibuf,1,1) = ' ') THEN DO /* Paragraph break, either kind */ IF (rotbuf ^= ' ') THEN DO /* Anything left in buffer? */ 'INPUT' rotbuf /* put it out */ rotbuf = '' END END IF (ibuf = ' ') THEN 'INPUT ' /* Blank line */ ELSE DO /* doit toit */ /* concatenate the new stuff */ IF (rotbuf = '') THEN rotbuf = STRIP(ibuf,'T') ELSE rotbuf = rotbuf STRIP(ibuf,'T') SELECT WHEN (LENGTH(rotbuf) = trunc.1) THEN DO /* perfect fit */ 'INPUT' rotbuf rotbuf = '' END WHEN (LENGTH(rotbuf) > trunc.1) THEN DO /* more than enough */ DO FOREVER /* Find last blank, starting at TRUNC.1+1, working backwards */ i = trunc.1+1 DO WHILE (SUBSTR(rotbuf,i,1) ^= ' ') i = i - 1 IF (i = 0) THEN SIGNAL word_too_long /* word > trunc */ END 'INPUT' SUBSTR(rotbuf,1,i-1) rotbuf = STRIP(SUBSTR(rotbuf,i),'B') IF (LENGTH(rotbuf) < trunc.1) THEN LEAVE /* Split enough? */ END END OTHERWISE NOP /* not long enough - read another line */ END /* end of select */ END END IF (rotbuf ^= ' ') THEN DO /* Anything left in buffer? */ 'INPUT' rotbuf /* put it out */ rotbuf = '' END /* Clean up our toys and go home */ CALL POPEN 'rm -f' tempfile RETURN /* Error routines */ word_too_long: 'INPUT **************************************************************' 'INPUT *ERROR* Justify encountered word longer than TRUNC setting.' 'INPUT Split word manually and restart justification from there.' 'INPUT Delete these error message lines.' 'INPUT **************************************************************' CALL EXIT 13 EXIT: PARSE ARG orc . EXIT orc