Annotation of OpenXM/src/ox_toolkit/sample3.c, Revision 1.1
1.1 ! takayama 1: /* $OpenXM$ */
! 2:
! 3: /* Example:
! 4: sample3
! 5: > fctr(x^10-1)
! 6: > def foo(N) { return (2*N); }
! 7: > foo(10)
! 8: > ctrl-C
! 9: */
! 10:
! 11: /*
! 12: gcc -o sample3 sample3.c -I${OpenXM_HOME}/include -L${OpenXM_HOME}/lib -lox -lgmp -lmpfr -lgc
! 13: */
! 14:
! 15: #include <stdio.h>
! 16: #include <stdlib.h>
! 17: #include <unistd.h>
! 18: #include <string.h>
! 19: #include <errno.h>
! 20: #include <fcntl.h>
! 21:
! 22: #include "ox_toolkit.h"
! 23:
! 24: extern OXFILE *ox_start(char* host, char* prog1, char* prog2);
! 25: OXFILE *sv;
! 26:
! 27: #define SIZE_CMDLINE 8192
! 28:
! 29: static int size = SIZE_CMDLINE;
! 30: static char cmdline[SIZE_CMDLINE];
! 31:
! 32: static void prompt()
! 33: {
! 34: fprintf(stdout, "> ");
! 35: fgets(cmdline, size, stdin);
! 36: }
! 37:
! 38:
! 39: int main(int argc, char* argv[])
! 40: {
! 41: ox* m = NULL;
! 42: cmo* c = NULL;
! 43: char cmd1[SIZE_CMDLINE+1024];
! 44: int code;
! 45: char *server = "ox_asir";
! 46:
! 47: ox_stderr_init(stderr);
! 48:
! 49: sv = ox_start("localhost", "ox", server);
! 50: if (sv == NULL) {
! 51: ox_printf("testclient:: I cannot connect to servers.\n");
! 52: exit(1);
! 53: }
! 54: printf("Input size is limited to %d bytes.\n",SIZE_CMDLINE-1);
! 55: while(prompt(),1) {
! 56: strcpy(cmd1,"(OX_DATA,(CMO_STRING,\"if(1){");
! 57: strcat(cmd1,cmdline);
! 58: strcat(cmd1,";}else{};\"))\n");
! 59: m = ox_parse_lisp(cmd1);
! 60: if (m == NULL) break;
! 61: send_ox(sv, m);
! 62: m = ox_parse_lisp("(OX_COMMAND,(SM_executeStringByLocalParser))\n");
! 63: send_ox(sv, m);
! 64: m = ox_parse_lisp("(OX_COMMAND,(SM_popString))\n");
! 65: send_ox(sv, m);
! 66: if (m->tag == OX_COMMAND) {
! 67: code = ((ox_command *)m)->command;
! 68: if (code >= 1024) {
! 69: break;
! 70: }else if (code == SM_popCMO || code == SM_popString) {
! 71: receive_ox_tag(sv);
! 72: c = receive_cmo(sv);
! 73: ox_printf("testclient:: cmo received.\n");
! 74: //print_cmo(c);
! 75: if (c->tag == CMO_STRING) printf("%s",((cmo_string *)c)->s);
! 76: else ; // error
! 77: }
! 78: }
! 79: }
! 80:
! 81: ox_reset(sv);
! 82: ox_printf("The testclient resets.\n");
! 83: ox_close(sv);
! 84: ox_printf("The testclient halts.\n");
! 85:
! 86: return 0;
! 87: }
! 88:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>