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