]> thyrsus.com Git - intercal.git/commitdiff
Code for compiling .b98 to .cio
authorAlex Smith <ais523@bham.ac.uk>
Sun, 6 Jul 2008 21:50:41 +0000 (17:50 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 26 Aug 2010 00:35:08 +0000 (20:35 -0400)
etc/cfunge.patch
src/ick_lose.h
src/perpet.c
src/uncommon.c

index ef2f513e34874db2def22c5fc2b2b72a59546362..5e145b1341efad3ae91c2e09f131a8d3a9a60020 100644 (file)
  #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]) {
index fae5c4eeed069d10f8ab7c44e421ee6e8cf8ee5d..1684b18e5e4ca58643120d477cc92f45e392c94e 100644 (file)
 /* 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"
index 804d5365b0c448f97c9dbb3dc69a62ac737d1fc2..bf2ed5039666fbced1c78a760bde10297b600fc6 100644 (file)
@@ -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);
 
index ed3dfb6fe664d4ed0319b60c93278c201235fb54..abc98bec48980a23b54325dbd03dd9f2f083198c 100644 (file)
@@ -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,