[REQUEST] Self running image for Unix type OS's
Ian Piumarta
Ian.Piumarta at inria.fr
Tue Oct 26 12:25:18 UTC 1999
David,
> How far are you from Boulogne or Les Ulis?
About 10km from Boulogne, and about 20-25km from Les Ulis.
Regards,
Ian ("will hack for beer!")
PS: Of course, "beer" was the default fail-safe option for VM
hacking in countries having a relatively low density of
really good restaurants. In France it's a meal at the
restaurant of my choice. ;-)
PPS: Couldn't resist (as usual). Hope you don't mind...
'From Squeak2.6 of 11 October 1999 [latest update: #1559] on 26 October 1999 at 2:17:36 pm'!
"Change Set: UnixExec
Date: 26 October 1999
Author: Ian Piumarta
Trivial modification to #writeImageFile: to add an exec prefix to the image. After saving image XYZ for the first time, do 'chmod +x XYX.image' to make the image be 'self-interpreting' (make sure 'squeak' is in somewhere on your PATH)."!
!Interpreter methodsFor: 'image save/restore' stamp: 'ikp 10/26/1999 14:10'!
putString: s toFile: f
"Append the given string and then a newline to the given file. Set successFlag to false if the write fails."
| eol |
self var: #s declareC: 'char *s'.
self var: #f declareC: 'sqImageFile f'.
self var: #eol declareC: 'char eol'.
eol _ self cCode: '''\n'''.
self success: 1 = (self cCode: 'sqImageFileWrite(s, strlen(s), 1, f)').
self success: 1 = (self cCode: 'sqImageFileWrite(&eol, 1, 1, f)').! !
!Interpreter methodsFor: 'image save/restore' stamp: 'ikp 10/26/1999 14:15'!
writeImageFile: imageBytes
| headerStart headerSize f bytesWritten |
self var: #f declareC: 'sqImageFile f'.
"local constants"
headerStart _ 0. "change to 512 to leave room for a Unix exec string"
headerSize _ 64. "header size in bytes; do not change!!"
f _ self cCode: 'sqImageFileOpen(imageName, "wb")'.
f = nil ifTrue: [
"could not open the image file for writing"
self success: false.
^ nil].
"On Unix systems write an exec prefix, padded to 512 bytes"
self asciiDirectoryDelimiter = 47 "/" ifTrue: [
self putString: '#!!squeak' toFile: f.
headerStart _ 512].
"position file to start of header"
self sqImageFile: f Seek: headerStart.
self putLong: (self imageFormatVersion) toFile: f.
self putLong: headerSize toFile: f.
self putLong: imageBytes toFile: f.
self putLong: (self startOfMemory) toFile: f.
self putLong: specialObjectsOop toFile: f.
self putLong: lastHash toFile: f.
self putLong: (self ioScreenSize) toFile: f.
self putLong: fullScreenFlag toFile: f.
self putLong: extraVMMemory toFile: f.
1 to: 7 do: [:i | self putLong: 0 toFile: f]. "fill remaining header words with zeros"
successFlag ifFalse: [
"file write or seek failure"
self cCode: 'sqImageFileClose(f)'.
^ nil].
"position file after the header"
self sqImageFile: f Seek: headerStart + headerSize.
"write the image data"
bytesWritten _ self cCode: 'sqImageFileWrite(memory, sizeof(unsigned char), imageBytes, f)'.
self success: bytesWritten = imageBytes.
self cCode: 'sqImageFileClose(f)'.
"set Mac file type and creator; this is a noop on other platforms"
self cCode: 'dir_SetMacFileTypeAndCreator(imageName, strlen(imageName), "STim", "FAST")'.
! !
More information about the Squeak-dev
mailing list
|