From f7a45fd9663720cc183d762aef20a7ef6472454f Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Sun, 6 Jul 2008 17:50:41 -0400 Subject: [PATCH] Code for compiling .b98 to .cio --- etc/cfunge.patch | 11 ++++++ src/ick_lose.h | 4 +++ src/perpet.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++- src/uncommon.c | 2 +- 4 files changed, 103 insertions(+), 2 deletions(-) diff --git a/etc/cfunge.patch b/etc/cfunge.patch index ef2f513..5e145b1 100644 --- a/etc/cfunge.patch +++ b/etc/cfunge.patch @@ -13,3 +13,14 @@ #define APPVERSION "0.2.1-pre2" /// For y instruction. +--- src/funge-space/funge-space.c 2008-07-06 00:49:23.000000000 +0100 ++++ src/funge-space/funge-space.c 2008-07-06 18:09:22.000000000 +0100 +@@ -312,7 +312,7 @@ + // Row in fungespace + FUNGEVECTORTYPE y = 0; + FUNGEVECTORTYPE x = 0; +- size_t linelen = strlen(program) + 1; ++ size_t linelen = strlen(program); + + for (size_t i = 0; i < linelen; i++) { + switch (program[i]) { diff --git a/src/ick_lose.h b/src/ick_lose.h index fae5c4e..1684b18 100644 --- a/src/ick_lose.h +++ b/src/ick_lose.h @@ -137,6 +137,10 @@ /* Source file name with invalid extension (use .i or .[3-7]i). */ #define IE998 "998 EXCUSE ME,\n\ YOU MUST HAVE ME CONFUSED WITH SOME OTHER COMPILER\n" +/* (AIS) File used of a type for which the required libraries aren't + available. */ +#define IE899 "899 HELLO?\n\ + CAN ANYONE GIVE ME A HAND HERE?\n" /* Illegal possession of a controlled unary operator. */ #define IE997 "997 ILLEGAL POSSESSION OF A CONTROLLED UNARY OPERATOR.\n\ ON THE WAY TO %d\n" diff --git a/src/perpet.c b/src/perpet.c index 804d536..bf2ed50 100644 --- a/src/perpet.c +++ b/src/perpet.c @@ -528,10 +528,12 @@ int main(int argc, char *argv[]) along the same lines as CLC-INTERCAL's preloads. Search for it in the usual places, then make a copy in a temp directory and substitute that on the command line. */ - char* tempfn="%s.c"; + char* tempfn; FILE* fromcopy; FILE* tocopy; int c2; + fixexpansionlibrary: + tempfn="%s.c"; #ifndef HAVE_SNPRINTF (void) sprintf(buf2, "%s.c", argv[optind]); #else @@ -616,6 +618,90 @@ int main(int argc, char *argv[]) continue; } + if(useickec && !strcmp(chp,"b98")) + { + /* AIS: Compile the .b98 file into a .cio so that it can be used + later, and include the necessary libraries to use it, or error + if the libraries aren't installed yet. I use a somewhat dubious + trick here: the .b98 file's .cio, and the necessary libraries, + are added in the libraries section of the command line, whereas + the space on the command line where the .b98 file was is used + for the expansion library ecto_b98. This is because ecto_b98 + requires preprocessing/prelinking/interprocessing or whatever + you want to call it, whereas unlike for other .cios, the .cio + produced from the Befunge file doesn't. + */ + +#define MARKERMAX 128 + + FILE* of; + int x,y,jlb; + int markerposns[MARKERMAX][2]; + int markercount=0; + + /* Error if libick_ecto_b98.a is missing. It might be, and not + just due to installation problems. */ + if(!ick_findandtestopen("libick_ecto_b98.a",libdir,"rb",argv[0])) + ick_lose(IE899,-1,(char *)NULL); + + /* Compile the .b98 file into a .cio. It's open on stdin right now, + so we just need to handle the output side of things. */ + +#ifndef HAVE_SPRINTF + sprintf(buf2, "%s.cio", argv[optind]); +#else + snprintf(buf2, sizeof buf2, "%s.cio", argv[optind]); +#endif + + if(!((of = ick_debfopen(buf2,"w")))) + ick_lose(IE888,-1,(char *)NULL); + + fprintf(of,"const char* ick_iffi_befungeString=\n\""); + + x=0; y=0; jlb=0; + for(;;) + { + int c=getchar(); + if(c==EOF) break; + if(c==0xB7) + { + /* Middot (0xB7) has special handling. */ + c='M'; + markerposns[markercount][0]=x; + markerposns[markercount++][1]=y; + } + if(c=='\r') {jlb = 1; x=0; y++; c='\n';} + else if(c=='\n' && jlb) {jlb = 0; continue;} + else if(c=='\n') {x=0; y++; jlb = 0;} + else x++; + fprintf(of,"\\x%x",c); + if(!x) fprintf(of,"\"\n\""); + } + fprintf(of,"\";\n\nint ick_iffi_markercount=%d;\n" + "long long ick_iffi_markerposns[][2]={\n",markercount); + if(!markercount) fprintf(of,"{0,0}\n"); + while(markercount--) fprintf(of,"{%d,%d},\n", + markerposns[markercount][0], + markerposns[markercount][1]); + fprintf(of,"};\n"); + + fclose(of); + + /* Put the libraries and .cio file in the command line. */ +#ifndef HAVE_SNPRINTF + sprintf(libbuf+strlen(libbuf), +#else + snprintf(libbuf+strlen(libbuf),sizeof libbuf - strlen(libbuf), +#endif +#if 0 + 0) // to unconfuse Emacs +#endif + " %s.cio -lick_ecto_b98 -lm", argv[optind]); + /* Sort out the ecto_b98 expansion library. */ + argv[optind] = "ecto_b98"; + goto fixexpansionlibrary; + } + if(useickec && firstfile == ick_FALSE) /* AIS */ ick_lose(IE998, 1, (char *)NULL); diff --git a/src/uncommon.c b/src/uncommon.c index ed3dfb6..abc98be 100644 --- a/src/uncommon.c +++ b/src/uncommon.c @@ -37,7 +37,7 @@ int ick_printfopens=0; return t; } -/* This function looks for the skeleton and syslib, searching ick_first the +/* This function looks for the skeleton and syslib, searching first the path they should be in, then the current directory, then argv[0]'s directory (if one was given). This function avoids possible buffer overflows, instead truncating filenames (and if that manages to find them, -- 2.43.0