* * CAPITALS.KEX * * Capitalize words in the current file starting at the current line. * You indicate which lines are capitalized by specifying a target which * can be "all", "*", "block" or "n". "All" means the entire file. "*" means * the current line through the last line. "Block" means the current box or * line block. "N" means the current line and the n-1 lines below it for a * total of "n" lines. * * For example, * * capitals 5 * * Will capitalize the current line and the 4 lines below it for a total of 5 * lines. * * Works with: * * KEDIT for Windows 1.5 * KEDIT 5.0 for DOS * KEDIT 5.0 for OS/2 * * Note that word boundaries are spaces. When using a box block though, the * left edge of the block is also assumed to be a word boundary. * parse upper arg target if target = "" then do 'emsg CAPITALS Error 1: No target specified...' exit 1 end if target \= "ALL" & target \= "*" & target \= "BLOCK" & datatype(target) \= "NUM" then do 'emsg CAPITALS Error 2: Invalid target specified "'target'"' exit 2 end "preserve" "set autosave off" ANSIFont = 0 if version.1() = 'KEDIT/WINDOWS' then do if \oemfont() then ANSIFont = 1 end call FirstLine * Process each line of the target area do while WithinTargetArea() line = NextLine() if line \= "" then do NewLine = "" * Capitalize each word in this line do i = 1 to words(line) n = wordindex(line, 1) m = wordindex(line, 2) if m = 0 then token = line else do token = substr(line, 1, m - 1) line = substr(line, m) end OldChar = substr(token, 1, 1) token = substr(token, 2) if ANSIFont then NewChar = ansiupper(OldChar) else NewChar = upper(OldChar) NewLine = NewLine || NewChar || token end * Update the file with the capitalized line "replace" left || NewLine || right end 'down 1' end "restore" call RestorePosition exit 0 * Make the first line of the target area the focus line FirstLine: ResetBlock = 0 if target = "BLOCK" then do if block.1() = "NONE" then do "emsg CAPITALS Error 3: No block is marked" exit 3 end if block.6() \= fileid.1() then do "emsg CAPITALS Error 4: Marked block is not in the current file" exit 4 end if block.1() = "STREAM" then do "emsg CAPITALS Error 5: Stream blocks are not supported" exit 5 end if version.1() = "KEDIT/WINDOWS" then do if block.7() = "SELECTION" then do * Need to make selections persistant blocks ResetBlock = 1 "mark persistant" end end end call SavePosition if target = "*" | datatype(target) = "NUM" then do if focustof() then "down 1" return end if target = "ALL" then do ":1" return end if target = "BLOCK" then "sos blockstart" return * Save the current line and cursor position SavePosition: "sos save" OnCmdline = command() StartLine = line.1() if \OnCmdline then do "cursor cmdline" n = StartLine StartLine = line.1() ":"n return end return * Restore the current line and cursor position RestorePosition: ":"StartLine if \OnCmdline then "sos current" "sos restore" return * Return 1 if the focusline is within the target area WithinTargetArea: if target = "*" | target = "ALL" then return \focuseof() if datatype(target) = "NUM" then return target > 0 return line.1() <= block.4() * Return the next line or portion of a line that needs to be capitalized NextLine: line = curline.3() if target = "BLOCK" & block.1() = "BOX" then do if block.3() > 1 then do left = substr(line, 1, block.3() - 1) right = substr(line, block.5() + 1) line = substr(line, block.3(), block.5() - block.3() + 1) end end if datatype(target) = "NUM" then target = target - 1 n = wordindex(line, 1) if n = 0 then do left = "" right = "" end else if n = 1 then left = "" else do left = substr(line, 1, n - 1) line = substr(line, n) end right = "" return line