1
2 canonicalizer: proc (
3 input_string_ptr
4 , initial_input_characters
5 , output_card_ptr
6 , initial_output_columns
7 );
8
9 NOTE
10
11
12
13 dcl initial_input_characters fixed bin(21) parm;
14 dcl initial_output_columns fixed bin(24)parm;
15 dcl input_string_ptr ptr parm;
16 dcl output_card_ptr ptr parm;
17 next_input_character, next_output_column = 1;
18 remaining_input_characters = initial_input_characters;
19 remaining_output_columns = initial_output_columns;
20 more_backspaces, more_tabs = "1"b;
21 if substr (input_string, remaining_input_characters, 1) = ascii_newline
22 then remaining_input_characters = remaining_input_characters - 1;
23
24
25
26 if substr (input_string, 1, 1) = "$" then
27 if length (input_string)>1 then
28 if (substr (input_string, 2, 1) = TAB) | (substr (input_string, 2, 1) = SP) then do;
29 tab_ptr = addr (tab (0));
30 goto selected;
31 end;
32 tab_ptr = addr (tab (nondollar_canon_index));
33 selected: ;
34
35
36
37 do while (remaining_output_columns > 0);
38 if more_backspaces then do;
39
40
41 next_backspace = index (substr (input_string, next_input_character,
42 remaining_input_characters), ascii_backspace);
43 if next_backspace = 0 then more_backspaces = "0"b;
44 end;
45
46 if more_tabs then
47 find_next_tab: do;
48 next_tab = index (substr (input_string, next_input_character,
49 remaining_input_characters), TAB);
50 if next_tab = 0 then more_tabs = "0"b;
51 end;
52
53 if more_backspaces then do;
54
55
56
57 if ^more_tabs | next_backspace ^= next_tab+1 then do;
58 code = 0;
59 err_msg = "canonicalizer: backspace (s) not following a tab in line from ^a:^/" || input_string;
60 goto file_error;
61 end;
62
63 end;
64
65 if more_tabs then do;
66
67 character_count = min (
68 next_tab - 1,
69 remaining_output_columns);
70
71 first_blank = next_output_column + character_count;
72
73 do i = 1 to hbound (tabstop, 1)
74 while (tabstop (i) <= first_blank);
75
76
77 end;
78
79 if i <= hbound (tabstop, 1) then
80 blank_count = min (
81 tabstop (i) - first_blank,
82 remaining_output_columns);
83 else
84 blank_count = min (1, remaining_output_columns);
85 end;
86 else do;
87
88
89
90
91 character_count = min (
92 remaining_input_characters,
93 remaining_output_columns);
94
95 blank_count = max (0,
96 remaining_output_columns - remaining_input_characters);
97 end;
98
99 if character_count > 0 then do;
100 substr (output_card, next_output_column, character_count) =
101 substr (input_string, next_input_character, character_count);
102 remaining_input_characters = remaining_input_characters - character_count;
103 next_input_character = next_input_character + character_count;
104 remaining_output_columns = remaining_output_columns - character_count;
105 next_output_column = next_output_column + character_count;
106 end;
107
108 if blank_count > 0 then do;
109 substr (output_card, next_output_column, blank_count) = "";
110 remaining_output_columns = remaining_output_columns - blank_count;
111 next_output_column = next_output_column + blank_count;
112 end;
113
114 if more_tabs then do;
115 remaining_input_characters = remaining_input_characters - 1;
116 next_input_character = next_input_character + 1;
117 end;
118
119 if more_backspaces then do;
120
121
122
123
124
125 do i = next_input_character to initial_input_characters
126 while (substr (input_string, i, 1) = ascii_backspace);
127 end;
128 character_count = i - next_input_character;
129 backspace_count = min (character_count,
130 next_output_column - 1);
131
132
133
134 remaining_input_characters = remaining_input_characters - character_count;
135 next_input_character = next_input_character + character_count;
136
137
138 remaining_output_columns = remaining_output_columns + backspace_count;
139 next_output_column = next_output_column - backspace_count;
140
141 end;
142 end;
143
144
145
146 if remaining_input_characters > 0 then
147 if ^gcos_ext_stat_$save_data.truncate then do;
148
149 code = 0;
150 err_num = initial_input_characters;
151 err_msg = "line from ^a is too long (^d characters)^/" || input_string;
152 if ^gcos_ext_stat_$save_data.continue then
153 goto file_error;
154 if ^gcos_ext_stat_$save_data.brief then
155 call ioa_ (err_msg, current_file.pathname, err_num);
156 end;
157 return;
158
159 dcl backspace_count fixed bin(24);
160 dcl blank_count fixed bin(24);
161 dcl character_count fixed bin(24);
162 dcl first_blank fixed bin(24);
163 dcl input_string char (initial_input_characters) based (input_string_ptr);
164 dcl more_backspaces bit(1) aligned;
165 dcl more_tabs bit(1)aligned;
166 dcl next_backspace fixed bin(24) ;
167 dcl next_input_character fixed bin(24);
168 dcl next_output_column fixed bin(24);
169 dcl next_tab fixed bin(24) ;
170 dcl output_card char (initial_output_columns) based (output_card_ptr);
171 dcl remaining_input_characters fixed bin(24);
172 dcl remaining_output_columns fixed bin(24);
173 dcl SP char(1)static int options(constant)init(" ");
174 dcl TAB char(1)static int options(constant)init(" ");
175 dcl tabstop (10) fixed bin(24)based (tab_ptr);
176 dcl tab_ptr ptr;
177 end canonicalizer;
178
179