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