author | Claus Gittinger <cg@exept.de> |
Wed, 13 Sep 2006 19:08:13 +0200 | |
changeset 4580 | 48c0580f3b9c |
parent 4534 | d71ca6ac7cbe |
child 4611 | 1be2168a79a0 |
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 |
4085 | 16 |
instanceVariableNames:'packsClassName fileReadFailed superPack projectPack' |
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 |
||
4093 | 183 |
" |
184 |
ResourcePack flushCachedResourcePacks |
|
185 |
" |
|
244 | 186 |
! |
187 |
||
188 |
initialize |
|
189 |
Packs isNil ifTrue:[ |
|
4094 | 190 |
Packs := WeakArray new:60 |
244 | 191 |
]. |
192 |
||
4093 | 193 |
" |
194 |
ResourcePack initialize |
|
195 |
" |
|
244 | 196 |
! ! |
197 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
198 |
!ResourcePack class methodsFor:'instance creation'! |
244 | 199 |
|
200 |
for:aClass |
|
201 |
"get the full resource definitions for aClass (i.e. with super packs). |
|
202 |
Also leave the resulting pack in the cache for faster access next time." |
|
203 |
||
4030 | 204 |
^ self for:aClass cached:true |
205 |
||
206 |
" |
|
207 |
ResourcePack for:TextView |
|
208 |
ResourcePack for:CodeView |
|
209 |
ResourcePack for:Workspace |
|
210 |
ResourcePack for:View |
|
211 |
ResourcePack for:ErrorLogger |
|
212 |
ResourcePack for:NewLauncher |
|
213 |
Workspace classResources |
|
214 |
" |
|
215 |
! |
|
216 |
||
217 |
for:aClass cached:cached |
|
218 |
"get the full resource definitions for aClass (i.e. with super packs). |
|
219 |
Also leave the resulting pack in the cache for faster access next time." |
|
220 |
||
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
221 |
|nm pack rsrcDir baseName| |
244 | 222 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
223 |
nm := aClass resourcePackName. |
4030 | 224 |
cached ifTrue:[ |
225 |
pack := self searchCacheFor:nm. |
|
226 |
pack notNil ifTrue:[^ pack]. |
|
227 |
]. |
|
244 | 228 |
|
3049
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
229 |
baseName := (Smalltalk fileNameForClass:nm) , '.rs'. |
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
230 |
rsrcDir := aClass resourceDirectory. |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
231 |
|
4148 | 232 |
"/ CHECK this |
233 |
"/ (rsrcDir notNil and:[rsrcDir suffix = 'rs']) ifTrue:[ |
|
234 |
"/ baseName := (Smalltalk fileNameForClass: rsrcDir tail asFilename withoutSuffix pathName),'.rs'. |
|
235 |
"/ rsrcDir := rsrcDir head asFilename. |
|
236 |
"/ ]. |
|
237 |
||
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
238 |
(rsrcDir notNil |
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
239 |
and:[rsrcDir exists |
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
240 |
and:[(rsrcDir construct:baseName) exists]]) ifTrue:[ |
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
241 |
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
|
242 |
] ifFalse:[ |
3808 | 243 |
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
|
244 |
]. |
244 | 245 |
aClass == Object ifFalse:[ |
3808 | 246 |
pack superPack:(self for:(aClass superclass)). |
244 | 247 |
]. |
4093 | 248 |
pack packsClassOrFileName:nm. |
4030 | 249 |
cached ifTrue:[ |
250 |
self addToCache:pack. |
|
251 |
]. |
|
244 | 252 |
^ pack |
253 |
||
254 |
" |
|
3046 | 255 |
ResourcePack for:TextView |
244 | 256 |
ResourcePack for:CodeView |
3046 | 257 |
ResourcePack for:Workspace |
3049
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
258 |
ResourcePack for:View |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
259 |
ResourcePack for:ErrorLogger |
3101
38cc69894380
fix to avoid loosing the directory with #includes
Claus Gittinger <cg@exept.de>
parents:
3097
diff
changeset
|
260 |
ResourcePack for:NewLauncher |
244 | 261 |
Workspace classResources |
262 |
" |
|
263 |
! |
|
264 |
||
4078 | 265 |
forPackage:package |
266 |
"get the full resource definitions given a package id (such as stx:libbasic'). |
|
267 |
Also leave the resulting pack in the cache for faster access next time." |
|
268 |
||
269 |
^ self forPackage:package cached:true |
|
270 |
||
271 |
" |
|
272 |
ResourcePack forPackage:'stx:libbasic' |
|
273 |
" |
|
274 |
! |
|
275 |
||
276 |
forPackage:package cached:cached |
|
277 |
"get the full resource definitions given a package id (such as stx:libbasic'). |
|
278 |
Also optionally leave the resulting pack in the cache for faster access next time." |
|
279 |
||
4428 | 280 |
|fullName pack rsrcDir file| |
4078 | 281 |
|
282 |
fullName := package , '/resources/resources.rs'. |
|
283 |
||
284 |
cached ifTrue:[ |
|
285 |
pack := self searchCacheFor:fullName. |
|
286 |
pack notNil ifTrue:[^ pack]. |
|
287 |
]. |
|
288 |
||
289 |
rsrcDir := Smalltalk projectDirectoryForPackage:package. |
|
4428 | 290 |
rsrcDir isNil ifTrue:[ |
291 |
file := Smalltalk getResourceFileName:'resources.rs' forPackage:package. |
|
292 |
file isNil ifTrue:[^ nil]. |
|
293 |
rsrcDir := file asFilename directory. |
|
294 |
] ifFalse:[ |
|
295 |
rsrcDir := rsrcDir asFilename construct:'resources'. |
|
296 |
rsrcDir exists ifFalse:[^ nil]. |
|
297 |
]. |
|
4078 | 298 |
|
299 |
pack := self fromFile:'resources.rs' directory:rsrcDir. |
|
4093 | 300 |
pack packsClassOrFileName:fullName. |
4078 | 301 |
cached ifTrue:[ |
302 |
self addToCache:pack. |
|
303 |
]. |
|
304 |
^ pack |
|
305 |
||
306 |
" |
|
307 |
ResourcePack forPackage:'stx:libbasic' cached:false |
|
308 |
" |
|
309 |
! |
|
310 |
||
244 | 311 |
fromFile:aFileName |
312 |
"get the resource definitions from a file in the default directory. |
|
313 |
Uncached low-level entry." |
|
314 |
||
315 |
^ self fromFile:aFileName directory:'resources' |
|
316 |
||
317 |
" |
|
318 |
ResourcePack fromFile:'SBrowser.rs' |
|
319 |
ResourcePack fromFile:'FBrowser.rs' |
|
320 |
ResourcePack fromFile:'Smalltalk.rs' |
|
3678 | 321 |
ResourcePack fromFile:'Smalltalk.rs' asFilename |
3983 | 322 |
ResourcePack fromFile:'../../libtool/resources/AboutBox_ru.rs' asFilename |
244 | 323 |
" |
324 |
! |
|
325 |
||
326 |
fromFile:aFileName directory:dirName |
|
327 |
"get the resource definitions from a file in a directory. |
|
328 |
Uncached low-level entry." |
|
329 |
||
330 |
|newPack| |
|
331 |
||
332 |
newPack := self new. |
|
333 |
newPack readFromFile:aFileName directory:dirName. |
|
334 |
^ newPack |
|
0 | 335 |
! ! |
336 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
337 |
!ResourcePack class methodsFor:'private'! |
54 | 338 |
|
339 |
addToCache:aPack |
|
340 |
|idx| |
|
0 | 341 |
|
4084 | 342 |
Packs isNil ifTrue:[ |
343 |
self initialize. |
|
344 |
]. |
|
345 |
||
54 | 346 |
idx := Packs identityIndexOf:nil. |
347 |
idx == 0 ifTrue:[ |
|
4084 | 348 |
idx := Packs identityIndexOf:0 |
1078
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
349 |
]. |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
350 |
idx == 0 ifTrue:[ |
4084 | 351 |
" |
352 |
throw away oldest |
|
353 |
" |
|
354 |
idx := Packs size. |
|
355 |
Packs replaceFrom:1 to:idx-1 with:Packs startingAt:2. |
|
54 | 356 |
]. |
357 |
Packs at:idx put:aPack |
|
358 |
! |
|
0 | 359 |
|
4093 | 360 |
searchCacheFor:aClassOrFileName |
998 | 361 |
|sz "{ Class: SmallInteger }" | |
0 | 362 |
|
24 | 363 |
Packs isNil ifTrue:[ |
4093 | 364 |
self initialize. |
365 |
^ nil |
|
0 | 366 |
]. |
54 | 367 |
|
368 |
sz := Packs size. |
|
369 |
1 to:sz do:[:idx | |
|
4093 | 370 |
|aPack| |
54 | 371 |
|
4093 | 372 |
aPack := Packs at:idx. |
373 |
(aPack notNil and:[aPack ~~ 0]) ifTrue:[ |
|
374 |
aClassOrFileName = aPack packsClassOrFileName ifTrue:[ |
|
375 |
" |
|
376 |
bring to front for LRU |
|
377 |
" |
|
378 |
idx ~~ 1 ifTrue:[ |
|
379 |
Packs replaceFrom:2 to:idx with:Packs startingAt:1. |
|
380 |
Packs at:1 put:aPack. |
|
381 |
]. |
|
382 |
^ aPack |
|
383 |
] |
|
384 |
] |
|
0 | 385 |
]. |
54 | 386 |
^ nil |
123 | 387 |
|
388 |
" |
|
389 |
ResourcePack searchCacheFor:'TextView' |
|
390 |
" |
|
54 | 391 |
! ! |
392 |
||
4509 | 393 |
!ResourcePack class methodsFor:'utilities'! |
394 |
||
395 |
extractEncodingFromLine:lineString |
|
396 |
|rest encoding| |
|
397 |
||
398 |
(lineString startsWith:'encoding') ifFalse:[^ nil]. |
|
399 |
||
400 |
rest := lineString copyFrom:9. |
|
401 |
rest := rest withoutSeparators. |
|
402 |
(rest startsWith:'#') ifTrue:[ |
|
403 |
rest := rest copyFrom:2. |
|
404 |
]. |
|
405 |
(rest startsWith:'''') ifTrue:[ |
|
406 |
rest := rest copyFrom:2. |
|
407 |
(rest endsWith:'''') ifTrue:[ |
|
408 |
rest := rest copyWithoutLast:1. |
|
409 |
]. |
|
410 |
]. |
|
411 |
encoding := rest asSymbol. |
|
412 |
^ encoding. |
|
413 |
! |
|
414 |
||
415 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack |
|
416 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
|
417 |
||
4510 | 418 |
self |
419 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack |
|
420 |
keepUselessTranslations:false. |
|
421 |
! |
|
422 |
||
423 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack keepUselessTranslations:keepUselessTranslations |
|
424 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
|
425 |
||
4531 | 426 |
|name decodedLine lineStream idx rest macroName value |
4510 | 427 |
conditional hasError decoder oldValue ignoreTranslation| |
4509 | 428 |
|
4531 | 429 |
encodingSymbolOrEncoder notNil ifTrue:[ |
430 |
encodingSymbolOrEncoder isSymbol ifTrue:[ |
|
431 |
decoder := CharacterEncoder encoderFor:encodingSymbolOrEncoder ifAbsent:nil. |
|
432 |
decoder isNil ifTrue:[ decoder := CharacterEncoder::NullEncoder ]. |
|
433 |
] ifFalse:[ |
|
434 |
decoder := encodingSymbolOrEncoder |
|
435 |
]. |
|
436 |
]. |
|
437 |
||
438 |
decoder notNil ifTrue:[ |
|
439 |
decodedLine := decoder decodeString:lineString. |
|
440 |
lineStream := ReadStream on:decodedLine. |
|
441 |
] ifFalse:[ |
|
442 |
lineStream := ReadStream on:lineString. |
|
443 |
]. |
|
4509 | 444 |
lineStream signalAtEnd:false. |
445 |
lineStream skipSeparators. |
|
446 |
lineStream peek == $# ifTrue:[ |
|
447 |
name := Array |
|
448 |
readFrom:lineStream |
|
449 |
onError:[ |
|
450 |
printError value:('invalid line <' , lineString , '>'). |
|
451 |
nil |
|
452 |
]. |
|
453 |
] ifFalse:[ |
|
454 |
lineStream peek == $' ifTrue:[ |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
455 |
name := UnicodeString |
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
456 |
readSmalltalkStringFrom:lineStream |
4509 | 457 |
onError:[ |
458 |
printError value:('invalid line <' , lineString , '>'). |
|
459 |
nil |
|
460 |
]. |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
461 |
name := name asSingleByteStringIfPossible. |
4509 | 462 |
] ifFalse:[ |
463 |
name := lineStream upToSeparator. |
|
464 |
]. |
|
465 |
]. |
|
466 |
||
4510 | 467 |
name isNil ifTrue:[^ self ]. |
468 |
||
469 |
ignoreTranslation := false. |
|
470 |
||
471 |
hasError := false. |
|
4509 | 472 |
|
4510 | 473 |
lineStream skipSeparators. |
474 |
idx := lineStream position1Based + 1. |
|
475 |
||
476 |
lineStream peek == $< ifTrue:[ |
|
477 |
" |
|
478 |
skip <type> if present |
|
479 |
" |
|
480 |
lineStream skipThrough:$>. |
|
4509 | 481 |
lineStream skipSeparators. |
482 |
idx := lineStream position1Based + 1. |
|
4510 | 483 |
]. |
4509 | 484 |
|
4510 | 485 |
conditional := false. |
486 |
lineStream peek == $? ifTrue:[ |
|
487 |
lineStream next. |
|
488 |
lineStream skipSeparators. |
|
489 |
conditional := true. |
|
490 |
]. |
|
4509 | 491 |
|
4510 | 492 |
lineStream peek == $= ifTrue:[ |
493 |
lineStream next. |
|
494 |
||
495 |
macroName := lineStream nextAlphaNumericWord. |
|
496 |
[lineStream peek == $.] whileTrue:[ |
|
4509 | 497 |
lineStream next. |
4510 | 498 |
lineStream peek notNil ifTrue:[ |
499 |
macroName := macroName , '.' , (lineStream nextAlphaNumericWord) |
|
500 |
] |
|
501 |
]. |
|
502 |
rest := lineStream upToEnd. |
|
503 |
value := aResourcePack at:macroName ifAbsent:nil. |
|
504 |
(value isNil) ifTrue:[ |
|
505 |
hasError := true. |
|
506 |
printError value:('bad (nil-valued) macro: ' , macroName). |
|
507 |
]. |
|
508 |
value isBlock ifTrue:[ |
|
509 |
value := value value |
|
4509 | 510 |
]. |
4510 | 511 |
value := Compiler evaluate:('self ' , rest) |
512 |
receiver:value |
|
513 |
notifying:nil |
|
514 |
compile:false. |
|
515 |
(value == #Error) ifTrue:[ |
|
516 |
hasError := true. |
|
517 |
printError value:('error in: "self ' , rest , '"'). |
|
518 |
] |
|
519 |
] ifFalse:[ |
|
520 |
lineStream peek == $' ifTrue:[ |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
521 |
value := UnicodeString |
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
522 |
readSmalltalkStringFrom:lineStream |
4510 | 523 |
onError:[ |
524 |
printError value:('invalid line <' , lineString , '>'). |
|
525 |
nil |
|
526 |
]. |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
527 |
value := value asSingleByteStringIfPossible. |
4510 | 528 |
] ifFalse:[ |
4509 | 529 |
rest := lineStream upToEnd. |
4510 | 530 |
value := Compiler evaluate:rest compile:false. |
531 |
]. |
|
532 |
(value == #Error) ifTrue:[ |
|
533 |
hasError := true. |
|
534 |
printError value:('error in: "' , rest , '"'). |
|
4509 | 535 |
] ifFalse:[ |
4531 | 536 |
"/ value isString ifTrue:[ |
537 |
"/ decoder notNil ifTrue:[ |
|
538 |
"/ value := decoder decodeString:value |
|
539 |
"/ ] |
|
540 |
"/ ] |
|
4510 | 541 |
] |
542 |
]. |
|
543 |
||
544 |
hasError ifFalse:[ |
|
545 |
(conditional not |
|
546 |
or:[(aResourcePack includesKey:name) not]) ifTrue:[ |
|
547 |
name = value ifTrue:[ |
|
548 |
keepUselessTranslations ifFalse:[ |
|
4509 | 549 |
printError value:('useless resource: "' , name , '"'). |
4510 | 550 |
ignoreTranslation := true |
551 |
]. |
|
552 |
]. |
|
553 |
ignoreTranslation ifFalse:[ |
|
554 |
oldValue := aResourcePack at:name ifAbsent:nil. |
|
555 |
oldValue notNil ifTrue:[ |
|
556 |
oldValue ~= value ifTrue:[ |
|
557 |
printError value:('conflicting resource: "' , name , '"'). |
|
558 |
printError value:('oldValue: ' , oldValue printString). |
|
559 |
printError value:('newValue: ' , value printString). |
|
560 |
] ifFalse:[ |
|
561 |
printError value:('duplicate resource: "' , name , '"'). |
|
4509 | 562 |
]. |
4510 | 563 |
]. |
564 |
aResourcePack at:name put:value. |
|
4509 | 565 |
] |
566 |
] |
|
567 |
] |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
568 |
|
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
569 |
"Modified: / 05-07-2006 / 17:25:07 / cg" |
4509 | 570 |
! ! |
571 |
||
0 | 572 |
!ResourcePack methodsFor:'accessing'! |
573 |
||
244 | 574 |
array:anArray |
575 |
"translate a collection of strings" |
|
0 | 576 |
|
244 | 577 |
^ anArray collect:[:r | self at:r default:r] |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
578 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
579 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
580 |
Launcher classResources array:#('file' 'classes') |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
581 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
582 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
583 |
"Modified: / 29.1.1998 / 22:44:22 / cg" |
0 | 584 |
! |
585 |
||
2 | 586 |
at:aKey |
123 | 587 |
"translate a string" |
588 |
||
72 | 589 |
^ self at:aKey ifAbsent:aKey |
0 | 590 |
! |
591 |
||
592 |
at:aKey default:default |
|
123 | 593 |
"translate a string" |
594 |
||
72 | 595 |
^ self at:aKey ifAbsent:default |
0 | 596 |
! |
597 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
598 |
at:aKey ifAbsent:defaultValue |
4035 | 599 |
"translate a string. |
600 |
Some special 'intelligence' has been added: |
|
601 |
if no value for aKey is found, |
|
4036 | 602 |
lookup aKey with first character caseChanged and change the results first characters case. |
603 |
or aKey ends with a ':', then lookup aKey without ':' and append ':' to the result. |
|
604 |
or aKey ends with a '=', then lookup aKey without '=' and append '=' to the result. |
|
4037 | 605 |
or aKey ends with a '.', then lookup aKey without '.' and append '.' to the result. |
4036 | 606 |
or aKey ends with a ' ', then lookup aKey without ' '. |
607 |
or aKey ends with a ' ...', then lookup aKey without ' ...' and append '...' to the result. |
|
608 |
or aKey ends with a '...', then lookup aKey without '...' and append '...' to the result. |
|
609 |
or aKey includes '&', then lookup aKey without '&'. |
|
4035 | 610 |
|
611 |
This means, that only a single translation is required to provide local translations for |
|
612 |
things like |
|
613 |
'search' |
|
614 |
'search:' |
|
615 |
'search...' |
|
616 |
" |
|
123 | 617 |
|
4017 | 618 |
|val alternativeKey rest usedKey idx| |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
619 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
620 |
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
|
621 |
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
|
622 |
val notNil ifTrue:[^ val]. |
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
623 |
|
4028 | 624 |
(aKey isString and:[aKey size > 0]) ifTrue:[ |
625 |
"/ try with case-first swapped... |
|
626 |
(aKey first isLetter) ifTrue:[ |
|
4506 | 627 |
alternativeKey := aKey isUppercaseFirst |
4028 | 628 |
ifTrue:[aKey asLowercaseFirst] |
629 |
ifFalse:[aKey asUppercaseFirst]. |
|
630 |
val := super at:alternativeKey ifAbsent:nil. |
|
631 |
val notNil ifTrue:[ |
|
4506 | 632 |
aKey isUppercaseFirst ifTrue:[ |
4028 | 633 |
^ val asUppercaseFirst |
4017 | 634 |
]. |
4028 | 635 |
^ val asLowercaseFirst. |
3979
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
636 |
]. |
4028 | 637 |
]. |
638 |
||
4580 | 639 |
(':=.?!!' includes:aKey last) ifTrue:[ |
4028 | 640 |
rest := aKey last. |
641 |
usedKey := aKey copyWithoutLast:1. |
|
642 |
||
643 |
val := self at:usedKey ifAbsent:nil. "/ recursion |
|
644 |
val notNil ifTrue:[^ val , rest]. |
|
645 |
]. |
|
4017 | 646 |
|
4465 | 647 |
((aKey startsWith:'(') and:[(aKey endsWith:')')]) ifTrue:[ |
648 |
usedKey := aKey copyFrom:2 to:(aKey size - 1). |
|
649 |
||
650 |
val := self at:usedKey ifAbsent:nil. "/ recursion |
|
651 |
val notNil ifTrue:[^ '(' , val , ')']. |
|
652 |
]. |
|
4028 | 653 |
(aKey endsWith:' ') ifTrue:[ |
654 |
usedKey := aKey withoutSeparators. |
|
4017 | 655 |
|
4028 | 656 |
val := self at:usedKey ifAbsent:nil. "/ recursion |
657 |
val notNil ifTrue:[^ val]. |
|
658 |
]. |
|
659 |
(aKey endsWith:' ...') ifTrue:[ |
|
660 |
usedKey := aKey copyWithoutLast:4. |
|
4017 | 661 |
|
4028 | 662 |
val := self at:usedKey ifAbsent:nil. "/ recursion |
663 |
val notNil ifTrue:[^ val , '...']. |
|
664 |
]. |
|
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
665 |
|
4028 | 666 |
(aKey endsWith:'...') ifTrue:[ |
667 |
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
|
668 |
|
4028 | 669 |
val := self at:usedKey ifAbsent:nil. "/ recursion |
670 |
val notNil ifTrue:[^ val , '...']. |
|
671 |
]. |
|
672 |
||
673 |
(idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
|
674 |
(aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
|
675 |
usedKey := (aKey copyTo:idx-1) , (aKey copyFrom:idx+1). |
|
676 |
val := self at:usedKey ifAbsent:nil. "/ recursion |
|
677 |
val notNil ifTrue:[^ val]. |
|
4017 | 678 |
]. |
679 |
]. |
|
3979
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
680 |
]. |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
681 |
|
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
682 |
superPack notNil ifTrue:[ |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
683 |
^ 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
|
684 |
]. |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
685 |
]. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
686 |
^ defaultValue value |
4580 | 687 |
|
688 |
"Modified: / 13-09-2006 / 19:08:11 / cg" |
|
2 | 689 |
! |
690 |
||
691 |
name:aKey default:default |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
692 |
"translate a string. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
693 |
Obsolete - use #string:default:" |
123 | 694 |
|
72 | 695 |
^ self at:aKey ifAbsent:default |
2 | 696 |
! |
697 |
||
0 | 698 |
string:s |
3097 | 699 |
"translate (retrieve) a string - if not present, return s" |
123 | 700 |
|
72 | 701 |
^ self at:s ifAbsent:s |
3097 | 702 |
|
703 |
" |
|
704 |
NewLauncher classResources |
|
3762 | 705 |
string:'LICENCEFILE' |
3097 | 706 |
" |
0 | 707 |
! |
708 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
709 |
string:s default:defaultString |
3097 | 710 |
"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
|
711 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
712 |
^ self at:s ifAbsent:defaultString |
3097 | 713 |
|
714 |
" |
|
715 |
NewLauncher classResources |
|
3762 | 716 |
string:'fooBar' default:'Hello world' |
3097 | 717 |
" |
718 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
719 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
720 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
721 |
string:s default:defaultString with:arg |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
722 |
"translate and expand arg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
723 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
724 |
^ self string:s default:defaultString withArgs:(Array with:arg) |
3097 | 725 |
|
726 |
" |
|
727 |
NewLauncher classResources |
|
3762 | 728 |
string:'%1 fooBar' default:'Hello %1' with:'foo' |
3097 | 729 |
" |
730 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
731 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
732 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
733 |
string:s default:defaultString with:arg1 with:arg2 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
734 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
735 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
736 |
^ 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
|
737 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
738 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
739 |
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
|
740 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
741 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
742 |
^ 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
|
743 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
744 |
"Created: 9.12.1995 / 19:08:50 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
745 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
746 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
747 |
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
|
748 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
749 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
750 |
^ 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
|
751 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
752 |
"Created: 9.9.1996 / 18:52:14 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
753 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
754 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
755 |
string:s default:defaultString withArgs:argArray |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
756 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
757 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
758 |
|template| |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
759 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
760 |
template := self at:s ifAbsent:defaultString. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
761 |
^ template expandPlaceholdersWith:argArray |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
762 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
763 |
|
0 | 764 |
string:s with:arg |
123 | 765 |
"translate and expand arg" |
766 |
||
0 | 767 |
^ self string:s withArgs:(Array with:arg) |
768 |
! |
|
769 |
||
770 |
string:s with:arg1 with:arg2 |
|
123 | 771 |
"translate and expand args" |
772 |
||
0 | 773 |
^ self string:s withArgs:(Array with:arg1 with:arg2) |
774 |
! |
|
775 |
||
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
776 |
string:s with:arg1 with:arg2 with:arg3 |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
777 |
"translate and expand args" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
778 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
779 |
^ 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
|
780 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
781 |
"Created: 9.12.1995 / 19:08:50 / cg" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
782 |
! |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
783 |
|
1042 | 784 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 |
785 |
"translate and expand args" |
|
786 |
||
787 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
788 |
||
789 |
"Created: 9.9.1996 / 18:52:14 / cg" |
|
790 |
! |
|
791 |
||
3184 | 792 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
793 |
"translate and expand args" |
|
794 |
||
795 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
796 |
||
797 |
! |
|
798 |
||
0 | 799 |
string:s withArgs:argArray |
123 | 800 |
"translate and expand args" |
801 |
||
135 | 802 |
|template| |
0 | 803 |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
804 |
template := self at:s ifAbsent:s. |
135 | 805 |
^ template expandPlaceholdersWith:argArray |
3823 | 806 |
! |
807 |
||
4402 | 808 |
stringWithCRs:s |
809 |
"translate (retrieve) a string - if not present, return s" |
|
810 |
||
811 |
^ (self string:s) withCRs |
|
812 |
||
813 |
" |
|
814 |
NewLauncher classResources |
|
815 |
stringWithCRs:'LICENCEFILE' |
|
816 |
" |
|
817 |
! |
|
818 |
||
3823 | 819 |
stringWithCRs:s with:arg |
820 |
"translate, replace \'s with CRs and finally expand arg. |
|
821 |
CR-replacement is donw before args are inserted |
|
822 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
823 |
||
824 |
^ self stringWithCRs:s withArgs:(Array with:arg) |
|
825 |
||
826 |
"Modified: / 21.3.2003 / 14:22:09 / cg" |
|
827 |
! |
|
828 |
||
829 |
stringWithCRs:s with:arg1 with:arg2 |
|
830 |
"translate, replace \'s with CRs and finally expand args. |
|
831 |
CR-replacement is donw before args are inserted |
|
832 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
833 |
||
834 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2) |
|
835 |
||
836 |
"Modified: / 21.3.2003 / 14:22:06 / cg" |
|
837 |
! |
|
838 |
||
839 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 |
|
840 |
"translate, replace \'s with CRs and finally expand args. |
|
841 |
CR-replacement is donw before args are inserted |
|
842 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
843 |
||
844 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3) |
|
845 |
||
846 |
"Created: 9.12.1995 / 19:08:50 / cg" |
|
847 |
! |
|
848 |
||
849 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 |
|
850 |
"translate, replace \'s with CRs and finally expand args. |
|
851 |
CR-replacement is donw before args are inserted |
|
852 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
853 |
||
854 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
855 |
||
856 |
"Modified: / 21.3.2003 / 14:21:48 / cg" |
|
857 |
! |
|
858 |
||
859 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
860 |
"translate, replace \'s with CRs and finally expand args. |
|
861 |
CR-replacement is donw before args are inserted |
|
862 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
863 |
||
864 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
865 |
||
866 |
"Modified: / 21.3.2003 / 14:21:55 / cg" |
|
867 |
! |
|
868 |
||
869 |
stringWithCRs:s withArgs:argArray |
|
870 |
"translate, replace \'s with CRs and finally expand args. |
|
871 |
CR-replacement is donw before args are inserted |
|
872 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
873 |
||
874 |
|template| |
|
875 |
||
876 |
template := self at:s ifAbsent:s. |
|
877 |
^ template withCRs expandPlaceholdersWith:argArray |
|
878 |
||
879 |
"Modified: / 21.3.2003 / 14:21:59 / cg" |
|
0 | 880 |
! ! |
881 |
||
3317 | 882 |
!ResourcePack methodsFor:'accessing-internals'! |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
883 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
884 |
name:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
885 |
"translate a string" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
886 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
887 |
^ self at:aKey ifAbsent:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
888 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
889 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
890 |
packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
891 |
^ packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
892 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
893 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
894 |
packsClassName:aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
895 |
packsClassName := aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
896 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
897 |
|
4093 | 898 |
packsClassOrFileName |
899 |
^ packsClassName |
|
900 |
! |
|
901 |
||
902 |
packsClassOrFileName:aString |
|
903 |
packsClassName := aString |
|
904 |
! |
|
905 |
||
4085 | 906 |
projectPack:anotherResourcePack |
907 |
projectPack := anotherResourcePack |
|
908 |
||
909 |
"Created: / 29.1.1998 / 22:43:09 / cg" |
|
910 |
! |
|
911 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
912 |
superPack:anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
913 |
superPack := anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
914 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
915 |
"Created: / 29.1.1998 / 22:43:09 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
916 |
! ! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
917 |
|
0 | 918 |
!ResourcePack methodsFor:'file reading'! |
919 |
||
684 | 920 |
fileReadFailed |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
921 |
"return true, if the pack does not really contain |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
922 |
valid translations, since the fileRead failed. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
923 |
However, all inherited translations are still available |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
924 |
through the receiver" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
925 |
|
687 | 926 |
^ fileReadFailed ~~ false |
684 | 927 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
928 |
"Created: / 14.5.1996 / 10:19:26 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
929 |
"Modified: / 29.1.1998 / 22:46:38 / cg" |
684 | 930 |
! |
931 |
||
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
932 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
933 |
"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
|
934 |
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
|
935 |
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
|
936 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
937 |
^ nil |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
938 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
939 |
"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
|
940 |
! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
941 |
|
4332 | 942 |
processLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError |
145 | 943 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
944 |
||
4509 | 945 |
self class |
946 |
processResourceLine:lineString |
|
947 |
encoding:encodingSymbolOrEncoder |
|
948 |
file:fileName |
|
949 |
printErrorWith:printError |
|
950 |
for:self |
|
144 | 951 |
! |
952 |
||
244 | 953 |
readFromFile:fileName directory:dirName |
954 |
"read definitions from a file in a directory" |
|
955 |
||
956 |
|inStream ok| |
|
957 |
||
686 | 958 |
fileReadFailed := false. |
244 | 959 |
dirName = 'resources' ifTrue:[ |
3769 | 960 |
inStream := Smalltalk resourceFileStreamFor:fileName |
244 | 961 |
] ifFalse:[ |
3769 | 962 |
inStream := Smalltalk |
963 |
systemFileStreamFor:(dirName |
|
964 |
isNil ifTrue:[fileName] |
|
965 |
ifFalse:[dirName asFilename construct:fileName]). |
|
244 | 966 |
]. |
967 |
inStream isNil ifTrue:[ |
|
3769 | 968 |
" |
969 |
an empty pack |
|
970 |
" |
|
971 |
^ self nonexistingFileRead |
|
244 | 972 |
]. |
2996 | 973 |
|
4093 | 974 |
ok := self readFromResourceStream:inStream in:(inStream pathName asFilename directoryName). |
244 | 975 |
inStream close. |
686 | 976 |
|
244 | 977 |
ok ifFalse:[ |
3769 | 978 |
fileReadFailed := true. |
684 | 979 |
|
3769 | 980 |
('ResourcePack [warning]: ''' , inStream pathName , ''' contains error(s) - data may be incomplete.') errorPrintCR. |
244 | 981 |
]. |
982 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
983 |
"Modified: 10.1.1997 / 18:05:17 / cg" |
244 | 984 |
! |
985 |
||
72 | 986 |
readFromResourceStream:inStream in:dirName |
145 | 987 |
"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
|
988 |
specify where #include files are searched for. |
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
989 |
Return true, if the style sheet could be read without errors, false otherwise." |
145 | 990 |
|
4058 | 991 |
|lineString l lineNumber rest value ifLevel skipping first ok encoding decoder pack errorHandler |
992 |
printError fileName| |
|
993 |
||
994 |
fileName := (inStream isFileStream |
|
995 |
ifTrue:[inStream pathName asFilename baseName] |
|
996 |
ifFalse:['---']). |
|
997 |
||
998 |
printError := [:message | |
|
999 |
'ResourcePack [warning]: ' errorPrint. |
|
1000 |
message errorPrint. |
|
1001 |
' in file:' errorPrint. |
|
1002 |
fileName errorPrint. |
|
1003 |
' line: ' errorPrint. |
|
1004 |
lineNumber errorPrintCR |
|
1005 |
]. |
|
1006 |
||
1007 |
printError := [:message | ]. |
|
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1008 |
|
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1009 |
encoding := nil. |
0 | 1010 |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1011 |
ok := true. |
0 | 1012 |
ifLevel := 0. |
1013 |
skipping := false. |
|
4058 | 1014 |
lineNumber := 0. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1015 |
|
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1016 |
errorHandler := [:ex | |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1017 |
|con| |
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
1018 |
self halt. |
3854 | 1019 |
('ResourcePack [warning]: ''' , ex description , '''') errorPrintCR. |
4058 | 1020 |
('ResourcePack [info]: file: ' , inStream pathName printString , ' line: ' , lineNumber printString , ': ''' , lineString , '''') errorPrintCR. |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1021 |
con := ex suspendedContext. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1022 |
('ResourcePack [info]: in: ' , con fullPrintString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1023 |
con := con sender. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1024 |
('ResourcePack [info]: : ' , con fullPrintString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1025 |
con := con sender. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1026 |
('ResourcePack [info]: : ' , con fullPrintString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1027 |
value := nil. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1028 |
ok := false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1029 |
]. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1030 |
|
0 | 1031 |
[inStream atEnd] whileFalse:[ |
4058 | 1032 |
lineString := inStream nextLine. lineNumber := lineNumber + 1. |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1033 |
[lineString notNil and:[lineString endsWith:$\]] whileTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1034 |
lineString := lineString copyWithoutLast:1. |
4058 | 1035 |
l := inStream nextLine. lineNumber := lineNumber + 1. |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1036 |
l notNil ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1037 |
lineString := lineString , l. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1038 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1039 |
]. |
177 | 1040 |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1041 |
(lineString size > 0) ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1042 |
first := lineString at:1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1043 |
"/ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1044 |
"/ for your convenience: treat ; AND "/ as comment-line |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1045 |
"/ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1046 |
((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ |
4332 | 1047 |
((first == $#) and:[(lineString startsWith:'#(') not]) ifTrue:[ |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1048 |
"/ a directive |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1049 |
lineString := (lineString copyFrom:2) withoutSpaces. |
72 | 1050 |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1051 |
(lineString startsWith:'if') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1052 |
skipping ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1053 |
rest := lineString copyFrom:3. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1054 |
Error |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1055 |
handle:errorHandler |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1056 |
do:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1057 |
value := Compiler evaluate:rest compile:false]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1058 |
(value == #Error) ifTrue:[ |
4058 | 1059 |
printError value:('error in resource:' , lineString). |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1060 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1061 |
(value == false) ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1062 |
skipping := true |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1063 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1064 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1065 |
ifLevel := ifLevel + 1 |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1066 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1067 |
(lineString startsWith:'endif') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1068 |
ifLevel := ifLevel - 1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1069 |
ifLevel == 0 ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1070 |
skipping := false |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1071 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1072 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1073 |
(lineString startsWith:'else') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1074 |
skipping := skipping not |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1075 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1076 |
skipping ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1077 |
(lineString startsWith:'include') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1078 |
(lineString startsWith:'includeResourcesFor') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1079 |
"/ include those resources ... |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1080 |
rest := lineString copyFrom:('includeResourcesFor' size + 1). |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1081 |
value := Compiler evaluate:rest compile:false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1082 |
value isBehavior ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1083 |
pack := self class for:value. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1084 |
pack notNil ifTrue:[ |
4198
bb05c0ae2595
Use #addAll: instead of #declareAllFrom:, since #declareAllFrom:
Stefan Vogel <sv@exept.de>
parents:
4148
diff
changeset
|
1085 |
self addAll:pack. |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1086 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1087 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1088 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1089 |
rest := lineString copyFrom:('include' size + 1). |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1090 |
value := Compiler evaluate:rest compile:false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1091 |
value isString ifFalse:[ |
4058 | 1092 |
printError value:('bad include filename: ' , value printString, ' "',lineString,'"'). |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1093 |
] ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1094 |
self readFromFile:value directory:dirName |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1095 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1096 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1097 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1098 |
(lineString startsWith:'encoding') ifTrue:[ |
4509 | 1099 |
encoding := self class extractEncodingFromLine:lineString. |
4019 | 1100 |
decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil. |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1101 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1102 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1103 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1104 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1105 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1106 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1107 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1108 |
skipping ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1109 |
Error |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1110 |
handle:errorHandler |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1111 |
do:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1112 |
(lineString at:1) == $!! ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1113 |
"/ evaluate the rest |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1114 |
Compiler evaluate:(lineString copyFrom:2) |
4332 | 1115 |
receiver:self |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1116 |
notifying:nil |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1117 |
compile:false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1118 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1119 |
"/ process as resource |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1120 |
self |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1121 |
processLine:lineString |
4017 | 1122 |
encoding:decoder |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1123 |
file:(inStream isFileStream |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1124 |
ifTrue:[inStream pathName] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1125 |
ifFalse:['---']) |
4058 | 1126 |
printErrorWith:printError |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1127 |
]] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1128 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1129 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1130 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1131 |
] |
0 | 1132 |
]. |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1133 |
^ ok |
177 | 1134 |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
1135 |
"Modified: / 31-08-1995 / 02:33:45 / claus" |
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
1136 |
"Modified: / 05-07-2006 / 16:36:43 / cg" |
0 | 1137 |
! ! |
1138 |
||
4093 | 1139 |
!ResourcePack methodsFor:'printing & storing'! |
1140 |
||
1141 |
displayString |
|
1142 |
^ String |
|
1143 |
streamContents: |
|
1144 |
[:s | |
|
1145 |
s nextPutAll:'ResourcePack for: '. |
|
1146 |
packsClassName printOn:s |
|
1147 |
] |
|
1148 |
! ! |
|
1149 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
1150 |
!ResourcePack class methodsFor:'documentation'! |
251 | 1151 |
|
1152 |
version |
|
4580 | 1153 |
^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.110 2006-09-13 17:08:13 cg Exp $' |
251 | 1154 |
! ! |
3769 | 1155 |
|
0 | 1156 |
ResourcePack initialize! |