--- a/XBMReader.st Wed Nov 19 14:20:37 2003 +0100
+++ b/XBMReader.st Wed Nov 19 16:24:57 2003 +0100
@@ -189,6 +189,27 @@
"Modified: / 18.3.1999 / 11:33:39 / cg"
! !
+!XBMReader methodsFor:'private-reading'!
+
+extractValueFor:keyword fromLine:lineString
+ |index value restString|
+
+ index := lineString indexOf:(Character space).
+ index := lineString indexOf:(Character space) startingAt:(index + 1).
+ (index == 0) ifTrue:[
+ ^ nil.
+ ].
+ ((lineString copyTo:index - 1) endsWith:keyword) ifFalse:[
+ ^ nil.
+ ].
+ restString := lineString copyFrom:(index + 1).
+ value := Number readFromString:restString onError:nil.
+ value isNil ifTrue:[
+ ^ nil.
+ ].
+ ^ value
+! !
+
!XBMReader methodsFor:'reading'!
fromStream:aStream
@@ -221,16 +242,7 @@
^ self fileFormatError:'format error (expected #define)'.
].
- index := lineString indexOf:(Character space).
- index := lineString indexOf:(Character space) startingAt:(index + 1).
- (index == 0) ifTrue:[
- ^ self fileFormatError:'format error'.
- ].
- ((lineString copyTo:index - 1) endsWith:'width') ifFalse:[
- ^ self fileFormatError:'format error (expected width)'.
- ].
- lineString := lineString copyFrom:(index + 1).
- width := Number readFromString:lineString onError:nil.
+ width := self extractValueFor:'width' fromLine:lineString.
width isNil ifTrue:[
^ self fileFormatError:'format error (expected width)'.
].
@@ -239,20 +251,13 @@
[lineString notNil and:[lineString isEmpty]] whileTrue:[
lineString := aStream nextLine.
].
- index := lineString indexOf:(Character space).
- index := lineString indexOf:(Character space) startingAt:(index + 1).
- (index == 0) ifTrue:[
- ^ self fileFormatError:'format error'.
- ].
- ((lineString copyTo:index - 1) endsWith:'height') ifFalse:[
- ^ self fileFormatError:'format error (expected height)'.
- ].
- lineString := lineString copyFrom:(index + 1).
- height := Number readFromString:lineString onError:nil.
+ height := self extractValueFor:'height' fromLine:lineString.
height isNil ifTrue:[
^ self fileFormatError:'format error (expected height)'.
].
+ self reportDimension.
+
bytesPerRow := width // 8.
((width \\ 8) ~~ 0) ifTrue:[
bytesPerRow := bytesPerRow + 1
@@ -387,7 +392,7 @@
!XBMReader class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.50 2003-09-12 11:42:56 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview2/XBMReader.st,v 1.51 2003-11-19 15:24:57 cg Exp $'
! !
XBMReader initialize!