summaryrefslogtreecommitdiff
path: root/info/examples/tip/csar.tip
blob: 9a451407b729eda2c152a4f4810c6aef415e2aab (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
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
105
106
107
108
109
110
111
112
113
114
% This macro source file is from the four volume series
% "TeX in Practice" by Stephan von Bechtolsheim, published
% 1993 by Springer-Verlag, New York.
% Copyright 1993 Stephan von Bechtolsheim.
% No warranty or liability is assumed.
% This macro may be copied freely if no fees other than
% media cost or shipping charges are charged and as long
% as this copyright and the following source code itself
% is not changed. Please see the series for further information.
%
% Version: 1.0
% Date: May 1, 1993
%
%
% This source code is documented in 19.2.2, p. III-78.
% Original source in file "tokens2.TEX", starting line 640.
\wlog{L: "csar.tip" ["tokens2.TEX," l. 640, p. III-78]}%
% This file DOES belong to format "texip."
\InputD{doloop.tip}
\InputD{rangetst.tip}
\InputD{compst.tip}
\InputD{strleng.tip}
\catcode`\@ = 11
\newcount\@CreateArrayCount
\def\CCreateArray #1#2#3{%
    \NameEdef{#1-low}{\number#2}%
    \NameEdef{#1-high}{#3}%
    \ifnum #3<#2
        \errmessage{\string\CCreateArray: low array boundary
            \number#2 is larger than upper array boundary
            \number#3}%
    \fi
    \DoLoop{\@CreateArrayCount}{#2}{1}{#3}{%
        \NameDef{#1-\the\@CreateArrayCount}{}%
    }
}
\newcount\@ConvertStringIntoArrayLength
\newcount\@ConvertStringIntoArrayCount
\def\ConvertStringIntoArray #1#2{%
    \def\@ConvertArrayName{#1}%
    \edef\@ConvertArrayString{#2}%
    \StringLength{\@ConvertArrayString}%
    \@ConvertStringIntoArrayLength = \StringLengthResult
    \advance\@ConvertStringIntoArrayLength by -1
    \CCreateArray{\@ConvertArrayName}%
        {0}{\the\@ConvertStringIntoArrayLength}%
    \@ConvertStringIntoArrayCount = 0
    \expandafter\@ConvertStringIntoArray
        \@ConvertArrayString\@ConvertEnd
}
\def\@ConvertStringIntoArray #1#2\@ConvertEnd{%
    \CLoadArrayElementEdef{\@ConvertArrayName}%
        {\the\@ConvertStringIntoArrayCount}{#1}%
    \if\EmptyStringConditional{#2}%
        \def\@ConvertStringIntoArrayNext{}%
    \else
        \advance\@ConvertStringIntoArrayCount by 1\relax
        \def\@ConvertStringIntoArrayNext{%
            \@ConvertStringIntoArray #2\@ConvertEnd%
        }%
    \fi
    \@ConvertStringIntoArrayNext
}
\def\CCheckIndex #1#2{%
    \expandafter\ifx\csname #1-low\endcsname\relax
        \errmessage{\string\CCheckIndex: no array #1.}%
    \fi
    \ifnum #2<\NameUse{#1-low}%
        \errmessage{Index #2 for array #1 too small.}%
    \fi
    \ifnum #2>\NameUse{#1-high}%
        \errmessage{Index #2 for array #1 too large.}%
    \fi
}
\def\CArrayAccess #1#2#3{%
    \CCheckIndex{#1}{#2}%
    \edef#3{\NameUse{#1-#2}}%
}
\newcount\@CArrayAccessIntervalCount
\def\CArrayAccessInterval #1#2#3#4{%
    \CCheckIndex{#1}{#2}%
    \CCheckIndex{#1}{#3}%
    \ifnum #2>#3\relax
        \errmessage{\string\CArrayAccessInterval: low index
            (\PoundSignText 2) > high index
            (PoundSignText 3).}%
    \fi
    \def#4{}%
    \DoLoop
        {\@CArrayAccessIntervalCount}{#2}{1}{#3}{%
        \CArrayAccess{#1}{\the\@CArrayAccessIntervalCount}%
            {\@CArrayAccessInterval}%
        \edef#4{#4\@CArrayAccessInterval}%
    }%
}
\def\CLoadArrayElement #1#2#3{%
    \CCheckIndex{#1}{#2}%
    \NameDef{#1-#2}{#3}%
}
\def\CLoadArrayElementEdef #1#2#3{%
    \CCheckIndex{#1}{#2}%
    \NameEdef{#1-#2}{#3}%
}
\newcount\@CShowArrayCount
\def\CShowArray #1{%
    \DoLoop
        {\@CShowArrayCount}%
        {\NameUse{#1-low}}% 
        {1}% 
        {\NameUse{#1-high}}%
        {\wlog{Index \the\@CShowArrayCount:
            \NameUse{#1-\the\@CShowArrayCount}}}%
}
\catcode`\@ = 12