CROSSREF Manual
TAL
Sample Listing
99 INT PROC Ascii(v,rjust,stg);
100 INT v; ! the integer value to convert
101 INT rjust; ! right justify result flag
102 STRING .stg; ! target STRING
103 BEGIN
104 STRING b[0:5] := [5*[" "],"0"];
105
106 INT n; ! number of digits converted
107 INT sgn := 0; ! nonzero if 'v' is negative
108 INT k := 5; ! index for converted digit
109
110 IF v < 0 ! value is negative
111 THEN
112 BEGIN
113 sgn := 1; ! set negative value flag
114 v := -v; ! take absolute value
115 END;
116
117 WHILE v ! while there is a value left....
118 DO
119 BEGIN
120 b[k] := $udbl(v) '\' 10 + "0"; ! convert a character
121 v := v / 10; ! compute the remainder
122 k := k - 1; ! count the converted character
123 END;
124
125 IF sgn ! number is negative
126 THEN
127 BEGIN
128 b[k] := "-"; ! insert the sign
129 k := k - 1; ! count it as a character
130 END;
131
132 IF NOT (n:=5-k) ! check for an overflow
133 THEN
134 n := 1; ! return one character in that case
135
136 IF rjust ! move the resultant string to the
137 THEN ! user's target
138 stg[n-1] '=:' b[5] FOR n ! reverse move if right justified
139 ELSE
140 stg ':=' b[6-n] FOR n; ! otherwise forward move
141
142 RETURN n; ! return the string's length
143 END !ascii! ;
144
145
Figure 12-1. TAL Sample Program
12-4