author | Claus Gittinger <cg@exept.de> |
Thu, 18 Feb 1999 14:42:32 +0100 | |
changeset 2461 | 3c212ae910ec |
parent 2459 | 55f57cb8551b |
child 2608 | a36fad717685 |
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 |
|
13 |
Dictionary subclass:#ResourcePack |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
14 |
instanceVariableNames:'superPack packsClassName fileReadFailed' |
308
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
15 |
classVariableNames:'Packs' |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
16 |
poolDictionaries:'' |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
17 |
category:'Interface-Support' |
0 | 18 |
! |
19 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
20 |
!ResourcePack class methodsFor:'documentation'! |
46 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
72 | 25 |
All Rights Reserved |
5 | 26 |
|
46 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
5 | 35 |
|
46 | 36 |
documentation |
37 |
" |
|
1942 | 38 |
This class supports easy customization of smalltalk code (i.e. internationalization |
39 |
and viewStyle adaption). |
|
145 | 40 |
ResourcePacks are class specific, meaning that every subclass of View |
1942 | 41 |
and ApplicationModel has an instance of ResourcePack (instVar called 'resources') |
42 |
which is created when the first instance of the view/app is created, |
|
43 |
and cached in a class-instVar (so the file is only read once). |
|
54 | 44 |
|
50 | 45 |
The resourcePack consists of a mapping from strings to values, which are |
46 |
then used in labels, buttons, menus etc. |
|
47 |
The resourcePack initializes itself from a file found in 'resources/<className>.rs', |
|
48 |
where 'className' is built by the usual abbreviation mechanism (see abbrev-files). |
|
1942 | 49 |
|
50 | 50 |
Conditional mappings are possible, by including lines as: |
2314 | 51 |
#if <expression> |
52 |
#endif |
|
50 | 53 |
in the resourcefile. Example: |
54 |
file 'foo.rs': |
|
2314 | 55 |
#if Language == #german |
56 |
'abort' 'Abbruch' |
|
57 |
#endif |
|
58 |
#if Language == #french |
|
59 |
'abort' 'canceller' |
|
60 |
#endif |
|
145 | 61 |
|
62 |
the corresponding resource-strings are accessed (from methods within the class) |
|
63 |
using: |
|
2314 | 64 |
resources string:'abort' |
145 | 65 |
|
54 | 66 |
returning the mapped string (i.e. 'Abbruch' if the global Language is set |
67 |
to #german).. |
|
145 | 68 |
|
1942 | 69 |
If no corresponding entry is found in the resources, the key is returned; |
70 |
alternatively, use: |
|
2314 | 71 |
resources string:'foo' default:'bar' |
1942 | 72 |
which returns 'bar', if no resource definition for 'foo' is found. |
73 |
||
54 | 74 |
Translations can also include arguments, such as: |
2314 | 75 |
resources string:'really delete %1' with:fileName |
145 | 76 |
|
77 |
This scheme has the advantage, that you can write your programs using your |
|
78 |
native language strings. Later, when new languages are to be supported, |
|
79 |
simply create a resource file for the class and add translations for |
|
80 |
all those strings. (find the keys by looking at users of resource or senders |
|
1942 | 81 |
of 'string:*'). |
82 |
Notice, that the grammar of different languages may imply a reordering, |
|
83 |
so the above string becomes the german 'wollen Sie %1 wirklich löschen'; |
|
84 |
so using percent-placeholders is much better than simple concatenations of |
|
85 |
arguments to the question. |
|
145 | 86 |
|
87 |
More languages can be added later without any change in the code, |
|
88 |
recompilation or the like. |
|
89 |
Even by people without access to the source code i.e. which only have the |
|
90 |
applications binary. |
|
91 |
||
92 |
Also, unsupported languages' strings are simply left unchanged - if you |
|
93 |
write your application in (say) english, and only plan to use it in english, |
|
94 |
no additional work is required (i.e you dont need a resource file then). |
|
95 |
Strings for unknown languages will come in english |
|
96 |
(which is better than nothing or empty button labels ;-) |
|
97 |
||
98 |
Summary: |
|
2314 | 99 |
in subclasses of View and ApplicationModel, |
100 |
instead of writing: |
|
145 | 101 |
|
2314 | 102 |
... |
103 |
b := Button label:'press me' |
|
104 |
... |
|
145 | 105 |
|
2314 | 106 |
always write: |
612 | 107 |
|
2314 | 108 |
... |
109 |
b := Button label:(resources string:'press me') |
|
110 |
... |
|
145 | 111 |
|
2314 | 112 |
if your class is not a subclass of one of the above, AND you need |
113 |
resource translations, you wont inherit the resources variable |
|
114 |
(which is automatically initialized). |
|
115 |
In this case, you have to ask the ResourcePack class explicitely for |
|
116 |
a corresponding package: |
|
145 | 117 |
|
2314 | 118 |
ResourcePack for:aClassName |
145 | 119 |
|
2314 | 120 |
as an example, see how the Date class gets the national names of |
121 |
week & monthnames. |
|
145 | 122 |
|
612 | 123 |
[author:] |
2314 | 124 |
Claus Gittinger |
145 | 125 |
" |
126 |
! |
|
127 |
||
128 |
examples |
|
129 |
" |
|
130 |
normally, resources are found in files named after their classes sourcefile |
|
131 |
For example, the FileBrowsers resources are found in 'FBrowser.rs'. |
|
132 |
For the examples below, we process resources from a constant string; |
|
2314 | 133 |
this is NOT representative. |
134 |
[exBegin] |
|
135 |
|stream res| |
|
145 | 136 |
|
2314 | 137 |
stream := ReadStream on:' |
145 | 138 |
foo ''the translation for foo'' |
139 |
#if Language == #german |
|
140 |
bar ''die deutsche uebersetzung von bar'' |
|
141 |
baz ''baz hat den Wert %1'' |
|
142 |
#endif |
|
143 |
#if Language == #french |
|
144 |
bar ''bar en francaise'' |
|
145 |
baz ''%1, c''''est baz'' |
|
146 |
#endif |
|
147 |
||
148 |
'. |
|
149 |
||
2314 | 150 |
res := ResourcePack new readFromResourceStream:stream in:nil. |
145 | 151 |
|
2314 | 152 |
Transcript showCR:'baz is translated to: ' , (res string:'baz' with:'1234'). |
153 |
Transcript showCR:'bar is translated to: ' , (res string:'bar'). |
|
154 |
Transcript showCR:'foo is translated to: ' , (res string:'foo'). |
|
155 |
Transcript showCR:'fooBar is translated to: ' , (res string:'fooBar'). |
|
156 |
[exEnd] |
|
145 | 157 |
set the Language to french: |
2314 | 158 |
[exBegin] |
159 |
Language := #french |
|
160 |
[exEnd] |
|
145 | 161 |
and repeat the above. |
620 | 162 |
back to english: |
2314 | 163 |
[exBegin] |
164 |
Language := #english |
|
165 |
[exEnd] |
|
620 | 166 |
back to german: |
2314 | 167 |
[exBegin] |
168 |
Language := #german |
|
169 |
[exEnd] |
|
46 | 170 |
" |
171 |
! ! |
|
5 | 172 |
|
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
173 |
!ResourcePack class methodsFor:'initialization'! |
0 | 174 |
|
72 | 175 |
flushCachedResourcePacks |
24 | 176 |
"forget all cached resources - needed after a style change" |
177 |
||
178 |
Packs := nil. |
|
179 |
self initialize |
|
180 |
||
72 | 181 |
"ResourcePack flushCachedResourcePacks" |
244 | 182 |
! |
183 |
||
184 |
initialize |
|
185 |
Packs isNil ifTrue:[ |
|
186 |
Packs := WeakArray new:30 |
|
187 |
]. |
|
188 |
||
189 |
"ResourcePack initialize" |
|
190 |
! ! |
|
191 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
192 |
!ResourcePack class methodsFor:'instance creation'! |
244 | 193 |
|
194 |
for:aClass |
|
195 |
"get the full resource definitions for aClass (i.e. with super packs). |
|
196 |
Also leave the resulting pack in the cache for faster access next time." |
|
197 |
||
198 |
|nm pack superPack| |
|
199 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
200 |
nm := aClass resourcePackName. |
244 | 201 |
pack := self searchCacheFor:nm. |
202 |
pack notNil ifTrue:[^ pack]. |
|
203 |
||
204 |
pack := self fromFile:(Smalltalk fileNameForClass:nm) , '.rs'. |
|
205 |
aClass == Object ifFalse:[ |
|
2314 | 206 |
pack superPack:(self for:(aClass superclass)). |
244 | 207 |
]. |
208 |
pack packsClassName:nm. |
|
209 |
self addToCache:pack. |
|
210 |
^ pack |
|
211 |
||
212 |
" |
|
213 |
ResourcePack for:TextView |
|
214 |
ResourcePack for:CodeView |
|
215 |
ResourcePack for:Workspace |
|
216 |
Workspace classResources |
|
217 |
" |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
218 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
219 |
"Modified: / 29.1.1998 / 22:42:53 / cg" |
244 | 220 |
! |
221 |
||
222 |
fromFile:aFileName |
|
223 |
"get the resource definitions from a file in the default directory. |
|
224 |
Uncached low-level entry." |
|
225 |
||
226 |
^ self fromFile:aFileName directory:'resources' |
|
227 |
||
228 |
" |
|
229 |
ResourcePack fromFile:'SBrowser.rs' |
|
230 |
ResourcePack fromFile:'FBrowser.rs' |
|
231 |
ResourcePack fromFile:'Smalltalk.rs' |
|
232 |
" |
|
233 |
! |
|
234 |
||
235 |
fromFile:aFileName directory:dirName |
|
236 |
"get the resource definitions from a file in a directory. |
|
237 |
Uncached low-level entry." |
|
238 |
||
239 |
|newPack| |
|
240 |
||
241 |
newPack := self new. |
|
242 |
newPack readFromFile:aFileName directory:dirName. |
|
243 |
^ newPack |
|
0 | 244 |
! ! |
245 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
246 |
!ResourcePack class methodsFor:'private'! |
54 | 247 |
|
248 |
addToCache:aPack |
|
249 |
|idx| |
|
0 | 250 |
|
54 | 251 |
idx := Packs identityIndexOf:nil. |
252 |
idx == 0 ifTrue:[ |
|
1078
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
253 |
idx := Packs identityIndexOf:0 |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
254 |
]. |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
255 |
idx == 0 ifTrue:[ |
72 | 256 |
" |
257 |
throw away oldest |
|
258 |
" |
|
259 |
idx := Packs size. |
|
260 |
Packs replaceFrom:1 to:idx-1 with:Packs startingAt:2. |
|
54 | 261 |
]. |
262 |
Packs at:idx put:aPack |
|
263 |
! |
|
0 | 264 |
|
54 | 265 |
searchCacheFor:aClassname |
998 | 266 |
|sz "{ Class: SmallInteger }" | |
0 | 267 |
|
24 | 268 |
Packs isNil ifTrue:[ |
72 | 269 |
self initialize. |
270 |
^ nil |
|
0 | 271 |
]. |
54 | 272 |
|
273 |
sz := Packs size. |
|
274 |
1 to:sz do:[:idx | |
|
72 | 275 |
|aPack| |
54 | 276 |
|
72 | 277 |
aPack := Packs at:idx. |
1078
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
278 |
(aPack notNil |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
279 |
and:[aPack ~~ 0]) ifTrue:[ |
72 | 280 |
aClassname = aPack packsClassName ifTrue:[ |
281 |
" |
|
282 |
bring to end for LRU |
|
283 |
" |
|
284 |
Packs replaceFrom:idx to:sz-1 with:Packs startingAt:idx+1. |
|
285 |
Packs at:sz put:aPack. |
|
286 |
^ aPack |
|
287 |
] |
|
288 |
] |
|
0 | 289 |
]. |
54 | 290 |
^ nil |
123 | 291 |
|
292 |
" |
|
293 |
ResourcePack searchCacheFor:'TextView' |
|
294 |
" |
|
54 | 295 |
! ! |
296 |
||
0 | 297 |
!ResourcePack methodsFor:'accessing'! |
298 |
||
244 | 299 |
array:anArray |
300 |
"translate a collection of strings" |
|
0 | 301 |
|
244 | 302 |
^ anArray collect:[:r | self at:r default:r] |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
303 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
304 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
305 |
Launcher classResources array:#('file' 'classes') |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
306 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
307 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
308 |
"Modified: / 29.1.1998 / 22:44:22 / cg" |
0 | 309 |
! |
310 |
||
2 | 311 |
at:aKey |
123 | 312 |
"translate a string" |
313 |
||
72 | 314 |
^ self at:aKey ifAbsent:aKey |
0 | 315 |
! |
316 |
||
317 |
at:aKey default:default |
|
123 | 318 |
"translate a string" |
319 |
||
72 | 320 |
^ self at:aKey ifAbsent:default |
0 | 321 |
! |
322 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
323 |
at:aKey ifAbsent:defaultValue |
123 | 324 |
"translate a string" |
325 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
326 |
|val| |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
327 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
328 |
aKey notNil ifTrue:[ |
2314 | 329 |
val := super at:aKey ifAbsent:nil. |
330 |
val notNil ifTrue:[^ val]. |
|
331 |
superPack notNil ifTrue:[ |
|
332 |
^ superPack at:aKey ifAbsent:defaultValue |
|
333 |
]. |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
334 |
]. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
335 |
^ defaultValue value |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
336 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
337 |
"Modified: / 29.1.1998 / 22:38:15 / cg" |
2 | 338 |
! |
339 |
||
340 |
name:aKey default:default |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
341 |
"translate a string. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
342 |
Obsolete - use #string:default:" |
123 | 343 |
|
72 | 344 |
^ self at:aKey ifAbsent:default |
2 | 345 |
! |
346 |
||
0 | 347 |
string:s |
123 | 348 |
"translate a string" |
349 |
||
72 | 350 |
^ self at:s ifAbsent:s |
0 | 351 |
! |
352 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
353 |
string:s default:defaultString |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
354 |
"translate a string" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
355 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
356 |
^ self at:s ifAbsent:defaultString |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
357 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
358 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
359 |
string:s default:defaultString with:arg |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
360 |
"translate and expand arg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
361 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
362 |
^ self string:s default:defaultString withArgs:(Array with:arg) |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
363 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
364 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
365 |
string:s default:defaultString with:arg1 with:arg2 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
366 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
367 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
368 |
^ 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
|
369 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
370 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
371 |
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
|
372 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
373 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
374 |
^ 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
|
375 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
376 |
"Created: 9.12.1995 / 19:08:50 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
377 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
378 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
379 |
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
|
380 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
381 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
382 |
^ 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
|
383 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
384 |
"Created: 9.9.1996 / 18:52:14 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
385 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
386 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
387 |
string:s default:defaultString withArgs:argArray |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
388 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
389 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
390 |
|template| |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
391 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
392 |
template := self at:s ifAbsent:defaultString. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
393 |
^ template expandPlaceholdersWith:argArray |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
394 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
395 |
|
0 | 396 |
string:s with:arg |
123 | 397 |
"translate and expand arg" |
398 |
||
0 | 399 |
^ self string:s withArgs:(Array with:arg) |
400 |
! |
|
401 |
||
402 |
string:s with:arg1 with:arg2 |
|
123 | 403 |
"translate and expand args" |
404 |
||
0 | 405 |
^ self string:s withArgs:(Array with:arg1 with:arg2) |
406 |
! |
|
407 |
||
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
408 |
string:s with:arg1 with:arg2 with:arg3 |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
409 |
"translate and expand args" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
410 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
411 |
^ 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
|
412 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
413 |
"Created: 9.12.1995 / 19:08:50 / cg" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
414 |
! |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
415 |
|
1042 | 416 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 |
417 |
"translate and expand args" |
|
418 |
||
419 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
420 |
||
421 |
"Created: 9.9.1996 / 18:52:14 / cg" |
|
422 |
! |
|
423 |
||
0 | 424 |
string:s withArgs:argArray |
123 | 425 |
"translate and expand args" |
426 |
||
135 | 427 |
|template| |
0 | 428 |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
429 |
template := self at:s ifAbsent:s. |
135 | 430 |
^ template expandPlaceholdersWith:argArray |
0 | 431 |
! ! |
432 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
433 |
!ResourcePack methodsFor:'accessing - internels'! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
434 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
435 |
name:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
436 |
"translate a string" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
437 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
438 |
^ self at:aKey ifAbsent:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
439 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
440 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
441 |
packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
442 |
^ packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
443 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
444 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
445 |
packsClassName:aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
446 |
packsClassName := aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
447 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
448 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
449 |
superPack:anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
450 |
superPack := anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
451 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
452 |
"Created: / 29.1.1998 / 22:43:09 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
453 |
! ! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
454 |
|
0 | 455 |
!ResourcePack methodsFor:'file reading'! |
456 |
||
684 | 457 |
fileReadFailed |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
458 |
"return true, if the pack does not really contain |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
459 |
valid translations, since the fileRead failed. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
460 |
However, all inherited translations are still available |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
461 |
through the receiver" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
462 |
|
687 | 463 |
^ fileReadFailed ~~ false |
684 | 464 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
465 |
"Created: / 14.5.1996 / 10:19:26 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
466 |
"Modified: / 29.1.1998 / 22:46:38 / cg" |
684 | 467 |
! |
468 |
||
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
469 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
470 |
"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
|
471 |
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
|
472 |
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
|
473 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
474 |
^ nil |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
475 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
476 |
"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
|
477 |
! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
478 |
|
2291
eaac1c5f2a61
show fileName if a line has error.
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
479 |
processLine:aLine encoding:encoding file:fileName |
145 | 480 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
481 |
||
2314 | 482 |
|lineString name stream l rest macroName value |
483 |
conditional hasError| |
|
144 | 484 |
|
145 | 485 |
lineString := aLine withoutSeparators. |
144 | 486 |
name := nil. |
487 |
(lineString at:1) == $' ifTrue:[ |
|
2314 | 488 |
stream := ReadStream on:lineString. |
489 |
stream signalAtEnd:false. |
|
490 |
name := String |
|
491 |
readFrom:stream |
|
492 |
onError:[('ResourcePack [warning]: invalid line <' |
|
493 |
,lineString |
|
494 |
,'> in file:' |
|
495 |
, fileName |
|
496 |
) errorPrintCR. nil]. |
|
158 | 497 |
"/ OLD: l := stream position |
2314 | 498 |
l := stream position + 1. |
144 | 499 |
|
500 |
"/ l := lineString indexOf:$' startingAt:2. |
|
501 |
"/ l ~~ 0 ifTrue:[ |
|
502 |
"/ name := (lineString copyFrom:2 to:l-1). |
|
503 |
"/ l := l + 1 |
|
504 |
"/ ] |
|
505 |
] ifFalse:[ |
|
2314 | 506 |
l := lineString indexOfSeparatorStartingAt:1. |
507 |
l ~~ 0 ifTrue:[ |
|
508 |
name := lineString copyFrom:1 to:l-1. |
|
509 |
] |
|
144 | 510 |
]. |
511 |
name notNil ifTrue:[ |
|
2314 | 512 |
hasError := false. |
2153 | 513 |
|
2314 | 514 |
rest := (lineString copyFrom:l) withoutSeparators. |
515 |
" |
|
516 |
skip <type> if present |
|
517 |
" |
|
518 |
(rest startsWith:$<) ifTrue:[ |
|
519 |
l := lineString indexOf:$> startingAt:l. |
|
520 |
rest := (lineString copyFrom:l+1) withoutSeparators. |
|
521 |
]. |
|
2153 | 522 |
|
2314 | 523 |
conditional := false. |
524 |
(rest startsWith:$?) ifTrue:[ |
|
525 |
rest := (rest copyFrom:2) withoutSeparators. |
|
526 |
conditional := true. |
|
527 |
]. |
|
2153 | 528 |
|
2314 | 529 |
(rest startsWith:$=) ifTrue:[ |
530 |
rest := rest copyFrom:2. |
|
531 |
stream := ReadStream on:rest. |
|
532 |
macroName := stream nextAlphaNumericWord. |
|
533 |
[stream peek == $.] whileTrue:[ |
|
534 |
stream next. |
|
535 |
stream peek notNil ifTrue:[ |
|
536 |
macroName := macroName , '.' , (stream nextAlphaNumericWord) |
|
537 |
] |
|
538 |
]. |
|
539 |
rest := stream upToEnd. |
|
540 |
value := self at:macroName ifAbsent:nil. |
|
541 |
(value isNil) ifTrue:[ |
|
542 |
hasError := true. |
|
543 |
('ResourcePack [warning]: bad =-macro in line: ' , lineString) errorPrintCR. |
|
544 |
]. |
|
545 |
||
546 |
value := Compiler evaluate:('self ' , rest) |
|
547 |
receiver:value |
|
548 |
notifying:nil |
|
549 |
compile:false. |
|
550 |
(value == #Error) ifTrue:[ |
|
551 |
hasError := true. |
|
552 |
('ResourcePack [warning]: error in line: "self ' , rest , '"') errorPrintCR. |
|
553 |
] |
|
554 |
] ifFalse:[ |
|
555 |
value := Compiler evaluate:rest compile:false. |
|
556 |
(value == #Error) ifTrue:[ |
|
557 |
hasError := true. |
|
558 |
('ResourcePack [warning]: error in line: "' , rest , '"') errorPrintCR. |
|
559 |
] ifFalse:[ |
|
560 |
encoding notNil ifTrue:[ |
|
561 |
value isString ifTrue:[ |
|
562 |
value := value decodeFrom:encoding |
|
563 |
] |
|
564 |
] |
|
565 |
] |
|
566 |
]. |
|
567 |
hasError ifFalse:[ |
|
568 |
(conditional not |
|
569 |
or:[(self includesKey:name) not]) ifTrue:[ |
|
570 |
self at:name put:value. |
|
571 |
] |
|
572 |
] |
|
144 | 573 |
] |
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
574 |
|
2291
eaac1c5f2a61
show fileName if a line has error.
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
575 |
"Modified: / 30.8.1998 / 12:33:22 / cg" |
eaac1c5f2a61
show fileName if a line has error.
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
576 |
"Created: / 30.8.1998 / 12:35:37 / cg" |
144 | 577 |
! |
578 |
||
244 | 579 |
readFromFile:fileName directory:dirName |
580 |
"read definitions from a file in a directory" |
|
581 |
||
582 |
|inStream ok| |
|
583 |
||
686 | 584 |
fileReadFailed := false. |
244 | 585 |
dirName = 'resources' ifTrue:[ |
2314 | 586 |
inStream := Smalltalk resourceFileStreamFor:fileName |
244 | 587 |
] ifFalse:[ |
2314 | 588 |
inStream := Smalltalk systemFileStreamFor:(dirName , '/' , fileName). |
244 | 589 |
]. |
590 |
inStream isNil ifTrue:[ |
|
2314 | 591 |
" |
592 |
an empty pack |
|
593 |
" |
|
594 |
^ self nonexistingFileRead |
|
244 | 595 |
]. |
596 |
ok := self readFromResourceStream:inStream in:dirName. |
|
597 |
inStream close. |
|
686 | 598 |
|
244 | 599 |
ok ifFalse:[ |
2314 | 600 |
fileReadFailed := true. |
684 | 601 |
|
2314 | 602 |
('ResourcePack [warning]: ''' , fileName , ''' contains error(s) - data may be incomplete.') errorPrintCR. |
244 | 603 |
]. |
604 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
605 |
"Modified: 10.1.1997 / 18:05:17 / cg" |
244 | 606 |
! |
607 |
||
72 | 608 |
readFromResourceStream:inStream in:dirName |
145 | 609 |
"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
|
610 |
specify where #include files are searched for. |
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
611 |
Return true, if the style sheet could be read without errors, false otherwise." |
145 | 612 |
|
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
613 |
|lineString l lNo rest value ifLevel skipping first ok encoding| |
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
614 |
|
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
615 |
encoding := nil. |
0 | 616 |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
617 |
ok := true. |
0 | 618 |
ifLevel := 0. |
619 |
skipping := false. |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
620 |
lNo := 0. |
0 | 621 |
[inStream atEnd] whileFalse:[ |
2459
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
622 |
lineString := inStream nextLine. lNo := lNo + 1. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
623 |
[lineString notNil and:[lineString endsWith:$\]] whileTrue:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
624 |
lineString := lineString copyWithoutLast:1. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
625 |
l := inStream nextLine. lNo := lNo + 1. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
626 |
l notNil ifTrue:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
627 |
lineString := lineString , l. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
628 |
]. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
629 |
]. |
177 | 630 |
|
2459
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
631 |
(lineString size > 0) ifTrue:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
632 |
first := lineString at:1. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
633 |
"/ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
634 |
"/ for your convenience: treat ; AND "/ as comment-line |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
635 |
"/ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
636 |
((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
637 |
first == $# ifTrue:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
638 |
lineString := (lineString copyFrom:2) withoutSpaces. |
72 | 639 |
|
2459
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
640 |
(lineString startsWith:'if') ifTrue:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
641 |
skipping ifFalse:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
642 |
rest := lineString copyFrom:3. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
643 |
value := Compiler evaluate:rest compile:false. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
644 |
(value == #Error) ifTrue:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
645 |
('ResourcePack [warning]: error in resource:' , lineString) errorPrintCR. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
646 |
]. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
647 |
(value == false) ifTrue:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
648 |
skipping := true |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
649 |
] |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
650 |
]. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
651 |
ifLevel := ifLevel + 1 |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
652 |
] ifFalse:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
653 |
(lineString startsWith:'endif') ifTrue:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
654 |
ifLevel := ifLevel - 1. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
655 |
ifLevel == 0 ifTrue:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
656 |
skipping := false |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
657 |
] |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
658 |
] ifFalse:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
659 |
(lineString startsWith:'else') ifTrue:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
660 |
skipping := skipping not |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
661 |
] ifFalse:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
662 |
skipping ifFalse:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
663 |
(lineString startsWith:'include') ifTrue:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
664 |
rest := lineString copyFrom:8. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
665 |
value := Compiler evaluate:rest compile:false. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
666 |
value isString ifFalse:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
667 |
('ResourcePack [warning]: bad include filename: ' , value printString) errorPrintCR. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
668 |
('ResourcePack [info]: line ' , lNo printString , ': ''' , lineString , '''') infoPrintCR. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
669 |
] ifTrue:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
670 |
self readFromFile:value directory:dirName |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
671 |
] |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
672 |
] ifFalse:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
673 |
(lineString startsWith:'encoding') ifTrue:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
674 |
rest := lineString copyFrom:9. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
675 |
encoding := rest withoutSeparators asSymbol |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
676 |
] |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
677 |
] |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
678 |
] |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
679 |
] |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
680 |
] |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
681 |
]. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
682 |
] ifFalse:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
683 |
skipping ifFalse:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
684 |
ErrorSignal handle:[:ex | |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
685 |
('ResourcePack [warning]: ''' , ex errorString , '''') errorPrintCR. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
686 |
('ResourcePack [info]: line ' , lNo printString , ': ''' , lineString , '''') infoPrintCR. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
687 |
ok := false. |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
688 |
] do:[ |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
689 |
self |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
690 |
processLine:lineString |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
691 |
encoding:encoding |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
692 |
file:(inStream isFileStream |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
693 |
ifTrue:[inStream pathName] |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
694 |
ifFalse:['---']) |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
695 |
] |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
696 |
] |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
697 |
] |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
698 |
] |
55f57cb8551b
(notNil and:[isEmpty not]) -> (size > 0)
Claus Gittinger <cg@exept.de>
parents:
2314
diff
changeset
|
699 |
] |
0 | 700 |
]. |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
701 |
^ ok |
177 | 702 |
|
2291
eaac1c5f2a61
show fileName if a line has error.
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
703 |
"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
|
704 |
"Modified: / 30.8.1998 / 12:35:24 / cg" |
0 | 705 |
! ! |
706 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
707 |
!ResourcePack class methodsFor:'documentation'! |
251 | 708 |
|
709 |
version |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
710 |
^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.50 1999-02-18 13:42:32 cg Exp $' |
251 | 711 |
! ! |
0 | 712 |
ResourcePack initialize! |