texmacs-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Texmacs-dev] Mathematica Plugin on macOS


From: Philippe Joyez
Subject: [Texmacs-dev] Mathematica Plugin on macOS
Date: Sat, 9 Jun 2012 08:34:50 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

By looking at what Bertrand provided a few weeks ago, I could reconstitute what
Miguel did to get the mathematica plugin working on his mac: On macOS you need
to provide a substitute for getline (separate c file added) and to fix a few
types in tm_mathematica.c for the compilation to proceed.

The compilation command was :

*************************
g++ -o tm_mathematica.bin tm_mathematica.c getline.c \
-L"/Applications/Mathematica/Mathematica.app/SystemFiles/Links/\
MathLink/DeveloperKit/CompilerAdditions" -lm -lpthread -lMLi3

chmod +x /sw2/bin/tm_mathematica.bin

cd /sw2/lib/TeXmacs/bin
chmod 755 tm_mathematica
**************************

You get the corrected tm_mathematica.c and getline.c sources by applying this
patch to the svn source:

Index: plugins/mathematica/src.lazy/getline.c
===================================================================
--- plugins/mathematica/src.lazy/getline.c      (révision 0)
+++ plugins/mathematica/src.lazy/getline.c      (révision 0)
@@ -0,0 +1,145 @@
+/* getline.c -- Replacement for GNU C library function getline
+
+Copyright (C) 1993 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.  */
+
+/* Written by Jan Brittenson, address@hidden  */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <assert.h>
+#include <errno.h>
+
+#if STDC_HEADERS
+#include <stdlib.h>
+#else
+char *malloc (), *realloc ();
+#endif
+
+/* Always add at least this many bytes when extending the buffer.  */
+#define MIN_CHUNK 64
+
+/* Read up to (and including) a TERMINATOR from STREAM into *LINEPTR
+   + OFFSET (and null-terminate it). *LINEPTR is a pointer returned from
+   malloc (or NULL), pointing to *N characters of space.  It is realloc'd
+   as necessary.  Return the number of characters read (not including the
+   null terminator), or -1 on error or EOF.  On a -1 return, the caller
+   should check feof(), if not then errno has been set to indicate
+   the error.  */
+
+int
+getstr (
+     char **lineptr,
+     size_t *n,
+     FILE *stream,
+     char terminator,
+     int offset)
+{
+  int nchars_avail;            /* Allocated but unused chars in *LINEPTR.  */
+  char *read_pos;              /* Where we're reading into *LINEPTR. */
+  int ret;
+
+  if (!lineptr || !n || !stream)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+
+  if (!*lineptr)
+    {
+      *n = MIN_CHUNK;
+      *lineptr = (char*)malloc (*n);
+      if (!*lineptr)
+       {
+         errno = ENOMEM;
+         return -1;
+       }
+    }
+
+  nchars_avail = *n - offset;
+  read_pos = *lineptr + offset;
+
+  for (;;)
+    {
+      int save_errno;
+      register int c = getc (stream);
+
+      save_errno = errno;
+
+      /* We always want at least one char left in the buffer, since we
+        always (unless we get an error while reading the first char)
+        NUL-terminate the line buffer.  */
+
+      assert((*lineptr + *n) == (read_pos + nchars_avail));
+      if (nchars_avail < 2)
+       {
+         if (*n > MIN_CHUNK)
+           *n *= 2;
+         else
+           *n += MIN_CHUNK;
+
+         nchars_avail = *n + *lineptr - read_pos;
+         *lineptr = (char *)realloc (*lineptr, *n);
+         if (!*lineptr)
+           {
+             errno = ENOMEM;
+             return -1;
+           }
+         read_pos = *n - nchars_avail + *lineptr;
+         assert((*lineptr + *n) == (read_pos + nchars_avail));
+       }
+
+      if (ferror (stream))
+       {
+         /* Might like to return partial line, but there is no
+            place for us to store errno.  And we don't want to just
+            lose errno.  */
+         errno = save_errno;
+         return -1;
+       }
+
+      if (c == EOF)
+       {
+         /* Return partial line, if any.  */
+         if (read_pos == *lineptr)
+           return -1;
+         else
+           break;
+       }
+
+      *read_pos++ = c;
+      nchars_avail--;
+
+      if (c == terminator)
+       /* Return the line.  */
+       break;
+    }
+
+  /* Done - NUL terminate and return the number of chars read.  */
+  *read_pos = '\0';
+
+  ret = read_pos - (*lineptr + offset);
+  return ret;
+}
+
+int
+getline (
+     char **lineptr,
+     size_t *n,
+     FILE *stream)
+{
+  return getstr (lineptr, n, stream, '\n', 0);
+}
Index: plugins/mathematica/src.lazy/tm_mathematica.c
===================================================================
--- plugins/mathematica/src.lazy/tm_mathematica.c       (révision 5359)
+++ plugins/mathematica/src.lazy/tm_mathematica.c       (copie de travail)
@@ -12,8 +12,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
 #include "mathlink.h"
 
+
+// Apple's replacement for getline. (getline.c)
+int getline (char **lineptr, size_t *n, FILE *stream);
+
 #define CLOSED 11L
 #define PRE_NAME  "/plugins/mathematica/ps/pre"
 #define POST_NAME "/plugins/mathematica/ps/post"
@@ -143,7 +148,7 @@
       more=0;
       break;
     case RETURNTEXTPKT:
-      MLGetString(link,&result);
+      MLGetString(link,(const char**) &result);
 #ifdef LOG
       fprintf(log,"RETURNTEXTPKT: \"%s\"\n",result); fflush(log);
 #endif
@@ -151,21 +156,21 @@
       more=0;
       break;
     case INPUTNAMEPKT:
-      MLGetString(link,&result);
+      MLGetString(link,(const char**)&result);
 #ifdef LOG
       fprintf(log,"INPUTNAMEPKT: \"%s\"\n",result); fflush(log);
 #endif
       MLDisownString(link,result);
       break;
     case OUTPUTNAMEPKT:
-      MLGetString(link,&result);
+      MLGetString(link,(const char**)&result);
 #ifdef LOG
       fprintf(log,"OUTPUTNAMEPKT: \"%s\"\n",result); fflush(log);
 #endif
       MLDisownString(link,result);
       break;
     case TEXTPKT:
-      MLGetString(link,&result);
+      MLGetString(link,(const char**)&result);
 #ifdef LOG
       fprintf(log,"TEXTPKT: \"%s\"\n",result); fflush(log);
 #endif
@@ -182,8 +187,8 @@
       MLDisownString(link,result);
       break;
     case MESSAGEPKT:
-      MLGetSymbol(link,&symbol);
-      MLGetString(link,&result);
+      MLGetSymbol(link,(const char**)&symbol);
+      MLGetString(link,(const char**)&result);
 #ifdef LOG
       fprintf(log,"MESSAGEPKT: \"%s\"  \"%s\"\n",symbol,result); fflush(log);
 #endif
@@ -192,7 +197,7 @@
       msg=1;
       break;
     case DISPLAYPKT:
-      MLGetString(link,&result);
+      MLGetString(link,(const char**)&result);
 #ifdef LOG
       fprintf(log,"DISPLAYPK: \"%s\"\n",result); fflush(log);
 #endif
@@ -207,7 +212,7 @@
       MLDisownString(link,result);
       break;
     case DISPLAYENDPKT:
-      MLGetString(link,&result);
+      MLGetString(link,(const char**)&result);
 #ifdef LOG
       fprintf(log,"DISPLAYENDPKT: \"%s\"\n",result); fflush(log);
 #endif
@@ -221,7 +226,7 @@
       MLDisownString(link,result);
       break;
     case INPUTPKT:
-      MLGetString(link,&result);
+      MLGetString(link,(const char**)&result);
 #ifdef LOG
       fprintf(log,"INPUTPKT: \"%s\"\n",result); fflush(log);
 #endif
@@ -249,14 +254,14 @@
       MLDeinitialize(env);
       exit(0);
     } else if (err) {
-      printf("\\red Error %1d: %s\5",err,MLErrorMessage(link));
+      printf("\\red Error %1ld: %s\5",err,MLErrorMessage(link));
       exit(1);
     }
   } while (more);
 }
 
 int main(int argc, char *argv[]) {
-  long err;
+  int err;
   size_t InNum=1,l;
   char *tm_path;
 #ifdef LOG
@@ -266,8 +271,8 @@
   tm_path=getenv("TEXMACS_PATH");
   if (tm_path==NULL) exit(1);
   l=strlen(tm_path);
-  pre_name=malloc(l+strlen(PRE_NAME)+1);
-  post_name=malloc(l+strlen(POST_NAME)+1);
+  pre_name=(char *)malloc(l+strlen(PRE_NAME)+1);
+  post_name=(char *)malloc(l+strlen(POST_NAME)+1);
   strcpy(pre_name,tm_path);  strcpy(pre_name+l,PRE_NAME);
   strcpy(post_name,tm_path); strcpy(post_name+l,POST_NAME);


Best,
Philippe
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]