author | Claus Gittinger <cg@exept.de> |
Tue, 03 Feb 2004 16:47:58 +0100 | |
changeset 3980 | 443283639aed |
parent 3979 | 75850ede052c |
child 3983 | 5c4422ca05c8 |
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 |
||
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
200 |
|nm pack rsrcDir baseName| |
244 | 201 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
202 |
nm := aClass resourcePackName. |
244 | 203 |
pack := self searchCacheFor:nm. |
204 |
pack notNil ifTrue:[^ pack]. |
|
205 |
||
3049
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
206 |
baseName := (Smalltalk fileNameForClass:nm) , '.rs'. |
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
207 |
rsrcDir := aClass resourceDirectory. |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
208 |
|
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
209 |
(rsrcDir notNil |
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
210 |
and:[rsrcDir exists |
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
211 |
and:[(rsrcDir construct:baseName) exists]]) ifTrue:[ |
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
212 |
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
|
213 |
] ifFalse:[ |
3808 | 214 |
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
|
215 |
]. |
244 | 216 |
aClass == Object ifFalse:[ |
3808 | 217 |
pack superPack:(self for:(aClass superclass)). |
244 | 218 |
]. |
219 |
pack packsClassName:nm. |
|
220 |
self addToCache:pack. |
|
221 |
^ pack |
|
222 |
||
223 |
" |
|
3046 | 224 |
ResourcePack for:TextView |
244 | 225 |
ResourcePack for:CodeView |
3046 | 226 |
ResourcePack for:Workspace |
3049
d5f2b3f66e37
load resources from package directory, if present
Claus Gittinger <cg@exept.de>
parents:
3047
diff
changeset
|
227 |
ResourcePack for:View |
2970
928387584c9c
for non-base system classes (i.e. package not stx:),
Claus Gittinger <cg@exept.de>
parents:
2608
diff
changeset
|
228 |
ResourcePack for:ErrorLogger |
3101
38cc69894380
fix to avoid loosing the directory with #includes
Claus Gittinger <cg@exept.de>
parents:
3097
diff
changeset
|
229 |
ResourcePack for:NewLauncher |
244 | 230 |
Workspace classResources |
231 |
" |
|
232 |
! |
|
233 |
||
234 |
fromFile:aFileName |
|
235 |
"get the resource definitions from a file in the default directory. |
|
236 |
Uncached low-level entry." |
|
237 |
||
238 |
^ self fromFile:aFileName directory:'resources' |
|
239 |
||
240 |
" |
|
241 |
ResourcePack fromFile:'SBrowser.rs' |
|
242 |
ResourcePack fromFile:'FBrowser.rs' |
|
243 |
ResourcePack fromFile:'Smalltalk.rs' |
|
3678 | 244 |
ResourcePack fromFile:'Smalltalk.rs' asFilename |
244 | 245 |
" |
246 |
! |
|
247 |
||
248 |
fromFile:aFileName directory:dirName |
|
249 |
"get the resource definitions from a file in a directory. |
|
250 |
Uncached low-level entry." |
|
251 |
||
252 |
|newPack| |
|
253 |
||
254 |
newPack := self new. |
|
255 |
newPack readFromFile:aFileName directory:dirName. |
|
256 |
^ newPack |
|
0 | 257 |
! ! |
258 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
259 |
!ResourcePack class methodsFor:'private'! |
54 | 260 |
|
261 |
addToCache:aPack |
|
262 |
|idx| |
|
0 | 263 |
|
54 | 264 |
idx := Packs identityIndexOf:nil. |
265 |
idx == 0 ifTrue:[ |
|
1078
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
266 |
idx := Packs identityIndexOf:0 |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
267 |
]. |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
268 |
idx == 0 ifTrue:[ |
72 | 269 |
" |
270 |
throw away oldest |
|
271 |
" |
|
272 |
idx := Packs size. |
|
273 |
Packs replaceFrom:1 to:idx-1 with:Packs startingAt:2. |
|
54 | 274 |
]. |
275 |
Packs at:idx put:aPack |
|
276 |
! |
|
0 | 277 |
|
54 | 278 |
searchCacheFor:aClassname |
998 | 279 |
|sz "{ Class: SmallInteger }" | |
0 | 280 |
|
24 | 281 |
Packs isNil ifTrue:[ |
72 | 282 |
self initialize. |
283 |
^ nil |
|
0 | 284 |
]. |
54 | 285 |
|
286 |
sz := Packs size. |
|
287 |
1 to:sz do:[:idx | |
|
72 | 288 |
|aPack| |
54 | 289 |
|
72 | 290 |
aPack := Packs at:idx. |
1078
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
291 |
(aPack notNil |
f7b6f15899ab
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
292 |
and:[aPack ~~ 0]) ifTrue:[ |
72 | 293 |
aClassname = aPack packsClassName ifTrue:[ |
294 |
" |
|
295 |
bring to end for LRU |
|
296 |
" |
|
297 |
Packs replaceFrom:idx to:sz-1 with:Packs startingAt:idx+1. |
|
298 |
Packs at:sz put:aPack. |
|
299 |
^ aPack |
|
300 |
] |
|
301 |
] |
|
0 | 302 |
]. |
54 | 303 |
^ nil |
123 | 304 |
|
305 |
" |
|
306 |
ResourcePack searchCacheFor:'TextView' |
|
307 |
" |
|
54 | 308 |
! ! |
309 |
||
0 | 310 |
!ResourcePack methodsFor:'accessing'! |
311 |
||
244 | 312 |
array:anArray |
313 |
"translate a collection of strings" |
|
0 | 314 |
|
244 | 315 |
^ anArray collect:[:r | self at:r default:r] |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
316 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
317 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
318 |
Launcher classResources array:#('file' 'classes') |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
319 |
" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
320 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
321 |
"Modified: / 29.1.1998 / 22:44:22 / cg" |
0 | 322 |
! |
323 |
||
2 | 324 |
at:aKey |
123 | 325 |
"translate a string" |
326 |
||
72 | 327 |
^ self at:aKey ifAbsent:aKey |
0 | 328 |
! |
329 |
||
330 |
at:aKey default:default |
|
123 | 331 |
"translate a string" |
332 |
||
72 | 333 |
^ self at:aKey ifAbsent:default |
0 | 334 |
! |
335 |
||
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
336 |
at:aKey ifAbsent:defaultValue |
123 | 337 |
"translate a string" |
338 |
||
3979
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
339 |
|val alternativeKey rest usedKey| |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
340 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
341 |
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
|
342 |
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
|
343 |
val notNil ifTrue:[^ val]. |
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
344 |
|
3979
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
345 |
"/ try with case-first swapped... |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
346 |
(aKey isString |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
347 |
and:[aKey size > 0 |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
348 |
and:[aKey first isLetter]]) ifTrue:[ |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
349 |
alternativeKey := aKey first isUppercase |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
350 |
ifTrue:[aKey asLowercaseFirst] |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
351 |
ifFalse:[aKey asUppercaseFirst]. |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
352 |
val := super at:alternativeKey ifAbsent:nil. |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
353 |
val notNil ifTrue:[ |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
354 |
aKey first isUppercase ifTrue:[ |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
355 |
^ val asUppercaseFirst |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
356 |
]. |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
357 |
^ val asLowercaseFirst. |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
358 |
]. |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
359 |
]. |
3549
8c924bf310ed
lower case first <-> upper case first
Claus Gittinger <cg@exept.de>
parents:
3484
diff
changeset
|
360 |
|
3979
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
361 |
(aKey isString |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
362 |
and:[aKey size > 0 |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
363 |
and:[':=' includes:aKey last]]) ifTrue:[ |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
364 |
rest := aKey last. |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
365 |
usedKey := aKey copyWithoutLast:1. |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
366 |
|
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
367 |
val := self at:usedKey ifAbsent:nil. |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
368 |
val notNil ifTrue:[^ val , rest]. |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
369 |
]. |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
370 |
|
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
371 |
superPack notNil ifTrue:[ |
75850ede052c
if no xlation is found, look for string folowed by ':' or '='
Claus Gittinger <cg@exept.de>
parents:
3854
diff
changeset
|
372 |
^ 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
|
373 |
]. |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
374 |
]. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
375 |
^ defaultValue value |
2 | 376 |
! |
377 |
||
378 |
name:aKey default:default |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
379 |
"translate a string. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
380 |
Obsolete - use #string:default:" |
123 | 381 |
|
72 | 382 |
^ self at:aKey ifAbsent:default |
2 | 383 |
! |
384 |
||
0 | 385 |
string:s |
3097 | 386 |
"translate (retrieve) a string - if not present, return s" |
123 | 387 |
|
72 | 388 |
^ self at:s ifAbsent:s |
3097 | 389 |
|
390 |
" |
|
391 |
NewLauncher classResources |
|
3762 | 392 |
string:'LICENCEFILE' |
3097 | 393 |
" |
0 | 394 |
! |
395 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
396 |
string:s default:defaultString |
3097 | 397 |
"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
|
398 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
399 |
^ self at:s ifAbsent:defaultString |
3097 | 400 |
|
401 |
" |
|
402 |
NewLauncher classResources |
|
3762 | 403 |
string:'fooBar' default:'Hello world' |
3097 | 404 |
" |
405 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
406 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
407 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
408 |
string:s default:defaultString with:arg |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
409 |
"translate and expand arg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
410 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
411 |
^ self string:s default:defaultString withArgs:(Array with:arg) |
3097 | 412 |
|
413 |
" |
|
414 |
NewLauncher classResources |
|
3762 | 415 |
string:'%1 fooBar' default:'Hello %1' with:'foo' |
3097 | 416 |
" |
417 |
||
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
418 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
419 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
420 |
string:s default:defaultString with:arg1 with:arg2 |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
421 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
422 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
423 |
^ 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
|
424 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
425 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
426 |
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
|
427 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
428 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
429 |
^ 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
|
430 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
431 |
"Created: 9.12.1995 / 19:08:50 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
432 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
433 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
434 |
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
|
435 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
436 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
437 |
^ 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
|
438 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
439 |
"Created: 9.9.1996 / 18:52:14 / cg" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
440 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
441 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
442 |
string:s default:defaultString withArgs:argArray |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
443 |
"translate and expand args" |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
444 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
445 |
|template| |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
446 |
|
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
447 |
template := self at:s ifAbsent:defaultString. |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
448 |
^ template expandPlaceholdersWith:argArray |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
449 |
! |
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
450 |
|
0 | 451 |
string:s with:arg |
123 | 452 |
"translate and expand arg" |
453 |
||
0 | 454 |
^ self string:s withArgs:(Array with:arg) |
455 |
! |
|
456 |
||
457 |
string:s with:arg1 with:arg2 |
|
123 | 458 |
"translate and expand args" |
459 |
||
0 | 460 |
^ self string:s withArgs:(Array with:arg1 with:arg2) |
461 |
! |
|
462 |
||
292
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
463 |
string:s with:arg1 with:arg2 with:arg3 |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
464 |
"translate and expand args" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
465 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
466 |
^ 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
|
467 |
|
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
468 |
"Created: 9.12.1995 / 19:08:50 / cg" |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
469 |
! |
62799b2ab9ae
new method: string:with:with:with:
Claus Gittinger <cg@exept.de>
parents:
251
diff
changeset
|
470 |
|
1042 | 471 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 |
472 |
"translate and expand args" |
|
473 |
||
474 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
475 |
||
476 |
"Created: 9.9.1996 / 18:52:14 / cg" |
|
477 |
! |
|
478 |
||
3184 | 479 |
string:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
480 |
"translate and expand args" |
|
481 |
||
482 |
^ self string:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
483 |
||
484 |
! |
|
485 |
||
0 | 486 |
string:s withArgs:argArray |
123 | 487 |
"translate and expand args" |
488 |
||
135 | 489 |
|template| |
0 | 490 |
|
2461
3c212ae910ec
added #string:default:with* methods.
Claus Gittinger <cg@exept.de>
parents:
2459
diff
changeset
|
491 |
template := self at:s ifAbsent:s. |
135 | 492 |
^ template expandPlaceholdersWith:argArray |
3823 | 493 |
! |
494 |
||
495 |
stringWithCRs:s with:arg |
|
496 |
"translate, replace \'s with CRs and finally expand arg. |
|
497 |
CR-replacement is donw before args are inserted |
|
498 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
499 |
||
500 |
^ self stringWithCRs:s withArgs:(Array with:arg) |
|
501 |
||
502 |
"Modified: / 21.3.2003 / 14:22:09 / cg" |
|
503 |
! |
|
504 |
||
505 |
stringWithCRs:s with:arg1 with:arg2 |
|
506 |
"translate, replace \'s with CRs and finally expand args. |
|
507 |
CR-replacement is donw before args are inserted |
|
508 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
509 |
||
510 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2) |
|
511 |
||
512 |
"Modified: / 21.3.2003 / 14:22:06 / cg" |
|
513 |
! |
|
514 |
||
515 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 |
|
516 |
"translate, replace \'s with CRs and finally expand args. |
|
517 |
CR-replacement is donw before args are inserted |
|
518 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
519 |
||
520 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3) |
|
521 |
||
522 |
"Created: 9.12.1995 / 19:08:50 / cg" |
|
523 |
! |
|
524 |
||
525 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 |
|
526 |
"translate, replace \'s with CRs and finally expand args. |
|
527 |
CR-replacement is donw before args are inserted |
|
528 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
529 |
||
530 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
531 |
||
532 |
"Modified: / 21.3.2003 / 14:21:48 / cg" |
|
533 |
! |
|
534 |
||
535 |
stringWithCRs:s with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
536 |
"translate, replace \'s with CRs and finally expand args. |
|
537 |
CR-replacement is donw before args are inserted |
|
538 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
539 |
||
540 |
^ self stringWithCRs:s withArgs:(Array with:arg1 with:arg2 with:arg3 with:arg4 with:arg5) |
|
541 |
||
542 |
"Modified: / 21.3.2003 / 14:21:55 / cg" |
|
543 |
! |
|
544 |
||
545 |
stringWithCRs:s withArgs:argArray |
|
546 |
"translate, replace \'s with CRs and finally expand args. |
|
547 |
CR-replacement is donw before args are inserted |
|
548 |
i.e. if any arg contains a backslash (DOS filenames), those are not translated." |
|
549 |
||
550 |
|template| |
|
551 |
||
552 |
template := self at:s ifAbsent:s. |
|
553 |
^ template withCRs expandPlaceholdersWith:argArray |
|
554 |
||
555 |
"Modified: / 21.3.2003 / 14:21:59 / cg" |
|
0 | 556 |
! ! |
557 |
||
3317 | 558 |
!ResourcePack methodsFor:'accessing-internals'! |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
559 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
560 |
name:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
561 |
"translate a string" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
562 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
563 |
^ self at:aKey ifAbsent:aKey |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
564 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
565 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
566 |
packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
567 |
^ packsClassName |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
568 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
569 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
570 |
packsClassName:aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
571 |
packsClassName := aString |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
572 |
! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
573 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
574 |
superPack:anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
575 |
superPack := anotherResourcePack |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
576 |
|
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
577 |
"Created: / 29.1.1998 / 22:43:09 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
578 |
! ! |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
579 |
|
0 | 580 |
!ResourcePack methodsFor:'file reading'! |
581 |
||
684 | 582 |
fileReadFailed |
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
583 |
"return true, if the pack does not really contain |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
584 |
valid translations, since the fileRead failed. |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
585 |
However, all inherited translations are still available |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
586 |
through the receiver" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
587 |
|
687 | 588 |
^ fileReadFailed ~~ false |
684 | 589 |
|
2033
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
590 |
"Created: / 14.5.1996 / 10:19:26 / cg" |
dad8f0ee02f4
do not merge superPacks data;
Claus Gittinger <cg@exept.de>
parents:
1956
diff
changeset
|
591 |
"Modified: / 29.1.1998 / 22:46:38 / cg" |
684 | 592 |
! |
593 |
||
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
594 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
595 |
"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
|
596 |
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
|
597 |
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
|
598 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
599 |
^ nil |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
600 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
601 |
"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
|
602 |
! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1803
diff
changeset
|
603 |
|
2291
eaac1c5f2a61
show fileName if a line has error.
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
604 |
processLine:aLine encoding:encoding file:fileName |
145 | 605 |
"process a single valid line (i.e. #ifdef & #include has already been processed)" |
606 |
||
2314 | 607 |
|lineString name stream l rest macroName value |
608 |
conditional hasError| |
|
144 | 609 |
|
145 | 610 |
lineString := aLine withoutSeparators. |
144 | 611 |
name := nil. |
612 |
(lineString at:1) == $' ifTrue:[ |
|
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
613 |
stream := ReadStream on:lineString. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
614 |
stream signalAtEnd:false. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
615 |
name := String |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
616 |
readFrom:stream |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
617 |
onError:[('ResourcePack [warning]: invalid line <' |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
618 |
,lineString |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
619 |
,'> in file:' |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
620 |
, fileName |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
621 |
) errorPrintCR. nil]. |
158 | 622 |
"/ OLD: l := stream position |
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
623 |
l := stream position1Based + 1. |
144 | 624 |
|
625 |
"/ l := lineString indexOf:$' startingAt:2. |
|
626 |
"/ l ~~ 0 ifTrue:[ |
|
627 |
"/ name := (lineString copyFrom:2 to:l-1). |
|
628 |
"/ l := l + 1 |
|
629 |
"/ ] |
|
630 |
] ifFalse:[ |
|
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
631 |
l := lineString indexOfSeparatorStartingAt:1. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
632 |
l ~~ 0 ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
633 |
name := lineString copyFrom:1 to:l-1. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
634 |
] |
144 | 635 |
]. |
636 |
name notNil ifTrue:[ |
|
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
637 |
hasError := false. |
2153 | 638 |
|
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
639 |
rest := (lineString copyFrom:l) withoutSeparators. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
640 |
" |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
641 |
skip <type> if present |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
642 |
" |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
643 |
(rest startsWith:$<) ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
644 |
l := lineString indexOf:$> startingAt:l. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
645 |
rest := (lineString copyFrom:l+1) withoutSeparators. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
646 |
]. |
2153 | 647 |
|
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
648 |
conditional := false. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
649 |
(rest startsWith:$?) ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
650 |
rest := (rest copyFrom:2) withoutSeparators. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
651 |
conditional := true. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
652 |
]. |
2153 | 653 |
|
3807
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
654 |
(rest startsWith:$=) ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
655 |
rest := rest copyFrom:2. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
656 |
stream := ReadStream on:rest. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
657 |
macroName := stream nextAlphaNumericWord. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
658 |
[stream peek == $.] whileTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
659 |
stream next. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
660 |
stream peek notNil ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
661 |
macroName := macroName , '.' , (stream nextAlphaNumericWord) |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
662 |
] |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
663 |
]. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
664 |
rest := stream upToEnd. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
665 |
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
|
666 |
(value isNil) ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
667 |
hasError := true. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
668 |
('ResourcePack [warning]: bad (nil-valued) macro: ' , macroName) errorPrintCR. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
669 |
('ResourcePack [warning]: in line: ' , lineString) errorPrintCR. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
670 |
('ResourcePack [warning]: in file: ' , fileName) errorPrintCR. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
671 |
]. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
672 |
value isBlock ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
673 |
value := value value |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
674 |
]. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
675 |
value := Compiler evaluate:('self ' , rest) |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
676 |
receiver:value |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
677 |
notifying:nil |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
678 |
compile:false. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
679 |
(value == #Error) ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
680 |
hasError := true. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
681 |
('ResourcePack [warning]: error in line: "self ' , rest , '"') errorPrintCR. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
682 |
('ResourcePack [warning]: in file: ' , fileName) errorPrintCR. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
683 |
] |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
684 |
] ifFalse:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
685 |
value := Compiler evaluate:rest compile:false. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
686 |
(value == #Error) ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
687 |
hasError := true. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
688 |
('ResourcePack [warning]: error in line: "' , rest , '"') errorPrintCR. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
689 |
('ResourcePack [warning]: in file: ' , fileName) errorPrintCR. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
690 |
] ifFalse:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
691 |
encoding notNil ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
692 |
value isString ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
693 |
value := value decodeFrom:encoding |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
694 |
] |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
695 |
] |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
696 |
] |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
697 |
]. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
698 |
hasError ifFalse:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
699 |
(conditional not |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
700 |
or:[(self includesKey:name) not]) ifTrue:[ |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
701 |
self at:name put:value. |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
702 |
] |
ddb031431ff6
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
703 |
] |
144 | 704 |
] |
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
705 |
|
2291
eaac1c5f2a61
show fileName if a line has error.
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
706 |
"Created: / 30.8.1998 / 12:35:37 / cg" |
2608 | 707 |
"Modified: / 28.4.1999 / 22:23:14 / cg" |
144 | 708 |
! |
709 |
||
244 | 710 |
readFromFile:fileName directory:dirName |
711 |
"read definitions from a file in a directory" |
|
712 |
||
713 |
|inStream ok| |
|
714 |
||
686 | 715 |
fileReadFailed := false. |
244 | 716 |
dirName = 'resources' ifTrue:[ |
3769 | 717 |
inStream := Smalltalk resourceFileStreamFor:fileName |
244 | 718 |
] ifFalse:[ |
3769 | 719 |
inStream := Smalltalk |
720 |
systemFileStreamFor:(dirName |
|
721 |
isNil ifTrue:[fileName] |
|
722 |
ifFalse:[dirName asFilename construct:fileName]). |
|
244 | 723 |
]. |
724 |
inStream isNil ifTrue:[ |
|
3769 | 725 |
" |
726 |
an empty pack |
|
727 |
" |
|
728 |
^ self nonexistingFileRead |
|
244 | 729 |
]. |
2996 | 730 |
|
244 | 731 |
ok := self readFromResourceStream:inStream in:dirName. |
732 |
inStream close. |
|
686 | 733 |
|
244 | 734 |
ok ifFalse:[ |
3769 | 735 |
fileReadFailed := true. |
684 | 736 |
|
3769 | 737 |
('ResourcePack [warning]: ''' , inStream pathName , ''' contains error(s) - data may be incomplete.') errorPrintCR. |
244 | 738 |
]. |
739 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
740 |
"Modified: 10.1.1997 / 18:05:17 / cg" |
244 | 741 |
! |
742 |
||
72 | 743 |
readFromResourceStream:inStream in:dirName |
145 | 744 |
"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
|
745 |
specify where #include files are searched for. |
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
746 |
Return true, if the style sheet could be read without errors, false otherwise." |
145 | 747 |
|
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
748 |
|lineString l lNo rest value ifLevel skipping first ok encoding pack errorHandler| |
462
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
749 |
|
423f8426fefc
added #encoding directive (I am lazy)
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
750 |
encoding := nil. |
0 | 751 |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
752 |
ok := true. |
0 | 753 |
ifLevel := 0. |
754 |
skipping := false. |
|
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
755 |
lNo := 0. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
756 |
|
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
757 |
errorHandler := [:ex | |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
758 |
|con| |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
759 |
|
3854 | 760 |
('ResourcePack [warning]: ''' , ex description , '''') errorPrintCR. |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
761 |
('ResourcePack [info]: file: ' , inStream pathName printString , ' line: ' , lNo printString , ': ''' , lineString , '''') errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
762 |
con := ex suspendedContext. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
763 |
('ResourcePack [info]: in: ' , con fullPrintString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
764 |
con := con sender. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
765 |
('ResourcePack [info]: : ' , con fullPrintString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
766 |
con := con sender. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
767 |
('ResourcePack [info]: : ' , con fullPrintString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
768 |
value := nil. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
769 |
ok := false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
770 |
]. |
3567
f85c170f14e8
allow expression evaluation in styleSheet
Claus Gittinger <cg@exept.de>
parents:
3549
diff
changeset
|
771 |
|
0 | 772 |
[inStream atEnd] whileFalse:[ |
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
773 |
lineString := inStream nextLine. lNo := lNo + 1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
774 |
[lineString notNil and:[lineString endsWith:$\]] whileTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
775 |
lineString := lineString copyWithoutLast:1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
776 |
l := inStream nextLine. lNo := lNo + 1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
777 |
l notNil ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
778 |
lineString := lineString , l. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
779 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
780 |
]. |
177 | 781 |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
782 |
(lineString size > 0) ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
783 |
first := lineString at:1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
784 |
"/ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
785 |
"/ for your convenience: treat ; AND "/ as comment-line |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
786 |
"/ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
787 |
((first == $;) or:[lineString startsWith:'"/']) ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
788 |
first == $# ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
789 |
"/ a directive |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
790 |
lineString := (lineString copyFrom:2) withoutSpaces. |
72 | 791 |
|
3817
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
792 |
(lineString startsWith:'if') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
793 |
skipping ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
794 |
rest := lineString copyFrom:3. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
795 |
Error |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
796 |
handle:errorHandler |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
797 |
do:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
798 |
value := Compiler evaluate:rest compile:false]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
799 |
(value == #Error) ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
800 |
('ResourcePack [warning]: error in resource:' , lineString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
801 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
802 |
(value == false) ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
803 |
skipping := true |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
804 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
805 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
806 |
ifLevel := ifLevel + 1 |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
807 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
808 |
(lineString startsWith:'endif') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
809 |
ifLevel := ifLevel - 1. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
810 |
ifLevel == 0 ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
811 |
skipping := false |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
812 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
813 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
814 |
(lineString startsWith:'else') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
815 |
skipping := skipping not |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
816 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
817 |
skipping ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
818 |
(lineString startsWith:'include') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
819 |
(lineString startsWith:'includeResourcesFor') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
820 |
"/ include those resources ... |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
821 |
rest := lineString copyFrom:('includeResourcesFor' size + 1). |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
822 |
value := Compiler evaluate:rest compile:false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
823 |
value isBehavior ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
824 |
pack := self class for:value. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
825 |
pack notNil ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
826 |
self declareAllFrom:pack. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
827 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
828 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
829 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
830 |
rest := lineString copyFrom:('include' size + 1). |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
831 |
value := Compiler evaluate:rest compile:false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
832 |
value isString ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
833 |
('ResourcePack [warning]: bad include filename: ' , value printString) errorPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
834 |
('ResourcePack [info]: line ' , lNo printString , ': ''' , lineString , '''') infoPrintCR. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
835 |
] ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
836 |
self readFromFile:value directory:dirName |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
837 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
838 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
839 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
840 |
(lineString startsWith:'encoding') ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
841 |
rest := lineString copyFrom:9. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
842 |
encoding := rest withoutSeparators asSymbol |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
843 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
844 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
845 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
846 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
847 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
848 |
]. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
849 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
850 |
skipping ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
851 |
Error |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
852 |
handle:errorHandler |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
853 |
do:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
854 |
(lineString at:1) == $!! ifTrue:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
855 |
"/ evaluate the rest |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
856 |
Compiler evaluate:(lineString copyFrom:2) |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
857 |
receiver:nil |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
858 |
notifying:nil |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
859 |
compile:false. |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
860 |
] ifFalse:[ |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
861 |
"/ process as resource |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
862 |
self |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
863 |
processLine:lineString |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
864 |
encoding:encoding |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
865 |
file:(inStream isFileStream |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
866 |
ifTrue:[inStream pathName] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
867 |
ifFalse:['---']) |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
868 |
]] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
869 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
870 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
871 |
] |
34deab81bfe2
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
3808
diff
changeset
|
872 |
] |
0 | 873 |
]. |
210
0f942dafc85a
gracefully handle errors when reading resource files
Claus Gittinger <cg@exept.de>
parents:
177
diff
changeset
|
874 |
^ ok |
177 | 875 |
|
2291
eaac1c5f2a61
show fileName if a line has error.
Claus Gittinger <cg@exept.de>
parents:
2153
diff
changeset
|
876 |
"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
|
877 |
"Modified: / 30.8.1998 / 12:35:24 / cg" |
0 | 878 |
! ! |
879 |
||
1173
86a212598655
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
880 |
!ResourcePack class methodsFor:'documentation'! |
251 | 881 |
|
882 |
version |
|
3980
443283639aed
resourceDirectory asked from class
Claus Gittinger <cg@exept.de>
parents:
3979
diff
changeset
|
883 |
^ '$Header: /cvs/stx/stx/libview/ResourcePack.st,v 1.81 2004-02-03 15:47:58 cg Exp $' |
251 | 884 |
! ! |
3769 | 885 |
|
0 | 886 |
ResourcePack initialize! |