[BACK]Return to sample4.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_toolkit

Annotation of OpenXM/src/ox_toolkit/sample4.c, Revision 1.1

1.1     ! takayama    1: /* $OpenXM$
        !             2:  */
        !             3:
        !             4: /*  Example:
        !             5:    OpenXM_HOME etc should be properly set by OpenXM/rc/dot.bashrc
        !             6:    python2
        !             7: import ctypes
        !             8: lib = ctypes.cdll.LoadLibrary('./sample4.so');
        !             9: lib.eval_string_by_ox_asir.argtypes = (ctypes.c_char_p,)
        !            10: lib.eval_string_by_ox_asir.restype = ctypes.c_char_p
        !            11: lib.open_ox_asir()
        !            12: s = lib.eval_string_by_ox_asir('fctr(x^10-1)')
        !            13: print(s)
        !            14: s = lib.eval_string_by_ox_asir('print_tex_form(poly_factor((x^10-1))')
        !            15: print(s)
        !            16: lib.close_ox_asir()
        !            17:  */
        !            18:
        !            19: /*
        !            20:   gcc -shared -fPIC -o sample4.so sample4.c -I${OpenXM_HOME}/include -L${OpenXM_HOME}/lib -lox -lgmp -lmpfr -lgc
        !            21: */
        !            22:
        !            23: #include <stdio.h>
        !            24: #include <stdlib.h>
        !            25: #include <unistd.h>
        !            26: #include <string.h>
        !            27: #include <errno.h>
        !            28: #include <fcntl.h>
        !            29:
        !            30: #include "ox_toolkit.h"
        !            31:
        !            32: extern OXFILE *ox_start(char* host, char* prog1, char* prog2);
        !            33: OXFILE *sv;
        !            34:
        !            35: #define SIZE_CMDLINE  8192
        !            36:
        !            37: static int  size = SIZE_CMDLINE;
        !            38: static char cmdline[SIZE_CMDLINE];
        !            39:
        !            40: int open_ox_asir()
        !            41: {
        !            42:   char *server = "ox_asir";
        !            43:   sv = ox_start("localhost", "ox", server);
        !            44:   if (sv == NULL) {
        !            45:     ox_printf("testclient:: I cannot connect to servers.\n");
        !            46:     exit(1);
        !            47:   }
        !            48:   printf("Input size is limited to %d bytes.\n",SIZE_CMDLINE-1);
        !            49:   ox_stderr_init(stderr);
        !            50:   return 0;
        !            51: }
        !            52: char *eval_string_by_ox_asir(char *cmdline)
        !            53: {
        !            54:   ox* m = NULL;
        !            55:   cmo* c = NULL;
        !            56:   char cmd1[SIZE_CMDLINE+1024];
        !            57:   int code;
        !            58:
        !            59:   if (strlen(cmdline)>SIZE_CMDLINE-1) return "Error: too long command. Increase SIZE_CMDLINE";
        !            60:   strcpy(cmd1,"(OX_DATA,(CMO_STRING,\"if(1){");
        !            61:   strcat(cmd1,cmdline);
        !            62:   strcat(cmd1,";}else{};\"))\n");
        !            63:   m = ox_parse_lisp(cmd1);
        !            64:   // if (m == NULL) ; //  error, not implemented
        !            65:   send_ox(sv, m);
        !            66:   m = ox_parse_lisp("(OX_COMMAND,(SM_executeStringByLocalParser))\n");
        !            67:   send_ox(sv, m);
        !            68:   m = ox_parse_lisp("(OX_COMMAND,(SM_popString))\n");
        !            69:   send_ox(sv, m);
        !            70:   code = ((ox_command *)m)->command;
        !            71:   if (code >= 1024) {
        !            72:     ; // error, not implemented
        !            73:   }else if (code == SM_popCMO || code == SM_popString) {
        !            74:     receive_ox_tag(sv);
        !            75:     c = receive_cmo(sv);
        !            76:     ox_printf("testclient:: cmo received.\n");
        !            77:     //print_cmo(c);
        !            78:     if (c->tag == CMO_STRING)  return ((cmo_string *)c)->s;
        !            79:     else ; // error
        !            80:   }
        !            81:   return NULL;
        !            82: }
        !            83:
        !            84: int close_ox_asir() {
        !            85:   ox_reset(sv);
        !            86:   ox_printf("The testclient resets.\n");
        !            87:   ox_close(sv);
        !            88:   ox_printf("The testclient halts.\n");
        !            89:   return(0);
        !            90: }
        !            91:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>