summaryrefslogtreecommitdiff
path: root/ipl/gprogs/procater.icn
blob: 721389f603182461225ed33d03e7ed1ee3e40699 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
############################################################################
#
#	File:     procater.icn
#
#	Subject:  Program to display concatenation sizes
#
#	Author:   Ralph E. Griswold
#
#	Date:     September 18, 1996
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This program displays successive numbers by lines of corresponding
#  height.  When the display area is full, it scrolls from right to
#  left.
#
#  In this version, input is piped in.
#
############################################################################
#
#  Requires:  Version 9 graphics
#
############################################################################
#
#  Links: interact, vsetup
#
############################################################################

link interact
link vsetup

global vidgets
global root
global strip
global state
global gc_gray
global gc_black
global reset
global scale

global width
global height

procedure main(args)

   init(args)

   display()

end

procedure init(args)

   WOpen ! ui_atts()

   vidgets := ui()

   root := vidgets["root"]

   state := &null
   scale := 1

   width :=  vidgets["strip"].uw
   height :=  vidgets["strip"].uh

   strip := Clone("dx=" || vidgets["strip"].ux, "dy=" || vidgets["strip"].uy)
   Clip(strip, 0, 0, width, height)
   gc_gray := Clone(strip, "fg=gray")
   gc_black := Clone(strip, "fg=black")

end

procedure display()
   local n, gc

   repeat {
      repeat {
         while (*Pending() > 0) | \state do
            ProcessEvent(root, , shortcuts)
         n := read() | {
            Notice("End of data.")
            fail
            }
         n ? {
            if ="a" then {
               n := tab(0)
               gc := gc_gray
               }
            else gc := gc_black
            }
         n := scale * integer(n) | {
            Notice("Nonnumeric data; terminating.")
            break
            }
         n >:= height			# Motif bug avoidance
         CopyArea(strip, 1, 0, width - 1, height, 0, 0)
         EraseArea(strip, width - 1, 0, width, height)
         DrawLine(gc, width - 1, height - n, width - 1, height)
         }
   }

end

procedure file_cb(vidget, value)

   case value[1] of {
      "snapshot  @S":  return snapshot(strip, 0, 0, width, height)
      "quit      @Q":  exit()
      }
   
   fail

end

procedure configure_cb(vidget, value)

   case value[1] of {
      "scale":  {
         repeat {
            if TextDialog(, "scale", scale, 10) == "Okay" then {
               scale := (0 < numeric(dialog_value[1])) | {
                  Notice("Invalid scale value.")
                  next
                  }
               reset_cb()
               return
               }
            else fail			# user canceled
            }
         }
      }

   fail

end
procedure pause_cb(vidget, value)

   state := value

   return

end

procedure reset_cb()

   EraseArea(strip)

   return

end

procedure shortcuts(e)

   if &meta then
      case map(e) of {
         "q":  exit()
         "s":  return snapshot(strip, 0, 0, width, height)
         }
   else fail

end

#===<<vib:begin>>===	modify using vib; do not remove this marker line
procedure ui_atts()
   return ["size=477,255", "bg=gray-white"]
end

procedure ui(win, cbk)
return vsetup(win, cbk,
   [":Sizer:::0,0,477,255:",],
   ["configure:Menu:pull::36,0,71,21:Configure",configure_cb,
      ["scale"]],
   ["file:Menu:pull::0,1,36,21:File",file_cb,
      ["open      @O","snapshot  @S","quit      @q"]],
   ["line1:Line:::0,22,477,22:",],
   ["pause:Button:regular:1:11,43,42,20:pause",pause_cb],
   ["reset:Button:regular::11,76,42,20:reset",reset_cb],
   ["strip:Rect:grooved::63,37,400,200:",],
   )
end
#===<<vib:end>>===	end of section maintained by vib