home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume16 / psterm / part03 < prev    next >
Encoding:
Internet Message Format  |  1988-11-01  |  53.9 KB

  1. Subject:  v16i050:  Terminal emulator for NeWS window system, Part03/04
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: hoptoad!gnu (John Gilmore)
  7. Posting-number: Volume 16, Issue 50
  8. Archive-name: psterm/part03
  9.  
  10. : psterm part 3 of 4
  11. echo ref
  12. mkdir ref
  13. : To unbundle, sh this file
  14. echo ref/config_aux
  15. cat >ref/config_aux <<'@@@ Fin de ref/config_aux'
  16. /* ref/config.h  --  Configuration and other very global information
  17.  *            Hugh Daniel 88/1/15 (c) Copyright, Grasshopper Group
  18.  * @(#)$Header: config_aux,v 2.0 88/09/16 01:39:55 eric Release $
  19.  */
  20. /* RCS ID
  21.  */
  22.  
  23. #define FNDELAY        O_NDELAY
  24.  
  25. /* Compile time controls for system dependances
  26.  */
  27. #define    mc68000
  28. /* Things we do have in A/UX */
  29. #define    HAVE_SELECT
  30. #define    HAVE_SOCKETS
  31. #define    HAVE_BSDSYSTIME
  32.     /* Useed by psterm & nterm -HD */
  33. #define    HAVE_SYSV_TTYS
  34. #define    HAVE_PUTTULINE
  35. #define    HAVE_TERMCAP
  36. #define    HAVE_STRINGS_H
  37.  
  38. /* Things that we dont have
  39.     #define    HAVE_MMAN_H
  40. */
  41.  
  42. #ifndef bcopy
  43. #define bcopy(s1, s2, len) { \
  44.     register char *s__s = (char *)(s1); \
  45.     register char *s__d = (char *)(s2); \
  46.     register int n__n; \
  47.     if ((n__n = len) > 0 && s__s != s__d) { \
  48.         if (s__d < s__s || (s__s + n__n) <= s__d) { \
  49.         memcpy(s__d, s__s, n__n); \
  50.         } else { \
  51.             register char *s__se = s__s + n__n - 1; \
  52.         register char *s__de = s__d + n__n - 1; \
  53.             do \
  54.                 *s__de-- = *s__se--; \
  55.             while (--n__n); \
  56.     }}};
  57. #endif
  58. #ifndef bzero
  59. #define bzero(s, n)        memset(s, '\0', n)
  60. #endif
  61. #define bcmp(s1, s2, n)        memcmp(s1, s2, n)
  62.  
  63. #define    srandom(n)    srand(n)
  64. #define    gettimeofday(time, tz) _gettimeofday(time)
  65. @@@ Fin de ref/config_aux
  66. echo ref/config_sunos
  67. cat >ref/config_sunos <<'@@@ Fin de ref/config_sunos'
  68. /* ref/config_sunos  --  Configuration and other very global information
  69.  *            Hugh Daniel 88/1/15 (c) Copyright, Grasshopper Group
  70.  * @(#)$Header: config_sunos,v 2.0 88/09/16 01:40:11 eric Release $
  71.  */
  72. /* RCS ID
  73.  */
  74.  
  75. /* Things we do have in sunos */
  76. #define    HAVE_SELECT
  77. #define    HAVE_SOCKETS
  78. #define    HAVE_BSDSYSTIME
  79.     /* Useed by psterm & nterm -HD */
  80. #define HAVE_BSD_TTYS
  81. /*#define    HAVE_PUTTULINE */
  82. #define    HAVE_TERMCAP
  83. #define    HAVE_STRINGS_H
  84.  
  85. /* #define    HAVE_MMAN_H */
  86. #define    HAVE_VFORK
  87. @@@ Fin de ref/config_sunos
  88. echo psterm.ps
  89. cat >psterm.ps <<'@@@ Fin de psterm.ps'
  90. %
  91. % This file is a product of Sun Microsystems, Inc. and is provided for
  92. % unrestricted use provided that this legend is included on all tape
  93. % media and as a part of the software program in whole or part.
  94. % Users may copy, modify or distribute this file at will.
  95. % THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  96. % WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  97. % PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  98. % This file is provided with no support and without any obligation on the
  99. % part of Sun Microsystems, Inc. to assist in its use, correction,
  100. % modification or enhancement.
  101. % SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  102. % INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS FILE
  103. % OR ANY PART THEREOF.
  104. % In no event will Sun Microsystems, Inc. be liable for any lost revenue
  105. % or profits or other special, indirect and consequential damages, even
  106. % if Sun has been advised of the possibility of such damages.
  107. % Sun Microsystems, Inc.
  108. % 2550 Garcia Avenue
  109. % Mountain View, California  94043
  110. %
  111. % Modifications to the original Sun Microsystems, Inc. source code
  112. % made by the Grasshopper Group are in the Public Domain.
  113. %
  114. % Extensions to this file by Eric Messick of the Grasshopper Group.
  115. %
  116. % Grasshopper Group
  117. % 212 Clayton St
  118. % San Francisco, CA 94117
  119. %
  120. %
  121. %
  122. % "@(#)psterm.ps 1.0 88/06/09 SMI
  123. % "@(#)$Header: psterm.ps,v 2.3 88/10/05 17:45:46 eric Release $
  124. %
  125. % Copyright (c) 1985 by Sun Microsystems, Inc.
  126. %/
  127.  
  128. /hourg /hourg_m framebuffer setstandardcursor
  129. pause
  130.  
  131. systemdict begin
  132.     /PSTermDict 150 dict def
  133. end
  134.  
  135. PSTermDict begin
  136.  
  137.         % user customization of these items can be done in ~/.pstermrc
  138.  
  139.     /DefaultTerminalFont    /Screen    def
  140.     /DefaultFontSize    12    def
  141.     /DefaultLines        24    def
  142.     /DefaultCols        80    def
  143.  
  144.     /morefontmenulength    25    def
  145.  
  146.     /EdgeLeft        1    def % space inside frame to leave white
  147.     /EdgeRight        1    def
  148.     /EdgeTop        1    def
  149.     /EdgeBottom        1    def
  150.  
  151.     /ScrollbarWidth        16    def
  152.  
  153.     /Shrink_To_Cols_Lines    true    def
  154.             % contract window to nearest integral size
  155.  
  156.     /DefaultSimpleShow    true    def
  157.             % false means monospace variable spaced fonts
  158.     /DefaultFastRepaint    true    def
  159.             % false means paint every screen, even if
  160.             %  we're in the middle of painting a screen
  161.     /DefaultUseCopyArea    true    def
  162.             % set to false on silicon graphics
  163.             % where reading pixels is expensive
  164.  
  165.     /smallest_font 1 def
  166.             % when font size is calculated, start here
  167.  
  168.     /next_font_size { 1 add } def
  169.             % and increment by doing this
  170.  
  171.     /OnePointFontXKludge    0    def
  172.     /OnePointFontYKludge    1    def
  173. % translate One Point Font by this with respect to background
  174. %     twiddle these if icon erases itself
  175. %    adjust so cursor is on correct line of text
  176. %    and delete actually wipes out characters
  177.  
  178.     /IconXKludge        0    def
  179.     /IconYKludge        0    def
  180. % translate contents of icon by this much
  181. %    twiddle these if icon borders go away on repaint
  182. %    adjust so there is EdgeTop point gap above top line of text
  183.  
  184. % we believe that these differences are related to color vs. b/w
  185. % systems.  some experimentally determined values are:
  186. %
  187. %    Screen Type
  188. %        FontX    FontY    IconX    IconY
  189. %
  190. %    Black&White
  191. %        0    1    0    0
  192. %
  193. %    Color
  194. %        0    -2    0    2
  195.  
  196.  
  197.     framebuffer setcanvas clippath pathbbox
  198.     /MaxWindowHeight exch 100 add def
  199.     /MaxWindowWidth exch 100 add def
  200.     pop pop
  201. % note:  this stuff doesn't work right with
  202. %   multiple framebuffers
  203. %   until then, it speeds things up
  204. %   and uses less memory for really big
  205. %   windows that can't be displayed
  206. %   completly anyway...
  207.  
  208.         % customization beyond this point is not recommended
  209.  
  210.     /RePaintCode        (\200a) def
  211.     /BeginSelectionCode    (\200b) def
  212.     /ExtendSelectionCode    (\200c) def
  213.     /EndSelectionCode    (\200d) def
  214.     /AutoMarginToggleCode    (\200e) def
  215.     /PageModeToggleCode    (\200f) def
  216.     /LineColCode        (\200g) def
  217.     /FixedFontCode        (\200h) def
  218.     /VariableFontCode    (\200i) def
  219.     /BeginRectSelectionCode    (\200j) def
  220.     /BeginRectExtendCode    (\200k) def
  221.     /ScrollBarCode        (\200l) def
  222.     /ScrollLengthCode    (\200m) def
  223.     /EndOfRefreshCode    (\200n) def
  224.     /FastRepaintCode    (\200o) def
  225.     /UseCopyAreaCode    (\200p) def
  226.  
  227.     /sortarray {    % array --> sorted_array
  228.         10 dict begin
  229.             /arr exch def
  230.             /len arr length def
  231.             1 1 len 1 sub {
  232.                 /i exch def
  233.                 0 1 i 1 sub {
  234.                     /j exch def
  235.                     arr i get arr j get lt {
  236.                     /ferd arr i get def
  237.                     arr i arr j get put
  238.                     arr j ferd put
  239.                     } if
  240.                 } for
  241.             } for
  242.             arr
  243.         end
  244.     } def
  245.  
  246.     /PrimarySelection    1 def
  247.  
  248.     /fontkey {findfont 14 scalefont} def
  249.     /longstring 256 string def
  250.  
  251.         /LineColMenu [
  252.             (24 x 80)        { 24 80 ChangeLineCol }
  253.             ( 8 x 80)        { 8 80 ChangeLineCol }
  254.             (16 x 64)        { 16 64 ChangeLineCol }
  255.             (34 x 80)        { 34 80 ChangeLineCol }
  256.             (60 x 80)        { 60 80 ChangeLineCol }
  257.             (28 x 90)        { 28 90 ChangeLineCol }
  258.             (40 x 90)        { 40 90 ChangeLineCol }
  259.             (48 x 96)        { 48 96 ChangeLineCol }
  260.             (66 x 132)        { 66 132 ChangeLineCol }
  261.         ] /new DefaultMenu send def
  262.         {    /LayoutStyle    [3 3] def
  263.             /CellHorizGap    5 def
  264.         } LineColMenu send
  265.  
  266.         /PointMenu
  267.             [(1)   (2)   (4)   (6)
  268.              (8)   (10)  (12)  (14)
  269.              (16)  (18)  (24)  (32)
  270.              (48)  (64)  (96)  (128)]
  271.             [{currentkey cvi ChangeFontSize}]
  272.         /new DefaultMenu send def
  273.         {    /LayoutStyle    [4 4] def
  274.             /CellHorizGap    5 def
  275.         } PointMenu send
  276.  
  277.         /FontMenu [
  278.             [(Courier)
  279.              /Courier        fontkey]
  280.             [(Courier-Bold)
  281.              /Courier-Bold        fontkey]
  282.             [(Courier-Oblique)
  283.              /Courier-Oblique    fontkey]
  284.             [(Courier-BoldOblique)
  285.              /Courier-BoldOblique    fontkey]
  286.             [(Screen)
  287.              /Screen        fontkey]
  288.             [(Screen-Bold)
  289.              /Screen-Bold        fontkey]
  290.         ] [{currentkey 1 get /FontName get ChangeFont}]
  291.         /new DefaultMenu send def
  292.         {
  293.             /LayoutStyle    [4 2] def
  294.             /RowMajor?    false def
  295.             /CenterItems?    false def
  296.         } FontMenu send
  297.  
  298.         /MoreFontsMenu [
  299.             FontDirectory {
  300.                 pop longstring cvs
  301.                 dup length string copy
  302.             } forall
  303.         ] sortarray
  304.         dup length /HowManyFontsCanYouCount? exch store
  305.         [{ currentkey ChangeFont }]
  306.         /new DefaultMenu send def
  307.         {
  308.             /LayoutStyle    [ morefontmenulength
  309.                       HowManyFontsCanYouCount? min
  310.                       HowManyFontsCanYouCount?
  311.                       1 sub morefontmenulength div
  312.                       truncate 1 add ] def
  313.             /RowMajor?    false def
  314.             /CenterItems?    false def
  315.         } MoreFontsMenu send
  316.         pause
  317.         /ScrollLengthMenu
  318.             [
  319.                 (0)   (64)   (128)  (256)
  320.                 (512) (1024) (2048) (4096)
  321.             ]
  322.             [{currentkey cvi ChangeScrollLength}]
  323.         /new DefaultMenu send def
  324.         {
  325.             /LayoutStyle    [4 2] def
  326.             /RowMajor?    false def
  327.             /CellHorizGap    5 def
  328.         } ScrollLengthMenu send
  329.  
  330.         /StuffToMenu [
  331.             (Stuff to Frame Label)    {
  332.  
  333.                 /PrimarySelection getselection
  334.                 dup null eq {pop}
  335.                         % See if null selection
  336.                 {   dup /ContentsAscii known
  337.                         % Get ascii contents
  338.                     {/ContentsAscii get SL }
  339.                     {pop} ifelse
  340.                 } ifelse
  341.  
  342.                         }
  343.             (Stuff to Icon Label)    {
  344.  
  345.                 /PrimarySelection getselection
  346.                 dup null eq {pop}
  347.                         % See if null selection
  348.                 {   dup /ContentsAscii known
  349.                         % Get ascii contents
  350.                     {/ContentsAscii get
  351.                         seticonlabel }
  352.                     {pop} ifelse
  353.                 } ifelse
  354.  
  355.                         }
  356.             (Stuff to Both)        {
  357.  
  358.                 /PrimarySelection getselection
  359.                 dup null eq {pop}
  360.                         % See if null selection
  361.                 {   dup /ContentsAscii known
  362.                         % Get ascii contents
  363.                     {/ContentsAscii get
  364.                         dup SL seticonlabel }
  365.                     {pop} ifelse
  366.                 } ifelse
  367.  
  368.                         }
  369.             (Version to Frame Label){
  370.                 ($Header: psterm.ps,v 2.3 88/10/05 17:45:46 eric Release $)
  371.                 8 1 index length 9 sub getinterval SL
  372.                         }
  373.         ] /new DefaultMenu send def
  374.  
  375.     pause
  376.  
  377.     systemdict /Item known not { (NeWS/liteitem.ps) run } if
  378.  
  379.     pause
  380.  
  381.     /PropScrollbar SimpleScrollbar
  382.     dictbegin
  383.         /Tracking false def
  384.     dictend
  385.     classbegin
  386.         /SetScale { % - => - (set BarScale from size)
  387.             /BarScale    % points per line of text
  388.                 ItemHeight ButtonSize 2 mul sub
  389.                 BarMax BarMin sub div def
  390.             /BoxSize BarViewPercent BarScale mul neg
  391.                 ItemHeight ButtonSize 2 mul sub min
  392.                 5 max
  393.                 def
  394.         } def
  395.         /ValueToY { % value -> y
  396.             BarMin BarViewPercent sub dup 0 le {
  397.                 pop ButtonSize
  398.             } {
  399.                 exch
  400.                 1 index exch sub
  401.                 1 index BarMax sub div mul neg
  402.                 BarScale mul ButtonSize add
  403.             } ifelse
  404.         } def
  405.         /YToValue { % y -> value
  406.             ButtonSize sub BoxSize 2 div add
  407.             BarScale div BarMin add .5 add truncate
  408.             CheckValueBounds
  409.         } def
  410.         /ferd pop
  411.         /CheckValueBounds { % value => value (in range)
  412.             BarMax max BarMin BarViewPercent sub min
  413.         } def
  414.         /DoScroll { % - => -
  415.             SetScrollValue
  416.             ItemValue ItemPaintedValue ne
  417.                 {EraseBox PaintBox NotifyUser}
  418.             if
  419.         } def
  420.         /SetValue { % value => -
  421.             /ItemValue exch def
  422.             /paint self send
  423.         } def
  424.         /ClientDown {
  425.             /Tracking true def
  426.             /ClientDown super send
  427.         } def
  428.         /ClientUp {
  429.             /Tracking false def
  430.         } def
  431.         /SetScrollBarValue { % value range_array => -
  432.             Tracking {
  433.                 pop pop        % it'll catch up
  434.             } {
  435.                 /setrange self send
  436.                 /SetValue self send
  437.             } ifelse
  438.         } def
  439.     classend def
  440.  
  441.     pause
  442.  
  443.     /PSTermWindow DefaultWindow 
  444.     dictbegin
  445.         /Scrollbar        null    def
  446.         /ScrollbarActive    false    def
  447.     dictend
  448.     classbegin
  449.         /BorderRight {
  450.             ScrollbarActive {
  451.                 {
  452.                     ScrollbarWidth BorderRight 5 min add
  453.                     BorderRight max
  454.                 } DefaultWindow send
  455.             } {
  456.                 DefaultWindow /BorderRight get
  457.             } ifelse
  458.         } def
  459.  
  460.         /ClientMinHeight {
  461.             ScrollbarActive {48} {5} ifelse
  462.         } def
  463.  
  464.         /ClientMinWidth 5 def
  465.  
  466.         /ScrollbarOn {
  467.             ScrollbarActive not {
  468.                 /map Scrollbar send
  469.                 BorderRight
  470.                 /ScrollbarActive true def
  471.                 BorderRight sub
  472.                     FrameX FrameY
  473.                     FrameWidth 4 -1 roll sub FrameHeight
  474.                 /doreshape self send
  475.                 /ShapeStretchControl self send
  476.             } if
  477.         } def
  478.  
  479.         /ScrollbarOff {
  480.             ScrollbarActive {
  481.                 /unmap Scrollbar send
  482.                 BorderRight
  483.                 /ScrollbarActive false def
  484.                 BorderRight sub
  485.                     FrameX FrameY
  486.                     FrameWidth 4 -1 roll sub FrameHeight
  487.                 /doreshape self send
  488.                 /ShapeStretchControl self send
  489.             } if
  490.         } def
  491.  
  492.         /ShapeStretchControl {
  493.             gsave
  494.                 FrameCanvas setcanvas
  495.                 ControlSize BorderRight gt
  496.                 ControlSize BorderBottom gt and {
  497.                     newpath
  498.                     0    0            moveto
  499.                     0    BorderBottom        lineto
  500.                     ControlSize BorderRight sub
  501.                         BorderBottom        lineto
  502.                     ControlSize BorderRight sub
  503.                         ControlSize        lineto
  504.                     ControlSize
  505.                         ControlSize        lineto
  506.                     ControlSize
  507.                         0            lineto
  508.                     closepath
  509.                 } {
  510.                     0 0 ControlSize ControlSize rectpath
  511.                 } ifelse
  512.                 StretchControl reshapecanvas
  513.                 /MoveFrameControls self send
  514.                 /PaintFrameControls self send
  515.             grestore
  516.         } def
  517.  
  518.         pause
  519.  
  520.         /destroy {
  521.             /Scrollbar null def
  522.             /destroy super send
  523.         } def
  524.  
  525.         /CreateFrameControls { % - => -
  526.                     % (Create frame control canvases/items)
  527.             /CreateFrameControls super send
  528.             /Scrollbar
  529.                 [10 0 1 10 10] 0
  530.                     { ScrollBarCode print ItemValue = }
  531.                 FrameCanvas /new PropScrollbar send
  532.                 def
  533.             { /ItemPaintedValue 0 def } Scrollbar send
  534.                     % this kludge shouldn't be needed
  535.         } def
  536.  
  537.         /CreateFrameInterests { % - => -
  538.                     % (Create frame control interests)
  539.             /CreateFrameInterests super send
  540.             FrameInterests begin
  541.     % Append the scroll bar "start" interests to the frame interests.
  542.     % The odd "forall" is used to create unique names for inclusion
  543.     % in the frame interests dictionary.
  544.                 /makestartinterests Scrollbar send {
  545.                     (Scrollbar) 1 index /Name get cvx 100
  546.                     string cvs append
  547.                     cvn exch def
  548.                 } forall
  549.             end
  550.         } def
  551.  
  552.         /MoveFrameControls { % - => - ([Re]set frame control shapes)
  553.             /MoveFrameControls super send
  554.             ScrollbarActive {
  555.                 FrameWidth BorderRight sub
  556.                 ControlSize 1 sub
  557.                 ScrollbarWidth
  558.                 FrameHeight ControlSize sub BorderTop sub 2 add
  559.                 /reshape Scrollbar send
  560.             } if
  561.         } def
  562.  
  563.         /PaintFrameControls { % - => - (Paint frame control areas)
  564.             gsave
  565.                 /PaintFrameControls super send
  566.                 ScrollbarActive { /paint Scrollbar send } if
  567.             grestore
  568.         } def
  569.  
  570.         /SetScrollBarValue { % totallines currentposition => -
  571.             ScrollbarActive {
  572.                 [
  573.                     2 index 0 1
  574.                     Window_lines dup 3 sub 1 max exch ]
  575.                 /SetScrollBarValue Scrollbar send
  576.             } { pop } ifelse
  577.             pop
  578.         } def
  579.  
  580.         /FixFrame {RePaintCode print} def
  581.         /PaintClient {RePaintCode print} def
  582.         /PaintIcon {RePaintCode print} def
  583.         /reshape { ChangeWidthHeight } def
  584.         /flipiconic { Flip_Iconic } def
  585.  
  586.         /ShapeIconCanvas {
  587.             gsave
  588.             ParentCanvas setcanvas
  589.             IconX null ne {
  590.                 IconX IconY translate
  591.             } if
  592.             0 0 IconWidth IconHeight IconPath
  593.             IconCanvas reshapecanvas
  594.             grestore
  595.         } def
  596.  
  597.         pause
  598.  
  599.         /makemenus {
  600.             /ResizeMenu [
  601.                 (Changing Font Size determines:) {}
  602.                 () {}
  603.                 () {}
  604.                 (Changing Lines/Cols determines:) {}
  605.                 () {}
  606.                 () {}
  607.                 (Changing Window Size determines:) {}
  608.                 () {}
  609.                 () {}
  610.             ] /new DefaultMenu send def
  611. % looks bad        { /CenterItems? false def } ResizeMenu send
  612.  
  613.             /ToggleMenu [
  614.                 (  Page Mode)        
  615.                     {PageModeToggleCode print}
  616.                 (  Auto-Margins)
  617.                     {AutoMarginToggleCode print}
  618.                 (  Var Width Fonts)
  619.                     { ToggleSimpleShow RePaintCode print}
  620.                 (  Fast Repaint)
  621.                     { ToggleFastRepaint }
  622.                 (  Scrolling Allowed)
  623.                     { ToggleUseCopyArea }
  624.             ] /new DefaultMenu send def
  625. % looks bad        { /CenterItems? false def } ToggleMenu send
  626.  
  627.             /ConfigMenu [
  628.                 (Lines x Cols...)    LineColMenu
  629.                 (Points...)        PointMenu
  630.                 (Fonts...)        FontMenu
  631.                 (More Fonts!...)    MoreFontsMenu
  632.                 (Resizing stuff...)    ResizeMenu
  633.                 (Save Lines...)        ScrollLengthMenu
  634.                 (Toggles...)        ToggleMenu
  635.                 (Set Labels...)        StuffToMenu
  636.             ] /new DefaultMenu send def
  637.  
  638.             /ClientMenu [
  639.                 (Stuff)        {
  640.  
  641.                     /PrimarySelection getselection
  642.                     dup null eq {pop}
  643.                             % See if null selection
  644.                     {   dup /ContentsAscii known
  645.                             % Get ascii contents
  646.                         {/ContentsAscii get print}
  647.                         {pop} ifelse
  648.                     } ifelse
  649.  
  650.                         }
  651.                 (Frame...)        { FrameMenu } MyWindow send
  652.                 (Config...)        ConfigMenu
  653.             ] /new DefaultMenu send def
  654.  
  655.         } def
  656.  
  657.         /PageModeMenuItem    0 def    % which item of /ToggleMenu?
  658.         /AutoMarginMenuItem    1 def    % likewise
  659.         /SimpleShowMenuItem    2 def    % likewise
  660.         /FastRepaintMenuItem    3 def    % likewise
  661.         /UseCopyAreaMenuItem    4 def    % likewise
  662.  
  663.         /doreshape { /reshape load } DefaultWindow send def
  664.  
  665.         /doflipiconic { /flipiconic load } DefaultWindow send def
  666.  
  667.     classend def
  668.  
  669.     pause
  670.  
  671.     gsave 0.0005 rotate
  672.     /Courier findfont setfont
  673.     /OnePointFont currentfont
  674.         [ 1 (m) stringwidth pop    div 0 0
  675.           1 currentfont fontheight div
  676.           0 0        % these are ignored by NeWS ---- FIXME!!
  677.         ] makefont def
  678.     grestore
  679.  
  680.     /TSB { % on/off => -   ``toggle'' scrollbar
  681.         0 eq { /ScrollbarOff } { /ScrollbarOn } ifelse MyWindow send
  682.     } def
  683.     /SSBV { % totallines currentpos => -   set scrollbar value
  684.         /SetScrollBarValue MyWindow send
  685.     } def
  686.  
  687.     /BRP {
  688.         {
  689.             gsave
  690.             Iconic? {
  691.                 IconCanvas setcanvas damagepath clipcanvas
  692.                 IconFillColor fillcanvas
  693.                 IconBorderColor strokecanvas
  694.                 PaintIconLabel
  695.             } {
  696.                 FrameCanvas setcanvas
  697.                 damagepath clipcanvas PaintFrame
  698.         % initialize client canvas with background color
  699.                 ClientCanvas setcanvas
  700.                 ClientFillColor fillcanvas
  701.             } ifelse
  702.             grestore
  703.         }
  704.         MyWindow send
  705.     } def
  706.  
  707.     /ERP { clipcanvas } def
  708.  
  709.     /EOR { EndOfRefreshCode print } def
  710.  
  711.     /CD {         % c x y cursordown
  712.         gsave
  713.         maxy add
  714.         translate
  715.         dup length dup
  716.         0 0 moveto
  717.         0 1 rlineto
  718.         0 rlineto        % x component is length of c
  719.         0 lineto        % x component is length of c
  720.         closepath
  721.         backgroundcolor setcolor
  722.         fill
  723.         textcolor setcolor
  724.         0 maxy neg moveto
  725.         showtext
  726.         grestore
  727.     } def
  728.  
  729.     /CU {         % c x y cursorup
  730.         gsave
  731.         maxy add
  732.         translate
  733.         dup length dup
  734.         0 0 moveto
  735.         0 1 rlineto
  736.         0 rlineto        % x component is length of c
  737.         0 lineto        % x component is length of c
  738.         closepath
  739.         textcolor setcolor
  740.         fill
  741.         backgroundcolor setcolor
  742.         0 maxy neg moveto
  743.         showtext
  744.         grestore
  745.     } def
  746.  
  747.     /CL {        % yby w yfrom nl CopyLine
  748.         gsave
  749.         /NumLin exch def            % yby w yfrom
  750.         maxy add 0 exch translate        % yby w
  751.         0 0 moveto
  752.         0 NumLin rlineto            % yby w
  753.         dup 0 rlineto                % yby w 
  754.         0 lineto                % yby
  755.         closepath
  756.         0 exch copyarea
  757.         grestore
  758.     } def
  759.  
  760.     /SL {                        % s SetFrameLabel
  761.         {
  762.             /FrameLabel exch store
  763.             gsave
  764.             FrameCanvas setcanvas
  765.             BorderLeft 1 add
  766.             FrameHeight BorderTop sub 1 add
  767.             FrameWidth BorderLeft BorderRight add sub 2 sub
  768.             BorderTop 2 sub
  769.             rectpath FrameFillColor setcolor fill
  770.                 % clear label area
  771.             /paintframelabel self send
  772.             FrameBorderColor setcolor
  773.             PaintFrameControls PaintFocus
  774.             grestore
  775.         } MyWindow send
  776.     } def
  777.  
  778.     /seticonlabel {
  779.         {
  780.             /IconLabel exch store
  781.             PaintIcon
  782.         } MyWindow send
  783.     } def
  784.  
  785.     /VB {
  786.         gsave
  787.             HiLightCanvas setcanvas
  788.             overlaydraw HlBgColor setcolor clippath fill
  789.             .05 60 div sleep
  790.             overlayerase erasepage
  791.         grestore
  792.     } def
  793.  
  794.     /AM {        % onoff => -        (define auto margins)
  795.         0 eq {(  Auto-Margins)}{(* Auto-Margins)} ifelse
  796.         { AutoMarginMenuItem } MyWindow send exch
  797.         {AutoMarginToggleCode print}
  798.         /changeitem MyWindow /ToggleMenu get send
  799.     } def
  800.  
  801.     /PM {        % onoff => -        (define page mode)
  802.         0 eq {(  Page Mode)}{(* Page Mode)} ifelse
  803.         { PageModeMenuItem } MyWindow send exch
  804.         {PageModeToggleCode print}
  805.         /changeitem MyWindow /ToggleMenu get send
  806.     } def
  807.  
  808.     /ToggleSimpleShow {
  809.         /SimpleShow SimpleShow not store
  810.         /FontFixedP MonoSpacedFont Font_size 1 eq or
  811.         SimpleShow not or store
  812.         FontFixedP { FixedFontCode } { VariableFontCode } ifelse print
  813.         { SimpleShowMenuItem } MyWindow send
  814.         SimpleShow {(* Var Width Fonts)}{(  Var Width Fonts)} ifelse
  815.         { ToggleSimpleShow RePaintCode print}
  816.         /changeitem MyWindow /ToggleMenu get send
  817.     } def
  818.  
  819.     /ToggleFastRepaint {
  820.         /FastRepaint FastRepaint not store
  821.         FastRepaintCode print
  822.         FastRepaint { 1 } { 0 } ifelse =
  823.         { FastRepaintMenuItem } MyWindow send
  824.         FastRepaint {(* Fast Repaint)}{(  Fast Repaint)} ifelse
  825.         { ToggleFastRepaint }
  826.         /changeitem MyWindow /ToggleMenu get send
  827.     } def
  828.  
  829.     /ToggleUseCopyArea {
  830.         /UseCopyArea UseCopyArea not store
  831.         UseCopyAreaCode print
  832.         UseCopyArea { 1 } { 0 } ifelse =
  833.         { UseCopyAreaMenuItem } MyWindow send
  834.         UseCopyArea {(* Scrolling Allowed)}{(  Scrolling Allowed)} ifelse
  835.         { ToggleUseCopyArea }
  836.         /changeitem MyWindow /ToggleMenu get send
  837.     } def
  838.  
  839.     /MT {
  840.         backgroundcolor setcolor
  841.         2 copy maxy add moveto
  842.         1 index 0 eq { -.25 0 rmoveto } if
  843.             % zap blats on left margin
  844.         0 1 rlineto
  845.         Window_cols .25 add 1 index maxy add 1 add lineto
  846.         0 -1 rlineto
  847.         closepath fill
  848.         moveto
  849.         pause
  850.     } def
  851.  
  852.     /PN {    % paint normal
  853.         textcolor setcolor
  854.         showtext
  855.     } def
  856.  
  857.     /PR {
  858.         dup textstringwidth
  859.         textcolor setcolor
  860.         stringbox
  861.         backgroundcolor setcolor
  862.         showtext
  863.     } def
  864.  
  865.     /UN {
  866.         dup textstringwidth
  867.         textcolor setcolor
  868.         underscore
  869.         showtext
  870.     } def
  871.  
  872.     /UR {
  873.         dup textstringwidth
  874.         textcolor setcolor
  875.         dup stringbox
  876.         backgroundcolor setcolor
  877.         underscore
  878.         showtext
  879.     } def
  880.  
  881.     /CE {
  882.     } def
  883.  
  884.     /textstringwidth {    % (str) => width
  885.         FontFixedP {
  886.             length
  887.         } {
  888.             stringwidth pop
  889.         } ifelse
  890.     } def
  891.  
  892.     /stringbox {    % width
  893.         currentpoint 3 2 roll
  894.         0 maxy rmoveto
  895.         0 1 rlineto
  896.         0 rlineto
  897.         0 -1 rlineto
  898.         closepath fill
  899.         moveto
  900.     } def
  901.  
  902.     /underscore {    % width
  903.         currentpoint 3 2 roll
  904.         1 maxy add 2 div 0 exch rmoveto
  905.         0 rlineto
  906.         stroke
  907.         moveto
  908.     } def        
  909.  
  910.     /showtext {
  911.         Font_size 1 eq {
  912.             OnePointFontXKludge OnePointFontYKludge rmoveto
  913.             show
  914.             OnePointFontXKludge neg OnePointFontYKludge neg rmoveto
  915.         } {
  916.             MonoSpacedFont SimpleShow or {
  917.                 show
  918.             } {
  919.                 currentpoint ShowChar 0        % (str) x y ( ) 0
  920.                 {                % x y ( ) 0 char
  921.                     put ShowChar        % x y (c)
  922.                     show
  923.                     exch 1 add exch moveto
  924.                     currentpoint        % x y
  925.                     ShowChar 0
  926.                 } 6 -1 roll exch forall
  927.                 pop pop
  928.                 exch 1 add exch moveto
  929.             } ifelse
  930.         } ifelse
  931.     } def
  932.  
  933.     /HL {    % strokeit [ ends of lines ] firstcol firstrow => -
  934.         % do highlighting
  935.         gsave
  936.         3 index 0 ne {
  937.             HiLightCanvas setcanvas
  938.             CurrentMatrix setmatrix
  939.             -0.005 rotate
  940.             erasepage
  941.         } if
  942.         maxy add 1 add dup        % [] x y y
  943.         4 1 roll            % y [] x y
  944.         exch dup type /stringtype eq {
  945.             textstringwidth
  946.         } if
  947.         exch moveto            % y []
  948.         0 -1 rlineto dup        % y [] []
  949.         {                 % ... x
  950.             dup type /stringtype eq {
  951.                 textstringwidth
  952.             } {
  953.                 1 add
  954.             } ifelse
  955.             currentpoint        % ... x cx cy
  956.             exch pop        % ... x cy
  957.             lineto
  958.             0 1 rlineto
  959.         } forall            % y []
  960.         length 1 gt {
  961.             currentpoint 0 exch    % y cx 0 cy
  962.             lineto pop 0 exch    % 0 y
  963.             lineto
  964.         } { pop } ifelse
  965.         closepath
  966.         currentpath /HiLightPath exch store
  967.         0 ne { stroke } if
  968.         grestore
  969.     } def
  970.  
  971.     /HiLightRect { % strokeit startcol startrow endcol endrow => -
  972.         gsave
  973.         4 index 0 ne {
  974.             HiLightCanvas setcanvas
  975.             CurrentMatrix setmatrix
  976.             -0.005 rotate
  977.             erasepage
  978.         } if
  979.         0 maxy translate
  980.         1 add exch 1 add exch
  981.         3 index 1 index moveto
  982.         1 index exch lineto
  983.         1 index lineto
  984.         lineto closepath
  985.         currentpath /HiLightPath exch store
  986.         0 ne { stroke } if
  987.         grestore
  988.     } def
  989.  
  990.     /takedownoutline {
  991. %        /HiLightCanvas null store
  992. %        HiLightCanvas /Mapped false put
  993.         gsave
  994.         HiLightCanvas setcanvas erasepage
  995.         grestore
  996.     } def
  997.  
  998.     /clearselectionpath {
  999.         /HiLightPath null store
  1000.     } def
  1001.  
  1002.     /PaintHiLight {
  1003.         HiLightPath null ne {
  1004.             gsave
  1005.             5 setrasteropcode
  1006.             HiLightPath setpath fill
  1007.             grestore
  1008.         } if
  1009.     } def
  1010.  
  1011.     /startselset {
  1012.         /CurrentSelection () store
  1013.     } def
  1014.  
  1015.     /extsel {
  1016.         CurrentSelection exch append /CurrentSelection exch store
  1017.     } def
  1018.  
  1019.     /finishselset {        % str
  1020.         10 dict dup begin
  1021.             /ContentsAscii        CurrentSelection    def
  1022.             /SelectionObjSize    1            def
  1023.             /SelectionHolder    childprocess        def
  1024.             /Canvas            currentcanvas        def
  1025.         end
  1026.         /PrimarySelection setselection
  1027.     } def
  1028.  
  1029.     /resetscale { 10 dict begin
  1030.         { Iconic? { IconCanvas } { ClientCanvas } ifelse }
  1031.             MyWindow send setcanvas
  1032.         0.0005 rotate
  1033.         clippath pathbbox EdgeLeft exch
  1034.         ScaledFont fontdescent add EdgeTop sub translate
  1035.         clear
  1036.  
  1037.         Font_size 1 eq {
  1038.             1 -1 scale
  1039.             IconXKludge IconYKludge translate
  1040.             OnePointFont setfont
  1041.         } {
  1042.             /xscale ScaledFont setfont (m) stringwidth pop def
  1043.             /yscale ScaledFont fontheight neg def
  1044.             xscale 0 eq { /xscale 0.0005 store } if
  1045.             yscale 0 eq { /yscale -0.0005 store } if
  1046.             xscale yscale scale
  1047.  
  1048.             Term_Font [
  1049.                 Font_size xscale div 0 0
  1050.                 Font_size yscale div 0 0 ] makefont setfont
  1051.         } ifelse
  1052.  
  1053.         textcolor setcolor
  1054. %        0 setgray
  1055.  
  1056.         0 1 translate
  1057.         /CurrentMatrix 6 array currentmatrix store
  1058.         /HiLightCanvas { ClientCanvas } MyWindow send
  1059.             createoverlay store
  1060.         clear
  1061.         childprocess dup null ne {
  1062.             MySetTransform createevent copy dup begin
  1063.                 /Action matrix currentmatrix def
  1064.                 /TimeStamp lasteventtime def
  1065.             end sendevent
  1066.         } {
  1067.             pop
  1068.         } ifelse
  1069.  
  1070.         end 
  1071.         /maxy currentfont fontascent neg store
  1072.     } def
  1073.  
  1074.     /whcl2f {
  1075.         gsave 0.0005 rotate
  1076.         /Term_Font SelectedFont store
  1077.         /char_width Window_width
  1078.             { BorderLeft sub BorderRight sub } MyWindow send
  1079.             EdgeLeft sub EdgeRight sub
  1080.             Window_cols div store
  1081.  
  1082.         /char_height Window_height
  1083.             { BorderTop sub BorderBottom sub } MyWindow send
  1084.             EdgeTop sub EdgeBottom sub
  1085.             Window_lines div store
  1086.  
  1087.         /Font_size 0 store
  1088.         smallest_font
  1089.         {
  1090.             dup Term_Font exch scalefont setfont
  1091.             currentfont fontheight char_height ge
  1092.             (m) stringwidth pop char_width ge or { exit } if
  1093.             dup /Font_size exch store
  1094.             next_font_size
  1095.         } loop
  1096.         pop
  1097.  
  1098.         Term_Font Font_size scalefont setfont
  1099.         /ScaledFont currentfont store
  1100.         grestore
  1101.         Shrink_To_Cols_Lines { clf2wh } if
  1102.     } def
  1103.  
  1104.     /whf2cl {
  1105.         gsave 0.0005 rotate
  1106.  
  1107.         Font_size 1 eq {
  1108.             /Term_Font /Courier findfont store
  1109.             /ScaledFont OnePointFont store
  1110.         } {
  1111.             /Term_Font SelectedFont store
  1112.             /ScaledFont Term_Font Font_size scalefont store
  1113.         } ifelse
  1114.  
  1115.         ScaledFont setfont
  1116.  
  1117.         /Window_cols Window_width
  1118.             { BorderLeft sub BorderRight sub } MyWindow send
  1119.             EdgeLeft sub EdgeRight sub
  1120.             (m) stringwidth pop div .5 add truncate 1 max store
  1121.  
  1122.         /Window_lines Window_height
  1123.             { BorderTop sub BorderBottom sub } MyWindow send
  1124.             EdgeTop sub EdgeBottom sub
  1125.             currentfont fontheight div .5 add truncate 1 max store
  1126.         grestore
  1127.         Shrink_To_Cols_Lines { clf2wh } if
  1128.     } def
  1129.  
  1130.     /clf2wh {
  1131.         gsave 0.0005 rotate
  1132.  
  1133.         Font_size 1 eq {
  1134.             /Term_Font /Courier findfont store
  1135.             /ScaledFont OnePointFont store
  1136.         } {
  1137.             /Term_Font SelectedFont store
  1138.             /ScaledFont Term_Font Font_size scalefont store
  1139.         } ifelse
  1140.  
  1141.         ScaledFont setfont
  1142.  
  1143.         /Window_width Window_cols (m) stringwidth pop mul
  1144.             { BorderLeft add BorderRight add } MyWindow send
  1145.             EdgeLeft add EdgeRight add store
  1146.  
  1147.         /Window_height Window_lines currentfont fontheight mul
  1148.             { BorderTop add BorderBottom add } MyWindow send
  1149.             EdgeTop add EdgeBottom add store
  1150.         grestore
  1151.     } def
  1152.  
  1153.     /SetupResizeMenu {
  1154.         /FontChangeProc load /clf2wh load eq {
  1155.             1 (* Window Size) {} /changeitem MyWindow
  1156.                 /ResizeMenu get send
  1157.             2 (  Lines/Cols ) { ToggleFont } /changeitem MyWindow
  1158.                 /ResizeMenu get send
  1159.         } {
  1160.             1 (  Window Size) { ToggleFont } /changeitem MyWindow
  1161.                 /ResizeMenu get send
  1162.             2 (* Lines/Cols ) {} /changeitem MyWindow
  1163.                 /ResizeMenu get send
  1164.         } ifelse
  1165.  
  1166.         /LineColChangeProc load /clf2wh load eq {
  1167.             4 (* Window Size) {} /changeitem MyWindow
  1168.                 /ResizeMenu get send
  1169.             5 (  Font Size  ) { ToggleLineCol }
  1170.                 /changeitem MyWindow
  1171.                 /ResizeMenu get send
  1172.         } {
  1173.             4 (  Window Size) { ToggleLineCol }
  1174.                 /changeitem MyWindow
  1175.                 /ResizeMenu get send
  1176.             5 (* Font Size  ) {} /changeitem MyWindow
  1177.                 /ResizeMenu get send
  1178.         } ifelse
  1179.  
  1180.  
  1181.         /WidthHeightChangeProc load /whf2cl load eq {
  1182.             7 (* Lines/Cols ) {} /changeitem MyWindow
  1183.                 /ResizeMenu get send
  1184.             8 (  Font Size  ) { ToggleWidthHeight }
  1185.                 /changeitem MyWindow
  1186.                 /ResizeMenu get send
  1187.         } {
  1188.             7 (  Lines/Cols ) { ToggleWidthHeight }
  1189.                 /changeitem MyWindow
  1190.                 /ResizeMenu get send
  1191.             8 (* Font Size  ) {} /changeitem MyWindow
  1192.                 /ResizeMenu get send
  1193.         } ifelse
  1194.  
  1195.     } def
  1196.  
  1197.     /DefaultFontChangeProc /clf2wh load def
  1198.     /ToggleFont {
  1199.         /FontChangeProc load /clf2wh load eq {
  1200.             /FontChangeProc /whf2cl load store
  1201.         } {
  1202.             /FontChangeProc /clf2wh load store
  1203.         } ifelse
  1204.         SetupResizeMenu
  1205.     } def
  1206.  
  1207.     /DefaultLineColChangeProc /clf2wh load def
  1208.     /ToggleLineCol {
  1209.         /LineColChangeProc load /clf2wh load eq {
  1210.             /LineColChangeProc /whcl2f load store
  1211.         } {
  1212.             /LineColChangeProc /clf2wh load store
  1213.         } ifelse
  1214.         SetupResizeMenu
  1215.     } def
  1216.  
  1217.     /DefaultWidthHeightChangeProc /whf2cl load def
  1218.     /ToggleWidthHeight {
  1219.         /WidthHeightChangeProc load /whf2cl load eq {
  1220.             /WidthHeightChangeProc /whcl2f load store
  1221.         } {
  1222.             /WidthHeightChangeProc /whf2cl load store
  1223.         } ifelse
  1224.         SetupResizeMenu
  1225.     } def
  1226.  
  1227.     /ChangeOne {
  1228.         dup /Font eq {
  1229.             pop
  1230.             FontChangeProc
  1231.         } {
  1232.             /LineCol eq {
  1233.                 LineColChangeProc
  1234.             } {
  1235.                 WidthHeightChangeProc
  1236.             } ifelse
  1237.         } ifelse
  1238.  
  1239.         {
  1240.             /IconWidth Window_cols gsave
  1241.                     IconFont setfont
  1242.                     IconLabel stringwidth pop
  1243.                 grestore max EdgeLeft add EdgeRight add def
  1244.             /IconHeight Window_lines EdgeTop add EdgeBottom add
  1245.                 IconFont fontheight add def
  1246.             /ShapeIconCanvas self send
  1247.         } MyWindow send
  1248.  
  1249.         LineColCode print
  1250.         Window_cols =
  1251.         Window_lines =
  1252.         /Window_x { FrameX } MyWindow send store
  1253.         /Window_y { FrameY } MyWindow send store
  1254.         Window_y Window_height add 0 lt { % don't disappear on us!
  1255.             /Window_y 10 Window_height sub store
  1256.         } if
  1257.         Window_x Window_y
  1258.         Window_width MaxWindowWidth min
  1259.         Window_height MaxWindowHeight min
  1260.         /doreshape MyWindow send
  1261.  
  1262.     } def
  1263.  
  1264.     /ChangeScrollLength {
  1265.         ScrollLengthCode print =
  1266.     } def
  1267.  
  1268.     /ChangeFontSize {
  1269.         /SelectedFontSize exch store
  1270.         /Font_size SelectedFontSize store
  1271.         /Font ChangeOne
  1272.     } def
  1273.  
  1274.     /ChangeWidthHeight {
  1275.         /Window_height exch store
  1276.         /Window_width exch store
  1277.         /Window_y exch store
  1278.         /Window_x exch store
  1279.         {
  1280.             /FrameX Window_x store
  1281.             /FrameY Window_y store
  1282.             ClientMinWidth BorderLeft add BorderRight add
  1283.             ClientMinHeight BorderTop add BorderBottom add
  1284.         } MyWindow send
  1285.         dup Window_height gt {
  1286.             /Window_height exch store
  1287.         } { pop } ifelse
  1288.         dup Window_width gt {
  1289.             /Window_width exch store
  1290.         } { pop } ifelse
  1291.         /WidthHeight ChangeOne
  1292.     } def
  1293.  
  1294.     /ChangeLineCol {
  1295.         /Window_cols exch store
  1296.         /Window_lines exch store
  1297.         /LineCol ChangeOne
  1298.     } def
  1299.  
  1300.     /ChangeFont {
  1301.         dup
  1302.         { findfont } errored {
  1303.             gsave framebuffer setcanvas currentcursorlocation
  1304.             [ (Could not find font:) 5 -1 roll 100 string cvs ] popmsg pop
  1305.             grestore
  1306.         } {
  1307.             /SelectedFont exch store
  1308.             pop
  1309.             /MonoSpacedFont SelectedFont /IsFixedPitch get store
  1310.             SelectedFont /FontName get
  1311.                 dup /Courier eq
  1312.                 1 index /Courier-Bold eq or
  1313.                 1 index /Courier-Oblique eq or
  1314.                 exch /Courier-BoldOblique eq or {
  1315.                     /MonoSpacedFont true store
  1316.                 } if
  1317.             /FontFixedP MonoSpacedFont Font_size 1 eq or
  1318.                 SimpleShow not or store
  1319.             FontFixedP { FixedFontCode } { VariableFontCode } ifelse print
  1320.             Font_size ChangeFontSize
  1321.         } ifelse
  1322.     } def
  1323.  
  1324.     /Flip_Iconic {
  1325.         /doflipiconic self send
  1326.         Iconic? {
  1327.             /Font_size 1 store
  1328.             /FontFixedP MonoSpacedFont Font_size 1 eq or
  1329.                 SimpleShow not or store
  1330.             FontFixedP
  1331.                 { FixedFontCode }
  1332.                 { VariableFontCode }
  1333.             ifelse print
  1334.             ClientCanvas setcanvas ClientFillColor fillcanvas
  1335.                 % keep it from repainting twice
  1336.             IconCanvas setcanvas
  1337.             /ScaledFont OnePointFont store
  1338.             ScaledFont setfont
  1339.             IconCanvas /Retained get {
  1340.                 /PaintIcon self send
  1341.             } if
  1342.         } {
  1343.             IconCanvas setcanvas IconFillColor fillcanvas
  1344.             ClientCanvas setcanvas
  1345.             /Font_size SelectedFontSize store
  1346.             /FontFixedP MonoSpacedFont Font_size 1 eq or
  1347.                 SimpleShow not or store
  1348.             FontFixedP
  1349.                 { FixedFontCode }
  1350.                 { VariableFontCode }
  1351.             ifelse print
  1352.             /ScaledFont Term_Font Font_size scalefont store
  1353.             ScaledFont setfont
  1354.             ClientCanvas /Retained get {
  1355.                 /PaintClient self send
  1356.             } if
  1357.         } ifelse
  1358.     } def
  1359.  
  1360.     /UserWindowCustom nullproc def
  1361.  
  1362.     /createwindow {
  1363. % x y fs col line framelabel iconlabel font starticonic iconx icony
  1364.         pause
  1365.         /IconInitialX exch store
  1366.         /IconInitialY exch store
  1367.         /StartIconic exch store
  1368.         /InitialFont exch store
  1369.         /MyIconLabel exch store
  1370.         /MyFrameLabel exch store
  1371.         /Window_lines exch store
  1372.         /Window_cols exch store
  1373.         /SelectedFontSize exch store
  1374.         /Window_y exch store
  1375.         /Window_x exch store
  1376.  
  1377.         /MyWindow framebuffer /new PSTermWindow send store
  1378.  
  1379.         /UserWindowCustom load MyWindow send
  1380.  
  1381.         Window_x Window_y 0 0 /doreshape MyWindow send
  1382.         % this calls checkcanvases to set up FrameMenu ... ugh...
  1383.  
  1384.         {
  1385.             /FrameLabel MyFrameLabel def
  1386.             /IconLabel MyIconLabel def
  1387.             makemenus
  1388.             ClientCanvas
  1389.  
  1390.         } MyWindow send
  1391.  
  1392.         createoverlay /HiLightCanvas exch store
  1393.  
  1394.         IconInitialX 0 ge IconInitialY 0 ge and {
  1395.             { /IconX IconInitialX def /IconY IconInitialY def }
  1396.             MyWindow send
  1397.         } if
  1398.  
  1399.         SetupResizeMenu
  1400.         ToggleSimpleShow
  1401.         ToggleFastRepaint
  1402.         ToggleUseCopyArea
  1403.  
  1404.         Window_cols 0 le Window_lines 0 le or {
  1405.             /Window_lines DefaultLines store
  1406.             /Window_cols DefaultCols store
  1407.         } if
  1408.  
  1409.         SelectedFontSize 0 le
  1410.             { /SelectedFontSize DefaultFontSize store } if
  1411.  
  1412.         { InitialFont findfont } errored not
  1413.             { InitialFont ChangeFont } if
  1414.  
  1415.         SelectedFontSize ChangeFontSize
  1416.  
  1417.         MyWindow /ClientCanvas get setcanvas
  1418.  
  1419.         InitialReshapeFromUser { /reshapefromuser MyWindow send } if
  1420.  
  1421.         StartIconic 0 ne { /flipiconic MyWindow send } if
  1422.         /map MyWindow send
  1423.         pause
  1424.  
  1425.         /MySetTransform createevent store
  1426.  
  1427.         MySetTransform begin
  1428.             /Name /SetTransform def
  1429.             /Canvas currentcanvas def
  1430.         end
  1431.  
  1432.         /MyMouseEvents createevent store
  1433.  
  1434.         MyMouseEvents begin
  1435.             /Name [ /MouseDragged /PointButton load
  1436.                 /AdjustButton load ] def
  1437.             /Canvas currentcanvas def
  1438.         end
  1439.  
  1440.     } def
  1441.  
  1442.     /startinput {
  1443.         /childprocess null store
  1444.         resetscale
  1445.         ( ) 0 0 CU
  1446.         pause
  1447.         {
  1448.             systemdict /Selections known {
  1449.                 { ClientCanvas } MyWindow send
  1450.                 dup addkbdinterests pop
  1451. %                dup addselectioninterests pop
  1452.                 addfunctionstringsinterest pop 
  1453.                 { FrameCanvas } MyWindow send
  1454.                 dup addkbdinterests pop
  1455.                 addfunctionstringsinterest pop 
  1456.                 { IconCanvas } MyWindow send
  1457.                 dup addkbdinterests pop
  1458.                 addfunctionstringsinterest pop 
  1459.             } {
  1460.                 /Ascii 128 dict def
  1461.                 /Template createevent def
  1462.                 Ascii begin
  1463.                 0 1 127 { dup def } for
  1464.                 end
  1465.                 Template
  1466.                 Ascii seteventname
  1467.                 currentcanvas seteventcanvas
  1468.                 expressinterest
  1469.             } ifelse
  1470.             MyMouseEvents expressinterest
  1471.             MySetTransform expressinterest
  1472.  
  1473.             /MyEventActions 20 dict dup begin
  1474.     
  1475.                 /Ignore {
  1476.                 } def
  1477.         
  1478.                 /AcceptFocus {
  1479.             %       true /reflectfocus MyWindow send
  1480.                 } def
  1481.                 /RestoreFocus {
  1482.             %       true /reflectfocus MyWindow send
  1483.                 } def
  1484.     
  1485.                 /SetTransform {
  1486.                     Action dup null ne {
  1487.                         setmatrix
  1488.                     } {
  1489.                         pop
  1490.                     } ifelse
  1491.                 } def
  1492.             
  1493.                 /SetSelectionAt {
  1494.                 } def
  1495.         
  1496.                 /ExtendSelectionTo {
  1497.                 } def
  1498.             
  1499.                 /DeSelect {
  1500.                 } def
  1501.         
  1502.                 /LoseFocus {    % NeWS/X version of DeSelect
  1503.                 } def
  1504.         
  1505.                 /SelectionRequest {
  1506.                 } def
  1507.  
  1508.                 /PointButton load {
  1509.                     Action /DownTransition eq {
  1510.                         false KeyState {
  1511.                             /Shift eq {
  1512.                                 pop true exit
  1513.                             } if
  1514.                         } forall {
  1515.                             BeginRectSelectionCode
  1516.                             print
  1517.                         } {
  1518.                             BeginSelectionCode
  1519.                             print
  1520.                         } ifelse
  1521.                         XLocation =
  1522.                         YLocation maxy sub =
  1523.                         1 =
  1524.                         /Selection_in_progress?
  1525.                             true store
  1526.                     } {    % /UpTransition
  1527.                         Selection_in_progress? {
  1528.                             EndSelectionCode print
  1529.                             XLocation =
  1530.                             YLocation maxy sub =
  1531.                             1 =
  1532.                             /Selection_in_progress?
  1533.                                 false store
  1534.                         } if
  1535.                     } ifelse
  1536.                 } def
  1537.  
  1538.                 /AdjustButton load {
  1539.                     Action /DownTransition eq {
  1540.                         false KeyState {
  1541.                             /Shift eq {
  1542.                                 pop true exit
  1543.                             } if
  1544.                         } forall {
  1545.                             BeginRectExtendCode
  1546.                             print
  1547.                         } {
  1548.                             ExtendSelectionCode
  1549.                             print
  1550.                         } ifelse
  1551.                         XLocation =
  1552.                         YLocation maxy sub =
  1553.                         1 =
  1554.                         /Selection_in_progress?
  1555.                             true store
  1556.                     } {    % /UpTransition
  1557.                         Selection_in_progress? {
  1558.                             EndSelectionCode print
  1559.                             XLocation =
  1560.                             YLocation maxy sub =
  1561.                             1 =
  1562.                             /Selection_in_progress?
  1563.                                 false store
  1564.                         } if
  1565.                     } ifelse
  1566.                 } def
  1567.  
  1568.                 /MouseDragged {
  1569.                     Selection_in_progress? {
  1570.                         ExtendSelectionCode print
  1571.                         XLocation =
  1572.                         YLocation maxy sub =
  1573.                         1 =
  1574.                     } if
  1575.                 } def
  1576.         
  1577.                 /InsertValue        {
  1578.                     Action print
  1579.                 } def
  1580.         
  1581.                 /Default    {
  1582.                     { UI_private /meta_keys_down get
  1583.                         /MetaP? exch store
  1584.                     } errored pop
  1585.                     ( ) dup 0 Name MetaP? 0 ne
  1586.                     { 128 add } if
  1587.                     put dup (\200) eq
  1588.                     { (\200) print } if print
  1589.                 } def
  1590.             end def
  1591.         
  1592.             {   awaitevent
  1593.         %        systemdict /_termlogger known { _termlogger } if
  1594.                 begin                % event
  1595.                 MyEventActions Name 2 copy known not {
  1596.                     pop /Default
  1597.                 } if
  1598.                 get exec
  1599.             end
  1600.             } loop
  1601.         } fork /childprocess exch store
  1602.         pause pause
  1603.     } def
  1604.  
  1605.     /StretchOpen {                % called from -ui StretchOpen
  1606.         /InitialReshapeFromUser true def
  1607.     } def
  1608.  
  1609.     /PSTermInit {
  1610.         /HowManyFontsCanYouCount? 1 def
  1611.         /Term_Font DefaultTerminalFont findfont def
  1612.         /SelectedFont Term_Font def
  1613.         /SelectedFontSize DefaultFontSize def
  1614.         /ScaledFont Term_Font def
  1615.         /InitialFont Term_Font def
  1616.         /InitialReshapeFromUser false def
  1617.         /StartIconic 0 def
  1618.         /IconInitialX -1 def
  1619.         /IconInitialY -1 def
  1620.         /MonoSpacedFont true def
  1621.         /FontFixedP true def
  1622.         /SimpleShow DefaultSimpleShow not def
  1623.                 % inverted because we toggle to set up menu
  1624.         /FastRepaint DefaultFastRepaint not def        % likewise
  1625.         /UseCopyArea DefaultUseCopyArea not def        % likewise
  1626.         /CurrentMatrix matrix def
  1627.         /CurrentSelection () def
  1628.  
  1629.         /char_width 1 def
  1630.         /char_height 1 def
  1631.         /MetaP?    0 def
  1632.         /ShowChar ( ) def
  1633.         /Selection_in_progress? false def
  1634.         /HiLightPath null def
  1635.         /HiLightCanvas null def
  1636.  
  1637.         /Font_size SelectedFontSize def
  1638.         /Window_cols    DefaultCols def
  1639.         /Window_lines    DefaultLines def
  1640.         /Window_width    0 def
  1641.         /Window_height    0 def
  1642.         /Window_x    0 def
  1643.         /Window_y    0 def
  1644.  
  1645.         /MyIconLabel    () def
  1646.         /MyFrameLabel    () def
  1647.  
  1648.         /MyWindow    null def
  1649.         /MyMouseEvents    null def
  1650.         /MySetTransform    null def
  1651.         /childprocess    null def
  1652.  
  1653.         /FontChangeProc    /DefaultFontChangeProc load def
  1654.         /LineColChangeProc /DefaultLineColChangeProc load def
  1655.         /WidthHeightChangeProc /DefaultWidthHeightChangeProc load def
  1656.  
  1657.         /HlBgColor where { pop } { /HlBgColor 0 0 0 rgbcolor def } ifelse
  1658.  
  1659.         pause
  1660.     } def
  1661.  
  1662. end
  1663.  
  1664. pause
  1665.  
  1666. /ptr /ptr_m framebuffer setstandardcursor
  1667. @@@ Fin de psterm.ps
  1668. echo selection.c
  1669. cat >selection.c <<'@@@ Fin de selection.c'
  1670. /*
  1671.  * This file is a product of Sun Microsystems, Inc. and is provided for
  1672.  * unrestricted use provided that this legend is included on all tape
  1673.  * media and as a part of the software program in whole or part.
  1674.  * Users may copy, modify or distribute this file at will.
  1675.  * 
  1676.  * THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  1677.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  1678.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  1679.  * 
  1680.  * This file is provided with no support and without any obligation on the
  1681.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  1682.  * modification or enhancement.
  1683.  * 
  1684.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  1685.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS FILE
  1686.  * OR ANY PART THEREOF.
  1687.  * 
  1688.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  1689.  * or profits or other special, indirect and consequential damages, even
  1690.  * if Sun has been advised of the possibility of such damages.
  1691.  * 
  1692.  * Sun Microsystems, Inc.
  1693.  * 2550 Garcia Avenue
  1694.  * Mountain View, California  94043
  1695.  *
  1696.  * Modifications to the original Sun Microsystems, Inc. source code
  1697.  * made by the Grasshopper Group are in the Public Domain.
  1698.  *
  1699.  * Extensions to this file by Eric Messick of the Grasshopper Group.
  1700.  *
  1701.  * Grasshopper Group
  1702.  * 212 Clayton St
  1703.  * San Francisco, CA 94117
  1704.  *
  1705.  */
  1706.  
  1707. #ifndef lint
  1708. static char sccsid[] = "@(#)selection.c 9.4 88/01/19 Copyright 1987 Sun Micro";
  1709. static    char RCSid[] =
  1710.     "@(#)$Header: selection.c,v 2.3 88/10/04 05:59:54 gnu Release $";
  1711. #endif
  1712.  
  1713. /*
  1714.  * Copyright (c) 1987 by Sun Microsystems, Inc. 
  1715.  */
  1716.  
  1717. /*-
  1718.     selection.c
  1719.  
  1720.     selection.c, Fri Feb 27 23:51:49 1987
  1721.  
  1722.  */
  1723.  
  1724. /*
  1725.  * Selection module 
  1726.  *
  1727.  * The external interfaces of this module are
  1728.  * tc_extend_to(col, row, rank, rect)
  1729.  * tc_report_selection(rank)
  1730.  * tc_deselect(rank)
  1731.  * tc_refresh_selection()
  1732.  */
  1733.  
  1734. #include    <sys/types.h>
  1735. #ifdef REF
  1736. #include    <ref/config.h>
  1737. #endif
  1738. #include    "screen.h"
  1739. #include    "tcap.h"
  1740.  
  1741. extern int    CharsPerLine;
  1742. extern int    LinesPerScreen;
  1743. extern int    ScrollY;
  1744. extern int    ScrollLength;
  1745. extern int    ScrollLinesSaved;
  1746.  
  1747. static int FixedRow, FixedCol, FloatRow, FloatCol;
  1748. static int ValidSelectionRange = 0 ;
  1749. static int FixedPointSet = 0 ;
  1750. static int Selecting = 0 ;
  1751. static int RectSelection = 0 ;
  1752. static char spaces[MaxCharsPerLine];
  1753.  
  1754. #define SelectionThreshold 32000
  1755.  
  1756. StartSelection(col, row)
  1757. int col, row;
  1758. {
  1759.     if (FixedPointSet)
  1760.         return;
  1761.     if (row<ScrollLinesSaved-ScrollLength)
  1762.         row = ScrollLinesSaved - ScrollLength ;
  1763.     if (row>=ScrollLength) row = ScrollLength - 1 ;
  1764.     if (col<0) col = 0 ;
  1765.     if (RectSelection) {
  1766.         if (col>=CharsPerLine) col = CharsPerLine - 1 ;
  1767.         }
  1768.     else    {
  1769.         if (col>lines[row]->length) col = lines[row]->length ;
  1770.         }
  1771.     DeSelect();
  1772.     FixedRow = row ;
  1773.     FixedCol = col ;
  1774.     FixedPointSet = 1 ;
  1775. }
  1776.  
  1777. ExtendTo(col, row, strokeoutline)
  1778. int col, row, strokeoutline;
  1779. {
  1780. /*    if (row<ScrollY)
  1781.         scroll_to(ScrollY - ScrollLength + ScrollLinesSaved - row); */
  1782.     if (row<ScrollLength-ScrollLinesSaved)
  1783.         row = ScrollLength - ScrollLinesSaved ;
  1784. /*    if (row>=ScrollY+LinesPerScreen)
  1785.         scroll_to(ScrollY - ScrollLength + ScrollLinesSaved +
  1786.                 LinesPerScreen - row) ; */
  1787.     if (row>=ScrollLength) row = ScrollLength - 1 ;
  1788.     if (col<0) col = 0 ;
  1789.     if (RectSelection) {
  1790.         if (col>=CharsPerLine) col = CharsPerLine - 1 ;
  1791.         }
  1792.     else    {
  1793.         if (col>lines[row]->length) col = lines[row]->length ;
  1794.         }
  1795.     if (ValidSelectionRange) {
  1796.         if (FloatRow==FixedRow) {
  1797.             if (FloatCol > FixedCol)
  1798.                 ChooseFixed(FixedCol, FixedRow,
  1799.                         FloatCol, FloatRow, col, row);
  1800.             else    ChooseFixed(FloatCol, FloatRow,
  1801.                         FixedCol, FixedRow, col, row);
  1802.             }
  1803.         else    if (FloatRow > FixedRow)
  1804.             ChooseFixed(FixedCol, FixedRow,
  1805.                     FloatCol, FloatRow, col, row);
  1806.         else    ChooseFixed(FloatCol, FloatRow,
  1807.                     FixedCol, FixedRow, col, row);
  1808.         }
  1809.     else    StartSelection(col, row);
  1810.     FloatRow = row ;
  1811.     FloatCol = col ;
  1812.     if (FloatRow==FixedRow) {
  1813.         if (FloatCol > FixedCol)
  1814.             HiLight(FixedCol, FixedRow,
  1815.                     FloatCol, FloatRow, strokeoutline);
  1816.         else    HiLight(FloatCol, FloatRow,
  1817.                     FixedCol, FixedRow, strokeoutline);
  1818.         }
  1819.     else    if (FloatRow > FixedRow)
  1820.         HiLight(FixedCol, FixedRow, FloatCol, FloatRow, strokeoutline);
  1821.     else    HiLight(FloatCol, FloatRow, FixedCol, FixedRow, strokeoutline);
  1822. }
  1823.  
  1824. ReportSelection()
  1825. {
  1826.     if (FloatRow==FixedRow) {
  1827.         if (FloatCol > FixedCol)
  1828.             Report(FixedCol, FixedRow, FloatCol, FloatRow);
  1829.         else    Report(FloatCol, FloatRow, FixedCol, FixedRow);
  1830.         }
  1831.     else    if (FloatRow > FixedRow)
  1832.         Report(FixedCol, FixedRow, FloatCol, FloatRow);
  1833.     else    Report(FloatCol, FloatRow, FixedCol, FixedRow);
  1834.     FixedPointSet = 0 ;
  1835. }
  1836.  
  1837. ChooseFixed(startcol, startrow, endcol, endrow, col, row)
  1838. int startcol, startrow, endcol, endrow, col, row;
  1839. {
  1840.     if (RectSelection) {
  1841.         if (abs(startrow-row) > abs(endrow-row))
  1842.             row = startrow ;
  1843.         else    row = endrow ;
  1844.         if (abs(startcol-col) > abs(endcol-col))
  1845.             col = startcol ;
  1846.         else    col = endcol ;
  1847.         StartSelection(col, row) ;
  1848.         return;
  1849.         }
  1850.     if ((row < startrow) || ((row == startrow) && (col <= startcol))) {
  1851.         StartSelection(endcol, endrow);
  1852.         return;
  1853.         }
  1854.     if ((row > endrow) || ((row == endrow) && (col >= endcol))) {
  1855.         StartSelection(startcol, startrow);
  1856.         return;
  1857.         }
  1858.     if (countchars(startcol, startrow, col, row) <
  1859.         countchars(col, row, endcol, endrow)) {
  1860.         StartSelection(endcol, endrow);
  1861.         }
  1862.     else    {
  1863.         StartSelection(startcol, startrow);
  1864.         }
  1865. }
  1866.  
  1867. countchars(startcol, startrow, endcol, endrow)
  1868. int startcol, startrow, endcol, endrow;
  1869. {
  1870.     int count ;
  1871.     struct line **sp;
  1872.  
  1873.     count = endcol-startcol ;
  1874.     for (sp = &lines[startrow]; startrow<endrow; sp++, startrow++)
  1875.         count += (*sp)->length ;
  1876.     return count;
  1877. }
  1878.  
  1879. HiLight(startcol, startrow, endcol, endrow, strokeoutline)
  1880. int startcol, startrow, endcol, endrow, strokeoutline;
  1881. {
  1882.     int row, col;
  1883.     struct line **sp;
  1884.     extern int fontisfixedwidth;
  1885.  
  1886.     startrow -= ScrollY ;
  1887.     endrow -= ScrollY ;
  1888.  
  1889.     if (RectSelection) {
  1890.         if (startrow>endrow) {
  1891.             row = startrow ;
  1892.             startrow = endrow ;
  1893.             endrow = row ;
  1894.             }
  1895.         if (startcol>endcol) {
  1896.             col = startcol ;
  1897.             startcol = endcol ;
  1898.             endcol = col ;
  1899.             }
  1900.         if (endrow < 0 || startrow >= LinesPerScreen) return;
  1901.         if (startrow < 0) startrow = 0 ;
  1902.         if (endrow >= LinesPerScreen) endrow = LinesPerScreen - 1 ;
  1903.         if (fontisfixedwidth) {
  1904.             HiLightRect(startcol, startrow,
  1905.                     endcol, endrow, strokeoutline);
  1906.             }
  1907.         else    {
  1908.             HiLightRect(startcol, startrow,
  1909.                     endcol, endrow, strokeoutline);
  1910.                 /* punt for now */
  1911.             }
  1912.         }
  1913.     else    {
  1914.         if (startrow < 0) {
  1915.             startrow = 0 ;
  1916.             startcol = 0 ;
  1917.             }
  1918.         if (endrow >= LinesPerScreen) {
  1919.             endrow = LinesPerScreen - 1 ;
  1920.             endcol = screen[endrow]->length ;
  1921.             }
  1922.         StartHiLighting(strokeoutline);
  1923.         for (sp = &lines[startrow+ScrollY], row = startrow;
  1924.                 row<endrow;
  1925.                 sp++, row++)
  1926.             if (fontisfixedwidth)
  1927.                 HiLightLine((*sp)->length);
  1928.             else    {
  1929.                 (*sp)->body[(*sp)->length] = ' ' ;
  1930.                 StrHiLightLine((*sp)->body, (*sp)->length + 1);
  1931.                 }
  1932.         if (fontisfixedwidth)
  1933.             EndHiLighting(endcol, startcol, startrow);
  1934.         else    {
  1935.             (*sp)->body[(*sp)->length] = ' ' ;
  1936.             StrEndHiLighting((*sp)->body, endcol+1,
  1937.                     lines[startrow+ScrollY]->body,
  1938.                     startcol, startrow);
  1939.             }
  1940.         }
  1941. }
  1942.  
  1943. Report(startcol, startrow, endcol, endrow)
  1944. int startcol, startrow, endcol, endrow;
  1945. {
  1946.     int row, col, selection_length, extra;
  1947.     struct line **sp;
  1948.  
  1949.     selection_length = 0 ;
  1950.  
  1951.     StartSavingSelection();
  1952.     if (RectSelection) {
  1953.         RePaintHiLight();
  1954.         if (startrow>endrow) {
  1955.             row = startrow ;
  1956.             startrow = endrow ;
  1957.             endrow = row ;
  1958.             }
  1959.         if (startcol>endcol) {
  1960.             col = startcol ;
  1961.             startcol = endcol ;
  1962.             endcol = col ;
  1963.             }
  1964.         for (sp = &lines[startrow];
  1965.                 startrow<=endrow;
  1966.                 startrow++, sp++) {
  1967.             selection_length += endrow - startrow + 1 ;
  1968.             if (selection_length > SelectionThreshold) {
  1969.                 bugprintf("Selection truncated. Max %d chars",
  1970.                     SelectionThreshold, 0, 0);
  1971.                 break;
  1972.                 }
  1973.             if ((*sp)->length < startcol) {
  1974.                 SaveSelectionPiece(spaces, endcol-startcol+1);
  1975.                 }
  1976.             else if ((*sp)->length < endcol) {
  1977.                 SaveSelectionPiece(&((*sp)->body[startcol]),
  1978.                         (*sp)->length - startcol);
  1979.                 SaveSelectionPiece(spaces,
  1980.                         endcol - (*sp)->length + 1);
  1981.                 }
  1982.             else    {
  1983.                 SaveSelectionPiece(&((*sp)->body[startcol]),
  1984.                         endcol - startcol + 1);
  1985.                 }
  1986.             SaveSelectionPiece("\r", 1);
  1987.             }
  1988.         }
  1989.     else    {
  1990.         sp = &lines[startrow] ;
  1991.         if (startrow == endrow) {
  1992.             if (endcol >= (*sp)->length)
  1993.                 extra = 0 ;
  1994.             else    extra = 1 ;
  1995.             if ((*sp)->buffer_length > 0)
  1996.                 SaveSelectionPiece(&((*sp)->body[startcol]),
  1997.                         endcol - startcol + extra);
  1998.             (*sp)->changeposition = 0 ;
  1999.             (*sp)->end_of_changes = CharsPerLine ;
  2000.             if ((*sp)->buffer_length > 0)
  2001.                 for (; startcol<=endcol; startcol++)
  2002.                     (*sp)->prop[startcol] |= PrimSelMode ;
  2003.             }
  2004.         else    {
  2005.             selection_length = (*sp)->length - startcol + 1 ;
  2006.             SaveSelectionPiece(&((*sp)->body[startcol]),
  2007.                         (*sp)->length - startcol);
  2008.             if ((((*sp)->flags) & LINE_WRAPPED) == 0)
  2009.                 SaveSelectionPiece("\r", 1);
  2010.             (*sp)->changeposition = 0 ;
  2011.             (*sp)->end_of_changes = CharsPerLine ;
  2012.             if ((*sp)->buffer_length > 0)
  2013.                 for (; startcol<=(*sp)->length; startcol++)
  2014.                     (*sp)->prop[startcol] |= PrimSelMode ;
  2015.             for (sp++, startrow++;
  2016.                     startrow<endrow;
  2017.                     sp++, startrow++) {
  2018.                 selection_length += (*sp)->length + 1 ;
  2019.                 if (selection_length > SelectionThreshold) {
  2020.                     break;
  2021.                     }
  2022.                 if ((*sp)->buffer_length > 0)
  2023.                     SaveSelectionPiece((*sp)->body,
  2024.                             (*sp)->length);
  2025.                 if ((((*sp)->flags) & LINE_WRAPPED) == 0)
  2026.                     SaveSelectionPiece("\r", 1);
  2027.                 (*sp)->changeposition = 0 ;
  2028.                 (*sp)->end_of_changes = CharsPerLine ;
  2029.                 if ((*sp)->buffer_length > 0)
  2030.                     for (startcol=0;
  2031.                         startcol<=(*sp)->length;
  2032.                         startcol++)
  2033.                         (*sp)->prop[startcol] |=
  2034.                             PrimSelMode ;
  2035.                 }
  2036.             selection_length += (endcol >= (*sp)->length) ?
  2037.                         (*sp)->length+1 : endcol+1;
  2038.             if ((*sp)->buffer_length > 0)
  2039.                 SaveSelectionPiece((*sp)->body,
  2040.                         (endcol >= (*sp)->length) ?
  2041.                         (*sp)->length : endcol+1);
  2042.             if (selection_length > SelectionThreshold) {
  2043.                 bugprintf("Selection truncated. Max %d chars",
  2044.                         SelectionThreshold, 0, 0);
  2045.                 }
  2046.             else    {
  2047.                 (*sp)->changeposition = 0 ;
  2048.                 (*sp)->end_of_changes = CharsPerLine ;
  2049.                 if ((*sp)->buffer_length > 0)
  2050.                     for (startcol=0;
  2051.                         startcol<=((endcol >=
  2052.                             (*sp)->length) ?
  2053.                             (*sp)->length :
  2054.                             endcol);
  2055.                         startcol++)
  2056.                         (*sp)->prop[startcol] |=
  2057.                             PrimSelMode ;
  2058.                 }
  2059.             }
  2060.         if (endcol>=(*sp)->length)
  2061.             SaveSelectionPiece("\r", 1);
  2062.         }
  2063.     FinishSavingSelection();
  2064.     TakeDownOutline();
  2065. }
  2066.  
  2067. DeSelect()
  2068. {
  2069.     int row, col, endrow;
  2070.  
  2071.     if (ValidSelectionRange == 0) return;
  2072.     if (RectSelection) {
  2073.         RePaintHiLight();
  2074.         }
  2075.     else    {
  2076.         if (FixedRow > FloatRow) {
  2077.             row = FloatRow;
  2078.             endrow = FixedRow;
  2079.             }
  2080.         else    {
  2081.             row = FixedRow;
  2082.             endrow = FloatRow;
  2083.             }
  2084.         for (; row<=endrow; row++) {
  2085.             lines[row]->changeposition = 0 ;
  2086.             lines[row]->end_of_changes = CharsPerLine;
  2087.             if (lines[row]->buffer_length > 0)
  2088.                 for(col=0; col<lines[row]->length+1; col++)
  2089.                     lines[row]->prop[col] &= ~PrimSelMode ;
  2090.             }
  2091.         }
  2092.     ClearSelectionPath();
  2093. }
  2094.  
  2095. /* --------------- External Routines Below ------------------- */
  2096. tc_init_selection()
  2097. {
  2098.     int i;
  2099.     char *s;
  2100.  
  2101.     for (i=0, s=spaces; i<MaxCharsPerLine; i++, s++)
  2102.         *s = ' ' ;
  2103. }
  2104. /*ARGSUSED*/
  2105. tc_extend_selection(col, row, rank, rect)
  2106.     int    col, row, rank, rect;
  2107. {
  2108.     if (rect)
  2109.         RectSelection = 1 ;
  2110.     ExtendTo(col, row + ScrollY, 1);
  2111.     ValidSelectionRange = 1 ;
  2112.     Selecting = 1 ;
  2113. }
  2114. /*ARGSUSED*/
  2115. tc_report_selection(rank)
  2116. int rank;
  2117. {
  2118.     if (Selecting) {
  2119.         ReportSelection();
  2120.         Selecting = 0 ;
  2121.         }
  2122. }
  2123. /*ARGSUSED*/
  2124. tc_deselect(rank)
  2125.     int rank;
  2126. {
  2127.     if (!Selecting) {
  2128.         DeSelect();
  2129.         ValidSelectionRange = 0 ;
  2130.         RectSelection = 0 ;
  2131.         }
  2132. }
  2133.  
  2134. tc_take_down_selection()
  2135. {
  2136.     if (!Selecting && ValidSelectionRange && RectSelection) {
  2137.         RePaintHiLight();
  2138.         }
  2139. }
  2140.  
  2141. tc_refresh_selection()
  2142. {
  2143.     ClearSelectionPath();
  2144.     if (!Selecting && ValidSelectionRange && RectSelection) {
  2145.         ExtendTo(FloatCol, FloatRow, 0);
  2146.         FixedPointSet = 0 ;
  2147.         RePaintHiLight();
  2148.         }
  2149. }
  2150. @@@ Fin de selection.c
  2151. echo sys5.c
  2152. cat >sys5.c <<'@@@ Fin de sys5.c'
  2153. /*
  2154.  * This file is a product of Sun Microsystems, Inc. and is provided for
  2155.  * unrestricted use provided that this legend is included on all tape
  2156.  * media and as a part of the software program in whole or part.
  2157.  * Users may copy, modify or distribute this file at will.
  2158.  * 
  2159.  * THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  2160.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  2161.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  2162.  * 
  2163.  * This file is provided with no support and without any obligation on the
  2164.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  2165.  * modification or enhancement.
  2166.  * 
  2167.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  2168.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS FILE
  2169.  * OR ANY PART THEREOF.
  2170.  * 
  2171.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  2172.  * or profits or other special, indirect and consequential damages, even
  2173.  * if Sun has been advised of the possibility of such damages.
  2174.  * 
  2175.  * Sun Microsystems, Inc.
  2176.  * 2550 Garcia Avenue
  2177.  * Mountain View, California  94043
  2178.  *
  2179.  * Modifications to the original Sun Microsystems, Inc. source code
  2180.  * made by the Grasshopper Group are in the Public Domain.
  2181.  *
  2182.  * Extensions to this file by Eric Messick of the Grasshopper Group.
  2183.  *
  2184.  * Grasshopper Group
  2185.  * 212 Clayton St
  2186.  * San Francisco, CA 94117
  2187.  *
  2188.  */
  2189.  
  2190. #ifndef lint
  2191. static  char sccsid[] = "@(#)sys5.c 9.6 88/01/19 SMI";
  2192. static    char RCSid[] =
  2193.     "@(#)$Header: sys5.c,v 2.1 88/10/04 05:59:56 gnu Release $";
  2194. #endif
  2195.  
  2196. /*
  2197.  * Copyright (c) 1987 by Sun Microsystems, Inc.
  2198.  */
  2199.  
  2200. #ifdef    REF
  2201. #include    <ref/config.h>
  2202. #endif
  2203.  
  2204. /*
  2205.  * System V Support Routines.
  2206.  */
  2207. #ifdef HAVE_SYSV_TTYS
  2208. #include <sys/types.h>
  2209. #include <fcntl.h>
  2210. #include <sys/ioctl.h>
  2211. #include <sys/termio.h>
  2212. #include <signal.h>
  2213. #include <stdio.h>
  2214.  
  2215. static    struct termio old_termio, slave_termio, default_termio = {
  2216.     BRKINT|IGNPAR|ISTRIP|ICRNL|IXON|IXANY,
  2217.     OPOST|ONLCR,
  2218.     B9600|CS8|CREAD|HUPCL|CLOCAL,
  2219.     ISIG|ICANON|ECHO|ECHOE|ECHOK,
  2220.     0,
  2221.     03,CQUIT,010,025,CEOF,CNUL,0,0
  2222. };
  2223. static    int notty = 0;
  2224. extern    int CharsPerLine;
  2225. extern    int LinesPerScreen;
  2226.  
  2227. GetTTYDefaults()
  2228.     int fd;
  2229.  
  2230.     /*
  2231.      * Try to copy the termio settings for our controlling terminal for
  2232.      * use on the slave pty, but watch out for the case where we were invoked
  2233.      * as a background process by a shell that may have subsequently put the
  2234.      * control terminal into raw mode (e.g. ksh will do this).
  2235.      */
  2236.     slave_termio = default_termio;    /* assume the worst */
  2237.     if ((fd = open("/dev/tty", O_RDWR|O_NDELAY)) >= 0) {
  2238.     if (ioctl(fd, TCGETA, &old_termio) == 0) {
  2239.         if (old_termio.c_line == default_termio.c_line) {
  2240.         if (old_termio.c_lflag & ICANON)
  2241.             slave_termio = old_termio;
  2242.         else {
  2243.             /* if not doing canonical input, we can probably still
  2244.              * use the VINTR, VQUIT, VERASE, and VKILL parameters
  2245.              */
  2246.             slave_termio.c_cc[VINTR] = old_termio.c_cc[VINTR];
  2247.             slave_termio.c_cc[VQUIT] = old_termio.c_cc[VQUIT];
  2248.             slave_termio.c_cc[VERASE] = old_termio.c_cc[VERASE];
  2249.             slave_termio.c_cc[VKILL] = old_termio.c_cc[VKILL];
  2250.         }
  2251.         }
  2252.     }
  2253.     close(fd);
  2254.     }
  2255.     else
  2256.     notty = 1;
  2257. }
  2258.  
  2259. SetTTYState(fd)
  2260.     int fd;
  2261. {
  2262.  
  2263.     (void) ioctl(fd, TCSETA, &slave_termio);
  2264.     {
  2265.     char num[16];
  2266.     sprintf(num, "%d", LinesPerScreen);
  2267.     set_environment_var("LINES",num);
  2268.     sprintf(num, "%d", CharsPerLine);
  2269.     set_environment_var("COLUMNS", num);
  2270.     }
  2271. }
  2272.  
  2273. DisAssociateTTY()
  2274. {
  2275.  
  2276. }
  2277.  
  2278. AssociateTTY()
  2279. {
  2280.  
  2281.     if (notty)
  2282.     setpgrp();
  2283. }
  2284.  
  2285. SetupControllingTTY(line)
  2286.     char line[];
  2287. {
  2288.  
  2289.     (void) setpgrp();
  2290.     (void) close(open(line, O_RDWR));
  2291. }
  2292.  
  2293. #include <utmp.h>
  2294. #ifndef UTMP_FILE
  2295. #define UTMP_FILE "/etc/utmp"
  2296. #endif
  2297. #include <pwd.h>
  2298.  
  2299. static    int tslot = -1;
  2300.  
  2301. addut(uid, line)
  2302.     char line[];
  2303. {
  2304. #ifdef UTMP
  2305.     struct passwd *pw, *getpwuid();
  2306.     int i;
  2307.  
  2308.     /*
  2309.      * Record entry in /etc/utmp if possible.
  2310.      */
  2311.     tslot = ttyslot();
  2312. #if defined(hpux)
  2313.     /*
  2314.      * Must create utmp entry before ttyslot will work.
  2315.      */
  2316.     if (tslot < 0) {
  2317.     int fd = open(UTMP_FILE, O_RDWR|O_APPEND);
  2318.  
  2319.     if (fd > -1) {
  2320.         struct utmp utmp;
  2321.         memset(&utmp, 0, sizeof (utmp));
  2322.         memcpy(utmp.ut_line, &line[5], sizeof (utmp.ut_line));
  2323.         utmp.ut_type = USER_PROCESS;
  2324.         write(fd, &utmp, sizeof (utmp));
  2325.         close(fd);
  2326.         tslot = ttyslot();        /* try again */
  2327.     } 
  2328.     }
  2329. #endif /* hpux */
  2330.     pw = getpwuid(uid);
  2331.     if (tslot > 0 && pw && (i = open(UTMP_FILE, O_RDWR)) >= 0) {
  2332.     struct utmp utmp;
  2333.     char *cp, *p, *getenv(), *index();
  2334.  
  2335.     memset(&utmp, 0, sizeof (utmp));
  2336.     memcpy(utmp.ut_line, &line[5], sizeof (utmp.ut_line));
  2337.     memcpy(utmp.ut_name, pw->pw_name, sizeof (utmp.ut_name));
  2338.     memcpy(utmp.ut_id, "NeWS", sizeof (utmp.ut_id));
  2339.     utmp.ut_type = USER_PROCESS;
  2340.     (void) time(&utmp.ut_time);
  2341.     (void) lseek(i, tslot * sizeof (utmp), 0);
  2342.     (void) write(i, &utmp, sizeof (utmp));
  2343.     (void) close(i);
  2344.     }
  2345. #endif /* UTMP */
  2346. }
  2347.  
  2348. rmut()
  2349. {
  2350. #ifdef UTMP
  2351.     int fd;
  2352.  
  2353.     if (tslot >= 0 && (fd = open(UTMP_FILE, O_WRONLY)) >= 0) {
  2354.     struct utmp utmp;
  2355.  
  2356.     (void) lseek(fd, tslot * sizeof (utmp), 0);
  2357.     (void) read(fd, &utmp, sizeof (utmp));
  2358.     utmp.ut_type = DEAD_PROCESS;
  2359.     (void) lseek(fd, tslot * sizeof (utmp), 0);
  2360.     (void) write(fd, &utmp, sizeof (utmp));
  2361.     (void) close(fd);
  2362.     }
  2363. #endif
  2364. }
  2365.  
  2366. killpg(pgrp, sig)
  2367. {
  2368.  
  2369.     kill(-pgrp, sig);
  2370. }
  2371. #endif /* HAVE_SYSV_TTYS */
  2372. @@@ Fin de sys5.c
  2373. exit 0
  2374.  
  2375.