home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / prodtool / epm / e_macros / draw.e < prev    next >
Encoding:
Text File  |  1992-08-11  |  13.8 KB  |  446 lines

  1. /******************************************************************************
  2.  
  3. DRAW.E         revised from SLIMDRAW.E                   Bryan Lewis 3/23/88
  4.  
  5. Two small changes have made this a separately-compilable and
  6. linkable-at-runtime module.  In EOS2 it makes more sense to
  7. "connect up" the DRAW feature only when needed, rather than compile it
  8. into the always-present base.  Any stand-alone command (not called as a
  9. subroutine by others) that's used only occasionally is a good candidate for
  10. linking.
  11.  
  12. (1) The conditional compilation test (WANT_DRAW) has been removed to
  13. make this separately compilable, since WANT_DRAW is defined in
  14. STDCNF.E, not available when this is compiled alone.
  15.  
  16. (2) A DEFMAIN has been added which merely invokes the original DRAW command.
  17.  
  18. When the user issues "draw" on the command line, DRAW.EX will be linked
  19. from disk and entered at DEFMAIN.  The effect seen by the user will be the same
  20. as before, except for the slight delay of searching the DPATH for DRAW.EX.
  21. When DEFMAIN finishes, DRAW.EX will be automatically unlinked to free up
  22. memory.
  23.  
  24.  
  25. (SlimDraw was revised from Davis Foulger's DRAW.E by Bryan Lewis 10/87.)
  26. (Insert-toggle feature suggested by John McAssey.)
  27.  
  28. ******************************************************************************/
  29.  
  30. compile if not defined(SMALL)  -- If being externally compiled...
  31. const
  32.    tryinclude 'MYCNF.E'
  33. const
  34.  compile if not defined(WANT_DBCS_SUPPORT)
  35.    WANT_DBCS_SUPPORT = 0
  36.  compile endif
  37.  compile if not defined(NLS_LANGUAGE)
  38.    NLS_LANGUAGE = 'ENGLISH'
  39.  compile endif
  40.  include NLS_LANGUAGE'.e'
  41.  include 'stdconst.e'
  42. compile endif
  43.  
  44. compile if EVERSION < 4       -- For EOS2, Removed to DRAWKEY.E, to make this
  45.  compile if WANT_DRAW <> 1    -- separately compilable.
  46. def F6=
  47.    cursor_command
  48.    'draw'
  49.  compile endif
  50.  
  51. compile else
  52.  
  53. defmain     --  We want to start executing as soon as we're linked.
  54.    'draw' arg(1)
  55.  
  56. compile endif  -- EVERSION < 4
  57.  
  58. defc draw
  59.    universal boxtab1,boxtab2,boxtab3,boxtab4
  60.    universal g1,g2,g3,g4,g5,g6,g7,g8,g9,ga,gb
  61. compile if WANT_DBCS_SUPPORT
  62.    universal ondbcs
  63. compile endif
  64. compile if EVERSION >= 5
  65.    universal draw_starting_keyset
  66.  compile if EVERSION >= '5.21'
  67.    universal cursor_mode
  68.  compile endif
  69.    if .keyset = 'DRAW_KEYS' then
  70.       sayerror ALREADY_DRAWING__MSG
  71.       return
  72.    endif
  73. compile endif
  74.  
  75.    style=upcase(substr(arg(1),1,1))
  76.    if not length(style) or verify(style,"123456B/") then
  77. compile if WANT_DBCS_SUPPORT
  78.    if ondbcs then
  79.       sayerror DRAW_ARGS_DBCS__MSG
  80.    else
  81. compile endif
  82.       sayerror DRAW_ARGS__MSG
  83. compile if WANT_DBCS_SUPPORT
  84.    endif
  85. compile endif
  86. compile if EVERSION < 5
  87.       setcommand 'Draw',6,1
  88. compile endif
  89.       return
  90.    endif
  91.  
  92.    /* Pick characters from a packed string rather than if's, to save space. */
  93. compile if WANT_DBCS_SUPPORT
  94.    if ondbcs then
  95.       all6=\23\5\2\4\3\1\21\22\25\6\16'+|+++++++-+'\11\11\11\11\11\11\11\11\11\11\11\14\14\14\14\14\14\14\14\14\14\14\20\20\20\20\20\20\20\20\20\20\20\26\26\26\26\26\26\26\26\26\26\26
  96.    else
  97. compile endif
  98.    all6='┤│┐┘└┌┴┬├─┼╣║╗╝╚╔╩╦╠═╬+|+++++++-+███▀▀█▀██▀█╡│╕╛╘╒╧╤╞═╪╢║╖╜╙╓╨╥╟─╫'
  99. compile if WANT_DBCS_SUPPORT
  100.    endif
  101. compile endif
  102.    if style='/' then
  103. compile if EVERSION > 5
  104.       drawchars=copies(substr(arg(1),2,1),11)
  105. compile else
  106.       drawchars=substr('',1,11,substr(arg(1),2,1)) /* 11 copies of 2nd char */
  107. compile endif
  108.    elseif style='B' then
  109.       drawchars=substr('',1,11)
  110.    else
  111.       drawchars=substr(all6,11*style-10,11)
  112.    endif
  113. ;  LAM - changed assignments to a parse statement.  Saved 140 bytes of .ex file.
  114.    parse value drawchars with g1 +1 g2 +1 g3 +1 g4 +1 g5 +1 g6 +1 g7 +1 g8 +1 g9 +1 ga +1 gb
  115.    boxtab1=g1||g2||g4||g5||g7||g9||gb
  116.    boxtab2=g1||g2||g3||g6||g8||g9||gb
  117.    boxtab3=g1||ga||g4||g3||g7||g8||gb
  118.    boxtab4=g9||ga||g5||g6||g7||g8||gb
  119.  
  120. compile if EVERSION < 5
  121.    if command_state() then cursor_data endif
  122. compile endif
  123.    istate=insert_state();
  124.    if istate then insert_toggle
  125. compile if EVERSION >= '5.50'
  126.       call fixup_cursor()
  127. compile endif
  128.    endif
  129.  
  130. compile if EVERSION < 5
  131.    sayerror DRAW_PROMPT__MSG
  132.    loop
  133.       k=getkey()
  134.       /* Insert key toggles drawing; if insert is on, simply do the key. */
  135.       if insert_state() then executekey k; iterate; endif
  136.       if k=left then
  137.          draw_left()
  138.       elseif k=right then
  139.          draw_right()
  140.       elseif k=up then
  141.          draw_up()
  142.       elseif k=down then
  143.          draw_down()
  144.       /* Allow a few other keys for minor editing. */
  145.       elseif k=backspace or k=' ' or k=home or k=end or k=del or k=ins then
  146.          executekey k
  147.       else /* All other keys simply exit draw. */
  148.          leave
  149.       endif
  150.    endloop
  151.    if istate<>insert_state() then insert_toggle
  152. compile if EVERSION >= '5.50'
  153.       call fixup_cursor()
  154. compile endif
  155.    endif
  156.    sayerror DRAW_ENDED__MSG
  157. compile else
  158.    -- EPM:  The old DRAW used a getkey() loop.  We don't have getkey() in EPM.
  159.    -- The new way:  define a clear keyset of only the active keys.
  160.    draw_starting_keyset = upcase(.keyset)
  161.    keys draw_keys
  162.  compile if EVERSION >= '5.21'
  163.    cursor_mode = querycontrol(26)
  164.    'togglecontrol 26 0'
  165.  compile endif
  166.  
  167. -- Make it a BASE CLEAR keyset so the only keys that do anything are
  168. -- the ones we explicitly define.  Without the CLEAR, the standard ASCII keys
  169. -- like 'a'-'z' would be automatically included.
  170. defkeys draw_keys base clear
  171. def left    =
  172.    if insert_state() then
  173.       left
  174.    else
  175.       draw_left()
  176.    endif
  177. def right   =
  178.    if insert_state() then
  179.       right
  180.    else
  181.       draw_right()
  182.    endif
  183. def up      =
  184.    if insert_state() then
  185.       up
  186.    else
  187.       draw_up()
  188.    endif
  189. def down    =
  190.    if insert_state() then
  191.       down
  192.    else
  193.       draw_down()
  194.    endif
  195. def backspace  =
  196.    rubout
  197. def ins        =
  198.    insert_toggle
  199. compile if EVERSION >= '5.50'
  200.     call fixup_cursor()
  201. compile endif
  202. def space      =
  203.    keyin ' '
  204. def home       =
  205.    begin_line
  206. def end        =
  207.    end_line
  208. def del        =
  209.    delete_char
  210.  
  211. -- New in EPM.  This event (pseudo-key) is triggered whenever an otherwise
  212. -- undefined key is pressed.  We let any other key exit draw mode.
  213. -- (Any other key but mouse_move, that is.  It's not considered an "other key"
  214. -- because the mouse movement is too sensitive.
  215. -- This new wrinkle isn't really required.  We could define only one or two
  216. -- keys (like Esc) as exits and simply ignore all others.
  217. def otherkeys, F3 =   -- or def Esc
  218.    universal draw_starting_keyset
  219.  compile if EVERSION >= '5.21'
  220.    universal cursor_mode
  221.  compile endif
  222.    -- Whatever other key the user pressed, remember it so we can execute it.
  223.    k = lastkey()
  224.    -- Just in case the user doesn't have a select_edit_keys(), return to
  225.    -- the standard keyset to make sure we don't get stuck in draw_keys.
  226.    keys edit_keys
  227.    .keyset = draw_starting_keyset -- Return to whatever keyset had been there.
  228.  compile if EVERSION >= '5.21'
  229.    'togglecontrol 26' cursor_mode
  230.  compile endif
  231.    -- Execute the key the user pressed when he quit drawing.
  232.    sayerror DRAW_ENDED__MSG
  233.    if k<>esc & k<>c_I & k<>F3 then executekey k; endif   -- But assume Esc was just to stop DRAW.
  234.  
  235. -- End of EPM mods. ----------------------------------------------------------
  236. compile endif
  237.  
  238. defproc get_char
  239.    universal linepos,colpos,target
  240.    colpos=.col
  241.    linepos=.line
  242.    getline target
  243.    return substr(target,.col,1)
  244.  
  245. defproc draw_up      /* draw logic for the up key */
  246.    universal last,l,r,u,d,boxtab1,linepos,colpos
  247.    universal g1,g2,g3,g4,g5,g6,g7,g8,g9,ga,gb
  248.  
  249.    if last='d' then up
  250.    else c=get_char()
  251.       if last=='u' and c==' ' then keyin g2;left;up
  252.          elseif not verify(c,boxtab1) then up
  253.          elseif c==g3 then keyin g1;left;up
  254.          elseif c==g6 then keyin g9;left;up
  255.          elseif c==g8 then keyin gb;left;up
  256.          elseif c==ga then
  257.             call left_right()
  258.             if l=1 and r=1 then keyin g7 elseif l=1 then keyin g4 else keyin g5 endif
  259.             left;up
  260.          else call left_right()
  261.               if last='r' and l=1 then keyin g4
  262.                  elseif last='l' and r=1 then keyin g5
  263.                  else keyin g2
  264.                  endif
  265.               left;up
  266.          endif
  267.       if linepos=1 then insert; .col=colpos
  268.       else
  269.          c=get_char()
  270.          if c==g4 then keyin g1;left
  271.             elseif c==g5 then keyin g9;left
  272.             elseif c==g7 then keyin gb;left
  273.             elseif c==ga then
  274.                 call left_right()
  275.                 if l=1 and r=1 then keyin g8
  276.                    elseif l=1 then keyin g3
  277.                    else keyin g6
  278.                    endif
  279.                 left
  280.             endif
  281.          endif
  282.       endif
  283.    last='u'
  284.  
  285.  
  286. defproc draw_down /* Draw logic for the Down key */
  287.    universal last,l,r,u,d,boxtab2,linepos,colpos
  288.    universal g1,g2,g3,g4,g5,g6,g7,g8,g9,ga,gb
  289.  
  290.    if last='u' then down
  291.    else c=get_char()
  292.       if last=='d' and c==' ' then keyin g2;left;down
  293.          elseif not verify(c,boxtab2) then down
  294.          elseif c==g4 then keyin g1;left;down
  295.          elseif c==g5 then keyin g9;left;down
  296.          elseif c==g7 then keyin gb;left;down
  297.          elseif c==ga then
  298.             call left_right()
  299.             if l=1 and r=1 then keyin g8 elseif l=1 then keyin g3 else keyin g6 endif
  300.             left;down
  301.          else call left_right()
  302.               if last='r' and l=1 then keyin g3
  303.                  elseif last='l' and r=1 then keyin g6
  304.                  else keyin g2
  305.                  endif
  306.               left;down
  307.          endif
  308.       if linepos=.last then insert;.col=colpos
  309.       else
  310.          c=get_char()
  311.          if c==g3 then keyin g1;left
  312.             elseif c==g6 then keyin g9;left
  313.             elseif c==g8 then keyin gb;left
  314.             elseif c==ga then
  315.                 call left_right()
  316.                 if l=1 and r=1 then keyin g7
  317.                    elseif l=1 then keyin g4
  318.                    else keyin g5
  319.                    endif
  320.                 left
  321.             endif
  322.          endif
  323.       endif
  324.    last='d'
  325.  
  326.  
  327. defproc left_right   /* Check character left and right of cursor position */
  328.    universal last,l,r,boxtab3,boxtab4,lpos,rpos,target,colpos
  329.    universal g1,g2,g3,g4,g5,g6,g7,g8,g9,ga,gb
  330.  
  331.    lpos=colpos-1
  332.    if lpos > 0 then l = substr(target,lpos,1) else l = ' ' endif
  333.    rpos=colpos+1
  334.    if rpos < MAXCOL then r = substr(target,rpos,1) else r = ' ' endif
  335.    l=not verify(l,boxtab4) /*if verify(l,boxtab4)==0 then l=1 else l=0 endif*/
  336.    r=not verify(r,boxtab3) /*if verify(r,boxtab3)==0 then r=1 else r=0 endif*/
  337.  
  338.  
  339. defproc draw_left    /* Draw logic for the Left key */
  340.    universal last,u,d,boxtab3
  341.    universal g1,g2,g3,g4,g5,g6,g7,g8,g9,ga,gb
  342.  
  343.    if last=='r' then left
  344.    else
  345.       c=get_char()
  346. compile if WANT_DBCS_SUPPORT
  347.       if last=='l' and isdbcs(c) then keyin ga;keyin ga;left;left;left
  348.          elseif last=='l' and c==' ' then keyin ga;left;left
  349. compile else
  350.       if last=='l' and c==' ' then keyin ga;left;left
  351. compile endif
  352.          elseif not verify(c,boxtab3) then left
  353.          elseif c==g5 then keyin g7;left;left
  354.          elseif c==g6 then keyin g8;left;left
  355.          elseif c==g9 then keyin gb;left;left
  356.          elseif c==g2 then
  357.             call up_down()
  358.             if u=1 and d=1 then keyin g1 elseif u=1 then keyin g4 else keyin g3 endif
  359.             left;left
  360.          else call up_down()
  361.               if last='u' and d=1 then keyin g3
  362.                  elseif last='d' and u=1 then keyin g4
  363.                  else keyin ga
  364.                  endif
  365.               left;left
  366.       endif
  367.       c=get_char()
  368. compile if WANT_DBCS_SUPPORT
  369.       if isdbcs(c) then keyin ' ';c=get_char();endif
  370. compile endif
  371.       if c==g4 then keyin g7;left
  372.          elseif c==g2 then
  373.              call up_down()
  374.              if u=1 and d=1 then keyin g9
  375.                 elseif d=1 then keyin g6
  376.                 else keyin g5
  377.                 endif
  378.              left
  379.          elseif c==g3 then keyin g8;left
  380.          elseif c==g1 then keyin gb;left
  381.       endif
  382.    endif
  383.    last='l'
  384.  
  385.  
  386. defproc draw_right   /* Draw logic for the Right key */
  387.    universal last,u,d,boxtab4,colpos
  388.    universal g1,g2,g3,g4,g5,g6,g7,g8,g9,ga,gb
  389.  
  390.    if last=='l' then right
  391.    else c=get_char()
  392.       if last=='r' and c==' ' then
  393.         keyin ga
  394.       else
  395.          if not verify(c,boxtab4) then right
  396.          elseif c==g4 then keyin g7
  397.          elseif c==g3 then keyin g8
  398.          elseif c==g1 then keyin gb
  399.          elseif c==g2 then
  400.             call up_down()
  401.             if u=1 and d=1 then keyin g9 elseif d=1 then keyin g6 else keyin g5 endif
  402.          else call up_down()
  403.               if last='u' and d=1 then keyin g6
  404.                  elseif last='d' and u=1 then keyin g5
  405.                  else keyin ga
  406.                  endif
  407.          endif
  408.          call left_right()
  409.       endif
  410.       c=get_char()
  411.       if c==g5 then keyin g7;left
  412.          elseif c==g2 then
  413.              call up_down()
  414.              if u=1 and d=1 then keyin g1
  415.                 elseif u=1 then keyin g4
  416.                 else keyin g3
  417.                 endif
  418.              left
  419.          elseif c==g6 then keyin g8;left
  420.          elseif c==g9 then keyin gb;left
  421.       endif
  422.    endif
  423.    last='r'
  424.    if colpos = MAXCOL then left endif
  425.  
  426.  
  427. defproc up_down   /* Check character above and below cursor position */
  428.    universal u,d,boxtab1,boxtab2,linepos,colpos,dpos,upos,target
  429.    universal g1,g2,g3,g4,g5,g6,g7,g8,g9,ga,gb
  430.  
  431.    if linepos=1 then u=0
  432.       else
  433.          upos=linepos-1
  434.          getline target,upos
  435.          u = substr(target,colpos,1)
  436.          u=not verify(u,boxtab2)
  437.    endif
  438.    dpos=linepos+1
  439.    if dpos > .last then d=' '
  440.      else getline target,dpos
  441.           d = substr(target,colpos,1)
  442.      endif
  443.    d=not verify(d,boxtab1)
  444.    getline target,linepos
  445.  
  446.