author | Claus Gittinger <cg@exept.de> |
Mon, 23 Oct 2006 23:11:08 +0200 | |
changeset 4670 | d4053f688cdb |
parent 4656 | e7746815918b |
child 4673 | e469f094c7e3 |
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 |
" |
|
3263 | 12 |
"{ Package: 'stx:libview' }" |
13 |
||
0 | 14 |
Dictionary subclass:#ResourcePack |
4085 | 15 |
instanceVariableNames:'packsClassName fileReadFailed superPack projectPack' |
308
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
16 |
classVariableNames:'Packs' |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
17 |
poolDictionaries:'' |
3484 | 18 |
category:'Interface-Internationalization' |
0 | 19 |
! |
20 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
21 |
!ResourcePack class methodsFor:'documentation'! |
46 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
72 | 26 |
All Rights Reserved |
5 | 27 |
|
46 | 28 |
This software is furnished under a license and may be used |
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
5 | 36 |
|
46 | 37 |
documentation |
38 |
" |
|
1942 | 39 |
This class supports easy customization of smalltalk code (i.e. internationalization |
40 |
and viewStyle adaption). |
|
145 | 41 |
ResourcePacks are class specific, meaning that every subclass of View |
1942 | 42 |
and ApplicationModel has an instance of ResourcePack (instVar called 'resources') |
43 |
which is created when the first instance of the view/app is created, |
|
44 |
and cached in a class-instVar (so the file is only read once). |
|
54 | 45 |
|
50 | 46 |
The resourcePack consists of a mapping from strings to values, which are |
47 |
then used in labels, buttons, menus etc. |
|
48 |
The resourcePack initializes itself from a file found in 'resources/<className>.rs', |
|
49 |
where 'className' is built by the usual abbreviation mechanism (see abbrev-files). |
|
1942 | 50 |
|
50 | 51 |
Conditional mappings are possible, by including lines as: |
3762 | 52 |
#if <expression> |
53 |
#endif |
|
50 | 54 |
in the resourcefile. Example: |
55 |
file 'foo.rs': |
|
3762 | 56 |
#if Language == #de |
57 |
'abort' 'Abbruch' |
|
58 |
#endif |
|
59 |
#if Language == #fr |
|
60 |
'abort' 'canceller' |
|
61 |
#endif |
|
145 | 62 |
|
63 |
the corresponding resource-strings are accessed (from methods within the class) |
|
64 |
using: |
|
3762 | 65 |
resources string:'abort' |
145 | 66 |
|
54 | 67 |
returning the mapped string (i.e. 'Abbruch' if the global Language is set |
3422 | 68 |
to #de).. |
145 | 69 |
|
1942 | 70 |
If no corresponding entry is found in the resources, the key is returned; |
71 |
alternatively, use: |
|
3762 | 72 |
resources string:'foo' default:'bar' |
1942 | 73 |
which returns 'bar', if no resource definition for 'foo' is found. |
74 |
||
54 | 75 |
Translations can also include arguments, such as: |
3762 | 76 |
resources string:'really delete %1' with:fileName |
145 | 77 |
|
78 |
This scheme has the advantage, that you can write your programs using your |
|
79 |
native language strings. Later, when new languages are to be supported, |
|
80 |
simply create a resource file for the class and add translations for |
|
81 |
all those strings. (find the keys by looking at users of resource or senders |
|
1942 | 82 |
of 'string:*'). |
83 |
Notice, that the grammar of different languages may imply a reordering, |
|
84 |
so the above string becomes the german 'wollen Sie %1 wirklich löschen'; |
|
85 |
so using percent-placeholders is much better than simple concatenations of |
|
86 |
arguments to the question. |
|
145 | 87 |
|
88 |
More languages can be added later without any change in the code, |
|
89 |
recompilation or the like. |
|
90 |
Even by people without access to the source code i.e. which only have the |
|
91 |
applications binary. |
|
92 |
||
93 |
Also, unsupported languages' strings are simply left unchanged - if you |
|
94 |
write your application in (say) english, and only plan to use it in english, |
|
95 |
no additional work is required (i.e you dont need a resource file then). |
|
96 |
Strings for unknown languages will come in english |
|
97 |
(which is better than nothing or empty button labels ;-) |
|
98 |
||
99 |
Summary: |
|
3762 | 100 |
in subclasses of View and ApplicationModel, |
101 |
instead of writing: |
|
145 | 102 |
|
3762 | 103 |
... |
104 |
b := Button label:'press me' |
|
105 |
... |
|
145 | 106 |
|
3762 | 107 |
always write: |
612 | 108 |
|
3762 | 109 |
... |
110 |
b := Button label:(resources string:'press me') |
|
111 |
... |
|
145 | 112 |
|
3762 | 113 |
if your class is not a subclass of one of the above, AND you need |
114 |
resource translations, you wont inherit the resources variable |
|
115 |
(which is automatically initialized). |
|
116 |
In this case, you have to ask the ResourcePack class explicitely for |
|
117 |
a corresponding package: |
|
145 | 118 |
|
3762 | 119 |
ResourcePack for:aClassName |
145 | 120 |
|
3762 | 121 |
as an example, see how the Date class gets the national names of |
122 |
week & monthnames. |
|
145 | 123 |
|
612 | 124 |
[author:] |
3762 | 125 |
Claus Gittinger |
145 | 126 |
" |
127 |
! |
|
128 |
||
129 |
examples |
|
130 |
" |
|
131 |
normally, resources are found in files named after their classes sourcefile |
|
132 |
For example, the FileBrowsers resources are found in 'FBrowser.rs'. |
|
133 |
For the examples below, we process resources from a constant string; |
|
3762 | 134 |
this is NOT representative. |
135 |
[exBegin] |
|
136 |
|stream res| |
|
145 | 137 |
|
3762 | 138 |
stream := ReadStream on:' |
145 | 139 |
foo ''the translation for foo'' |
3422 | 140 |
#if Language == #de |
145 | 141 |
bar ''die deutsche uebersetzung von bar'' |
142 |
baz ''baz hat den Wert %1'' |
|
143 |
#endif |
|
3422 | 144 |
#if Language == #fr |
145 | 145 |
bar ''bar en francaise'' |
146 |
baz ''%1, c''''est baz'' |
|
147 |
#endif |
|
148 |
||
149 |
'. |
|
150 |
||
3762 | 151 |
res := ResourcePack new readFromResourceStream:stream in:nil. |
145 | 152 |
|
3762 | 153 |
Transcript showCR:'baz is translated to: ' , (res string:'baz' with:'1234'). |
154 |
Transcript showCR:'bar is translated to: ' , (res string:'bar'). |
|
155 |
Transcript showCR:'foo is translated to: ' , (res string:'foo'). |
|
156 |
Transcript showCR:'fooBar is translated to: ' , (res string:'fooBar'). |
|
157 |
[exEnd] |
|
145 | 158 |
set the Language to french: |
3762 | 159 |
[exBegin] |
160 |
Language := #fr |
|
161 |
[exEnd] |
|
145 | 162 |
and repeat the above. |
620 | 163 |
back to english: |
3762 | 164 |
[exBegin] |
165 |
Language := #en |
|
166 |
[exEnd] |
|
620 | 167 |
back to german: |
3762 | 168 |
[exBegin] |
169 |
Language := #de |
|
170 |
[exEnd] |
|
46 | 171 |
" |
172 |
! ! |
|
5 | 173 |
|
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
174 |
!ResourcePack class methodsFor:'initialization'! |
0 | 175 |
|
72 | 176 |
flushCachedResourcePacks |
24 | 177 |
"forget all cached resources - needed after a style change" |
178 |
||
179 |
Packs := nil. |
|
180 |
self initialize |
|
181 |
||
4093 | 182 |
" |
183 |
ResourcePack flushCachedResourcePacks |
|
184 |
" |
|
244 | 185 |
! |
186 |
||
187 |
initialize |
|
188 |
Packs isNil ifTrue:[ |
|
4623 | 189 |
Packs := WeakArray new:100 |
244 | 190 |
]. |
191 |
||
4093 | 192 |
" |
193 |
ResourcePack initialize |
|
194 |
" |
|
4623 | 195 |
|
196 |
"Modified: / 18-09-2006 / 20:37:38 / cg" |
|
244 | 197 |
! ! |
198 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
199 |
!ResourcePack class methodsFor:'instance creation'! |
244 | 200 |
|
201 |
for:aClass |
|
202 |
"get the full resource definitions for aClass (i.e. with super packs). |
|
203 |
Also leave the resulting pack in the cache for faster access next time." |
|
204 |
||
4619 | 205 |
^ self for:aClass cached:false |
4030 | 206 |
|
207 |
" |
|
208 |
ResourcePack for:TextView |
|
209 |
ResourcePack for:CodeView |
|
210 |
ResourcePack for:Workspace |
|
211 |
ResourcePack for:View |
|
212 |
ResourcePack for:ErrorLogger |
|
213 |
ResourcePack for:NewLauncher |
|
214 |
Workspace classResources |
|
215 |
" |
|
4619 | 216 |
|
217 |
"Modified: / 18-09-2006 / 19:02:57 / cg" |
|
4030 | 218 |
! |
219 |
||
220 |
for:aClass cached:cached |
|
221 |
"get the full resource definitions for aClass (i.e. with super packs). |
|
222 |
Also leave the resulting pack in the cache for faster access next time." |
|
223 |
||
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
224 |
|nm pack rsrcDir baseName| |
244 | 225 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
226 |
nm := aClass resourcePackName. |
4030 | 227 |
cached ifTrue:[ |
228 |
pack := self searchCacheFor:nm. |
|
229 |
pack notNil ifTrue:[^ pack]. |
|
230 |
]. |
|
244 | 231 |
|
3049
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
232 |
baseName := (Smalltalk fileNameForClass:nm) , '.rs'. |
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
233 |
rsrcDir := aClass resourceDirectory. |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
234 |
|
4148 | 235 |
"/ CHECK this |
236 |
"/ (rsrcDir notNil and:[rsrcDir suffix = 'rs']) ifTrue:[ |
|
237 |
"/ baseName := (Smalltalk fileNameForClass: rsrcDir tail asFilename withoutSuffix pathName),'.rs'. |
|
238 |
"/ rsrcDir := rsrcDir head asFilename. |
|
239 |
"/ ]. |
|
240 |
||
4643 | 241 |
rsrcDir notNil ifTrue:[ |
242 |
pack := self new. |
|
243 |
rsrcDir exists ifTrue:[ |
|
244 |
(rsrcDir construct:baseName) exists ifTrue:[ |
|
245 |
pack := self fromFile:baseName directory:(rsrcDir name) cached:true. |
|
246 |
]. |
|
247 |
] |
|
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
248 |
] ifFalse:[ |
4643 | 249 |
pack := self fromFile:baseName directory:'resources' cached:true. |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
250 |
]. |
4619 | 251 |
aClass superclass notNil ifTrue:[ |
3808 | 252 |
pack superPack:(self for:(aClass superclass)). |
244 | 253 |
]. |
4093 | 254 |
pack packsClassOrFileName:nm. |
4030 | 255 |
cached ifTrue:[ |
256 |
self addToCache:pack. |
|
257 |
]. |
|
4617 | 258 |
pack projectPack:(self forPackage:(aClass resourcePackage) cached:true). |
259 |
||
244 | 260 |
^ pack |
261 |
||
4656 | 262 |
" |
263 |
ResourcePack forPackage:'bosch:dapasx' cached:true |
|
264 |
||
3046 | 265 |
ResourcePack for:TextView |
244 | 266 |
ResourcePack for:CodeView |
3046 | 267 |
ResourcePack for:Workspace |
3049
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
268 |
ResourcePack for:View |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
269 |
ResourcePack for:ErrorLogger |
3101
38cc69894380
fix to avoid loosing the directory with #includes
Claus Gittinger <cg@exept.de>
parents:
3097
diff
changeset
|
270 |
ResourcePack for:NewLauncher |
244 | 271 |
Workspace classResources |
272 |
" |
|
4617 | 273 |
|
4656 | 274 |
"Modified: / 19-10-2006 / 23:10:02 / cg" |
244 | 275 |
! |
276 |
||
4078 | 277 |
forPackage:package |
278 |
"get the full resource definitions given a package id (such as stx:libbasic'). |
|
279 |
Also leave the resulting pack in the cache for faster access next time." |
|
280 |
||
281 |
^ self forPackage:package cached:true |
|
282 |
||
283 |
" |
|
284 |
ResourcePack forPackage:'stx:libbasic' |
|
4618 | 285 |
ResourcePack forPackage:'stx:libtool' |
4078 | 286 |
" |
4618 | 287 |
|
288 |
"Modified: / 18-09-2006 / 18:45:31 / cg" |
|
4078 | 289 |
! |
290 |
||
291 |
forPackage:package cached:cached |
|
292 |
"get the full resource definitions given a package id (such as stx:libbasic'). |
|
293 |
Also optionally leave the resulting pack in the cache for faster access next time." |
|
294 |
||
4428 | 295 |
|fullName pack rsrcDir file| |
4078 | 296 |
|
297 |
fullName := package , '/resources/resources.rs'. |
|
298 |
||
299 |
cached ifTrue:[ |
|
300 |
pack := self searchCacheFor:fullName. |
|
301 |
pack notNil ifTrue:[^ pack]. |
|
302 |
]. |
|
303 |
||
304 |
rsrcDir := Smalltalk projectDirectoryForPackage:package. |
|
4428 | 305 |
rsrcDir isNil ifTrue:[ |
306 |
file := Smalltalk getResourceFileName:'resources.rs' forPackage:package. |
|
307 |
file isNil ifTrue:[^ nil]. |
|
308 |
rsrcDir := file asFilename directory. |
|
309 |
] ifFalse:[ |
|
310 |
rsrcDir := rsrcDir asFilename construct:'resources'. |
|
311 |
rsrcDir exists ifFalse:[^ nil]. |
|
312 |
]. |
|
4078 | 313 |
|
4611 | 314 |
pack := self fromFile:'resources.rs' directory:rsrcDir cached:cached. |
4093 | 315 |
pack packsClassOrFileName:fullName. |
4078 | 316 |
^ pack |
317 |
||
318 |
" |
|
319 |
ResourcePack forPackage:'stx:libbasic' cached:false |
|
320 |
" |
|
4656 | 321 |
|
322 |
"Modified: / 19-10-2006 / 23:18:28 / cg" |
|
4078 | 323 |
! |
324 |
||
244 | 325 |
fromFile:aFileName |
4611 | 326 |
"get the resource definitions from a file in the default directory." |
244 | 327 |
|
328 |
^ self fromFile:aFileName directory:'resources' |
|
329 |
||
330 |
" |
|
331 |
ResourcePack fromFile:'SBrowser.rs' |
|
332 |
ResourcePack fromFile:'FBrowser.rs' |
|
333 |
ResourcePack fromFile:'Smalltalk.rs' |
|
3678 | 334 |
ResourcePack fromFile:'Smalltalk.rs' asFilename |
3983 | 335 |
ResourcePack fromFile:'../../libtool/resources/AboutBox_ru.rs' asFilename |
244 | 336 |
" |
337 |
! |
|
338 |
||
339 |
fromFile:aFileName directory:dirName |
|
4611 | 340 |
"get the resource definitions from a file in a directory." |
341 |
||
342 |
^ self fromFile:aFileName directory:dirName cached:false |
|
343 |
! |
|
344 |
||
345 |
fromFile:aFileName directory:dirName cached:cached |
|
244 | 346 |
"get the resource definitions from a file in a directory. |
347 |
Uncached low-level entry." |
|
348 |
||
349 |
|newPack| |
|
350 |
||
351 |
newPack := self new. |
|
352 |
newPack readFromFile:aFileName directory:dirName. |
|
4611 | 353 |
cached ifTrue:[ |
354 |
self addToCache:newPack. |
|
355 |
]. |
|
244 | 356 |
^ newPack |
0 | 357 |
! ! |
358 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
359 |
!ResourcePack class methodsFor:'private'! |
54 | 360 |
|
361 |
addToCache:aPack |
|
362 |
|idx| |
|
0 | 363 |
|
4084 | 364 |
Packs isNil ifTrue:[ |
365 |
self initialize. |
|
366 |
]. |
|
367 |
||
54 | 368 |
idx := Packs identityIndexOf:nil. |
369 |
idx == 0 ifTrue:[ |
|
4084 | 370 |
idx := Packs identityIndexOf:0 |
1078
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
371 |
]. |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
372 |
idx == 0 ifTrue:[ |
4084 | 373 |
" |
374 |
throw away oldest |
|
375 |
" |
|
376 |
idx := Packs size. |
|
377 |
Packs replaceFrom:1 to:idx-1 with:Packs startingAt:2. |
|
54 | 378 |
]. |
4619 | 379 |
aPack at:'__language__' put:(Smalltalk language,'_',Smalltalk languageTerritory). |
380 |
Packs at:idx put:aPack. |
|
381 |
||
382 |
"Modified: / 18-09-2006 / 19:12:12 / cg" |
|
54 | 383 |
! |
0 | 384 |
|
4093 | 385 |
searchCacheFor:aClassOrFileName |
4619 | 386 |
|sz "{ Class: SmallInteger }" lang| |
0 | 387 |
|
24 | 388 |
Packs isNil ifTrue:[ |
4093 | 389 |
self initialize. |
390 |
^ nil |
|
0 | 391 |
]. |
54 | 392 |
|
4619 | 393 |
lang := (Smalltalk language,'_',Smalltalk languageTerritory). |
394 |
||
54 | 395 |
sz := Packs size. |
396 |
1 to:sz do:[:idx | |
|
4093 | 397 |
|aPack| |
54 | 398 |
|
4093 | 399 |
aPack := Packs at:idx. |
400 |
(aPack notNil and:[aPack ~~ 0]) ifTrue:[ |
|
4619 | 401 |
(aPack at:'__language__' ifAbsent:nil) = lang ifTrue:[ |
402 |
aClassOrFileName = aPack packsClassOrFileName ifTrue:[ |
|
403 |
" |
|
404 |
bring to front for LRU |
|
405 |
" |
|
406 |
idx ~~ 1 ifTrue:[ |
|
407 |
Packs replaceFrom:2 to:idx with:Packs startingAt:1. |
|
408 |
Packs at:1 put:aPack. |
|
409 |
]. |
|
410 |
^ aPack |
|
411 |
] |
|
4093 | 412 |
] |
413 |
] |
|
0 | 414 |
]. |
54 | 415 |
^ nil |
123 | 416 |
|
417 |
" |
|
418 |
ResourcePack searchCacheFor:'TextView' |
|
419 |
" |
|
4619 | 420 |
|
421 |
"Modified: / 18-09-2006 / 19:13:13 / cg" |
|
54 | 422 |
! ! |
423 |
||
4509 | 424 |
!ResourcePack class methodsFor:'utilities'! |
425 |
||
426 |
extractEncodingFromLine:lineString |
|
427 |
|rest encoding| |
|
428 |
||
429 |
(lineString startsWith:'encoding') ifFalse:[^ nil]. |
|
430 |
||
431 |
rest := lineString copyFrom:9. |
|
432 |
rest := rest withoutSeparators. |
|
433 |
(rest startsWith:'#') ifTrue:[ |
|
434 |
rest := rest copyFrom:2. |
|
435 |
]. |
|
436 |
(rest startsWith:'''') ifTrue:[ |
|
437 |
rest := rest copyFrom:2. |
|
438 |
(rest endsWith:'''') ifTrue:[ |
|
439 |
rest := rest copyWithoutLast:1. |
|
440 |
]. |
|
441 |
]. |
|
442 |
encoding := rest asSymbol. |
|
443 |
^ encoding. |
|
444 |
! |
|
445 |
||
446 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack |
|
447 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
|
448 |
||
4510 | 449 |
self |
450 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack |
|
451 |
keepUselessTranslations:false. |
|
452 |
! |
|
453 |
||
454 |
processResourceLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError for:aResourcePack keepUselessTranslations:keepUselessTranslations |
|
455 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
|
456 |
||
4531 | 457 |
|name decodedLine lineStream idx rest macroName value |
4670 | 458 |
conditional hasError decoder oldValue ignoreTranslation indirect| |
4509 | 459 |
|
4531 | 460 |
encodingSymbolOrEncoder notNil ifTrue:[ |
461 |
encodingSymbolOrEncoder isSymbol ifTrue:[ |
|
462 |
decoder := CharacterEncoder encoderFor:encodingSymbolOrEncoder ifAbsent:nil. |
|
463 |
decoder isNil ifTrue:[ decoder := CharacterEncoder::NullEncoder ]. |
|
464 |
] ifFalse:[ |
|
465 |
decoder := encodingSymbolOrEncoder |
|
466 |
]. |
|
467 |
]. |
|
468 |
||
469 |
decoder notNil ifTrue:[ |
|
470 |
decodedLine := decoder decodeString:lineString. |
|
471 |
lineStream := ReadStream on:decodedLine. |
|
472 |
] ifFalse:[ |
|
473 |
lineStream := ReadStream on:lineString. |
|
474 |
]. |
|
4509 | 475 |
lineStream signalAtEnd:false. |
476 |
lineStream skipSeparators. |
|
477 |
lineStream peek == $# ifTrue:[ |
|
478 |
name := Array |
|
479 |
readFrom:lineStream |
|
480 |
onError:[ |
|
481 |
printError value:('invalid line <' , lineString , '>'). |
|
482 |
nil |
|
483 |
]. |
|
484 |
] ifFalse:[ |
|
485 |
lineStream peek == $' ifTrue:[ |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
486 |
name := UnicodeString |
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
487 |
readSmalltalkStringFrom:lineStream |
4509 | 488 |
onError:[ |
489 |
printError value:('invalid line <' , lineString , '>'). |
|
490 |
nil |
|
491 |
]. |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
492 |
name := name asSingleByteStringIfPossible. |
4509 | 493 |
] ifFalse:[ |
494 |
name := lineStream upToSeparator. |
|
495 |
]. |
|
496 |
]. |
|
497 |
||
4510 | 498 |
name isNil ifTrue:[^ self ]. |
499 |
||
500 |
ignoreTranslation := false. |
|
501 |
||
502 |
hasError := false. |
|
4509 | 503 |
|
4510 | 504 |
lineStream skipSeparators. |
505 |
idx := lineStream position1Based + 1. |
|
506 |
||
507 |
lineStream peek == $< ifTrue:[ |
|
508 |
" |
|
509 |
skip <type> if present |
|
510 |
" |
|
511 |
lineStream skipThrough:$>. |
|
4509 | 512 |
lineStream skipSeparators. |
513 |
idx := lineStream position1Based + 1. |
|
4510 | 514 |
]. |
4509 | 515 |
|
4670 | 516 |
conditional := indirect := false. |
4510 | 517 |
lineStream peek == $? ifTrue:[ |
4670 | 518 |
conditional := true. |
4510 | 519 |
lineStream next. |
520 |
lineStream skipSeparators. |
|
4670 | 521 |
]. |
522 |
||
523 |
lineStream peek == $@ ifTrue:[ |
|
524 |
indirect := true. |
|
525 |
lineStream next. |
|
526 |
lineStream skipSeparators. |
|
4510 | 527 |
]. |
4509 | 528 |
|
4510 | 529 |
lineStream peek == $= ifTrue:[ |
530 |
lineStream next. |
|
531 |
||
532 |
macroName := lineStream nextAlphaNumericWord. |
|
533 |
[lineStream peek == $.] whileTrue:[ |
|
4509 | 534 |
lineStream next. |
4510 | 535 |
lineStream peek notNil ifTrue:[ |
536 |
macroName := macroName , '.' , (lineStream nextAlphaNumericWord) |
|
537 |
] |
|
538 |
]. |
|
539 |
rest := lineStream upToEnd. |
|
540 |
value := aResourcePack at:macroName ifAbsent:nil. |
|
541 |
(value isNil) ifTrue:[ |
|
542 |
hasError := true. |
|
543 |
printError value:('bad (nil-valued) macro: ' , macroName). |
|
544 |
]. |
|
545 |
value isBlock ifTrue:[ |
|
546 |
value := value value |
|
4509 | 547 |
]. |
4510 | 548 |
value := Compiler evaluate:('self ' , rest) |
549 |
receiver:value |
|
550 |
notifying:nil |
|
551 |
compile:false. |
|
552 |
(value == #Error) ifTrue:[ |
|
553 |
hasError := true. |
|
554 |
printError value:('error in: "self ' , rest , '"'). |
|
555 |
] |
|
556 |
] ifFalse:[ |
|
557 |
lineStream peek == $' ifTrue:[ |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
558 |
value := UnicodeString |
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
559 |
readSmalltalkStringFrom:lineStream |
4510 | 560 |
onError:[ |
561 |
printError value:('invalid line <' , lineString , '>'). |
|
562 |
nil |
|
563 |
]. |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
564 |
value := value asSingleByteStringIfPossible. |
4510 | 565 |
] ifFalse:[ |
4509 | 566 |
rest := lineStream upToEnd. |
4510 | 567 |
value := Compiler evaluate:rest compile:false. |
568 |
]. |
|
569 |
(value == #Error) ifTrue:[ |
|
570 |
hasError := true. |
|
571 |
printError value:('error in: "' , rest , '"'). |
|
4509 | 572 |
] ifFalse:[ |
4531 | 573 |
"/ value isString ifTrue:[ |
574 |
"/ decoder notNil ifTrue:[ |
|
575 |
"/ value := decoder decodeString:value |
|
576 |
"/ ] |
|
577 |
"/ ] |
|
4510 | 578 |
] |
579 |
]. |
|
580 |
||
581 |
hasError ifFalse:[ |
|
582 |
(conditional not |
|
583 |
or:[(aResourcePack includesKey:name) not]) ifTrue:[ |
|
584 |
name = value ifTrue:[ |
|
585 |
keepUselessTranslations ifFalse:[ |
|
4509 | 586 |
printError value:('useless resource: "' , name , '"'). |
4510 | 587 |
ignoreTranslation := true |
588 |
]. |
|
589 |
]. |
|
590 |
ignoreTranslation ifFalse:[ |
|
591 |
oldValue := aResourcePack at:name ifAbsent:nil. |
|
592 |
oldValue notNil ifTrue:[ |
|
593 |
oldValue ~= value ifTrue:[ |
|
594 |
printError value:('conflicting resource: "' , name , '"'). |
|
595 |
printError value:('oldValue: ' , oldValue printString). |
|
596 |
printError value:('newValue: ' , value printString). |
|
597 |
] ifFalse:[ |
|
598 |
printError value:('duplicate resource: "' , name , '"'). |
|
4509 | 599 |
]. |
4510 | 600 |
]. |
4670 | 601 |
indirect ifTrue:[ |
602 |
value := aResourcePack string:value. |
|
603 |
]. |
|
4510 | 604 |
aResourcePack at:name put:value. |
4509 | 605 |
] |
606 |
] |
|
607 |
] |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
608 |
|
4670 | 609 |
"Modified: / 23-10-2006 / 23:11:22 / cg" |
4509 | 610 |
! ! |
611 |
||
0 | 612 |
!ResourcePack methodsFor:'accessing'! |
613 |
||
244 | 614 |
array:anArray |
615 |
"translate a collection of strings" |
|
0 | 616 |
|
244 | 617 |
^ anArray collect:[:r | self at:r default:r] |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
618 |
|
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 |
Launcher classResources array:#('file' 'classes') |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
621 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
622 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
623 |
"Modified: / 29.1.1998 / 22:44:22 / cg" |
0 | 624 |
! |
625 |
||
2 | 626 |
at:aKey |
123 | 627 |
"translate a string" |
628 |
||
72 | 629 |
^ self at:aKey ifAbsent:aKey |
0 | 630 |
! |
631 |
||
632 |
at:aKey default:default |
|
123 | 633 |
"translate a string" |
634 |
||
72 | 635 |
^ self at:aKey ifAbsent:default |
0 | 636 |
! |
637 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
638 |
at:aKey ifAbsent:defaultValue |
4617 | 639 |
"translate a string; search here, in my projects pack and in my superpack(s)" |
640 |
||
641 |
|val pack projectPack alreadySearched| |
|
642 |
||
643 |
aKey isNil ifTrue:[ ^ defaultValue value ]. |
|
644 |
||
645 |
val := self localAt:aKey. |
|
646 |
val notNil ifTrue:[^ val]. |
|
647 |
||
648 |
(projectPack := self projectPack) notNil ifTrue:[ |
|
649 |
val := projectPack localAt:aKey. |
|
650 |
val notNil ifTrue:[^ val]. |
|
651 |
]. |
|
652 |
alreadySearched := Set new. |
|
653 |
projectPack notNil ifTrue:[ alreadySearched add:projectPack ]. |
|
654 |
||
655 |
pack := self superPack. |
|
656 |
[ pack notNil ] whileTrue:[ |
|
657 |
val := pack localAt:aKey. |
|
658 |
val notNil ifTrue:[^ val]. |
|
659 |
||
660 |
(projectPack := pack projectPack) notNil ifTrue:[ |
|
661 |
(alreadySearched includes:projectPack) ifFalse:[ |
|
662 |
val := projectPack localAt:aKey. |
|
663 |
val notNil ifTrue:[^ val]. |
|
664 |
alreadySearched add:projectPack. |
|
665 |
]. |
|
666 |
]. |
|
667 |
pack := pack superPack |
|
668 |
]. |
|
669 |
||
4618 | 670 |
alreadySearched copy do:[:projectPack | |
671 |
|p| |
|
672 |
||
673 |
p := projectPack superPack. |
|
674 |
[p notNil and:[(alreadySearched includes:p) not]] whileTrue:[ |
|
675 |
val := p localAt:aKey. |
|
676 |
val notNil ifTrue:[^ val]. |
|
677 |
alreadySearched add:p. |
|
678 |
p := p superPack. |
|
679 |
]. |
|
680 |
]. |
|
681 |
||
4617 | 682 |
^ defaultValue value |
683 |
||
4618 | 684 |
"Modified: / 18-09-2006 / 18:50:52 / cg" |
4617 | 685 |
! |
686 |
||
687 |
localAt:aKey |
|
4035 | 688 |
"translate a string. |
689 |
Some special 'intelligence' has been added: |
|
690 |
if no value for aKey is found, |
|
4036 | 691 |
lookup aKey with first character caseChanged and change the results first characters case. |
692 |
or aKey ends with a ':', then lookup aKey without ':' and append ':' to the result. |
|
693 |
or aKey ends with a '=', then lookup aKey without '=' and append '=' to the result. |
|
4037 | 694 |
or aKey ends with a '.', then lookup aKey without '.' and append '.' to the result. |
4036 | 695 |
or aKey ends with a ' ', then lookup aKey without ' '. |
696 |
or aKey ends with a ' ...', then lookup aKey without ' ...' and append '...' to the result. |
|
697 |
or aKey ends with a '...', then lookup aKey without '...' and append '...' to the result. |
|
698 |
or aKey includes '&', then lookup aKey without '&'. |
|
4035 | 699 |
|
700 |
This means, that only a single translation is required to provide local translations for |
|
701 |
things like |
|
702 |
'search' |
|
703 |
'search:' |
|
704 |
'search...' |
|
705 |
" |
|
123 | 706 |
|
4017 | 707 |
|val alternativeKey rest usedKey idx| |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
708 |
|
4617 | 709 |
val := super at:aKey ifAbsent:nil. |
710 |
val notNil ifTrue:[^ val]. |
|
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
711 |
|
4617 | 712 |
(aKey isString and:[aKey size > 0]) ifTrue:[ |
713 |
"/ try with case-first swapped... |
|
714 |
(aKey first isLetter) ifTrue:[ |
|
715 |
alternativeKey := aKey isUppercaseFirst |
|
716 |
ifTrue:[aKey asLowercaseFirst] |
|
717 |
ifFalse:[aKey asUppercaseFirst]. |
|
718 |
val := super at:alternativeKey ifAbsent:nil. |
|
719 |
val notNil ifTrue:[ |
|
720 |
aKey isUppercaseFirst ifTrue:[ |
|
721 |
^ val asUppercaseFirst |
|
3979
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
722 |
]. |
4617 | 723 |
^ val asLowercaseFirst. |
4028 | 724 |
]. |
4617 | 725 |
]. |
726 |
||
4634 | 727 |
(aKey endsWith:' ...') ifTrue:[ |
728 |
usedKey := aKey copyWithoutLast:4. |
|
729 |
||
730 |
val := self localAt:usedKey. "/ recursion |
|
731 |
val notNil ifTrue:[^ val , '...']. |
|
732 |
]. |
|
733 |
(aKey endsWith:'...') ifTrue:[ |
|
734 |
usedKey := aKey copyWithoutLast:3. |
|
735 |
||
736 |
val := self localAt:usedKey. "/ recursion |
|
737 |
val notNil ifTrue:[^ val , '...']. |
|
738 |
]. |
|
739 |
||
4617 | 740 |
(':=.?!!' includes:aKey last) ifTrue:[ |
4634 | 741 |
aKey size > 2 ifTrue:[ |
742 |
rest := aKey last. |
|
743 |
usedKey := aKey copyWithoutLast:1. |
|
4617 | 744 |
|
4634 | 745 |
val := self localAt:usedKey. "/ recursion |
746 |
val notNil ifTrue:[^ val , rest]. |
|
747 |
]. |
|
748 |
]. |
|
749 |
(':=.?!!' includes:aKey first) ifTrue:[ |
|
750 |
aKey size > 2 ifTrue:[ |
|
751 |
rest := aKey first. |
|
752 |
usedKey := aKey copyFrom:2. |
|
753 |
||
754 |
val := self localAt:usedKey. "/ recursion |
|
755 |
val notNil ifTrue:[^ rest asString , val]. |
|
756 |
]. |
|
4617 | 757 |
]. |
4028 | 758 |
|
4617 | 759 |
((aKey startsWith:'(') and:[(aKey endsWith:')')]) ifTrue:[ |
760 |
usedKey := aKey copyFrom:2 to:(aKey size - 1). |
|
4028 | 761 |
|
4634 | 762 |
val := self localAt:usedKey. "/ recursion |
4617 | 763 |
val notNil ifTrue:[^ '(' , val , ')']. |
764 |
]. |
|
765 |
(aKey endsWith:' ') ifTrue:[ |
|
766 |
usedKey := aKey withoutSeparators. |
|
767 |
||
4634 | 768 |
val := self localAt:usedKey. "/ recursion |
4617 | 769 |
val notNil ifTrue:[^ val]. |
770 |
]. |
|
4017 | 771 |
|
4617 | 772 |
(idx := aKey indexOf:$&) ~~ 0 ifTrue:[ |
773 |
(aKey at:idx+1 ifAbsent:nil) ~~ $& ifTrue:[ |
|
774 |
usedKey := (aKey copyTo:idx-1) , (aKey copyFrom:idx+1). |
|
775 |
val := super at:usedKey ifAbsent:nil. "/ recursion |
|
4028 | 776 |
val notNil ifTrue:[^ val]. |
777 |
]. |
|
3979
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
778 |
]. |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
779 |
]. |
4617 | 780 |
^ nil. |
4580 | 781 |
|
4617 | 782 |
"Created: / 18-09-2006 / 17:33:27 / cg" |
4634 | 783 |
"Modified: / 07-10-2006 / 15:38:35 / cg" |
2 | 784 |
! |
785 |
||
786 |
name:aKey default:default |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
787 |
"translate a string. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
788 |
Obsolete - use #string:default:" |
123 | 789 |
|
72 | 790 |
^ self at:aKey ifAbsent:default |
2 | 791 |
! |
792 |
||
0 | 793 |
string:s |
3097 | 794 |
"translate (retrieve) a string - if not present, return s" |
123 | 795 |
|
72 | 796 |
^ self at:s ifAbsent:s |
3097 | 797 |
|
798 |
" |
|
799 |
NewLauncher classResources |
|
3762 | 800 |
string:'LICENCEFILE' |
3097 | 801 |
" |
0 | 802 |
! |
803 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
804 |
string:s default:defaultString |
3097 | 805 |
"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
|
806 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
807 |
^ self at:s ifAbsent:defaultString |
3097 | 808 |
|
809 |
" |
|
810 |
NewLauncher classResources |
|
3762 | 811 |
string:'fooBar' default:'Hello world' |
3097 | 812 |
" |
813 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
814 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
815 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
816 |
string:s default:defaultString with:arg |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
817 |
"translate and expand arg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
818 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
819 |
^ self string:s default:defaultString withArgs:(Array with:arg) |
3097 | 820 |
|
821 |
" |
|
822 |
NewLauncher classResources |
|
3762 | 823 |
string:'%1 fooBar' default:'Hello %1' with:'foo' |
3097 | 824 |
" |
825 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
826 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
827 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
828 |
string:s default:defaultString with:arg1 with:arg2 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
829 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
830 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
831 |
^ 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
|
832 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
833 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
834 |
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
|
835 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
836 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
837 |
^ 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
|
838 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
839 |
"Created: 9.12.1995 / 19:08:50 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
840 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
841 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
842 |
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
|
843 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
844 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
845 |
^ 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
|
846 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
847 |
"Created: 9.9.1996 / 18:52:14 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
848 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
849 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
850 |
string:s default:defaultString withArgs:argArray |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
851 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
852 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
853 |
|template| |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
854 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
855 |
template := self at:s ifAbsent:defaultString. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
856 |
^ template expandPlaceholdersWith:argArray |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
857 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
858 |
|
0 | 859 |
string:s with:arg |
123 | 860 |
"translate and expand arg" |
861 |
||
0 | 862 |
^ self string:s withArgs:(Array with:arg) |
863 |
! |
|
864 |
||
865 |
string:s with:arg1 with:arg2 |
|
123 | 866 |
"translate and expand args" |
867 |
||
0 | 868 |
^ self string:s withArgs:(Array with:arg1 with:arg2) |
869 |
! |
|
870 |
||
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
871 |
string:s with:arg1 with:arg2 with:arg3 |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
872 |
"translate and expand args" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
873 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
874 |
^ 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
|
875 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
876 |
"Created: 9.12.1995 / 19:08:50 / cg" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
877 |
! |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
878 |
|
1042 | 879 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 |
880 |
"translate and expand args" |
|
881 |
||
882 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
883 |
||
884 |
"Created: 9.9.1996 / 18:52:14 / cg" |
|
885 |
! |
|
886 |
||
3184 | 887 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
888 |
"translate and expand args" |
|
889 |
||
890 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
891 |
||
892 |
! |
|
893 |
||
0 | 894 |
string:s withArgs:argArray |
123 | 895 |
"translate and expand args" |
896 |
||
135 | 897 |
|template| |
0 | 898 |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
899 |
template := self at:s ifAbsent:s. |
135 | 900 |
^ template expandPlaceholdersWith:argArray |
3823 | 901 |
! |
902 |
||
4402 | 903 |
stringWithCRs:s |
904 |
"translate (retrieve) a string - if not present, return s" |
|
905 |
||
906 |
^ (self string:s) withCRs |
|
907 |
||
908 |
" |
|
909 |
NewLauncher classResources |
|
910 |
stringWithCRs:'LICENCEFILE' |
|
911 |
" |
|
912 |
! |
|
913 |
||
3823 | 914 |
stringWithCRs:s with:arg |
915 |
"translate, replace \'s with CRs and finally expand arg. |
|
916 |
CR-replacement is donw before args are inserted |
|
917 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
918 |
||
919 |
^ self stringWithCRs:s withArgs:(Array with:arg) |
|
920 |
||
921 |
"Modified: / 21.3.2003 / 14:22:09 / cg" |
|
922 |
! |
|
923 |
||
924 |
stringWithCRs:s with:arg1 with:arg2 |
|
925 |
"translate, replace \'s with CRs and finally expand args. |
|
926 |
CR-replacement is donw before args are inserted |
|
927 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
928 |
||
929 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2) |
|
930 |
||
931 |
"Modified: / 21.3.2003 / 14:22:06 / cg" |
|
932 |
! |
|
933 |
||
934 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 |
|
935 |
"translate, replace \'s with CRs and finally expand args. |
|
936 |
CR-replacement is donw before args are inserted |
|
937 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
938 |
||
939 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3) |
|
940 |
||
941 |
"Created: 9.12.1995 / 19:08:50 / cg" |
|
942 |
! |
|
943 |
||
944 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 |
|
945 |
"translate, replace \'s with CRs and finally expand args. |
|
946 |
CR-replacement is donw before args are inserted |
|
947 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
948 |
||
949 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
950 |
||
951 |
"Modified: / 21.3.2003 / 14:21:48 / cg" |
|
952 |
! |
|
953 |
||
954 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
955 |
"translate, replace \'s with CRs and finally expand args. |
|
956 |
CR-replacement is donw before args are inserted |
|
957 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
958 |
||
959 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
960 |
||
961 |
"Modified: / 21.3.2003 / 14:21:55 / cg" |
|
962 |
! |
|
963 |
||
964 |
stringWithCRs:s withArgs:argArray |
|
965 |
"translate, replace \'s with CRs and finally expand args. |
|
966 |
CR-replacement is donw before args are inserted |
|
967 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
968 |
||
969 |
|template| |
|
970 |
||
971 |
template := self at:s ifAbsent:s. |
|
972 |
^ template withCRs expandPlaceholdersWith:argArray |
|
973 |
||
974 |
"Modified: / 21.3.2003 / 14:21:59 / cg" |
|
0 | 975 |
! ! |
976 |
||
3317 | 977 |
!ResourcePack methodsFor:'accessing-internals'! |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
978 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
979 |
name:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
980 |
"translate a string" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
981 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
982 |
^ self at:aKey ifAbsent:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
983 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
984 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
985 |
packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
986 |
^ packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
987 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
988 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
989 |
packsClassName:aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
990 |
packsClassName := aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
991 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
992 |
|
4093 | 993 |
packsClassOrFileName |
994 |
^ packsClassName |
|
995 |
! |
|
996 |
||
997 |
packsClassOrFileName:aString |
|
998 |
packsClassName := aString |
|
999 |
! |
|
1000 |
||
4617 | 1001 |
projectPack |
1002 |
^ projectPack |
|
1003 |
||
1004 |
"Created: / 18-09-2006 / 17:38:07 / cg" |
|
1005 |
! |
|
1006 |
||
4085 | 1007 |
projectPack:anotherResourcePack |
1008 |
projectPack := anotherResourcePack |
|
1009 |
||
1010 |
"Created: / 29.1.1998 / 22:43:09 / cg" |
|
1011 |
! |
|
1012 |
||
4617 | 1013 |
superPack |
1014 |
^ superPack |
|
1015 |
||
1016 |
"Created: / 18-09-2006 / 17:38:12 / cg" |
|
1017 |
! |
|
1018 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1019 |
superPack:anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1020 |
superPack := anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1021 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1022 |
"Created: / 29.1.1998 / 22:43:09 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1023 |
! ! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1024 |
|
0 | 1025 |
!ResourcePack methodsFor:'file reading'! |
1026 |
||
684 | 1027 |
fileReadFailed |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1028 |
"return true, if the pack does not really contain |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1029 |
valid translations, since the fileRead failed. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1030 |
However, all inherited translations are still available |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1031 |
through the receiver" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1032 |
|
687 | 1033 |
^ fileReadFailed ~~ false |
684 | 1034 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1035 |
"Created: / 14.5.1996 / 10:19:26 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
1036 |
"Modified: / 29.1.1998 / 22:46:38 / cg" |
684 | 1037 |
! |
1038 |
||
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1039 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1040 |
"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
|
1041 |
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
|
1042 |
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
|
1043 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1044 |
^ nil |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1045 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1046 |
"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
|
1047 |
! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
1048 |
|
4332 | 1049 |
processLine:lineString encoding:encodingSymbolOrEncoder file:fileName printErrorWith:printError |
145 | 1050 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
1051 |
||
4509 | 1052 |
self class |
1053 |
processResourceLine:lineString |
|
1054 |
encoding:encodingSymbolOrEncoder |
|
1055 |
file:fileName |
|
1056 |
printErrorWith:printError |
|
1057 |
for:self |
|
144 | 1058 |
! |
1059 |
||
244 | 1060 |
readFromFile:fileName directory:dirName |
1061 |
"read definitions from a file in a directory" |
|
1062 |
||
1063 |
|inStream ok| |
|
1064 |
||
686 | 1065 |
fileReadFailed := false. |
244 | 1066 |
dirName = 'resources' ifTrue:[ |
3769 | 1067 |
inStream := Smalltalk resourceFileStreamFor:fileName |
244 | 1068 |
] ifFalse:[ |
3769 | 1069 |
inStream := Smalltalk |
1070 |
systemFileStreamFor:(dirName |
|
1071 |
isNil ifTrue:[fileName] |
|
1072 |
ifFalse:[dirName asFilename construct:fileName]). |
|
244 | 1073 |
]. |
1074 |
inStream isNil ifTrue:[ |
|
3769 | 1075 |
" |
1076 |
an empty pack |
|
1077 |
" |
|
1078 |
^ self nonexistingFileRead |
|
244 | 1079 |
]. |
2996 | 1080 |
|
4093 | 1081 |
ok := self readFromResourceStream:inStream in:(inStream pathName asFilename directoryName). |
244 | 1082 |
inStream close. |
686 | 1083 |
|
244 | 1084 |
ok ifFalse:[ |
3769 | 1085 |
fileReadFailed := true. |
684 | 1086 |
|
3769 | 1087 |
('ResourcePack [warning]: ''' , inStream pathName , ''' contains error(s) - data may be incomplete.') errorPrintCR. |
244 | 1088 |
]. |
1089 |
||
4656 | 1090 |
"Modified: / 19-10-2006 / 22:46:48 / cg" |
244 | 1091 |
! |
1092 |
||
72 | 1093 |
readFromResourceStream:inStream in:dirName |
145 | 1094 |
"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
|
1095 |
specify where #include files are searched for. |
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1096 |
Return true, if the style sheet could be read without errors, false otherwise." |
145 | 1097 |
|
4058 | 1098 |
|lineString l lineNumber rest value ifLevel skipping first ok encoding decoder pack errorHandler |
1099 |
printError fileName| |
|
1100 |
||
1101 |
fileName := (inStream isFileStream |
|
1102 |
ifTrue:[inStream pathName asFilename baseName] |
|
1103 |
ifFalse:['---']). |
|
1104 |
||
1105 |
printError := [:message | |
|
1106 |
'ResourcePack [warning]: ' errorPrint. |
|
1107 |
message errorPrint. |
|
1108 |
' in file:' errorPrint. |
|
1109 |
fileName errorPrint. |
|
1110 |
' line: ' errorPrint. |
|
1111 |
lineNumber errorPrintCR |
|
1112 |
]. |
|
1113 |
||
1114 |
printError := [:message | ]. |
|
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1115 |
|
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1116 |
encoding := nil. |
0 | 1117 |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1118 |
ok := true. |
0 | 1119 |
ifLevel := 0. |
1120 |
skipping := false. |
|
4058 | 1121 |
lineNumber := 0. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1122 |
|
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1123 |
errorHandler := [:ex | |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1124 |
|con| |
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
1125 |
self halt. |
3854 | 1126 |
('ResourcePack [warning]: ''' , ex description , '''') errorPrintCR. |
4058 | 1127 |
('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
|
1128 |
con := ex suspendedContext. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1129 |
('ResourcePack [info]: in: ' , con fullPrintString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1130 |
con := con sender. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1131 |
('ResourcePack [info]: : ' , con fullPrintString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1132 |
con := con sender. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1133 |
('ResourcePack [info]: : ' , con fullPrintString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1134 |
value := nil. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1135 |
ok := false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1136 |
]. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
1137 |
|
0 | 1138 |
[inStream atEnd] whileFalse:[ |
4058 | 1139 |
lineString := inStream nextLine. lineNumber := lineNumber + 1. |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1140 |
[lineString notNil and:[lineString endsWith:$\]] whileTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1141 |
lineString := lineString copyWithoutLast:1. |
4058 | 1142 |
l := inStream nextLine. lineNumber := lineNumber + 1. |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1143 |
l notNil ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1144 |
lineString := lineString , l. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1145 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1146 |
]. |
177 | 1147 |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1148 |
(lineString size > 0) ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1149 |
first := lineString at:1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1150 |
"/ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1151 |
"/ for your convenience: treat ; AND "/ as comment-line |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1152 |
"/ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1153 |
((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ |
4332 | 1154 |
((first == $#) and:[(lineString startsWith:'#(') not]) ifTrue:[ |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1155 |
"/ a directive |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1156 |
lineString := (lineString copyFrom:2) withoutSpaces. |
72 | 1157 |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1158 |
(lineString startsWith:'if') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1159 |
skipping ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1160 |
rest := lineString copyFrom:3. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1161 |
Error |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1162 |
handle:errorHandler |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1163 |
do:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1164 |
value := Compiler evaluate:rest compile:false]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1165 |
(value == #Error) ifTrue:[ |
4058 | 1166 |
printError value:('error in resource:' , lineString). |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1167 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1168 |
(value == false) ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1169 |
skipping := true |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1170 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1171 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1172 |
ifLevel := ifLevel + 1 |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1173 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1174 |
(lineString startsWith:'endif') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1175 |
ifLevel := ifLevel - 1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1176 |
ifLevel == 0 ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1177 |
skipping := false |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1178 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1179 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1180 |
(lineString startsWith:'else') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1181 |
skipping := skipping not |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1182 |
] ifFalse:[ |
4618 | 1183 |
(lineString startsWith:'superpack') ifTrue:[ |
1184 |
rest := lineString copyFrom:('superpack' size + 1). |
|
1185 |
value := Compiler evaluate:rest compile:false. |
|
1186 |
(value isKindOf:ResourcePack) ifTrue:[ |
|
1187 |
superPack := value |
|
1188 |
] |
|
1189 |
] ifFalse:[ |
|
1190 |
skipping ifFalse:[ |
|
1191 |
(lineString startsWith:'include') ifTrue:[ |
|
1192 |
(lineString startsWith:'includeResourcesFor') ifTrue:[ |
|
1193 |
"/ include those resources ... |
|
1194 |
rest := lineString copyFrom:('includeResourcesFor' size + 1). |
|
1195 |
value := Compiler evaluate:rest compile:false. |
|
1196 |
value isBehavior ifTrue:[ |
|
1197 |
pack := self class for:value. |
|
1198 |
pack notNil ifTrue:[ |
|
1199 |
self addAll:pack. |
|
1200 |
] |
|
1201 |
] |
|
1202 |
] ifFalse:[ |
|
1203 |
rest := lineString copyFrom:('include' size + 1). |
|
1204 |
value := Compiler evaluate:rest compile:false. |
|
1205 |
value isString ifFalse:[ |
|
1206 |
printError value:('bad include filename: ' , value printString, ' "',lineString,'"'). |
|
1207 |
] ifTrue:[ |
|
1208 |
self readFromFile:value directory:dirName |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1209 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1210 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1211 |
] ifFalse:[ |
4618 | 1212 |
(lineString startsWith:'encoding') ifTrue:[ |
4619 | 1213 |
decoder notNil ifTrue:[self halt:'oops - encoding change in file']. |
4618 | 1214 |
encoding := self class extractEncodingFromLine:lineString. |
1215 |
decoder := CharacterEncoder encoderFor:encoding ifAbsent:nil. |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1216 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1217 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1218 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1219 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1220 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1221 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1222 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1223 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1224 |
skipping ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1225 |
Error |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1226 |
handle:errorHandler |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1227 |
do:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1228 |
(lineString at:1) == $!! ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1229 |
"/ evaluate the rest |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1230 |
Compiler evaluate:(lineString copyFrom:2) |
4332 | 1231 |
receiver:self |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1232 |
notifying:nil |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1233 |
compile:false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1234 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1235 |
"/ process as resource |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1236 |
self |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1237 |
processLine:lineString |
4017 | 1238 |
encoding:decoder |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1239 |
file:(inStream isFileStream |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1240 |
ifTrue:[inStream pathName] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1241 |
ifFalse:['---']) |
4058 | 1242 |
printErrorWith:printError |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1243 |
]] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1244 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1245 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1246 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
1247 |
] |
0 | 1248 |
]. |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
1249 |
^ ok |
177 | 1250 |
|
4534
d71ca6ac7cbe
handle unicode string-keys and values
Claus Gittinger <cg@exept.de>
parents:
4531
diff
changeset
|
1251 |
"Modified: / 31-08-1995 / 02:33:45 / claus" |
4619 | 1252 |
"Modified: / 18-09-2006 / 20:35:37 / cg" |
0 | 1253 |
! ! |
1254 |
||
4093 | 1255 |
!ResourcePack methodsFor:'printing & storing'! |
1256 |
||
1257 |
displayString |
|
1258 |
^ String |
|
1259 |
streamContents: |
|
1260 |
[:s | |
|
1261 |
s nextPutAll:'ResourcePack for: '. |
|
1262 |
packsClassName printOn:s |
|
1263 |
] |
|
1264 |
! ! |
|
1265 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
1266 |
!ResourcePack class methodsFor:'documentation'! |
251 | 1267 |
|
1268 |
version |
|
4670 | 1269 |
^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.120 2006-10-23 21:11:08 cg Exp $' |
251 | 1270 |
! ! |
3769 | 1271 |
|
0 | 1272 |
ResourcePack initialize! |