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
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <pkg/rg.h>
# RG_ENCODE -- Encode a range structure into a string, return the
# number of characters that were written or ERR for string overflow.
int procedure rg_encode (rg, outstr, maxch)
pointer rg # First set of ranges
char outstr[maxch] # String to receive the ranges
int maxch # Maximum length of the string
char tmpstr[SZ_LINE]
int i, outlen
int strlen()
begin
if (rg == NULL)
call error (0, "Range descriptor undefined")
outlen = 0
outstr[1] = EOS
do i = 1, RG_NRGS(rg) {
if (RG_X1(rg, i) != RG_X2(rg, i)) {
call sprintf (tmpstr, maxch, "%d:%d,")
call pargi (RG_X1(rg, i))
call pargi (RG_X2(rg, i))
} else {
call sprintf (tmpstr, maxch, "%d,")
call pargi (RG_X1(rg, i))
}
outlen = outlen + strlen (tmpstr)
if (outlen <= maxch)
call strcat (tmpstr, outstr, maxch)
else {
outstr[1] = EOS
return (ERR)
}
}
# remove the last comma
outstr[outlen] = EOS
outlen = outlen - 1
return (outlen)
end
|