home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmsmp.zip / COLORMAR.E < prev    next >
Text File  |  1992-08-26  |  2KB  |  66 lines

  1. ; COLORMARK.E - routine to color a marked region
  2. ;
  3. ; The following is set up to be a separate .ex file that you execute by
  4. ; typing its name on the EPM command line.
  5.  
  6. ; Color a marked region in EPM, by Larry Margolis
  7.  
  8. defmain
  9.    argstring = upcase(arg(1))
  10.    parse value argstring with w1 rest
  11.    if w1 = '' | w1 = '?' then
  12.       sayerror 'colormark [foreground] [[ON] background]  e.g., Colormark red on light cyan'
  13.       return
  14.    endif
  15.    mt = marktype()
  16.    if mt = '' then
  17.       sayerror -280  -- 'Text not marked.'
  18.       return
  19.    endif
  20.    fg = trunc(.textcolor//16)
  21.    bg = .textcolor%16
  22.    if w1 <> 'ON' then
  23.       fg = getcolor(argstring)
  24.       parse value argstring with w1 rest
  25.       if w1='ON' then argstring = rest; endif
  26.    else
  27.       argstring = rest
  28.    endif
  29.    if argstring <> '' then
  30.       bg = getcolor(argstring)
  31.    endif
  32.    attribute = bg * 16 + fg
  33. ; following from ProcessFontRequest in STDCTRL.E
  34.    getmark fstline, lstline, fstcol, lstcol, mkfileid
  35.    call attribute_on(1)  -- Colors flag
  36.    if mt='BLOCK' then
  37.       do i = fstline to lstline
  38.          Insert_Attribute_Pair(1, attribute, i, i, fstcol, lstcol, mkfileid)
  39.       enddo
  40.    else
  41.       if mt='LINE' then
  42.          getline line, lstline, mkfileid
  43.          lstcol=length(line)
  44.       endif
  45.       Insert_Attribute_Pair(1, attribute, fstline, lstline, fstcol, lstcol, mkfileid)
  46.    endif
  47.    call attribute_on(8)  -- "Save attributes" flag
  48.  
  49. const --wrd# 1     2    3     4    5   6       7     8          9         10         11        12         13          14         15        16            17     18          19
  50.    colors = 'BLACK BLUE GREEN CYAN RED MAGENTA BROWN LIGHT_GREY DARK_GREY LIGHT_GRAY DARK_GRAY LIGHT_BLUE LIGHT_GREEN LIGHT_CYAN LIGHT_RED LIGHT_MAGENTA YELLOW LIGHT_BROWN WHITE'
  51.    values = '0     1    2     3    4   5       6     7          8         7          8         9          10          11         12        13            14     14          15'
  52.  
  53. defproc getcolor(var colorstring)
  54.    parse value colorstring with w1 colorstring
  55.    if w1 = 'LIGHT' | w1='DARK' then
  56.       parse value colorstring with c colorstring
  57.       w1 = w1'_'c
  58.    endif
  59.    p = wordpos(w1, colors)
  60.    if p then
  61.       return word(values, p)
  62.    endif
  63.    sayerror 'Invalid argument:  'w1
  64.    stop
  65.  
  66.