aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/decod_tablst.x
blob: 16fb9c4432a27bfb197f7dd0e14a58e22ca378b3 (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
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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include <ctype.h>

define	DEFAULT_FSTSTOP	1
define	DEFAULT_TABSIZE	8

# DECODE_TABLIST -- Procedure to decode a string containing a list of
# tabstops into an integer array of tabs. A tabstop is indicated by
# YES. The string may be blank in which case the default
# tabsize is 8, a series of 1,2 or more arguments separated by blanks
# and/or commas, or two arguments of the form m +n where m specifies
# the first tabstop and n the tabsize.

int procedure decode_tablist (tab_list, tabs, maxtabs)

char	tab_list[ARB]
int	tabs[ARB]
int	maxtabs

bool	noarg, plusarg
int	ip, tp, narg, first_tabstop, tabsize, tabstop

int	decode_tabstop(), strlen(), stridxs(), ctoi()

errchk	decode_tabstop, gstrsettab

begin
	ip = 1

	for (tp = 1;  tp <= maxtabs;  tp = tp+1)
	    tabs[tp] = NO

	noarg = true
	plusarg = false

	if (strlen (tab_list) != 0)
	    noarg = false
	if (stridxs ("+", tab_list) != 0)
	    plusarg = true
	
	for (narg = 1;  narg <= maxtabs;  narg = narg + 1) {

	    while (IS_WHITE(tab_list[ip]) || tab_list[ip] == ',')
		ip = ip + 1

	    if (tab_list[ip] == EOS)
		if (noarg) {
		    first_tabstop = DEFAULT_FSTSTOP
		    tabsize = DEFAULT_TABSIZE
		    break
		} else
		    return (OK)

	    if (plusarg) {

		if (narg == 1) {
		    if (decode_tabstop (tab_list, ip, tabs, maxtabs,
			first_tabstop) == ERR)
			return (ERR)
		} else if (narg == 2) {
		    ip = ip + 1
		    if (ctoi (tab_list, ip, tabsize) == 0)
			return (ERR)
		    else
			break
		} else
		    return (ERR)

	    } else if (decode_tabstop (tab_list, ip, tabs, maxtabs, 
		tabstop) == ERR) {

		return (ERR)
	    }
	}

	if (noarg || plusarg)
	    call gstrsettab (tabs, maxtabs, first_tabstop, tabsize)

	return (OK)
end


# DECODE_TABSTOP -- Procedure to decode tabstops

int procedure  decode_tabstop (tab_list, ip, tabs, maxtabs, tabstop)

char	tab_list[ARB]
int	maxtabs
int	ip
int	tabs[ARB]
int	tabstop

int	ctoi()

begin
	if (ctoi (tab_list, ip, tabstop) == 0)
	    return (ERR)
	else if (tabstop <= maxtabs) {
	    tabs[tabstop] = YES
	    return (OK)
	} else
	    return (ERR)
end