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: zipsort.icn
#
# Subject: Program to sort mailing labels by ZIP code
#
# Author: Ralph E. Griswold
#
# Date: November 17, 1994
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# This program sorts labels produced by labels in ascending
# order of their postal zip codes.
#
# Option:
#
# The option -d n sets the number of lines per label to n.
# The default is 9. This value must agree with the value used to
# format the labels.
#
# Zip Codes:
#
# The zip code must be the last nonblank string at the
# end of the label. It must consist of digits but may have an
# embedded dash for extended zip codes. If a label does not end
# with a legal zip code, it is placed after all labels with legal
# zip codes. In such a case, an error messages also is written to
# standard error output.
#
############################################################################
#
# Links: options
#
# See also: labels.icn
#
############################################################################
link options
procedure main(args)
local t, a, label, zip, y, lsize, opts
opts := options(args,"d+")
lsize := (0 < integer(opts["d"])) | 9
t := table("")
repeat {
label := ""
every 1 to lsize do
label ||:= read() || "\n" | break break
label ? {
while tab(upto(' ')) do tab(many(' '))
zip := tab(upto('-') | 0)
zip := integer(zip) | write(&errout,"*** illegal zipcode: ",label)
}
t[zip] ||:= label
}
a := sort(t,3)
while get(a) do
writes(get(a))
end
|