aboutsummaryrefslogtreecommitdiff
path: root/vendor/x11iraf/ximtool/clients.old/lib/idxstr.x
blob: 7b0556589a9fa99f382b120e64989a4561cff05f (plain) (blame)
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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.


# IDXSTR -- Search a dictionary string for a given string index number.
# This is the opposite function of strdic(), that returns the index for
# given string.  The entries in the dictionary string are separated by
# a delimiter character which is the first character of the dictionary
# string.  The index of the string found is returned as the function value.
# Otherwise, if there is no string for that index, a zero is returned.

int procedure idxstr (index, outstr, maxch, dict)

int	index				#i String index
char	outstr[ARB]			#o Output string as found in dictionary
int	maxch				#i Maximum length of output string
char	dict[ARB]			#i Dictionary string

int	i, len, start, count

int	strlen()

begin
	# Clear the output string.
	outstr[1] = EOS

	# Return if the dictionary is not long enough.
	if (dict[1] == EOS)
	    return (0)

	# Initialize the counters.
	count = 1
	len   = strlen (dict)

	# Search the dictionary string. This loop only terminates
	# successfully if the index is found. Otherwise the procedure
	# returns with and error condition.
	for (start = 2; count < index; start = start + 1) {
	    if (dict[start] == dict[1])
		count = count + 1
	    if (start == len)
		return (0)
	}

	# Extract the output string from the dictionary.
	for (i = start; dict[i] != EOS && dict[i] != dict[1]; i = i + 1) {
	    if (i - start + 1 > maxch)
		break
	    outstr[i - start + 1] = dict[i]
	}
	outstr[i - start + 1] = EOS

	# Return index for output string.
	return (count)
end