<\body> Instead of connecting your system to using a pipe, it is also possible to connect it as a dynamically linked library. Although communication through pipes is usually easier to implement, more robust and compatible with gradual output, the second option is faster. In order to dynamically link your application to , you should follow the communication protocol, which is specified in the following header file: <\verbatim> \ \ \ \ In this file it is specified that your application should export a data structure <\cpp-fragment> typedef struct package_exports_1 { \ \ char* version_protocol; /* "TeXmacs communication protocol 1" */ \ \ char* version_package; \ \ char* (*install) (TeXmacs_exports_1* TeXmacs, \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ char* options, char** errors); \ \ char* (*evaluate) (char* what, char* session, char** errors); } package_exports_1; which contains an installation routine for your application, as well as an evaluation routine for further input (for more information, see the header file). will on its turn export a structure <\cpp-fragment> typedef struct TeXmacs_exports_1 { \ \ char* version_protocol; /* "TeXmacs communication protocol 1" */ \ \ char* version_TeXmacs; } TeXmacs_exports_1; It is assumed that each application takes care of its own memory management. Hence, strings created by will be destroyed by and strings created by the application need to be destroyed by the application. The string should contain and the string the version of your package. The routine will be called once by in order to initialize your system with options . It communicates the routines exported by to your system in the form of a pointer to a structure of type . The routine should return a status message like <\verbatim> \ \ \ \ "yourcas-version successfully linked to TeXmacs" If installation failed, then you should return and should contain an error message. The routine is used to evaluate the expression inside a -session with name . It should return the evaluation of or if an error occurred. either contains one or more warning messages or an error message, if the evaluation failed. The formats being used obey the same rules as in the case of communication by pipes. Finally, the configuration file of your plug-in should contain something as follows: <\scheme-fragment> (plugin-configure \ \ (:require (url-exists? (url "$LD_LIBRARY_PATH" "lib.so"))) \ \ (:link "lib.so" "_exports" "") \ \ ) Here _exports> is a pointer to a structure of the type . <\remark> It is possible that the communication protocol changes in the future. In that case, the data structures and will be replaced by data structures and , where is the version of the protocol. These structures will always have the abstract data structures and in common, with information about the versions of the protocol, and your package. plug-in> The plug-in gives an example of how to write dynamically linked libraries. It consists of the following files: <\verbatim> \ \ \ \ \ \ \ \ \ \ \ \ The contains <\quotation> <\framed-fragment> <\with|par-par-sep|0fn> <\with|font-family|tt> tmsrc = /home/vdhoeven/texmacs/src/TeXmacs CXX = g++ LD \ = g++ \; lib/libtmdynlink.so: src/dynlink.cpp \ \ \ \ \ \ \ \ $(CXX) -I$(tmsrc)/include -c src/dynlink.cpp -o src/dynlink.o \ \ \ \ \ \ \ \ $(LD) -shared -o lib/libtmdynlink.so src/dynlink.o so that running it will create a dynamic library from . The variable should contain , so as to find the include file . The configuration file simply contains <\scheme-fragment> (plugin-configure dynlink \ \ (:require (url-exists? (url "$LD_LIBRARY_PATH" \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ "libtmdynlink.so"))) \ \ (:link "libtmdynlink.so" "dynlink_exports" "") \ \ (:session "Dynlink")) As to the file , it contains a string <\cpp-fragment> static char* output= NULL; with the last output, the initialization routine <\cpp-fragment> char* dynlink_install (TeXmacs_exports_1* TM, char* opts, char** errs) { \ \ output= (char*) malloc (50); \ \ strcpy (output, "\\2verbatim:Started dynamic link\\5"); \ \ return output; } the evaluation routine <\cpp-fragment> char* dynlink_eval (char* what, char* session, char** errors) { \ \ free (output); \ \ output= (char*) malloc (50 + strlen (what)); \ \ strcpy (output, "\\2verbatim:You typed "); \ \ strcat (output, what); \ \ strcat (output, "\\5"); \ \ return output; } and the data structure with the public exports: <\cpp-fragment> package_exports_1 dynlink_exports= { \ \ "TeXmacs communication protocol 1", \ \ "Dynlink 1", \ \ dynlink_install, \ \ dynlink_eval }; Notice that the application takes care of the memory allocation and deallocation of . <\initial> <\collection>