* * BOXMATH.KEX * * Perform the specified math operation on the numbers in the currently marked * line or box block using the specified value. Each number in the block is * replaced by the result. Results are leftadjusted within the block. * * Works with: * * KEDIT for Windows 1.5 * * For example, if the following was enclosed in a box block * * 10 * 243 * 25 * 260 * * and you issued the command * * boxmath * .75 * * the result would be: * * 75.00 * 182.25 * 18.75 * 195.00 * * Original author: Kent Downs, MSG, 8/96 * Updated 12/06 to change " " to "_" in line 64 - rightmost digits of input data * weren't always cleared from output data - JC/KJK, MSG parse arg op number * Check for possible errors. If one is encountered then we won't return. call ErrorCheck * Go to the top of the block "sos blockstart" * Process each line in the block do while line.1() <= block.4() * Get a copy of the entire current line line = curline.3() if block.1() = "LINE" then CurNumber = line else do * Compute the width of the block BlockWidth = block.5() - block.3() + 1 CurNumber = substr(line, block.3(), BlockWidth) end if datatype(CurNumber) \= "NUM" then do 'emsg BOXMATH Error 6: Invalid number encountered "'CurNumber'"' exit 6 end interpret "result =" CurNumber op number if block.1() = "LINE" then "replace" result else do "clocate :"block.3() if length(result) < BlockWidth then result = result || copies("_", BlockWidth - length(result)) "coverlay" result end * Move down a line to the next number "down 1" end * Go back to the top of the block "sos blockstart" if ResetBlock then "reset block" exit 0 * Do some basic error checking ErrorCheck: if block.1() = "NONE" then do "emsg BOXMATH Error 1: You must mark a box block around some numbers" exit 1 end if block.1() = "STREAM" then do "emsg BOXMATH Error 2: Only line and box blocks are supported" exit 2 end if op = "" then do "emsg BOXMATH Error 3: No math operation or number specified" exit 3 end if number = "" then do "emsg BOXMATH Error 4: No number specified" exit 4 end if datatype(number) \= "NUM" then do 'emsg BOXMATH Error 5: Invalid number specified "'number'"' exit 5 end if pos(op, "+-*/") = 0 then do "emsg BOXMATH Error 6: Invalid math operation specified" 'emsg Only "+", "-", "*" and "/" are supported' exit 3 end if block.7() = "PERSISTENT" then ResetBlock = 0 else do ResetBlock = 1 "mark persistent" end return