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