David T. Lewis uploaded a new version of ImageFormat to project VM Maker: http://source.squeak.org/VMMaker/ImageFormat-dtl.29.mcz ==================== Summary ==================== Name: ImageFormat-dtl.29 Author: dtl Time: 11 April 2018, 8:54:16.07 am UUID: ea0c2ff3-c413-4917-a6fb-8177e5a2ebec Ancestors: ImageFormat-dtl.28 Fix by K K Subbu: Use memcmp instead of strncmp in ckformat to compare byte arrays. =============== Diff against ImageFormat-dtl.28 =============== Item was changed: ----- Method: ImageFormat class>>generateCkFormatProgram:on: (in category 'ckformat') ----- generateCkFormatProgram: programName on: stream "Generate source code for an image format version reader. The program is intended for testing image file format from a unix shell script such that the shell script can decide what VM to run based on image requirements." | formatNumber | stream nextPutAll: '/* ', programName, ': Print the image format number on standard output */'; cr; nextPutAll: '/* for use in a shell script to test image format requirements. */'; cr; nextPutAll: '/* A non-zero return status code indicates failure. */'; cr; cr; nextPutAll: '/* Usage: ', programName, ' imageFileName */'; cr; cr; nextPutAll: '/* --- DO NOT EDIT THIS FILE --- */'; cr; nextPutAll: '/* --- Automatically generated from class ', self name, ' ', DateAndTime now asString, '--- */'; cr; nextPutAll: '/* --- Source code is in package ImageFormat in the VMMaker repository --- */'; cr; nextPutAll: '/* --- DO NOT EDIT THIS FILE --- */'; cr; cr; nextPutAll: '#include <stdio.h>'; cr; nextPutAll: '#include <stdlib.h>'; cr; nextPutAll: '#include <string.h>'; cr; cr; nextPutAll: 'main(int argc, char **argv) {'; cr; tab; nextPutAll: 'FILE *f;'; cr; tab; nextPutAll: 'unsigned char buf[8];'; cr; tab; nextPutAll: 'int formatNumber;'; cr; tab; nextPutAll: 'unsigned char c;'; cr; tab; nextPutAll: 'int match;'; cr; tab; nextPutAll: 'if (argc !!= 2) {'; cr; tab; tab; nextPutAll: 'printf("usage: ', programName, ' imageFileName\n");'; cr; tab; tab; nextPutAll: 'exit(1);'; cr; tab; nextPutAll: '}'; cr; tab; nextPutAll: 'f = fopen(argv[1], "r");'; cr; tab; nextPutAll: 'if (f == NULL) {'; cr; tab; tab; nextPutAll: 'perror(argv[1]);'; cr; tab; tab; nextPutAll: 'exit(2);'; cr; tab; nextPutAll: '}'; cr. { 0. 512 } do: [:offset | stream tab; nextPutAll: 'if(fseek(f, '; nextPutAll: offset asString; nextPutAll: 'L, SEEK_SET) !!= 0) {';cr; tab; tab; nextPutAll: 'fprintf(stderr, "cannot go to pos %d in %s\n", '; nextPutAll: offset asString; nextPutAll: ', argv[1]);'; cr; tab; tab; nextPutAll: 'exit(3);'; cr; tab; nextPutAll: '}'; cr; tab; nextPutAll: 'if (fread(buf, 1, 8, f) < 8) {'; cr; tab; tab; nextPutAll: 'fprintf(stderr, "cannot read %s\n", argv[1]);'; cr; tab; tab; nextPutAll: 'exit(3);'; cr; tab; nextPutAll: '}'; cr. self versionNumberByteArrays withIndexDo: [ :v :tag | | b | formatNumber := (self fromBytes: v) asInteger. b := 'b_', formatNumber asString, '_', tag asString. stream tab; nextPutAll: '{'; cr; tab; nextPutAll: 'unsigned char ', b, '[', v size asString, ']= { '. v inject: true into: [:first : elem | first ifFalse: [stream nextPutAll: ', ']. stream nextPutAll: elem asString. false]. stream nextPutAll: '};'; cr; + tab; nextPutAll: 'if (memcmp(buf, ', b, ', ', v size asString, ') == 0) {'; cr; - tab; nextPutAll: 'if (strncmp(buf, ', b, ', ', v size asString, ') == 0) {'; cr; tab; tab; nextPutAll: 'printf("%d\n", ', formatNumber, ');'; cr; tab; tab; nextPutAll: 'exit(0);'; cr; tab; nextPutAll: '}'; cr; tab; nextPutAll: '}'; cr]]. stream tab; nextPutAll: 'printf("0\n"); /* print an invalid format number */';cr; tab; nextPutAll: 'exit (-1); /* not found, exit with error code */'; cr; nextPutAll: '}'; cr ! |
Hi David, Subbu, forgive me... > On Apr 11, 2018, at 4:54 AM, [hidden email] wrote: > > > David T. Lewis uploaded a new version of ImageFormat to project VM Maker: > http://source.squeak.org/VMMaker/ImageFormat-dtl.29.mcz > > ==================== Summary ==================== > > Name: ImageFormat-dtl.29 > Author: dtl > Time: 11 April 2018, 8:54:16.07 am > UUID: ea0c2ff3-c413-4917-a6fb-8177e5a2ebec > Ancestors: ImageFormat-dtl.28 > > Fix by K K Subbu: Use memcmp instead of strncmp in ckformat to compare byte arrays. > > =============== Diff against ImageFormat-dtl.28 =============== > > Item was changed: > ----- Method: ImageFormat class>>generateCkFormatProgram:on: (in category 'ckformat') ----- > generateCkFormatProgram: programName on: stream > "Generate source code for an image format version reader. The program > is intended for testing image file format from a unix shell script such that > the shell script can decide what VM to run based on image requirements." > > | formatNumber | > stream nextPutAll: '/* ', programName, ': Print the image format number on standard output */'; cr; > nextPutAll: '/* for use in a shell script to test image format requirements. */'; cr; > nextPutAll: '/* A non-zero return status code indicates failure. */'; cr; cr; > nextPutAll: '/* Usage: ', programName, ' imageFileName */'; cr; cr; > nextPutAll: '/* --- DO NOT EDIT THIS FILE --- */'; cr; > nextPutAll: '/* --- Automatically generated from class ', self name, ' ', DateAndTime now asString, '--- */'; cr; > nextPutAll: '/* --- Source code is in package ImageFormat in the VMMaker repository --- */'; cr; > nextPutAll: '/* --- DO NOT EDIT THIS FILE --- */'; cr; cr; > nextPutAll: '#include <stdio.h>'; cr; > nextPutAll: '#include <stdlib.h>'; cr; > nextPutAll: '#include <string.h>'; cr; cr; > nextPutAll: 'main(int argc, char **argv) {'; cr; > tab; nextPutAll: 'FILE *f;'; cr; > tab; nextPutAll: 'unsigned char buf[8];'; cr; > tab; nextPutAll: 'int formatNumber;'; cr; > tab; nextPutAll: 'unsigned char c;'; cr; > tab; nextPutAll: 'int match;'; cr; > tab; nextPutAll: 'if (argc !!= 2) {'; cr; > tab; tab; nextPutAll: 'printf("usage: ', programName, ' imageFileName\n");'; cr; > tab; tab; nextPutAll: 'exit(1);'; cr; > tab; nextPutAll: '}'; cr; > tab; nextPutAll: 'f = fopen(argv[1], "r");'; cr; > tab; nextPutAll: 'if (f == NULL) {'; cr; > tab; tab; nextPutAll: 'perror(argv[1]);'; cr; > tab; tab; nextPutAll: 'exit(2);'; cr; > tab; nextPutAll: '}'; cr. > { 0. 512 } do: [:offset | > stream > tab; nextPutAll: 'if(fseek(f, '; nextPutAll: offset asString; nextPutAll: 'L, SEEK_SET) !!= 0) {';cr; > tab; tab; nextPutAll: 'fprintf(stderr, "cannot go to pos %d in %s\n", '; nextPutAll: offset asString; nextPutAll: ', argv[1]);'; cr; > tab; tab; nextPutAll: 'exit(3);'; cr; > tab; nextPutAll: '}'; cr; > tab; nextPutAll: 'if (fread(buf, 1, 8, f) < 8) {'; cr; > tab; tab; nextPutAll: 'fprintf(stderr, "cannot read %s\n", argv[1]);'; cr; > tab; tab; nextPutAll: 'exit(3);'; cr; > tab; nextPutAll: '}'; cr. > self versionNumberByteArrays withIndexDo: [ :v :tag | | b | > formatNumber := (self fromBytes: v) asInteger. > b := 'b_', formatNumber asString, '_', tag asString. > stream tab; nextPutAll: '{'; cr; tab; nextPutAll: 'unsigned char ', b, '[', v size asString, ']= { '. > v inject: true into: [:first : elem | > first ifFalse: [stream nextPutAll: ', ']. > stream nextPutAll: elem asString. > false]. > stream nextPutAll: '};'; cr; > + tab; nextPutAll: 'if (memcmp(buf, ', b, ', ', v size asString, ') == 0) {'; cr; > - tab; nextPutAll: 'if (strncmp(buf, ', b, ', ', v size asString, ') == 0) {'; cr; > tab; tab; nextPutAll: 'printf("%d\n", ', formatNumber, ');'; cr; > tab; tab; nextPutAll: 'exit(0);'; cr; > tab; nextPutAll: '}'; cr; tab; nextPutAll: '}'; cr]]. > stream tab; nextPutAll: 'printf("0\n"); /* print an invalid format number */';cr; > tab; nextPutAll: 'exit (-1); /* not found, exit with error code */'; cr; > nextPutAll: '}'; cr > ! This is unreadable. Either express it as a string or as a Slang program; anything but this horrid mashup of nextPutAll:s and C fragments :-( |
What about this style:
'void main({1}) \{ return 1; \}' format: {'char* args'}. Best, Marcel
|
In reply to this post by Eliot Miranda-2
On Thursday 12 April 2018 12:19 AM, Eliot Miranda wrote: > This is unreadable. Either express it as a string or as a Slang > program; anything but this horrid mashup of nextPutAll:s and C > fragments :-( > The program itself is not needed. There is a file(1) utility to detect file types from file content based on pattern specs (aka magic file). Squeak can already generate this magic file (save in $HOME/.magic). E.g. $ file --mime-type /opt/gits/oscogvm/image/*.image /opt/gits/oscogvm/image/spurreader.image: application/spur-image /opt/gits/oscogvm/image/SpurVMMaker.image: application/spur-image /opt/gits/oscogvm/image/trunk50.image: application/spur-image /opt/gits/oscogvm/image/trunk6.image: application/spur-image To add a launcher to the desktop menu, the following desktop spec --- spur.desktop --- [Desktop Entry] Type=Application Exec=cog %F Name=Cog GenericName=Squeak VM Icon=cog Terminal=false Categories=Development; MimeType=application/spur-image;application/cog-image;application/squeak-image; ----- $ xdg-desktop-menu install --novendor spur.desktop On my machine, I symlink cog to /opt/gits/oscogvm/image/sqlinux..../squeak and then I can open any image from file browser or from command line with: $ xdg-open blahblah.image HTH .. Subbu |
In reply to this post by marcel.taeumel
|
In reply to this post by K K Subbu
Hi Subbu, > On Apr 12, 2018, at 4:58 AM, K K Subbu <[hidden email]> wrote: > >> On Thursday 12 April 2018 12:19 AM, Eliot Miranda wrote: >> This is unreadable. Either express it as a string or as a Slang >> program; anything but this horrid mashup of nextPutAll:s and C >> fragments :-( >> > > The program itself is not needed. There is a file(1) utility to detect file types from file content based on pattern specs (aka magic file). Squeak can already generate this magic file (save in $HOME/.magic). While we can't rely on a system having its file database up-to-date we can rely on our district containing a runnable version of ckformat.c. So while what you say is v nice in an ideal world, I think we do need something like ckformat.c now we're on the cusp of a cleaving between the 32/64 compatibility world ushered in by x86_64. > E.g. > > $ file --mime-type /opt/gits/oscogvm/image/*.image > /opt/gits/oscogvm/image/spurreader.image: application/spur-image > /opt/gits/oscogvm/image/SpurVMMaker.image: application/spur-image > /opt/gits/oscogvm/image/trunk50.image: application/spur-image > /opt/gits/oscogvm/image/trunk6.image: application/spur-image > > To add a launcher to the desktop menu, the following desktop spec > --- spur.desktop --- > [Desktop Entry] > Type=Application > Exec=cog %F > Name=Cog > GenericName=Squeak VM > Icon=cog > Terminal=false > Categories=Development; > MimeType=application/spur-image;application/cog-image;application/squeak-image; > ----- > > $ xdg-desktop-menu install --novendor spur.desktop > > On my machine, I symlink cog to /opt/gits/oscogvm/image/sqlinux..../squeak and then I can open any image from file browser or from command line with: > > $ xdg-open blahblah.image > > HTH .. Subbu |
On Thursday 12 April 2018 08:21 PM, Eliot Miranda wrote: > While we can't rely on a system having its file database up-to-date > we can rely on our district containing a runnable version of > ckformat.c. So while what you say is v nice in an ideal world, I > think we do need something like ckformat.c now we're on the cusp of a > cleaving between the 32/64 compatibility world ushered in by x86_64. Eliot, file(1) has been around since 1973 and many tools and package managers depend on it. Others VMs like Python etc. also use it. Squeak already has code to emit the magic file. Package managers could use it in their post-install script. The existing Debian package uses an outdated one so we may as well generate a supported version. file can also take the filename as an argument: file -m /usr/local/lib/squeak/magic --mime blah.image Also customizing a magic file doesn't require a recompilation, so it definitely helps us in the 32/64 transition. Regards .. Subbu |
Hi Subbu,
On Thu, Apr 12, 2018 at 10:43 AM, K K Subbu <[hidden email]> wrote:
OK, but we also have to deal with Mac OS X and Windows, and we have to work reliably no matter what the user's permissions are. So if you pursue a file(1) based strategy please check on these other platforms. For example, if it turns out that file(1) is not a viable option on Windows (which I think is the truth) then it might be less costly overall to use ckformat because it can be a cross-platform solution. BTW I was altering the file database for BrouHaHa images back in the 80's. I'm aware of file, use it often, and like it. But that doesn't mean I think it is always appropriate. _,,,^..^,,,_ best, Eliot |
In reply to this post by Eliot Miranda-2
int main > ---------- Original Message ---------- > From: Eliot Miranda <[hidden email]> > Date: April 12, 2018 at 10:47 AM > > > > > > On Apr 12, 2018, at 1:57 AM, Marcel Taeumel <[hidden email]> wrote: > > > > What about this style: > > > > 'void main({1}) \{ return 1; \}' format: {'char* args'}. > > +1. Exactly. > > > > Best, > > Marcel > >> Am 11.04.2018 20:49:12 schrieb Eliot Miranda <[hidden email]>: > >> > >> > >> Hi David, Subbu, > >> > >> forgive me... > >> > >> > On Apr 11, 2018, at 4:54 AM, [hidden email] wrote: > >> > > >> > > >> > David T. Lewis uploaded a new version of ImageFormat to project VM Maker: > >> > http://source.squeak.org/VMMaker/ImageFormat-dtl.29.mcz > >> > > >> > ==================== Summary ==================== > >> > > >> > Name: ImageFormat-dtl.29 > >> > Author: dtl > >> > Time: 11 April 2018, 8:54:16.07 am > >> > UUID: ea0c2ff3-c413-4917-a6fb-8177e5a2ebec > >> > Ancestors: ImageFormat-dtl.28 > >> > > >> > Fix by K K Subbu: Use memcmp instead of strncmp in ckformat to compare byte arrays. > >> > > >> > =============== Diff against ImageFormat-dtl.28 =============== > >> > > >> > Item was changed: > >> > ----- Method: ImageFormat class>>generateCkFormatProgram:on: (in category 'ckformat') ----- > >> > generateCkFormatProgram: programName on: stream > >> > "Generate source code for an image format version reader. The program > >> > is intended for testing image file format from a unix shell script such that > >> > the shell script can decide what VM to run based on image requirements." > >> > > >> > | formatNumber | > >> > stream nextPutAll: '/* ', programName, ': Print the image format number on standard output */'; cr; > >> > nextPutAll: '/* for use in a shell script to test image format requirements. */'; cr; > >> > nextPutAll: '/* A non-zero return status code indicates failure. */'; cr; cr; > >> > nextPutAll: '/* Usage: ', programName, ' imageFileName */'; cr; cr; > >> > nextPutAll: '/* --- DO NOT EDIT THIS FILE --- */'; cr; > >> > nextPutAll: '/* --- Automatically generated from class ', self name, ' ', DateAndTime now asString, '--- */'; cr; > >> > nextPutAll: '/* --- Source code is in package ImageFormat in the VMMaker repository --- */'; cr; > >> > nextPutAll: '/* --- DO NOT EDIT THIS FILE --- */'; cr; cr; > >> > nextPutAll: '#include '; cr; > >> > nextPutAll: '#include '; cr; > >> > nextPutAll: '#include '; cr; cr; > >> > nextPutAll: 'main(int argc, char **argv) {'; cr; > >> > tab; nextPutAll: 'FILE *f;'; cr; > >> > tab; nextPutAll: 'unsigned char buf[8];'; cr; > >> > tab; nextPutAll: 'int formatNumber;'; cr; > >> > tab; nextPutAll: 'unsigned char c;'; cr; > >> > tab; nextPutAll: 'int match;'; cr; > >> > tab; nextPutAll: 'if (argc !!= 2) {'; cr; > >> > tab; tab; nextPutAll: 'printf("usage: ', programName, ' imageFileName\n");'; cr; > >> > tab; tab; nextPutAll: 'exit(1);'; cr; > >> > tab; nextPutAll: '}'; cr; > >> > tab; nextPutAll: 'f = fopen(argv[1], "r");'; cr; > >> > tab; nextPutAll: 'if (f == NULL) {'; cr; > >> > tab; tab; nextPutAll: 'perror(argv[1]);'; cr; > >> > tab; tab; nextPutAll: 'exit(2);'; cr; > >> > tab; nextPutAll: '}'; cr. > >> > { 0. 512 } do: [:offset | > >> > stream > >> > tab; nextPutAll: 'if(fseek(f, '; nextPutAll: offset asString; nextPutAll: 'L, SEEK_SET) !!= 0) {';cr; > >> > tab; tab; nextPutAll: 'fprintf(stderr, "cannot go to pos %d in %s\n", '; nextPutAll: offset asString; nextPutAll: ', argv[1]);'; cr; > >> > tab; tab; nextPutAll: 'exit(3);'; cr; > >> > tab; nextPutAll: '}'; cr; > >> > tab; nextPutAll: 'if (fread(buf, 1, 8, f) < 8)="" {';=""> > >> > tab; tab; nextPutAll: 'fprintf(stderr, "cannot read %s\n", argv[1]);'; cr; > >> > tab; tab; nextPutAll: 'exit(3);'; cr; > >> > tab; nextPutAll: '}'; cr. > >> > self versionNumberByteArrays withIndexDo: [ :v :tag | | b | > >> > formatNumber := (self fromBytes: v) asInteger. > >> > b := 'b_', formatNumber asString, '_', tag asString. > >> > stream tab; nextPutAll: '{'; cr; tab; nextPutAll: 'unsigned char ', b, '[', v size asString, ']= { '. > >> > v inject: true into: [:first : elem | > >> > first ifFalse: [stream nextPutAll: ', ']. > >> > stream nextPutAll: elem asString. > >> > false]. > >> > stream nextPutAll: '};'; cr; > >> > + tab; nextPutAll: 'if (memcmp(buf, ', b, ', ', v size asString, ') == 0) {'; cr; > >> > - tab; nextPutAll: 'if (strncmp(buf, ', b, ', ', v size asString, ') == 0) {'; cr; > >> > tab; tab; nextPutAll: 'printf("%d\n", ', formatNumber, ');'; cr; > >> > tab; tab; nextPutAll: 'exit(0);'; cr; > >> > tab; nextPutAll: '}'; cr; tab; nextPutAll: '}'; cr]]. > >> > stream tab; nextPutAll: 'printf("0\n"); /* print an invalid format number */';cr; > >> > tab; nextPutAll: 'exit (-1); /* not found, exit with error code */'; cr; > >> > nextPutAll: '}'; cr > >> > ! > >> > >> This is unreadable. Either express it as a string or as a Slang program; anything but this horrid mashup of nextPutAll:s and C fragments :-( |
In reply to this post by Eliot Miranda-2
Hi, Catching up on email. With all due respect, no I am not going to rewrite it. And thank you to Subbu for catching a serious error in the code. For those who may not know the background, the ckformat program is used in the classic interpreter VM distribution, and supports the /usr/bin/squeak mechanism for selecting whether cog for 32 bit V3 image, interpreter VM for 32 bit V3 image, or interpreter VM for 64 bit image should be be used. The rationale for storing and writing the ckformat.c source code from ImageFormat class>>createCkFormatProgram is to keep the source in sync with any updates that may be made to ImageFormat. Thus if someone invents a new image format, and gives it a new image format number that is documented in class ImageFormat, then the source code for the ckformat utility is automatically updated accordingly. The ckformat utility can also be used to select the right cog or spur32 or spur64 or intepreter32/64 VM for a given image file, although some naming conventions will need to be agreed for the various VM installations. Dave On Wed, Apr 11, 2018 at 11:49:02AM -0700, Eliot Miranda wrote: > > Hi David, Subbu, > > forgive me... > > > On Apr 11, 2018, at 4:54 AM, [hidden email] wrote: > > > > > > David T. Lewis uploaded a new version of ImageFormat to project VM Maker: > > http://source.squeak.org/VMMaker/ImageFormat-dtl.29.mcz > > > > ==================== Summary ==================== > > > > Name: ImageFormat-dtl.29 > > Author: dtl > > Time: 11 April 2018, 8:54:16.07 am > > UUID: ea0c2ff3-c413-4917-a6fb-8177e5a2ebec > > Ancestors: ImageFormat-dtl.28 > > > > Fix by K K Subbu: Use memcmp instead of strncmp in ckformat to compare byte arrays. > > > > =============== Diff against ImageFormat-dtl.28 =============== > > > > Item was changed: > > ----- Method: ImageFormat class>>generateCkFormatProgram:on: (in category 'ckformat') ----- > > generateCkFormatProgram: programName on: stream > > "Generate source code for an image format version reader. The program > > is intended for testing image file format from a unix shell script such that > > the shell script can decide what VM to run based on image requirements." > > > > | formatNumber | > > stream nextPutAll: '/* ', programName, ': Print the image format number on standard output */'; cr; > > nextPutAll: '/* for use in a shell script to test image format requirements. */'; cr; > > nextPutAll: '/* A non-zero return status code indicates failure. */'; cr; cr; > > nextPutAll: '/* Usage: ', programName, ' imageFileName */'; cr; cr; > > nextPutAll: '/* --- DO NOT EDIT THIS FILE --- */'; cr; > > nextPutAll: '/* --- Automatically generated from class ', self name, ' ', DateAndTime now asString, '--- */'; cr; > > nextPutAll: '/* --- Source code is in package ImageFormat in the VMMaker repository --- */'; cr; > > nextPutAll: '/* --- DO NOT EDIT THIS FILE --- */'; cr; cr; > > nextPutAll: '#include <stdio.h>'; cr; > > nextPutAll: '#include <stdlib.h>'; cr; > > nextPutAll: '#include <string.h>'; cr; cr; > > nextPutAll: 'main(int argc, char **argv) {'; cr; > > tab; nextPutAll: 'FILE *f;'; cr; > > tab; nextPutAll: 'unsigned char buf[8];'; cr; > > tab; nextPutAll: 'int formatNumber;'; cr; > > tab; nextPutAll: 'unsigned char c;'; cr; > > tab; nextPutAll: 'int match;'; cr; > > tab; nextPutAll: 'if (argc !!= 2) {'; cr; > > tab; tab; nextPutAll: 'printf("usage: ', programName, ' imageFileName\n");'; cr; > > tab; tab; nextPutAll: 'exit(1);'; cr; > > tab; nextPutAll: '}'; cr; > > tab; nextPutAll: 'f = fopen(argv[1], "r");'; cr; > > tab; nextPutAll: 'if (f == NULL) {'; cr; > > tab; tab; nextPutAll: 'perror(argv[1]);'; cr; > > tab; tab; nextPutAll: 'exit(2);'; cr; > > tab; nextPutAll: '}'; cr. > > { 0. 512 } do: [:offset | > > stream > > tab; nextPutAll: 'if(fseek(f, '; nextPutAll: offset asString; nextPutAll: 'L, SEEK_SET) !!= 0) {';cr; > > tab; tab; nextPutAll: 'fprintf(stderr, "cannot go to pos %d in %s\n", '; nextPutAll: offset asString; nextPutAll: ', argv[1]);'; cr; > > tab; tab; nextPutAll: 'exit(3);'; cr; > > tab; nextPutAll: '}'; cr; > > tab; nextPutAll: 'if (fread(buf, 1, 8, f) < 8) {'; cr; > > tab; tab; nextPutAll: 'fprintf(stderr, "cannot read %s\n", argv[1]);'; cr; > > tab; tab; nextPutAll: 'exit(3);'; cr; > > tab; nextPutAll: '}'; cr. > > self versionNumberByteArrays withIndexDo: [ :v :tag | | b | > > formatNumber := (self fromBytes: v) asInteger. > > b := 'b_', formatNumber asString, '_', tag asString. > > stream tab; nextPutAll: '{'; cr; tab; nextPutAll: 'unsigned char ', b, '[', v size asString, ']= { '. > > v inject: true into: [:first : elem | > > first ifFalse: [stream nextPutAll: ', ']. > > stream nextPutAll: elem asString. > > false]. > > stream nextPutAll: '};'; cr; > > + tab; nextPutAll: 'if (memcmp(buf, ', b, ', ', v size asString, ') == 0) {'; cr; > > - tab; nextPutAll: 'if (strncmp(buf, ', b, ', ', v size asString, ') == 0) {'; cr; > > tab; tab; nextPutAll: 'printf("%d\n", ', formatNumber, ');'; cr; > > tab; tab; nextPutAll: 'exit(0);'; cr; > > tab; nextPutAll: '}'; cr; tab; nextPutAll: '}'; cr]]. > > stream tab; nextPutAll: 'printf("0\n"); /* print an invalid format number */';cr; > > tab; nextPutAll: 'exit (-1); /* not found, exit with error code */'; cr; > > nextPutAll: '}'; cr > > ! > > This is unreadable. Either express it as a string or as a Slang program; anything but this horrid mashup of nextPutAll:s and C fragments :-( |
Free forum by Nabble | Edit this page |