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