author | Claus Gittinger <cg@exept.de> |
Mon, 19 Feb 1996 23:59:33 +0100 | |
changeset 426 | 7f0f723980e2 |
parent 308 | 54fa63d274fa |
child 444 | 1f67d369190d |
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 |
|
308
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
14 |
instanceVariableNames:'elements dependents packsClassName' |
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 |
||
46 | 20 |
!ResourcePack class methodsFor:'documentation'! |
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 |
" |
|
38 |
to allow easy customization of smalltalk code (i.e. internationalization) |
|
50 | 39 |
(replaces the obsolete Resource class). |
145 | 40 |
ResourcePacks are class specific, meaning that every subclass of View |
41 |
and ApplicationModel has an instance of ResourcePack (called resources) |
|
42 |
which is created when the first instance of the view is created. |
|
54 | 43 |
|
50 | 44 |
The resourcePack consists of a mapping from strings to values, which are |
45 |
then used in labels, buttons, menus etc. |
|
46 |
The resourcePack initializes itself from a file found in 'resources/<className>.rs', |
|
47 |
where 'className' is built by the usual abbreviation mechanism (see abbrev-files). |
|
48 |
Conditional mappings are possible, by including lines as: |
|
72 | 49 |
#if <expression> |
50 |
#endif |
|
50 | 51 |
in the resourcefile. Example: |
52 |
file 'foo.rs': |
|
72 | 53 |
#if Language == #german |
54 |
'abort' 'Abbruch' |
|
55 |
#endif |
|
56 |
#if Language == #french |
|
57 |
'abort' 'canceller' |
|
58 |
#endif |
|
145 | 59 |
|
60 |
the corresponding resource-strings are accessed (from methods within the class) |
|
61 |
using: |
|
62 |
||
72 | 63 |
resource string:'abort' |
145 | 64 |
|
54 | 65 |
returning the mapped string (i.e. 'Abbruch' if the global Language is set |
66 |
to #german).. |
|
145 | 67 |
|
54 | 68 |
If no corresponding entry is found in the resources, the key is returned. |
69 |
Translations can also include arguments, such as: |
|
72 | 70 |
resources string:'really delete %1' with:fileName |
145 | 71 |
|
72 |
This scheme has the advantage, that you can write your programs using your |
|
73 |
native language strings. Later, when new languages are to be supported, |
|
74 |
simply create a resource file for the class and add translations for |
|
75 |
all those strings. (find the keys by looking at users of resource or senders |
|
76 |
of 'string:*'. |
|
77 |
||
78 |
More languages can be added later without any change in the code, |
|
79 |
recompilation or the like. |
|
80 |
Even by people without access to the source code i.e. which only have the |
|
81 |
applications binary. |
|
82 |
||
83 |
Also, unsupported languages' strings are simply left unchanged - if you |
|
84 |
write your application in (say) english, and only plan to use it in english, |
|
85 |
no additional work is required (i.e you dont need a resource file then). |
|
86 |
Strings for unknown languages will come in english |
|
87 |
(which is better than nothing or empty button labels ;-) |
|
88 |
||
89 |
Summary: |
|
90 |
in subclasses of View and ApplicationModel, |
|
91 |
instead of writing: |
|
92 |
||
93 |
... |
|
94 |
b := Button label:'press me' |
|
95 |
... |
|
96 |
||
97 |
always write: |
|
98 |
||
99 |
... |
|
100 |
b := Button label:(resources string:'press me') |
|
101 |
... |
|
102 |
||
103 |
if your class is not a subclass of one of the above, AND you need |
|
104 |
resource translations, you wont inherit the resources variable |
|
105 |
(which is automatically initialized). |
|
106 |
In this case, you have to ask the ResourcePack class explicitely for |
|
107 |
a corresponding package: |
|
108 |
||
109 |
ResourcePack for:aClassName |
|
110 |
||
111 |
as an example, see how the Date class gets the national names of |
|
112 |
week & monthnames. |
|
113 |
" |
|
114 |
! |
|
115 |
||
116 |
examples |
|
117 |
" |
|
118 |
normally, resources are found in files named after their classes sourcefile |
|
119 |
For example, the FileBrowsers resources are found in 'FBrowser.rs'. |
|
120 |
For the examples below, we process resources from a constant string; |
|
121 |
this is NOT representative. |
|
122 |
||
123 |
|stream res| |
|
124 |
||
125 |
stream := ReadStream on:' |
|
126 |
foo ''the translation for foo'' |
|
127 |
#if Language == #german |
|
128 |
bar ''die deutsche uebersetzung von bar'' |
|
129 |
baz ''baz hat den Wert %1'' |
|
130 |
#endif |
|
131 |
#if Language == #french |
|
132 |
bar ''bar en francaise'' |
|
133 |
baz ''%1, c''''est baz'' |
|
134 |
#endif |
|
135 |
||
136 |
'. |
|
137 |
||
138 |
res := ResourcePack new readFromResourceStream:stream in:nil. |
|
139 |
||
140 |
Transcript showCr:'baz is translated to: ' , (res string:'baz' with:'1234'). |
|
141 |
Transcript showCr:'bar is translated to: ' , (res string:'bar'). |
|
142 |
Transcript showCr:'foo is translated to: ' , (res string:'foo'). |
|
143 |
Transcript showCr:'fooBar is translated to: ' , (res string:'fooBar'). |
|
144 |
||
145 |
set the Language to french: |
|
146 |
||
147 |
Language := #french |
|
148 |
||
149 |
and repeat the above. |
|
150 |
||
151 |
Language := #english |
|
152 |
Language := #german |
|
46 | 153 |
" |
154 |
! ! |
|
5 | 155 |
|
0 | 156 |
!ResourcePack class methodsFor:'initialization'! |
157 |
||
72 | 158 |
flushCachedResourcePacks |
24 | 159 |
"forget all cached resources - needed after a style change" |
160 |
||
161 |
Packs := nil. |
|
162 |
self initialize |
|
163 |
||
72 | 164 |
"ResourcePack flushCachedResourcePacks" |
244 | 165 |
! |
166 |
||
167 |
initialize |
|
168 |
Packs isNil ifTrue:[ |
|
169 |
Packs := WeakArray new:30 |
|
170 |
]. |
|
171 |
||
172 |
"ResourcePack initialize" |
|
173 |
! ! |
|
174 |
||
175 |
!ResourcePack class methodsFor:'instance creation'! |
|
176 |
||
177 |
for:aClass |
|
178 |
"get the full resource definitions for aClass (i.e. with super packs). |
|
179 |
Also leave the resulting pack in the cache for faster access next time." |
|
180 |
||
181 |
|nm pack superPack| |
|
182 |
||
183 |
nm := aClass name. |
|
184 |
pack := self searchCacheFor:nm. |
|
185 |
pack notNil ifTrue:[^ pack]. |
|
186 |
||
187 |
pack := self fromFile:(Smalltalk fileNameForClass:nm) , '.rs'. |
|
188 |
aClass == Object ifFalse:[ |
|
189 |
superPack := self for:(aClass superclass). |
|
190 |
pack := pack merge:superPack |
|
191 |
]. |
|
192 |
pack packsClassName:nm. |
|
193 |
self addToCache:pack. |
|
194 |
^ pack |
|
195 |
||
196 |
" |
|
197 |
ResourcePack for:TextView |
|
198 |
ResourcePack for:CodeView |
|
199 |
ResourcePack for:Workspace |
|
200 |
Workspace classResources |
|
201 |
" |
|
202 |
! |
|
203 |
||
204 |
fromFile:aFileName |
|
205 |
"get the resource definitions from a file in the default directory. |
|
206 |
Uncached low-level entry." |
|
207 |
||
208 |
^ self fromFile:aFileName directory:'resources' |
|
209 |
||
210 |
" |
|
211 |
ResourcePack fromFile:'SBrowser.rs' |
|
212 |
ResourcePack fromFile:'FBrowser.rs' |
|
213 |
ResourcePack fromFile:'Smalltalk.rs' |
|
214 |
" |
|
215 |
! |
|
216 |
||
217 |
fromFile:aFileName directory:dirName |
|
218 |
"get the resource definitions from a file in a directory. |
|
219 |
Uncached low-level entry." |
|
220 |
||
221 |
|newPack| |
|
222 |
||
223 |
newPack := self new. |
|
224 |
newPack readFromFile:aFileName directory:dirName. |
|
225 |
^ newPack |
|
0 | 226 |
! ! |
227 |
||
54 | 228 |
!ResourcePack class methodsFor:'private'! |
229 |
||
230 |
addToCache:aPack |
|
231 |
|idx| |
|
0 | 232 |
|
54 | 233 |
idx := Packs identityIndexOf:nil. |
234 |
idx == 0 ifTrue:[ |
|
72 | 235 |
" |
236 |
throw away oldest |
|
237 |
" |
|
238 |
idx := Packs size. |
|
239 |
Packs replaceFrom:1 to:idx-1 with:Packs startingAt:2. |
|
54 | 240 |
]. |
241 |
Packs at:idx put:aPack |
|
242 |
! |
|
0 | 243 |
|
54 | 244 |
searchCacheFor:aClassname |
245 |
|sz| |
|
0 | 246 |
|
24 | 247 |
Packs isNil ifTrue:[ |
72 | 248 |
self initialize. |
249 |
^ nil |
|
0 | 250 |
]. |
54 | 251 |
|
252 |
sz := Packs size. |
|
253 |
1 to:sz do:[:idx | |
|
72 | 254 |
|aPack| |
54 | 255 |
|
72 | 256 |
aPack := Packs at:idx. |
257 |
aPack notNil ifTrue:[ |
|
258 |
aClassname = aPack packsClassName ifTrue:[ |
|
259 |
" |
|
260 |
bring to end for LRU |
|
261 |
" |
|
262 |
Packs replaceFrom:idx to:sz-1 with:Packs startingAt:idx+1. |
|
263 |
Packs at:sz put:aPack. |
|
264 |
^ aPack |
|
265 |
] |
|
266 |
] |
|
0 | 267 |
]. |
54 | 268 |
^ nil |
123 | 269 |
|
270 |
" |
|
271 |
ResourcePack searchCacheFor:'TextView' |
|
272 |
" |
|
54 | 273 |
! ! |
274 |
||
0 | 275 |
!ResourcePack methodsFor:'accessing'! |
276 |
||
244 | 277 |
array:anArray |
278 |
"translate a collection of strings" |
|
0 | 279 |
|
244 | 280 |
^ anArray collect:[:r | self at:r default:r] |
0 | 281 |
! |
282 |
||
2 | 283 |
at:aKey |
123 | 284 |
"translate a string" |
285 |
||
72 | 286 |
^ self at:aKey ifAbsent:aKey |
0 | 287 |
! |
288 |
||
289 |
at:aKey default:default |
|
123 | 290 |
"translate a string" |
291 |
||
72 | 292 |
^ self at:aKey ifAbsent:default |
0 | 293 |
! |
294 |
||
244 | 295 |
dependents |
296 |
^ dependents |
|
297 |
! |
|
298 |
||
299 |
dependents:aCollection |
|
300 |
dependents := aCollection |
|
301 |
! |
|
302 |
||
2 | 303 |
name:aKey |
123 | 304 |
"translate a string" |
305 |
||
72 | 306 |
^ self at:aKey ifAbsent:aKey |
2 | 307 |
! |
308 |
||
309 |
name:aKey default:default |
|
123 | 310 |
"translate a string" |
311 |
||
72 | 312 |
^ self at:aKey ifAbsent:default |
2 | 313 |
! |
314 |
||
244 | 315 |
packsClassName |
316 |
^ packsClassName |
|
317 |
! |
|
123 | 318 |
|
244 | 319 |
packsClassName:aString |
320 |
packsClassName := aString |
|
0 | 321 |
! |
322 |
||
323 |
string:s |
|
123 | 324 |
"translate a string" |
325 |
||
72 | 326 |
^ self at:s ifAbsent:s |
0 | 327 |
! |
328 |
||
329 |
string:s with:arg |
|
123 | 330 |
"translate and expand arg" |
331 |
||
0 | 332 |
^ self string:s withArgs:(Array with:arg) |
333 |
! |
|
334 |
||
335 |
string:s with:arg1 with:arg2 |
|
123 | 336 |
"translate and expand args" |
337 |
||
0 | 338 |
^ self string:s withArgs:(Array with:arg1 with:arg2) |
339 |
! |
|
340 |
||
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
341 |
string:s with:arg1 with:arg2 with:arg3 |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
342 |
"translate and expand args" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
343 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
344 |
^ 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
|
345 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
346 |
"Created: 9.12.1995 / 19:08:50 / cg" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
347 |
! |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
348 |
|
0 | 349 |
string:s withArgs:argArray |
123 | 350 |
"translate and expand args" |
351 |
||
135 | 352 |
|template| |
0 | 353 |
|
354 |
template := self at:s ifAbsent:[s]. |
|
135 | 355 |
^ template expandPlaceholdersWith:argArray |
0 | 356 |
! ! |
357 |
||
358 |
!ResourcePack methodsFor:'file reading'! |
|
359 |
||
144 | 360 |
processLine:aLine |
145 | 361 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
362 |
||
144 | 363 |
|lineString name stream l rest macroName value| |
364 |
||
145 | 365 |
lineString := aLine withoutSeparators. |
144 | 366 |
name := nil. |
367 |
(lineString at:1) == $' ifTrue:[ |
|
368 |
stream := ReadStream on:lineString. |
|
369 |
name := String |
|
370 |
readFrom:stream |
|
145 | 371 |
onError:[('RESOURCEPACK: invalid line <',lineString,'>') errorPrintNL. nil]. |
158 | 372 |
"/ OLD: l := stream position |
373 |
l := stream position + 1. |
|
144 | 374 |
|
375 |
"/ l := lineString indexOf:$' startingAt:2. |
|
376 |
"/ l ~~ 0 ifTrue:[ |
|
377 |
"/ name := (lineString copyFrom:2 to:l-1). |
|
378 |
"/ l := l + 1 |
|
379 |
"/ ] |
|
380 |
] ifFalse:[ |
|
381 |
l := lineString indexOfSeparatorStartingAt:1. |
|
382 |
l ~~ 0 ifTrue:[ |
|
383 |
name := lineString copyFrom:1 to:l-1. |
|
384 |
] |
|
385 |
]. |
|
386 |
name notNil ifTrue:[ |
|
387 |
rest := (lineString copyFrom:l) withoutSeparators. |
|
388 |
" |
|
389 |
skip <type> if present |
|
390 |
" |
|
391 |
(rest startsWith:$<) ifTrue:[ |
|
392 |
l := lineString indexOf:$> startingAt:l. |
|
393 |
rest := (lineString copyFrom:l+1) withoutSeparators. |
|
394 |
]. |
|
395 |
(rest startsWith:$=) ifTrue:[ |
|
396 |
rest := rest copyFrom:2. |
|
397 |
stream := ReadStream on:rest. |
|
398 |
macroName := stream nextAlphaNumericWord. |
|
399 |
rest := stream upToEnd. |
|
400 |
value := self at:macroName. |
|
401 |
value := Compiler evaluate:('self ' , rest) |
|
402 |
receiver:value |
|
403 |
notifying:nil |
|
404 |
compile:false. |
|
405 |
] ifFalse:[ |
|
406 |
value := Compiler evaluate:rest compile:false. |
|
407 |
(value == #Error) ifTrue:[ |
|
408 |
Transcript show:('error in resource:' , name). |
|
409 |
] |
|
410 |
]. |
|
411 |
self at:name put:value. |
|
412 |
] |
|
413 |
! |
|
414 |
||
244 | 415 |
readFromFile:fileName directory:dirName |
416 |
"read definitions from a file in a directory" |
|
417 |
||
418 |
|inStream ok| |
|
419 |
||
420 |
dirName = 'resources' ifTrue:[ |
|
421 |
inStream := Smalltalk resourceFileStreamFor:fileName |
|
422 |
] ifFalse:[ |
|
423 |
inStream := Smalltalk systemFileStreamFor:(dirName , '/' , fileName). |
|
424 |
]. |
|
425 |
inStream isNil ifTrue:[ |
|
426 |
" |
|
427 |
an empty pack |
|
428 |
" |
|
429 |
^ nil |
|
430 |
]. |
|
431 |
ok := self readFromResourceStream:inStream in:dirName. |
|
432 |
inStream close. |
|
433 |
ok ifFalse:[ |
|
434 |
('RESOURCEPACK: ''' , fileName , ''' contains error(s) - data may be incomplete.') errorPrintNL. |
|
435 |
]. |
|
436 |
||
437 |
"Modified: 8.11.1995 / 15:14:04 / cg" |
|
438 |
! |
|
439 |
||
72 | 440 |
readFromResourceStream:inStream in:dirName |
145 | 441 |
"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
|
442 |
specify where #include files are searched for. |
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
443 |
Return true, if the style sheet could be read without errors, false otherwise." |
145 | 444 |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
445 |
|lineString l lNo rest value ifLevel skipping first ok| |
0 | 446 |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
447 |
ok := true. |
0 | 448 |
ifLevel := 0. |
449 |
skipping := false. |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
450 |
lNo := 0. |
0 | 451 |
[inStream atEnd] whileFalse:[ |
308
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
452 |
lineString := inStream nextLine. lNo := lNo + 1. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
453 |
[lineString notNil and:[lineString endsWith:$\]] whileTrue:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
454 |
lineString := lineString copyWithoutLast:1. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
455 |
l := inStream nextLine. lNo := lNo + 1. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
456 |
l notNil ifTrue:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
457 |
lineString := lineString , l. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
458 |
]. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
459 |
]. |
177 | 460 |
|
308
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
461 |
(lineString notNil and:[lineString isEmpty not]) ifTrue:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
462 |
first := lineString at:1. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
463 |
"/ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
464 |
"/ for your convenience: treat ; AND "/ as comment-line |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
465 |
"/ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
466 |
((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
467 |
first == $# ifTrue:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
468 |
lineString := (lineString copyFrom:2) withoutSpaces. |
72 | 469 |
|
308
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
470 |
(lineString startsWith:'if') ifTrue:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
471 |
skipping ifFalse:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
472 |
rest := lineString copyFrom:3. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
473 |
value := Compiler evaluate:rest compile:false. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
474 |
(value == #Error) ifTrue:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
475 |
Transcript show:('error in resource:' , lineString). |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
476 |
]. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
477 |
(value == false) ifTrue:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
478 |
skipping := true |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
479 |
] |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
480 |
]. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
481 |
ifLevel := ifLevel + 1 |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
482 |
] ifFalse:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
483 |
(lineString startsWith:'endif') ifTrue:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
484 |
ifLevel := ifLevel - 1. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
485 |
ifLevel == 0 ifTrue:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
486 |
skipping := false |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
487 |
] |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
488 |
] ifFalse:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
489 |
(lineString startsWith:'else') ifTrue:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
490 |
skipping := skipping not |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
491 |
] ifFalse:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
492 |
(lineString startsWith:'include') ifTrue:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
493 |
rest := lineString copyFrom:8. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
494 |
value := Compiler evaluate:rest compile:false. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
495 |
self readFromFile:value directory:dirName |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
496 |
] |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
497 |
] |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
498 |
] |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
499 |
]. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
500 |
] ifFalse:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
501 |
skipping ifFalse:[ |
426 | 502 |
ErrorSignal handle:[:ex | |
308
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
503 |
('RESOURCEPACK: error: ''' , ex errorString , '''') errorPrintNL. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
504 |
('RESOURCEPACK: line ' , lNo printString , ': ''' , lineString , '''') errorPrintNL. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
505 |
ok := false. |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
506 |
] do:[ |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
507 |
self processLine:lineString |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
508 |
] |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
509 |
] |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
510 |
] |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
511 |
] |
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
512 |
] |
0 | 513 |
]. |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
514 |
^ ok |
177 | 515 |
|
516 |
"Modified: 31.8.1995 / 02:33:45 / claus" |
|
308
54fa63d274fa
also allow "/ for comment lines
Claus Gittinger <cg@exept.de>
parents:
292
diff
changeset
|
517 |
"Modified: 14.12.1995 / 14:26:06 / cg" |
0 | 518 |
! ! |
519 |
||
244 | 520 |
!ResourcePack methodsFor:'merging'! |
521 |
||
522 |
merge:anotherPack |
|
523 |
anotherPack keysAndValuesDo:[:key :value | |
|
524 |
(self includesKey:key) ifFalse:[ |
|
525 |
self at:key put:value |
|
526 |
] |
|
527 |
] |
|
528 |
! ! |
|
529 |
||
251 | 530 |
!ResourcePack class methodsFor:'documentation'! |
531 |
||
532 |
version |
|
426 | 533 |
^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.25 1996-02-19 22:59:08 cg Exp $' |
251 | 534 |
! ! |
0 | 535 |
ResourcePack initialize! |