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

Diff for /OpenXM/src/ox_toolkit/ox_Xsample.c between version 1.1 and 1.8

version 1.1, 1999/12/16 11:35:48 version 1.8, 2005/07/26 12:52:05
Line 1 
Line 1 
 /* -*- mode: C; coding: euc-japan -*- */  /* -*- mode: C; coding: euc-japan -*- */
 /* $OpenXM$ */  /* $OpenXM: OpenXM/src/ox_toolkit/ox_Xsample.c,v 1.7 2004/12/01 17:32:26 ohara Exp $ */
   
 #include <stdio.h>  #include <stdio.h>
 #include "ox.h"  #include <stdlib.h>
   #include "ox_toolkit.h"
   
 int fd_rw = 3;  OXFILE *fd_rw;
   
 #define INIT_S_SIZE 2048  #define INIT_S_SIZE 2048
 #define EXT_S_SIZE  2048  #define EXT_S_SIZE  2048
Line 16  static cmo **stack = NULL;
Line 17  static cmo **stack = NULL;
 int initialize_stack()  int initialize_stack()
 {  {
     stack_pointer = 0;      stack_pointer = 0;
         stack_size = INIT_S_SIZE;      stack_size = INIT_S_SIZE;
         stack = malloc(stack_size*sizeof(cmo*));      stack = malloc(stack_size*sizeof(cmo*));
 }  }
   
 static int extend_stack()  static int extend_stack()
 {  {
         int size2 = stack_size + EXT_S_SIZE;      int size2 = stack_size + EXT_S_SIZE;
         cmo **stack2 = malloc(size2*sizeof(cmo*));      cmo **stack2 = malloc(size2*sizeof(cmo*));
         memcpy(stack2, stack, stack_size*sizeof(cmo *));      memcpy(stack2, stack, stack_size*sizeof(cmo *));
         free(stack);      free(stack);
         stack = stack2;      stack = stack2;
         stack_size = size2;      stack_size = size2;
 }  }
   
 int push(cmo* m)  int push(cmo* m)
Line 35  int push(cmo* m)
Line 36  int push(cmo* m)
     stack[stack_pointer] = m;      stack[stack_pointer] = m;
     stack_pointer++;      stack_pointer++;
     if (stack_pointer >= stack_size) {      if (stack_pointer >= stack_size) {
                 extend_stack();          extend_stack();
     }      }
 }  }
   
Line 56  void pops(int n)
Line 57  void pops(int n)
     }      }
 }  }
   
 #define VERSION 0x11121400  #define OX_XSAMPLE_VERSION "1999/12/14 15:25:00"
 #define ID_STRING  "ox_math server 1999/12/14 15:25:00"  
   
 int sm_mathcap()  int sm_mathcap()
 {  {
     push(make_mathcap_object(VERSION, ID_STRING));      mathcap_init(OX_XSAMPLE_VERSION, "ox_Xsample");
       push(oxf_cmo_mathcap(fd_rw));
     return 0;      return 0;
 }  }
   
Line 78  int sm_popCMO()
Line 79  int sm_popCMO()
   
 cmo_error2 *make_error2(int code)  cmo_error2 *make_error2(int code)
 {  {
         return new_cmo_int32(-1);      return new_cmo_int32(-1);
 }  }
   
 int get_i()  int get_i()
 {  {
         cmo *c = pop();      cmo *c = pop();
         if (c->tag == CMO_INT32) {      if (c->tag == CMO_INT32) {
                 return ((cmo_int32 *)c)->i;          return ((cmo_int32 *)c)->i;
         }else if (c->tag == CMO_ZZ) {      }else if (c->tag == CMO_ZZ) {
                 return mpz_get_si(((cmo_zz *)c)->mpz);          return mpz_get_si(((cmo_zz *)c)->mpz);
         }      }
         make_error2(-1);      make_error2(-1);
         return 0;      return 0;
 }  }
   
 int get_xy(int *x, int *y)  int get_xy(int *x, int *y)
 {  {
         cmo *c = pop();      pop();
         *x = get_i();      *x = get_i();
         *y = get_i();      *y = get_i();
 }  }
   
 int my_setpixel()  int my_setpixel()
 {  {
         int x, y;      int x, y;
         get_xy(&x, &y);      get_xy(&x, &y);
         setpixel(x, y);      setpixel(x, y);
         push(new_cmo_int32(0));      push(new_cmo_int32(0));
 }  }
   
 int my_moveto()  int my_moveto()
 {  {
         int x, y;      int x, y;
         get_xy(&x, &y);      get_xy(&x, &y);
         moveto(x, y);      moveto(x, y);
         push(new_cmo_int32(0));      push(new_cmo_int32(0));
 }  }
   
 int my_lineto()  int my_lineto()
 {  {
         int x, y;      int x, y;
         get_xy(&x, &y);      get_xy(&x, &y);
         lineto(x, y);      lineto(x, y);
         push(new_cmo_int32(0));      push(new_cmo_int32(0));
 }  }
   
 int my_clear()  int my_clear()
 {  {
         /* dummy */      /* dummy */
         pop();      pop();
         push(new_cmo_int32(0));      push(new_cmo_int32(0));
 }  }
   
 int sm_executeFunction()  int sm_executeFunction()
 {  {
         cmo_string *func = (cmo_string *)pop();      cmo_string *func = (cmo_string *)pop();
         if (func->tag != CMO_STRING) {      if (func->tag != CMO_STRING) {
                 push(make_error2(0));          push(make_error2(0));
                 return -1;          return -1;
         }      }
         if (strcmp(func->s, "setpixel") == 0) {      if (strcmp(func->s, "setpixel") == 0) {
                 my_setpixel();          my_setpixel();
         }else if (strcmp(func->s, "moveto") == 0) {      }else if (strcmp(func->s, "moveto") == 0) {
                 my_moveto();          my_moveto();
         }else if (strcmp(func->s, "lineto") == 0) {      }else if (strcmp(func->s, "lineto") == 0) {
                 my_lineto();          my_lineto();
         }else if (strcmp(func->s, "clear") == 0) {      }else if (strcmp(func->s, "clear") == 0) {
                 my_clear();          my_clear();
         }else {      }else {
                 push(make_error2(0));          push(make_error2(0));
                 return -1;          return -1;
         }      }
 }  }
   
   
Line 170  int receive_and_execute_sm_command()
Line 171  int receive_and_execute_sm_command()
         pop();          pop();
         break;          break;
     default:      default:
                   ;
     }      }
 }  }
   
Line 186  int receive()
Line 188  int receive()
         receive_and_execute_sm_command();          receive_and_execute_sm_command();
         break;          break;
     default:      default:
                   ;
     }      }
     return 0;      return 0;
 }  }
   
 int main()  int main()
 {  {
       ox_stderr_init(stderr);
     initialize_stack();      initialize_stack();
     decideByteOrderServer(fd_rw, 0);  
   
         gopen();          fd_rw = oxf_open(3);
           oxf_determine_byteorder_server(fd_rw);
   
       gopen();
     while(1) {      while(1) {
         receive();          receive();
                 gFlush();          gFlush();
     }      }
         gclose();      gclose();
 }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.8

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