135 This exception was added to make it easier to edit primitive code with |
137 This exception was added to make it easier to edit primitive code with |
136 external editors. However, this means, that other Smalltalks cannot always |
138 external editors. However, this means, that other Smalltalks cannot always |
137 read chunks containing primitive code |
139 read chunks containing primitive code |
138 - but that doesn't really matter, since C-primitives are an ST/X feature anyway." |
140 - but that doesn't really matter, since C-primitives are an ST/X feature anyway." |
139 |
141 |
140 |theString chunkSeparator newString done thisChar nextChar |
142 |buffer theString chunkSeparator newString done thisChar nextChar |
141 atBeginOfLine inPrimitive hasCR hasLF |
143 atBeginOfLine inPrimitive hasCR hasLF |
142 index "{ Class:SmallInteger }" |
144 index "{ Class:SmallInteger }" |
143 currSize "{ Class:SmallInteger }" | |
145 currSize "{ Class:SmallInteger }" | |
144 |
146 |
145 chunkSeparator := ChunkSeparator. |
147 chunkSeparator := ChunkSeparator. |
146 currSize := 500. |
148 buffer := CharacterWriteStream on:(String new:100). |
147 theString := String new:currSize. |
|
148 self skipSeparators. |
149 self skipSeparators. |
149 thisChar := self nextOrNil. |
150 thisChar := self nextOrNil. |
150 index := 0. |
|
151 done := false. |
151 done := false. |
152 atBeginOfLine := true. |
152 atBeginOfLine := true. |
153 inPrimitive := false. |
153 inPrimitive := false. |
154 hasCR := hasLF := false. |
154 hasCR := hasLF := false. |
155 |
155 |
156 [done not and:[thisChar notNil]] whileTrue:[ |
156 [done not and:[thisChar notNil]] whileTrue:[ |
157 ((index + 2) <= currSize) ifFalse:[ |
|
158 newString := String new:(currSize * 2). |
|
159 newString replaceFrom:1 to:currSize with:theString. |
|
160 currSize := currSize * 2. |
|
161 theString := newString |
|
162 ]. |
|
163 |
|
164 "match primitive only at beginning of line |
157 "match primitive only at beginning of line |
165 (ExternalStream>>#nextChunk did this, although stc allows primitive to start anywhere)" |
158 (ExternalStream>>#nextChunk did this, although stc allows primitive to start anywhere)" |
166 |
159 |
167 (atBeginOfLine and:[thisChar == $%]) ifTrue:[ |
160 (atBeginOfLine and:[thisChar == $%]) ifTrue:[ |
168 nextChar := self peekOrNil. |
161 nextChar := self peekOrNil. |
169 (nextChar == ${ ) ifTrue:[ |
162 (nextChar == ${ ) ifTrue:[ |
170 inPrimitive := true. |
163 inPrimitive := true. |
171 index := index + 1. |
164 buffer nextPut:thisChar. |
172 theString at:index put:thisChar. |
|
173 thisChar := self next |
165 thisChar := self next |
174 ] ifFalse:[ |
166 ] ifFalse:[ |
175 (nextChar == $} ) ifTrue:[ |
167 (nextChar == $} ) ifTrue:[ |
176 inPrimitive := false. |
168 inPrimitive := false. |
177 index := index + 1. |
169 buffer nextPut:thisChar. |
178 theString at:index put:thisChar. |
|
179 thisChar := self next |
170 thisChar := self next |
180 ] |
171 ] |
181 ] |
172 ] |
182 ] ifFalse:[ |
173 ] ifFalse:[ |
183 "chunk can not end in primitive code" |
174 "chunk can not end in primitive code" |
207 ] ifFalse:[thisChar == Character lf ifTrue:[ |
198 ] ifFalse:[thisChar == Character lf ifTrue:[ |
208 hasLF := true. |
199 hasLF := true. |
209 atBeginOfLine := true. |
200 atBeginOfLine := true. |
210 ]]. |
201 ]]. |
211 |
202 |
212 index := index + 1. |
203 buffer nextPut:thisChar. |
213 theString at:index put:thisChar. |
|
214 thisChar := self nextOrNil. |
204 thisChar := self nextOrNil. |
215 ]. |
205 ]. |
216 ]. |
206 ]. |
217 |
207 |
218 (index == 0) ifTrue:[^ '']. |
208 theString := buffer contents. |
219 |
|
220 theString := theString copyTo:index. |
|
221 (hasCR and:[hasLF not]) ifTrue:[ |
209 (hasCR and:[hasLF not]) ifTrue:[ |
222 "map all CR in a CR only file to NL (ExternalStream>>#nextChunk did this)" |
210 "map all CR in a CR only file to NL (ExternalStream>>#nextChunk did this)" |
223 theString replaceAll:Character cr with:Character nl. |
211 theString replaceAll:Character cr with:Character nl. |
224 ]. |
212 ]. |
225 |
213 |