author | Claus Gittinger <cg@exept.de> |
Fri, 20 Feb 2004 19:47:41 +0100 | |
changeset 4028 | 207665fe4397 |
parent 4019 | f843f59a3c74 |
child 4030 | 34cdc7a25687 |
permissions | -rw-r--r-- |
5 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
72 | 3 |
All Rights Reserved |
5 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
0 | 12 |
|
3263 | 13 |
"{ Package: 'stx:libview' }" |
14 |
||
0 | 15 |
Dictionary subclass:#ResourcePack |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
16 |
instanceVariableNames:'superPack packsClassName fileReadFailed' |
308
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
17 |
classVariableNames:'Packs' |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
18 |
poolDictionaries:'' |
3484 | 19 |
category:'Interface-Internationalization' |
0 | 20 |
! |
21 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
22 |
!ResourcePack class methodsFor:'documentation'! |
46 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
72 | 27 |
All Rights Reserved |
5 | 28 |
|
46 | 29 |
This software is furnished under a license and may be used |
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
5 | 37 |
|
46 | 38 |
documentation |
39 |
" |
|
1942 | 40 |
This class supports easy customization of smalltalk code (i.e. internationalization |
41 |
and viewStyle adaption). |
|
145 | 42 |
ResourcePacks are class specific, meaning that every subclass of View |
1942 | 43 |
and ApplicationModel has an instance of ResourcePack (instVar called 'resources') |
44 |
which is created when the first instance of the view/app is created, |
|
45 |
and cached in a class-instVar (so the file is only read once). |
|
54 | 46 |
|
50 | 47 |
The resourcePack consists of a mapping from strings to values, which are |
48 |
then used in labels, buttons, menus etc. |
|
49 |
The resourcePack initializes itself from a file found in 'resources/<className>.rs', |
|
50 |
where 'className' is built by the usual abbreviation mechanism (see abbrev-files). |
|
1942 | 51 |
|
50 | 52 |
Conditional mappings are possible, by including lines as: |
3762 | 53 |
#if <expression> |
54 |
#endif |
|
50 | 55 |
in the resourcefile. Example: |
56 |
file 'foo.rs': |
|
3762 | 57 |
#if Language == #de |
58 |
'abort' 'Abbruch' |
|
59 |
#endif |
|
60 |
#if Language == #fr |
|
61 |
'abort' 'canceller' |
|
62 |
#endif |
|
145 | 63 |
|
64 |
the corresponding resource-strings are accessed (from methods within the class) |
|
65 |
using: |
|
3762 | 66 |
resources string:'abort' |
145 | 67 |
|
54 | 68 |
returning the mapped string (i.e. 'Abbruch' if the global Language is set |
3422 | 69 |
to #de).. |
145 | 70 |
|
1942 | 71 |
If no corresponding entry is found in the resources, the key is returned; |
72 |
alternatively, use: |
|
3762 | 73 |
resources string:'foo' default:'bar' |
1942 | 74 |
which returns 'bar', if no resource definition for 'foo' is found. |
75 |
||
54 | 76 |
Translations can also include arguments, such as: |
3762 | 77 |
resources string:'really delete %1' with:fileName |
145 | 78 |
|
79 |
This scheme has the advantage, that you can write your programs using your |
|
80 |
native language strings. Later, when new languages are to be supported, |
|
81 |
simply create a resource file for the class and add translations for |
|
82 |
all those strings. (find the keys by looking at users of resource or senders |
|
1942 | 83 |
of 'string:*'). |
84 |
Notice, that the grammar of different languages may imply a reordering, |
|
85 |
so the above string becomes the german 'wollen Sie %1 wirklich löschen'; |
|
86 |
so using percent-placeholders is much better than simple concatenations of |
|
87 |
arguments to the question. |
|
145 | 88 |
|
89 |
More languages can be added later without any change in the code, |
|
90 |
recompilation or the like. |
|
91 |
Even by people without access to the source code i.e. which only have the |
|
92 |
applications binary. |
|
93 |
||
94 |
Also, unsupported languages' strings are simply left unchanged - if you |
|
95 |
write your application in (say) english, and only plan to use it in english, |
|
96 |
no additional work is required (i.e you dont need a resource file then). |
|
97 |
Strings for unknown languages will come in english |
|
98 |
(which is better than nothing or empty button labels ;-) |
|
99 |
||
100 |
Summary: |
|
3762 | 101 |
in subclasses of View and ApplicationModel, |
102 |
instead of writing: |
|
145 | 103 |
|
3762 | 104 |
... |
105 |
b := Button label:'press me' |
|
106 |
... |
|
145 | 107 |
|
3762 | 108 |
always write: |
612 | 109 |
|
3762 | 110 |
... |
111 |
b := Button label:(resources string:'press me') |
|
112 |
... |
|
145 | 113 |
|
3762 | 114 |
if your class is not a subclass of one of the above, AND you need |
115 |
resource translations, you wont inherit the resources variable |
|
116 |
(which is automatically initialized). |
|
117 |
In this case, you have to ask the ResourcePack class explicitely for |
|
118 |
a corresponding package: |
|
145 | 119 |
|
3762 | 120 |
ResourcePack for:aClassName |
145 | 121 |
|
3762 | 122 |
as an example, see how the Date class gets the national names of |
123 |
week & monthnames. |
|
145 | 124 |
|
612 | 125 |
[author:] |
3762 | 126 |
Claus Gittinger |
145 | 127 |
" |
128 |
! |
|
129 |
||
130 |
examples |
|
131 |
" |
|
132 |
normally, resources are found in files named after their classes sourcefile |
|
133 |
For example, the FileBrowsers resources are found in 'FBrowser.rs'. |
|
134 |
For the examples below, we process resources from a constant string; |
|
3762 | 135 |
this is NOT representative. |
136 |
[exBegin] |
|
137 |
|stream res| |
|
145 | 138 |
|
3762 | 139 |
stream := ReadStream on:' |
145 | 140 |
foo ''the translation for foo'' |
3422 | 141 |
#if Language == #de |
145 | 142 |
bar ''die deutsche uebersetzung von bar'' |
143 |
baz ''baz hat den Wert %1'' |
|
144 |
#endif |
|
3422 | 145 |
#if Language == #fr |
145 | 146 |
bar ''bar en francaise'' |
147 |
baz ''%1, c''''est baz'' |
|
148 |
#endif |
|
149 |
||
150 |
'. |
|
151 |
||
3762 | 152 |
res := ResourcePack new readFromResourceStream:stream in:nil. |
145 | 153 |
|
3762 | 154 |
Transcript showCR:'baz is translated to: ' , (res string:'baz' with:'1234'). |
155 |
Transcript showCR:'bar is translated to: ' , (res string:'bar'). |
|
156 |
Transcript showCR:'foo is translated to: ' , (res string:'foo'). |
|
157 |
Transcript showCR:'fooBar is translated to: ' , (res string:'fooBar'). |
|
158 |
[exEnd] |
|
145 | 159 |
set the Language to french: |
3762 | 160 |
[exBegin] |
161 |
Language := #fr |
|
162 |
[exEnd] |
|
145 | 163 |
and repeat the above. |
620 | 164 |
back to english: |
3762 | 165 |
[exBegin] |
166 |
Language := #en |
|
167 |
[exEnd] |
|
620 | 168 |
back to german: |
3762 | 169 |
[exBegin] |
170 |
Language := #de |
|
171 |
[exEnd] |
|
46 | 172 |
" |
173 |
! ! |
|
5 | 174 |
|
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
175 |
!ResourcePack class methodsFor:'initialization'! |
0 | 176 |
|
72 | 177 |
flushCachedResourcePacks |
24 | 178 |
"forget all cached resources - needed after a style change" |
179 |
||
180 |
Packs := nil. |
|
181 |
self initialize |
|
182 |
||
72 | 183 |
"ResourcePack flushCachedResourcePacks" |
244 | 184 |
! |
185 |
||
186 |
initialize |
|
187 |
Packs isNil ifTrue:[ |
|
188 |
Packs := WeakArray new:30 |
|
189 |
]. |
|
190 |
||
191 |
"ResourcePack initialize" |
|
192 |
! ! |
|
193 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
194 |
!ResourcePack class methodsFor:'instance creation'! |
244 | 195 |
|
196 |
for:aClass |
|
197 |
"get the full resource definitions for aClass (i.e. with super packs). |
|
198 |
Also leave the resulting pack in the cache for faster access next time." |
|
199 |
||
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
200 |
|nm pack rsrcDir baseName| |
244 | 201 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
202 |
nm := aClass resourcePackName. |
244 | 203 |
pack := self searchCacheFor:nm. |
204 |
pack notNil ifTrue:[^ pack]. |
|
205 |
||
3049
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
206 |
baseName := (Smalltalk fileNameForClass:nm) , '.rs'. |
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
207 |
rsrcDir := aClass resourceDirectory. |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
208 |
|
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
209 |
(rsrcDir notNil |
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
210 |
and:[rsrcDir exists |
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
211 |
and:[(rsrcDir construct:baseName) exists]]) ifTrue:[ |
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
212 |
pack := self fromFile:baseName directory:rsrcDir pathName. |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
213 |
] ifFalse:[ |
3808 | 214 |
pack := self fromFile:baseName. |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
215 |
]. |
244 | 216 |
aClass == Object ifFalse:[ |
3808 | 217 |
pack superPack:(self for:(aClass superclass)). |
244 | 218 |
]. |
219 |
pack packsClassName:nm. |
|
220 |
self addToCache:pack. |
|
221 |
^ pack |
|
222 |
||
223 |
" |
|
3046 | 224 |
ResourcePack for:TextView |
244 | 225 |
ResourcePack for:CodeView |
3046 | 226 |
ResourcePack for:Workspace |
3049
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
227 |
ResourcePack for:View |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
228 |
ResourcePack for:ErrorLogger |
3101
38cc69894380
fix to avoid loosing the directory with #includes
Claus Gittinger <cg@exept.de>
parents:
3097
diff
changeset
|
229 |
ResourcePack for:NewLauncher |
244 | 230 |
Workspace classResources |
231 |
" |
|
232 |
! |
|
233 |
||
234 |
fromFile:aFileName |
|
235 |
"get the resource definitions from a file in the default directory. |
|
236 |
Uncached low-level entry." |
|
237 |
||
238 |
^ self fromFile:aFileName directory:'resources' |
|
239 |
||
240 |
" |
|
241 |
ResourcePack fromFile:'SBrowser.rs' |
|
242 |
ResourcePack fromFile:'FBrowser.rs' |
|
243 |
ResourcePack fromFile:'Smalltalk.rs' |
|
3678 | 244 |
ResourcePack fromFile:'Smalltalk.rs' asFilename |
3983 | 245 |
ResourcePack fromFile:'../../libtool/resources/AboutBox_ru.rs' asFilename |
244 | 246 |
" |
247 |
! |
|
248 |
||
249 |
fromFile:aFileName directory:dirName |
|
250 |
"get the resource definitions from a file in a directory. |
|
251 |
Uncached low-level entry." |
|
252 |
||
253 |
|newPack| |
|
254 |
||
255 |
newPack := self new. |
|
256 |
newPack readFromFile:aFileName directory:dirName. |
|
257 |
^ newPack |
|
0 | 258 |
! ! |
259 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
260 |
!ResourcePack class methodsFor:'private'! |
54 | 261 |
|
262 |
addToCache:aPack |
|
263 |
|idx| |
|
0 | 264 |
|
54 | 265 |
idx := Packs identityIndexOf:nil. |
266 |
idx == 0 ifTrue:[ |
|
1078
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
267 |
idx := Packs identityIndexOf:0 |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
268 |
]. |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
269 |
idx == 0 ifTrue:[ |
72 | 270 |
" |
271 |
throw away oldest |
|
272 |
" |
|
273 |
idx := Packs size. |
|
274 |
Packs replaceFrom:1 to:idx-1 with:Packs startingAt:2. |
|
54 | 275 |
]. |
276 |
Packs at:idx put:aPack |
|
277 |
! |
|
0 | 278 |
|
54 | 279 |
searchCacheFor:aClassname |
998 | 280 |
|sz "{ Class: SmallInteger }" | |
0 | 281 |
|
24 | 282 |
Packs isNil ifTrue:[ |
72 | 283 |
self initialize. |
284 |
^ nil |
|
0 | 285 |
]. |
54 | 286 |
|
287 |
sz := Packs size. |
|
288 |
1 to:sz do:[:idx | |
|
72 | 289 |
|aPack| |
54 | 290 |
|
72 | 291 |
aPack := Packs at:idx. |
1078
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
292 |
(aPack notNil |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
293 |
and:[aPack ~~ 0]) ifTrue:[ |
72 | 294 |
aClassname = aPack packsClassName ifTrue:[ |
295 |
" |
|
296 |
bring to end for LRU |
|
297 |
" |
|
298 |
Packs replaceFrom:idx to:sz-1 with:Packs startingAt:idx+1. |
|
299 |
Packs at:sz put:aPack. |
|
300 |
^ aPack |
|
301 |
] |
|
302 |
] |
|
0 | 303 |
]. |
54 | 304 |
^ nil |
123 | 305 |
|
306 |
" |
|
307 |
ResourcePack searchCacheFor:'TextView' |
|
308 |
" |
|
54 | 309 |
! ! |
310 |
||
0 | 311 |
!ResourcePack methodsFor:'accessing'! |
312 |
||
244 | 313 |
array:anArray |
314 |
"translate a collection of strings" |
|
0 | 315 |
|
244 | 316 |
^ anArray collect:[:r | self at:r default:r] |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
317 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
318 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
319 |
Launcher classResources array:#('file' 'classes') |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
320 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
321 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
322 |
"Modified: / 29.1.1998 / 22:44:22 / cg" |
0 | 323 |
! |
324 |
||
2 | 325 |
at:aKey |
123 | 326 |
"translate a string" |
327 |
||
72 | 328 |
^ self at:aKey ifAbsent:aKey |
0 | 329 |
! |
330 |
||
331 |
at:aKey default:default |
|
123 | 332 |
"translate a string" |
333 |
||
72 | 334 |
^ self at:aKey ifAbsent:default |
0 | 335 |
! |
336 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
337 |
at:aKey ifAbsent:defaultValue |
123 | 338 |
"translate a string" |
339 |
||
4017 | 340 |
|val alternativeKey rest usedKey idx| |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
341 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
342 |
aKey notNil ifTrue:[ |
3979
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
343 |
val := super at:aKey ifAbsent:nil. |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
344 |
val notNil ifTrue:[^ val]. |
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
345 |
|
4028 | 346 |
(aKey isString and:[aKey size > 0]) ifTrue:[ |
347 |
"/ try with case-first swapped... |
|
348 |
(aKey first isLetter) ifTrue:[ |
|
349 |
alternativeKey := aKey first isUppercase |
|
350 |
ifTrue:[aKey asLowercaseFirst] |
|
351 |
ifFalse:[aKey asUppercaseFirst]. |
|
352 |
val := super at:alternativeKey ifAbsent:nil. |
|
353 |
val notNil ifTrue:[ |
|
354 |
aKey first isUppercase ifTrue:[ |
|
355 |
^ val asUppercaseFirst |
|
4017 | 356 |
]. |
4028 | 357 |
^ val asLowercaseFirst. |
3979
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
358 |
]. |
4028 | 359 |
]. |
360 |
||
361 |
(':=' includes:aKey last) ifTrue:[ |
|
362 |
rest := aKey last. |
|
363 |
usedKey := aKey copyWithoutLast:1. |
|
364 |
||
365 |
val := self at:usedKey ifAbsent:nil. "/ recursion |
|
366 |
val notNil ifTrue:[^ val , rest]. |
|
367 |
]. |
|
4017 | 368 |
|
4028 | 369 |
(aKey endsWith:' ') ifTrue:[ |
370 |
usedKey := aKey withoutSeparators. |
|
4017 | 371 |
|
4028 | 372 |
val := self at:usedKey ifAbsent:nil. "/ recursion |
373 |
val notNil ifTrue:[^ val]. |
|
374 |
]. |
|
375 |
(aKey endsWith:' ...') ifTrue:[ |
|
376 |
usedKey := aKey copyWithoutLast:4. |
|
4017 | 377 |
|
4028 | 378 |
val := self at:usedKey ifAbsent:nil. "/ recursion |
379 |
val notNil ifTrue:[^ val , '...']. |
|
380 |
]. |
|
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
381 |
|
4028 | 382 |
(aKey endsWith:'...') ifTrue:[ |
383 |
usedKey := aKey copyWithoutLast:3. |
|
3979
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
384 |
|
4028 | 385 |
val := self at:usedKey ifAbsent:nil. "/ recursion |
386 |
val notNil ifTrue:[^ val , '...']. |
|
387 |
]. |
|
388 |
||
389 |
(idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
|
390 |
(aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
|
391 |
usedKey := (aKey copyTo:idx-1) , (aKey copyFrom:idx+1). |
|
392 |
val := self at:usedKey ifAbsent:nil. "/ recursion |
|
393 |
val notNil ifTrue:[^ val]. |
|
4017 | 394 |
]. |
395 |
]. |
|
3979
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
396 |
]. |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
397 |
|
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
398 |
superPack notNil ifTrue:[ |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
399 |
^ superPack at:aKey ifAbsent:defaultValue. |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
400 |
]. |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
401 |
]. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
402 |
^ defaultValue value |
2 | 403 |
! |
404 |
||
405 |
name:aKey default:default |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
406 |
"translate a string. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
407 |
Obsolete - use #string:default:" |
123 | 408 |
|
72 | 409 |
^ self at:aKey ifAbsent:default |
2 | 410 |
! |
411 |
||
0 | 412 |
string:s |
3097 | 413 |
"translate (retrieve) a string - if not present, return s" |
123 | 414 |
|
72 | 415 |
^ self at:s ifAbsent:s |
3097 | 416 |
|
417 |
" |
|
418 |
NewLauncher classResources |
|
3762 | 419 |
string:'LICENCEFILE' |
3097 | 420 |
" |
0 | 421 |
! |
422 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
423 |
string:s default:defaultString |
3097 | 424 |
"translate (retrieve) a string - if not present, return defaultString" |
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
425 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
426 |
^ self at:s ifAbsent:defaultString |
3097 | 427 |
|
428 |
" |
|
429 |
NewLauncher classResources |
|
3762 | 430 |
string:'fooBar' default:'Hello world' |
3097 | 431 |
" |
432 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
433 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
434 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
435 |
string:s default:defaultString with:arg |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
436 |
"translate and expand arg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
437 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
438 |
^ self string:s default:defaultString withArgs:(Array with:arg) |
3097 | 439 |
|
440 |
" |
|
441 |
NewLauncher classResources |
|
3762 | 442 |
string:'%1 fooBar' default:'Hello %1' with:'foo' |
3097 | 443 |
" |
444 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
445 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
446 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
447 |
string:s default:defaultString with:arg1 with:arg2 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
448 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
449 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
450 |
^ self string:s default:defaultString withArgs:(Array with:arg1 with:arg2) |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
451 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
452 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
453 |
string:s default:defaultString with:arg1 with:arg2 with:arg3 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
454 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
455 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
456 |
^ self string:s default:defaultString withArgs:(Array with:arg1 with:arg2 with:arg3) |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
457 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
458 |
"Created: 9.12.1995 / 19:08:50 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
459 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
460 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
461 |
string:s default:defaultString with:arg1 with:arg2 with:arg3 with:arg4 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
462 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
463 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
464 |
^ self string:s default:defaultString withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
465 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
466 |
"Created: 9.9.1996 / 18:52:14 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
467 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
468 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
469 |
string:s default:defaultString withArgs:argArray |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
470 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
471 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
472 |
|template| |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
473 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
474 |
template := self at:s ifAbsent:defaultString. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
475 |
^ template expandPlaceholdersWith:argArray |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
476 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
477 |
|
0 | 478 |
string:s with:arg |
123 | 479 |
"translate and expand arg" |
480 |
||
0 | 481 |
^ self string:s withArgs:(Array with:arg) |
482 |
! |
|
483 |
||
484 |
string:s with:arg1 with:arg2 |
|
123 | 485 |
"translate and expand args" |
486 |
||
0 | 487 |
^ self string:s withArgs:(Array with:arg1 with:arg2) |
488 |
! |
|
489 |
||
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
490 |
string:s with:arg1 with:arg2 with:arg3 |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
491 |
"translate and expand args" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
492 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
493 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3) |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
494 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
495 |
"Created: 9.12.1995 / 19:08:50 / cg" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
496 |
! |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
497 |
|
1042 | 498 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 |
499 |
"translate and expand args" |
|
500 |
||
501 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
502 |
||
503 |
"Created: 9.9.1996 / 18:52:14 / cg" |
|
504 |
! |
|
505 |
||
3184 | 506 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
507 |
"translate and expand args" |
|
508 |
||
509 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
510 |
||
511 |
! |
|
512 |
||
0 | 513 |
string:s withArgs:argArray |
123 | 514 |
"translate and expand args" |
515 |
||
135 | 516 |
|template| |
0 | 517 |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
518 |
template := self at:s ifAbsent:s. |
135 | 519 |
^ template expandPlaceholdersWith:argArray |
3823 | 520 |
! |
521 |
||
522 |
stringWithCRs:s with:arg |
|
523 |
"translate, replace \'s with CRs and finally expand arg. |
|
524 |
CR-replacement is donw before args are inserted |
|
525 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
526 |
||
527 |
^ self stringWithCRs:s withArgs:(Array with:arg) |
|
528 |
||
529 |
"Modified: / 21.3.2003 / 14:22:09 / cg" |
|
530 |
! |
|
531 |
||
532 |
stringWithCRs:s with:arg1 with:arg2 |
|
533 |
"translate, replace \'s with CRs and finally expand args. |
|
534 |
CR-replacement is donw before args are inserted |
|
535 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
536 |
||
537 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2) |
|
538 |
||
539 |
"Modified: / 21.3.2003 / 14:22:06 / cg" |
|
540 |
! |
|
541 |
||
542 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 |
|
543 |
"translate, replace \'s with CRs and finally expand args. |
|
544 |
CR-replacement is donw before args are inserted |
|
545 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
546 |
||
547 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3) |
|
548 |
||
549 |
"Created: 9.12.1995 / 19:08:50 / cg" |
|
550 |
! |
|
551 |
||
552 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 |
|
553 |
"translate, replace \'s with CRs and finally expand args. |
|
554 |
CR-replacement is donw before args are inserted |
|
555 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
556 |
||
557 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
558 |
||
559 |
"Modified: / 21.3.2003 / 14:21:48 / cg" |
|
560 |
! |
|
561 |
||
562 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
563 |
"translate, replace \'s with CRs and finally expand args. |
|
564 |
CR-replacement is donw before args are inserted |
|
565 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
566 |
||
567 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
568 |
||
569 |
"Modified: / 21.3.2003 / 14:21:55 / cg" |
|
570 |
! |
|
571 |
||
572 |
stringWithCRs:s withArgs:argArray |
|
573 |
"translate, replace \'s with CRs and finally expand args. |
|
574 |
CR-replacement is donw before args are inserted |
|
575 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
576 |
||
577 |
|template| |
|
578 |
||
579 |
template := self at:s ifAbsent:s. |
|
580 |
^ template withCRs expandPlaceholdersWith:argArray |
|
581 |
||
582 |
"Modified: / 21.3.2003 / 14:21:59 / cg" |
|
0 | 583 |
! ! |
584 |
||
3317 | 585 |
!ResourcePack methodsFor:'accessing-internals'! |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
586 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
587 |
name:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
588 |
"translate a string" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
589 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
590 |
^ self at:aKey ifAbsent:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
591 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
592 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
593 |
packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
594 |
^ packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
595 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
596 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
597 |
packsClassName:aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
598 |
packsClassName := aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
599 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
600 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
601 |
superPack:anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
602 |
superPack := anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
603 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
604 |
"Created: / 29.1.1998 / 22:43:09 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
605 |
! ! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
606 |
|
0 | 607 |
!ResourcePack methodsFor:'file reading'! |
608 |
||
684 | 609 |
fileReadFailed |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
610 |
"return true, if the pack does not really contain |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
611 |
valid translations, since the fileRead failed. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
612 |
However, all inherited translations are still available |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
613 |
through the receiver" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
614 |
|
687 | 615 |
^ fileReadFailed ~~ false |
684 | 616 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
617 |
"Created: / 14.5.1996 / 10:19:26 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
618 |
"Modified: / 29.1.1998 / 22:46:38 / cg" |
684 | 619 |
! |
620 |
||
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
621 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
622 |
"asked to read definitions for a non-existing file. |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
623 |
Here, this is legal and ignored (typically using inherited resources). |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
624 |
However, subclasses (such as styleSheet) may flag it as an error." |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
625 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
626 |
^ nil |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
627 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
628 |
"Created: 6.9.1997 / 11:38:53 / cg" |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
629 |
! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
630 |
|
4017 | 631 |
processLine:aLine encoding:encodingSymbolOrEncoder file:fileName |
145 | 632 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
633 |
||
2314 | 634 |
|lineString name stream l rest macroName value |
4017 | 635 |
conditional hasError decoder| |
144 | 636 |
|
145 | 637 |
lineString := aLine withoutSeparators. |
144 | 638 |
name := nil. |
639 |
(lineString at:1) == $' ifTrue:[ |
|
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
640 |
stream := ReadStream on:lineString. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
641 |
stream signalAtEnd:false. |
3986 | 642 |
|
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
643 |
name := String |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
644 |
readFrom:stream |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
645 |
onError:[('ResourcePack [warning]: invalid line <' |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
646 |
,lineString |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
647 |
,'> in file:' |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
648 |
, fileName |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
649 |
) errorPrintCR. nil]. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
650 |
l := stream position1Based + 1. |
144 | 651 |
] ifFalse:[ |
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
652 |
l := lineString indexOfSeparatorStartingAt:1. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
653 |
l ~~ 0 ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
654 |
name := lineString copyFrom:1 to:l-1. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
655 |
] |
144 | 656 |
]. |
657 |
name notNil ifTrue:[ |
|
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
658 |
hasError := false. |
2153 | 659 |
|
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
660 |
rest := (lineString copyFrom:l) withoutSeparators. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
661 |
" |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
662 |
skip <type> if present |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
663 |
" |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
664 |
(rest startsWith:$<) ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
665 |
l := lineString indexOf:$> startingAt:l. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
666 |
rest := (lineString copyFrom:l+1) withoutSeparators. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
667 |
]. |
2153 | 668 |
|
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
669 |
conditional := false. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
670 |
(rest startsWith:$?) ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
671 |
rest := (rest copyFrom:2) withoutSeparators. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
672 |
conditional := true. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
673 |
]. |
2153 | 674 |
|
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
675 |
(rest startsWith:$=) ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
676 |
rest := rest copyFrom:2. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
677 |
stream := ReadStream on:rest. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
678 |
macroName := stream nextAlphaNumericWord. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
679 |
[stream peek == $.] whileTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
680 |
stream next. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
681 |
stream peek notNil ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
682 |
macroName := macroName , '.' , (stream nextAlphaNumericWord) |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
683 |
] |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
684 |
]. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
685 |
rest := stream upToEnd. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
686 |
value := self at:macroName ifAbsent:nil. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
687 |
(value isNil) ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
688 |
hasError := true. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
689 |
('ResourcePack [warning]: bad (nil-valued) macro: ' , macroName) errorPrintCR. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
690 |
('ResourcePack [warning]: in line: ' , lineString) errorPrintCR. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
691 |
('ResourcePack [warning]: in file: ' , fileName) errorPrintCR. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
692 |
]. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
693 |
value isBlock ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
694 |
value := value value |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
695 |
]. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
696 |
value := Compiler evaluate:('self ' , rest) |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
697 |
receiver:value |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
698 |
notifying:nil |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
699 |
compile:false. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
700 |
(value == #Error) ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
701 |
hasError := true. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
702 |
('ResourcePack [warning]: error in line: "self ' , rest , '"') errorPrintCR. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
703 |
('ResourcePack [warning]: in file: ' , fileName) errorPrintCR. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
704 |
] |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
705 |
] ifFalse:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
706 |
value := Compiler evaluate:rest compile:false. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
707 |
(value == #Error) ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
708 |
hasError := true. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
709 |
('ResourcePack [warning]: error in line: "' , rest , '"') errorPrintCR. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
710 |
('ResourcePack [warning]: in file: ' , fileName) errorPrintCR. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
711 |
] ifFalse:[ |
4017 | 712 |
value isString ifTrue:[ |
713 |
encodingSymbolOrEncoder notNil ifTrue:[ |
|
714 |
encodingSymbolOrEncoder isSymbol ifTrue:[ |
|
4019 | 715 |
decoder := CharacterEncoder encoderFor:encodingSymbolOrEncoder ifAbsent:nil. |
4017 | 716 |
decoder isNil ifTrue:[ decoder := CharacterEncoder::NullEncoder ]. |
717 |
] ifFalse:[ |
|
718 |
decoder := encodingSymbolOrEncoder |
|
719 |
]. |
|
720 |
value := decoder decodeString:value |
|
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
721 |
] |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
722 |
] |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
723 |
] |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
724 |
]. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
725 |
hasError ifFalse:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
726 |
(conditional not |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
727 |
or:[(self includesKey:name) not]) ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
728 |
self at:name put:value. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
729 |
] |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
730 |
] |
144 | 731 |
] |
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
732 |
|
2291
eaac1c5f2a61
show fileName if a line has error.
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
733 |
"Created: / 30.8.1998 / 12:35:37 / cg" |
2608 | 734 |
"Modified: / 28.4.1999 / 22:23:14 / cg" |
144 | 735 |
! |
736 |
||
244 | 737 |
readFromFile:fileName directory:dirName |
738 |
"read definitions from a file in a directory" |
|
739 |
||
740 |
|inStream ok| |
|
741 |
||
686 | 742 |
fileReadFailed := false. |
244 | 743 |
dirName = 'resources' ifTrue:[ |
3769 | 744 |
inStream := Smalltalk resourceFileStreamFor:fileName |
244 | 745 |
] ifFalse:[ |
3769 | 746 |
inStream := Smalltalk |
747 |
systemFileStreamFor:(dirName |
|
748 |
isNil ifTrue:[fileName] |
|
749 |
ifFalse:[dirName asFilename construct:fileName]). |
|
244 | 750 |
]. |
751 |
inStream isNil ifTrue:[ |
|
3769 | 752 |
" |
753 |
an empty pack |
|
754 |
" |
|
755 |
^ self nonexistingFileRead |
|
244 | 756 |
]. |
2996 | 757 |
|
244 | 758 |
ok := self readFromResourceStream:inStream in:dirName. |
759 |
inStream close. |
|
686 | 760 |
|
244 | 761 |
ok ifFalse:[ |
3769 | 762 |
fileReadFailed := true. |
684 | 763 |
|
3769 | 764 |
('ResourcePack [warning]: ''' , inStream pathName , ''' contains error(s) - data may be incomplete.') errorPrintCR. |
244 | 765 |
]. |
766 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
767 |
"Modified: 10.1.1997 / 18:05:17 / cg" |
244 | 768 |
! |
769 |
||
72 | 770 |
readFromResourceStream:inStream in:dirName |
145 | 771 |
"read definitions from a stream. THe dirName argument is required to |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
772 |
specify where #include files are searched for. |
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
773 |
Return true, if the style sheet could be read without errors, false otherwise." |
145 | 774 |
|
4017 | 775 |
|lineString l lNo rest value ifLevel skipping first ok encoding decoder pack errorHandler| |
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
776 |
|
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
777 |
encoding := nil. |
0 | 778 |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
779 |
ok := true. |
0 | 780 |
ifLevel := 0. |
781 |
skipping := false. |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
782 |
lNo := 0. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
783 |
|
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
784 |
errorHandler := [:ex | |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
785 |
|con| |
4019 | 786 |
|
3854 | 787 |
('ResourcePack [warning]: ''' , ex description , '''') errorPrintCR. |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
788 |
('ResourcePack [info]: file: ' , inStream pathName printString , ' line: ' , lNo printString , ': ''' , lineString , '''') errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
789 |
con := ex suspendedContext. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
790 |
('ResourcePack [info]: in: ' , con fullPrintString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
791 |
con := con sender. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
792 |
('ResourcePack [info]: : ' , con fullPrintString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
793 |
con := con sender. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
794 |
('ResourcePack [info]: : ' , con fullPrintString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
795 |
value := nil. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
796 |
ok := false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
797 |
]. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
798 |
|
0 | 799 |
[inStream atEnd] whileFalse:[ |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
800 |
lineString := inStream nextLine. lNo := lNo + 1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
801 |
[lineString notNil and:[lineString endsWith:$\]] whileTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
802 |
lineString := lineString copyWithoutLast:1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
803 |
l := inStream nextLine. lNo := lNo + 1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
804 |
l notNil ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
805 |
lineString := lineString , l. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
806 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
807 |
]. |
177 | 808 |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
809 |
(lineString size > 0) ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
810 |
first := lineString at:1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
811 |
"/ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
812 |
"/ for your convenience: treat ; AND "/ as comment-line |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
813 |
"/ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
814 |
((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
815 |
first == $# ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
816 |
"/ a directive |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
817 |
lineString := (lineString copyFrom:2) withoutSpaces. |
72 | 818 |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
819 |
(lineString startsWith:'if') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
820 |
skipping ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
821 |
rest := lineString copyFrom:3. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
822 |
Error |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
823 |
handle:errorHandler |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
824 |
do:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
825 |
value := Compiler evaluate:rest compile:false]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
826 |
(value == #Error) ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
827 |
('ResourcePack [warning]: error in resource:' , lineString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
828 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
829 |
(value == false) ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
830 |
skipping := true |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
831 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
832 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
833 |
ifLevel := ifLevel + 1 |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
834 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
835 |
(lineString startsWith:'endif') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
836 |
ifLevel := ifLevel - 1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
837 |
ifLevel == 0 ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
838 |
skipping := false |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
839 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
840 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
841 |
(lineString startsWith:'else') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
842 |
skipping := skipping not |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
843 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
844 |
skipping ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
845 |
(lineString startsWith:'include') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
846 |
(lineString startsWith:'includeResourcesFor') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
847 |
"/ include those resources ... |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
848 |
rest := lineString copyFrom:('includeResourcesFor' size + 1). |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
849 |
value := Compiler evaluate:rest compile:false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
850 |
value isBehavior ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
851 |
pack := self class for:value. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
852 |
pack notNil ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
853 |
self declareAllFrom:pack. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
854 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
855 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
856 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
857 |
rest := lineString copyFrom:('include' size + 1). |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
858 |
value := Compiler evaluate:rest compile:false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
859 |
value isString ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
860 |
('ResourcePack [warning]: bad include filename: ' , value printString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
861 |
('ResourcePack [info]: line ' , lNo printString , ': ''' , lineString , '''') infoPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
862 |
] ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
863 |
self readFromFile:value directory:dirName |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
864 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
865 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
866 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
867 |
(lineString startsWith:'encoding') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
868 |
rest := lineString copyFrom:9. |
3983 | 869 |
rest := rest withoutSeparators. |
870 |
(rest startsWith:'#') ifTrue:[ |
|
871 |
rest := rest copyFrom:2. |
|
872 |
]. |
|
873 |
(rest startsWith:'''') ifTrue:[ |
|
874 |
rest := rest copyFrom:2. |
|
875 |
(rest endsWith:'''') ifTrue:[ |
|
876 |
rest := rest copyWithoutLast:1. |
|
877 |
]. |
|
878 |
]. |
|
879 |
encoding := rest asSymbol. |
|
4019 | 880 |
decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil. |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
881 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
882 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
883 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
884 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
885 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
886 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
887 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
888 |
skipping ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
889 |
Error |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
890 |
handle:errorHandler |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
891 |
do:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
892 |
(lineString at:1) == $!! ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
893 |
"/ evaluate the rest |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
894 |
Compiler evaluate:(lineString copyFrom:2) |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
895 |
receiver:nil |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
896 |
notifying:nil |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
897 |
compile:false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
898 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
899 |
"/ process as resource |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
900 |
self |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
901 |
processLine:lineString |
4017 | 902 |
encoding:decoder |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
903 |
file:(inStream isFileStream |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
904 |
ifTrue:[inStream pathName] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
905 |
ifFalse:['---']) |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
906 |
]] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
907 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
908 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
909 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
910 |
] |
0 | 911 |
]. |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
912 |
^ ok |
177 | 913 |
|
2291
eaac1c5f2a61
show fileName if a line has error.
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
914 |
"Modified: / 31.8.1995 / 02:33:45 / claus" |
eaac1c5f2a61
show fileName if a line has error.
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
915 |
"Modified: / 30.8.1998 / 12:35:24 / cg" |
0 | 916 |
! ! |
917 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
918 |
!ResourcePack class methodsFor:'documentation'! |
251 | 919 |
|
920 |
version |
|
4028 | 921 |
^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.86 2004-02-20 18:47:41 cg Exp $' |
251 | 922 |
! ! |
3769 | 923 |
|
0 | 924 |
ResourcePack initialize! |