summaryrefslogtreecommitdiff
path: root/ipl/mprogs/strucget.icn
blob: f06ab440c76be2e01d76cc8a6a5a336780248835 (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
############################################################################
#
#	File:     strucget.icn
#
#	Subject:  Program to collect SP structures
#
#	Author:   Ralph E. Griswold
#
#	Date:     March 26, 2002
#
############################################################################
#
#  This file is in the public domain.
#
############################################################################
#
#  This program collects the structures in an SP and when the SP
#  terminates, it saves them as an xencoded file.  Records are not
#  collected because they cannot be decoded in the absence of the
#  appropriate record declaration.
#
#  By keeping pointers to the structures in an SP, it assures that
#  all structures produced by that program are intact at the time
#  the SP terminates.  Be aware, however, that some structures may
#  have been "emptied" by the time the SP terminates, for example,
#  by get(L).
#
#  Saving the SP structure prevents them from being collected, which may
#  affect SP performance or even behavior.
#
#  The xencoded file is named <sp>.xcode there <sp> is the name of the
#  SP as given on the command line.
#
############################################################################
#
#  Requires:  MT Icon and instrumentation
#
############################################################################
#
#  Links:  evinit, xcodes
#
############################################################################

link evinit
link xcodes

$include "evdefs.icn"

procedure main(args)
   local mask, structs, name

   name := args[1] | stop("*** no SP")

   EvInit(args) | stop("*** cannot open SP")

   variable("write", &eventsource) := -1	# turn off SP output
   variable("writes", &eventsource) := -1

   structs := set()

   mask := cset(E_Lcreate || E_Rcreate || E_Screate || E_Tcreate)

   while EvGet(mask) do
      insert(structs, &eventvalue)		# add new structure

   xencoden(sort(structs), name || ".xcode")	# save SP structures

end