/* ----------------------------------------------------------------- Execution of this macro requires a license for uni-XEDIT Extended for each concurrent user of the macro. ----------------------------------------------------------------- bmove.xedit adapted and generalized, by: The Workstation Group supplied to TWG by: H. F. Veldman - IST original author: A. B. Doremus, University of Oregon description: This XEDIT macro may be used to move any arbitrary rectangular block of text in a file being edited to any arbitrary new position within the confines of the file. The term "move" is used to mean that the source block is blanked out before the copy is completed. The macro name should be assigned to a PF key. To use: position cursor over any corner of block to be moved and press assignd PF key. Then position cursor to diagonally opposite corner of block and again enter Pf key. Finally, move cursor to upper left corner where block should be moved and enter PF key. dependencies: Only works on display terminals. The program stack must be empty on entry (XEDIT READ doesn't work, otherwise). =======================================================================*/ trace o TRUE = 1 FALSE = 0 macname = 'BMOVE' call get_src_corners call get_dest_corners 'extract /line' /* store current line position */ /* See if file needs to be expanded to hold moved block */ 'extract /size' lastln = dest_line + lines - 1 if size.1 < lastln then do 'bot' 'add' lastln-size.1 end /* position to first line of block */ ':'start_line /* stack (actually, queue) the piece of each line */ /* following loop is equivalent of CMS 'STACK' command */ do lines 'extract /curline' string = substr(curline.3,start_col,length) queue string 'down 1' end /* blank out source block */ ':'start_line 'cl:'start_col blanks = left('', length, ' ') /* get string of blanks */ do lines 'creplace' blanks /* replace existing string with blanks */ 'down' /* position for next line */ end /* position to destination line and column */ /* (could check here that block will fit) */ ':'dest_line 'cl:'dest_col do lines parse pull str /* get source string from stack */ 'creplace' str /* replace existing string */ 'down' /* position for next line */ end /* position to old current line and first column */ ':'line.1 'cfirst' exit /*=====================================================================*/ /**************/ get_src_corners: /**************/ if queued() > 0 then do /* XEDIT READ won't work unls pgm stk empty*/ 'msg' macname': program stack must be empty' signal exit16 end /* extract cursor position, validate, and save */ /* also get number of alterations */ 'extract /cursor/alt' /* compare current to original position */ if cursor.3 ~= cursor.7 | cursor.4 ~= cursor.8 then do 'msg' macname': file was changed by prefix operation, aborting' signal exit16 end if cursor.3 = -1 | cursor.4 = -1 then do /* cursor within file? */ 'msg' macname': cursor is not within file, aborting' signal exit16 end c1_line = cursor.3 /* line number in file for first corner */ c1_col = cursor.4 /* column num in file for first corner */ entryalt.1 = alt.1 /* save alteration values on entry */ entryalt.2 = alt.2 done = FALSE do while ~done thismac = FALSE 'msg' macname': move cursor to diagonally opposite corner', 'and enter pf key' 'read cmdline tag' /* see what user hath wrought */ /* (stacked LIFO) */ queued = queued() parse pull tag pfnum pfstring if queued = 2 then do /* => something on cmd line */ parse pull cmdtag cmdstring dot = pos('.xedit',cmdstring) if dot >0 then macstring = substr(cmdstring,1,dot-1) else macstring = cmdstring if wordpos(macname,upper(macstring))=0 then cmdstring else thismac = TRUE end select when tag = 'PFK' | tag = 'PAK' then do dot = pos('.xedit',pfstring) if dot >0 then macstring = substr(pfstring,1,dot-1) else macstring = pfstring if wordpos(macname,upper(macstring))=0 then pfstring else thismac = TRUE end when tag = 'CMD' | tag = 'ETK' then do dot = pos('.xedit',pfnum) if dot >0 then macstring = substr(pfnum,1,dot-1) else macstring = pfnum if wordpos(macname,upper(macstring))=0 then pfnum pfstring else thismac = TRUE end otherwise nop end if thismac then done = TRUE /* If we've somehow quit from last file in ring, get out of here */ 'extract /ring' if rc=6 then exit end /* extract cursor position, validate, and save */ 'extract /cursor/alt' /* compare current to original position */ if cursor.3 ~= cursor.7 | cursor.4 ~= cursor.8 then do 'msg' macname': file was changed by prefix operation, aborting' signal exit16 end if cursor.3 = -1 | cursor.4 = -1 then do /* cursor within file? */ 'msg' macname': cursor is not within file, aborting' signal exit16 end if entryalt.1 ~= alt.1 | entryalt.2 ~= alt.2 then do 'msg' macname': file has been changed, aborting' signal exit16 end c2_line = cursor.3 /* line number in file for second corner */ c2_col = cursor.4 /* column num in file for second corner */ /* calculate number of lines, number of columns */ start_col = min(c1_col, c2_col) length = abs(c1_col - c2_col) + 1 start_line = min(c1_line, c2_line) lines = abs(c1_line - c2_line) + 1 return /***************/ get_dest_corners: /***************/ /* now handle destination */ done = FALSE do while ~done thismac = FALSE 'msg' macname': move to upper lefthand corner of destination,', 'enter pf key' 'read cmdline tag' /* see what user hath wrought */ /* (stacked LIFO) */ queued = queued() parse pull tag pfnum pfstring if queued = 2 then do /* => something on cmd line */ parse pull cmdtag cmdstring dot = pos('.xedit',cmdstring) if dot >0 then macstring = substr(cmdstring,1,dot-1) else macstring = cmdstring if wordpos(macname,upper(macstring))=0 then cmdstring else thismac = TRUE end select when tag = 'PFK' | tag = 'PAK' then do dot = pos('.xedit',pfstring) if dot >0 then macstring = substr(pfstring,1,dot-1) else macstring = pfstring if wordpos(macname,upper(macstring))=0 then pfstring else thismac = TRUE end when tag = 'CMD' | tag = 'ETK' then do dot = pos('.xedit',pfnum) if dot >0 then macstring = substr(pfnum,1,dot-1) else macstring = pfnum if wordpos(macname,upper(macstring))=0 then pfnum pfstring else thismac = TRUE end otherwise nop end if thismac then done = TRUE /* If we've somehow quit from last file in ring, get out of here */ 'extract /ring' if rc=6 then exit end /* extract cursor position, validate, and save */ /* also get number of alterations and current line number */ 'extract /cursor/alt' /* compare current to original position */ if cursor.3 ~= cursor.7 | cursor.4 ~= cursor.8 then do 'msg' macname': file was changed by prefix operation, aborting' signal exit16 end if cursor.3 = -1 | cursor.4 = -1 then do /* cursor within file? */ 'msg' macname': cursor is not within file, aborting' signal exit16 end if entryalt.1 ~= alt.1 | entryalt.2 ~= alt.2 then do 'msg' macname': file has been changed, aborting' signal exit16 end dest_line = cursor.3 /* line number in file for destination corner */ dest_col = cursor.4 /* column num in file for destination corner */ return /*=====================================================================*/ exit16: /* error return */ exit(16)