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