Levente Uzonyi uploaded a new version of Multilingual to project The Trunk:
http://source.squeak.org/trunk/Multilingual-ul.130.mcz
==================== Summary ====================
Name: Multilingual-ul.130
Author: ul
Time: 2 November 2010, 3:24:09.278 am
UUID: 3bd5d5a6-9eba-594f-8712-0bbdbeb9df7c
Ancestors: Multilingual-cmm.129
- make sure MultiByteFileStream can also be used as an stdio stream
=============== Diff against Multilingual-cmm.129 ===============
Item was added:
+ ----- Method: MultiByteFileStream>>openOnHandle:name:forWrite: (in category 'open/close') -----
+ openOnHandle: aFileID name: streamName forWrite: writeMode
+
+ super openOnHandle: aFileID name: streamName forWrite: writeMode.
+ self converter "Make sure that converter is initialized."!
Levente Uzonyi uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-ul.90.mcz
==================== Summary ====================
Name: Files-ul.90
Author: ul
Time: 27 September 2010, 3:56:36.551 am
UUID: aff6ed6c-5823-6342-b175-65f0f4e8f403
Ancestors: Files-ul.89
- Integrated Eliot's stdio changes with a minor fix/optimization
=============== Diff against Files-ul.89 ===============
Item was added:
+ ----- Method: CrLfFileStream class>>newForStdio (in category 'instance creation') -----
+ newForStdio
+ "Circumvent CrLfFileStream new's retuning an instance of MultiBteFileStream"
+ ^super new!
Item was added:
+ ----- Method: CrLfFileStream>>openOnHandle:name:forWrite: (in category 'open/close') -----
+ openOnHandle: aFileID name: streamName forWrite: writeMode
+ "Initialize the file with the given handle. If writeMode is true then
+ allow writing, otherwise put the file in read-only mode."
+ super openOnHandle: aFileID name: streamName forWrite: writeMode.
+ lineEndConvention := LineEndDefault!
Item was changed:
----- Method: DirectoryEntry>>fullName (in category 'access') -----
fullName
+ "The fully-qualified name.
+ Since this method falls into the equality test, make it safe when directory is nil."
+ ^ directory
+ ifNotNil: [ directory fullNameFor: self name ]
+ ifNil: [ self name ]!
- "The fully-qualified name."
- ^ directory fullNameFor: self name!
Item was added:
+ ----- Method: FileDirectory>>directoryEntryForName: (in category 'private') -----
+ directoryEntryForName: aFileName
+
+ "Return a single DirectoryEntry for the given (non-path) entry name,
+ or nil if the entry could not be found.
+ Raises InvalidDirectoryError if this directory's path does not identify a directory."
+
+ | entryArray sysPath sysName |
+
+ sysPath := pathName asVmPathName.
+ sysName := aFileName asVmPathName.
+
+ "New linear-time primitive."
+ entryArray := self primLookupEntryIn: sysPath name: sysName.
+ entryArray == #primFailed ifFalse:[
+ ^ entryArray ifNotNil: [(DirectoryEntry fromArray: entryArray directory: self) convertFromSystemName]
+ ].
+
+ "If the new primitive fails, use the old slow method.
+ (This fallback can be changed to signal InvalidDirectoryError once
+ VM's with FilePlugin #primitiveDirectoryEntry have been distributed everywhere;
+ the new primitive was introduced 6/13/2007."
+
+ ^self isCaseSensitive ifTrue: [
+ self entries detect: [:entry | entry name = aFileName ] ifNone: [ nil ]
+ ] ifFalse: [
+ self entries detect: [:entry | entry name sameAs: aFileName ] ifNone: [ nil ]
+ ]
+ !
Item was changed:
FileStream subclass: #StandardFileStream
instanceVariableNames: 'name fileID buffer1'
+ classVariableNames: 'Registry StdioHandles'
- classVariableNames: 'Registry'
poolDictionaries: ''
category: 'Files-Kernel'!
+ StandardFileStream class
+ instanceVariableNames: 'stdioFiles'!
!StandardFileStream commentStamp: 'ul 12/6/2009 05:13' prior: 0!
Provides a simple, platform-independent, interface to a file system. The instance variable rwmode, inherited from class PositionableStream, here is used to hold a Boolean -- true means opened for read-write, false means opened for read-only. 2/12/96 sw
I implement a simple read buffering scheme with the variables defined in PositionableStream (which are unused in me otherwise) in the following way:
collection <ByteString> or <ByteArray> This is the buffer.
position <Integer> The relative position in the buffer. Greater or equal to zero.
readLimit <Integer> The number of bytes buffered. Greater or equal to zero.
Read buffering is enabled with #enableReadBuffering, disabled with #disableReadBuffering and it is enabled by default. The buffer is filled when a read attempt of an unbuffered absolute position is requested, or when a negative repositioning is made (with #position: with an argument < than the current absolute position) to an absolute position which is not buffered. In the first case, the buffer is positioned to the given absolute position. In the latter case the repositioning is made to the requested absolute position minus fourth of the buffer size. This means that further small negative repositionings won't result in buffer flushing. This is really useful when filing in code.
The read buffer is flushed (#flushReadBuffer) whenever a write attempt is made.
The buffer state is valid if and only if collection is not nil and position < readLimit.!
+ StandardFileStream class
+ instanceVariableNames: 'stdioFiles'!
Item was changed:
----- Method: StandardFileStream class>>fileExistsUserHandling: (in category 'error handling') -----
fileExistsUserHandling: fullFileName
| dir localName choice newName newFullFileName |
dir := FileDirectory forFileName: fullFileName.
localName := FileDirectory localNameFor: fullFileName.
+ choice := (UIManager default
+ chooseFrom: #('overwrite that file' 'append (risky!!!!)' 'choose another name' 'cancel')
+ title: localName, ' already exists.').
- choice := UIManager default chooseFrom:{
- 'overwrite that file'.
- 'choose another name'.
- 'cancel'
- } title: localName, '
- already exists.'.
choice = 1 ifTrue: [
dir deleteFileNamed: localName
ifAbsent: [self error: 'Could not delete the old version of that file'].
^ self new open: fullFileName forWrite: true].
choice = 2 ifTrue: [
+ ^ (self new open: fullFileName forWrite: true) setToEnd].
+
+ choice = 3 ifTrue: [
newName := UIManager default request: 'Enter a new file name' initialAnswer: fullFileName.
newFullFileName := self fullName: newName.
^ self newFileNamed: newFullFileName].
self error: 'Please close this to abort file opening'!
Item was added:
+ ----- Method: StandardFileStream class>>flushAndVoidStdioFiles (in category 'class initialization') -----
+ flushAndVoidStdioFiles
+ stdioFiles ifNotNil:
+ [stdioFiles do:
+ [:f| f isReadOnly ifFalse: [[f flush] on: Error do: [:ex|"care less"]]].
+ stdioFiles := nil]!
Item was added:
+ ----- Method: StandardFileStream class>>initialize (in category 'class initialization') -----
+ initialize
+ "StandardFileStream initialize"
+ StdioHandles := Array new: 3.
+ Smalltalk
+ addToStartUpList: self after: SecurityManager; "the intent being before: AutoStart"
+ addToShutDownList: self after: SecurityManager!
Item was added:
+ ----- Method: StandardFileStream class>>newForStdio (in category 'private-file creation') -----
+ newForStdio
+ "Circumvent CrLfFileStream new's returning an instance of MultiBteFileStream"
+ ^self new!
Item was added:
+ ----- Method: StandardFileStream class>>shutDown: (in category 'class initialization') -----
+ shutDown: quitting
+ quitting ifTrue:
+ [self withAllSubclassesDo:
+ [:fileStreamClass| fileStreamClass flushAndVoidStdioFiles]]!
Item was added:
+ ----- Method: StandardFileStream class>>standardIOStreamNamed:forWrite: (in category 'private-file creation') -----
+ standardIOStreamNamed: moniker forWrite: forWrite
+
+ | index |
+ index := #(stdin stdout stderr) identityIndexOf: moniker.
+ ^((stdioFiles ifNil: [ stdioFiles := Array new: 3 ]) at: index)
+ ifNil: [
+ stdioFiles
+ at: index
+ put: (
+ (StdioHandles at: index)
+ ifNil: [ ^self error: moniker, ' is unavailable' ]
+ ifNotNil: [ :handle|
+ self newForStdio
+ openOnHandle: handle
+ name: moniker
+ forWrite: forWrite ]) ]!
Item was added:
+ ----- Method: StandardFileStream class>>startUp: (in category 'class initialization') -----
+ startUp: resuming
+ (resuming and: [self == StandardFileStream]) ifTrue:
+ [self withAllSubclassesDo:
+ [:fileStreamClass| fileStreamClass voidStdioFiles].
+ [StdioHandles := self stdioHandles]
+ on: Error
+ do: [:ex|
+ StdioHandles isArray ifFalse:
+ [StdioHandles := Array new: 3]]]!
Item was added:
+ ----- Method: StandardFileStream class>>stderr (in category 'file creation') -----
+ stderr
+ ^self standardIOStreamNamed: #stderr forWrite: true!
Item was added:
+ ----- Method: StandardFileStream class>>stdin (in category 'file creation') -----
+ stdin
+ ^self standardIOStreamNamed: #stdin forWrite: false!
Item was added:
+ ----- Method: StandardFileStream class>>stdioHandles (in category 'private-file creation') -----
+ stdioHandles
+ <primitive: 'primitiveFileStdioHandles' module: 'FilePlugin' error: ec>
+ self primitiveFailed!
Item was added:
+ ----- Method: StandardFileStream class>>stdout (in category 'file creation') -----
+ stdout
+ ^self standardIOStreamNamed: #stdout forWrite: true!
Item was added:
+ ----- Method: StandardFileStream class>>voidStdioFiles (in category 'class initialization') -----
+ voidStdioFiles
+ stdioFiles := nil!
Item was added:
+ ----- Method: StandardFileStream>>openOnHandle:name:forWrite: (in category 'open/close') -----
+ openOnHandle: aFileID name: streamName forWrite: writeMode
+ "Initialize the file with the given handle. If writeMode is true then
+ allow writing, otherwise put the file in read-only mode.
+ N.B. Do _not_ register the stream. We do not want it to be
+ closed implicitly (e.g. on GC). There may be multiple instances
+ accessing the same stream. The stream is not a file."
+ fileID := aFileID.
+ name := streamName.
+ rwmode := writeMode.
+ buffer1 := String new: 1.
+ self enableReadBuffering!
Levente Uzonyi uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-ul.152.mcz
==================== Summary ====================
Name: Graphics-ul.152
Author: ul
Time: 2 November 2010, 3:12:47.835 am
UUID: f2a5386f-5f44-5f45-a35c-1dab7538fb00
Ancestors: Graphics-dtl.151
- use paragma declarations for #inline: and #var:declareC:
=============== Diff against Graphics-dtl.151 ===============
Item was changed:
----- Method: WarpBlt>>rgbMap:from:to: (in category 'smoothing') -----
rgbMap: sourcePixel from: nBitsIn to: nBitsOut
"NOTE: This code is copied verbatim from BitBltSimulation so that it
may be removed from the system"
"Convert the given pixel value with nBitsIn bits for each color component to a pixel value with nBitsOut bits for each color component. Typical values for nBitsIn/nBitsOut are 3, 5, or 8."
| mask d srcPix destPix |
+ <inline: true>
- self inline: true.
(d := nBitsOut - nBitsIn) > 0
ifTrue:
["Expand to more bits by zero-fill"
mask := (1 << nBitsIn) - 1. "Transfer mask"
srcPix := sourcePixel << d.
mask := mask << d.
destPix := srcPix bitAnd: mask.
mask := mask << nBitsOut.
srcPix := srcPix << d.
^ destPix + (srcPix bitAnd: mask)
+ (srcPix << d bitAnd: mask << nBitsOut)]
ifFalse:
["Compress to fewer bits by truncation"
d = 0 ifTrue: [^ sourcePixel]. "no compression"
sourcePixel = 0 ifTrue: [^ sourcePixel]. "always map 0 (transparent) to 0"
d := nBitsIn - nBitsOut.
mask := (1 << nBitsOut) - 1. "Transfer mask"
srcPix := sourcePixel >> d.
destPix := srcPix bitAnd: mask.
mask := mask << nBitsOut.
srcPix := srcPix >> d.
destPix := destPix + (srcPix bitAnd: mask)
+ (srcPix >> d bitAnd: mask << nBitsOut).
destPix = 0 ifTrue: [^ 1]. "Dont fall into transparent by truncation"
^ destPix]!
Hello
I read the post by Stephane Ducasse about writing XML (see below) with
a bibliography example.
Recently I (re)-discovered the port to Squeak/Pharo of the Writing API
for XML (WAX) (http://java.ociweb.com/mark/programming/WAX.html) and
could put it to good use for writing an XML file a bit more complex
than the bibliography example.
>From the web site
WAX has the following characteristics:
* focuses on writing XML, not reading it
* requires less code than other approaches
* uses less memory than other approaches
(because it outputs XML as each method is called rather than
storing it in a DOM-like structure and outputting it later)
* writes all XML node types
* always outputs well-formed XML or throws an exception unless
running in "trust me" mode
* knows how to associate DTDs, XML Schemas and XSLT stylesheets
with the XML it outputs
* is well-suited for writing XML request and response messages for
REST-based and SOAP-based services
However I do not know how far these points apply to the Squeak/Pharo port.
http://www.squeaksource.com/WAX
It needs the VB Regex package (http://www.squeaksource.com/Regex)
As an exercise I did the code to produce the example Stephane gave. It
worked fine; see below.
Regards
Hannes
==========================================================
WAX new
stream: (FileStream newFileNamed: 'myBibliography.xml');
writeXMLDeclaration: #1.0;
start: 'BDBase';
attr: 'date' value: '25 May 2010';
attr: 'note' value: 'nil';
start: 'bd';
attr: 'authors' value: 'Larcenet';
attr: 'editor' value: 'Dargaud';
attr: 'entryCreationDate' value: '25 March 2006';
attr: 'entryNumber' value: '1';
attr: 'number' value: '1';
attr: 'original' value: 'true';
attr: 'serie' value: 'Nic oumouk';
attr: 'serieComplete' value: 'false';
attr: 'title' value: 'Total souk pour nic oumouk';
attr: 'year' value: '2005';
end;
start: 'bd';
attr: 'authors' value: 'Greg';
attr: 'editor' value: 'Dargaud';
attr: 'entryCreationDate' value: '5 May 2006';
attr: 'entryNumber' value: '2';
attr: 'notes' value: 'sur le 4eme de couv aventure a manhattan';
attr: 'number' value: '9';
attr: 'original' value: 'true';
attr: 'serie' value: 'Achille Talon';
attr: 'title' value: 'Les petits desseins d''Achille Talon';
attr: 'year' value: '1974';
end;
start: 'bd';
attr: 'authors' value: 'Greg';
attr: 'editor' value: 'Dargaud';
attr: 'entryCreationDate' value: '5 May 2006';
attr: 'entryNumber' value: '3';
attr: 'notes' value: 'sur la couverture une histoire du journal tintin';
attr: 'number' value: '13';
attr: 'original' value: 'true';
attr: 'serie' value: 'Achille Talon';
attr: 'title' value: 'Pas de pitié pour Achille Talon';
attr: 'year' value: '1976';
end;
end;
close.
==========================================================
Output
<?xml version="1.0" encoding="UTF-8"?>
<BDBase date="25 May 2010" note="nil">
<bd authors="Larcenet" editor="Dargaud" entryCreationDate="25 March
2006" entryNumber="1" number="1" original="true" serie="Nic oumouk"
serieComplete="false" title="Total souk pour nic oumouk" year="2005"/>
<bd authors="Greg" editor="Dargaud" entryCreationDate="5 May 2006"
entryNumber="2" notes="sur le 4eme de couv aventure a manhattan"
number="9" original="true" serie="Achille Talon" title="Les petits
desseins d'Achille Talon" year="1974"/>
<bd authors="Greg" editor="Dargaud" entryCreationDate="5 May 2006"
entryNumber="3" notes="sur la couverture une histoire du journal
tintin" number="13" original="true" serie="Achille Talon" title="Pas
de pitié pour Achille Talon" year="1976"/>
</BDBase>
==========================================================
On 10/31/10, stephane ducasse <stephane.ducasse(a)free.fr> wrote:
> How can I control that each of the node of my document get printed a cr at
> its end?
>
> In the past I got that
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <BDBase date="25 May 2010" entriesNumber="2440" note="nil">
> <bd authors="Larcenet" editor="Dargaud" entryCreationDate="25 March 2006"
> entryNumber="1" number="1" original="true" serie="Nic oumouk"
> serieComplete="false" title="Total souk pour nic oumouk" year="2005"/>
> <bd authors="Greg" editor="Dargaud" entryCreationDate="5 May 2006"
> entryNumber="2" notes="sur le 4eme de couv aventure a manhattan" number="9"
> original="true" serie="Achille Talon" title="Les petits desseins d'Achille
> Talon" year="1974"/>
> <bd authors="Greg" editor="Dargaud" entryCreationDate="5 May 2006"
> entryNumber="3" notes="sur la couverture une histoire du journal tintin"
> number="13" original="true" serie="Achille Talon" title="Pas de pitié pour
> Achille Talon" year="1976"/>
> <bd aut
>
> Now I get
>
> <?xml version="1.0" encoding="UTF-8"?><Base date="31 October 2010"
> entriesNumber="2448" note="nil"><bd serieComplete="false" editor="Dargaud"
> entryCreationDate="25 March 2006" entryNumber="1" authors="Larcenet"
> title="Total souk pour nic oumouk" serie="Nic oumouk" original="true"
> number="1" year="2005" /><bd serieComplete="false" editor="Dargaud"
> entryCreationDate="5 May 2006" entryNumber="2" authors="Greg" title="Les
> petits desseins d'Achille Talon" serie="Achille Talon" original="true"
> notes="sur le 4eme de couv aventure a manhattan" number="9" year="1974"
> /><bd serieComplete="false" editor="Dargaud" entryCreationDate="5 May 2006"
> entryNumber="3" authors="Greg" title="Pas de pitié pour Achille Talon"
> serie="Achille Talon" original="true" notes="sur la couverture une histoire
> du journal tintin" number="13" year="1976" /><bd serieComplete="false"
> editor="Dargaud" entryCreationDate="5 May 2006" entryNumber="4"
> authors="Greg" title
>
> Thanks
>
> Stef
>