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

Annotation of OpenXM/src/ox_toolkit/ox_toolkit.h, Revision 1.47

1.1       ohara       1: /* -*- mode: C -*- */
1.47    ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/ox_toolkit.h,v 1.46 2020/11/01 10:28:22 noro Exp $ */
1.1       ohara       3:
                      4: #ifndef _OX_TOOLKIT_H_
                      5: #define _OX_TOOLKIT_H_
                      6:
1.27      iwane       7:
1.28      ohara       8: #include <stdio.h>
1.46      noro        9: #include <string.h>
1.28      ohara      10: #include <gmp.h>
1.36      noro       11: #include <mpfr.h>
1.5       ohara      12: #include <ox/cmotag.h>
                     13: #include <ox/oxMessageTag.h>
                     14: #include <ox/smCommand.h>
1.21      ohara      15: #include <gc/gc.h>
1.20      ohara      16:
1.40      ohara      17: #if defined(_MSC_VER)
                     18: #include <malloc.h>
1.42      ohara      19: #else
                     20: #include <sys/select.h>
1.40      ohara      21: #endif
                     22:
1.21      ohara      23: #define MALLOC(x) GC_MALLOC((x))
1.23      ohara      24: #define MALLOC_ATOMIC(x) GC_MALLOC_ATOMIC((x))
1.20      ohara      25: #define ALLOCA(x) alloca((x))
1.21      ohara      26: /* #define FREE(x)   free((x)) */
                     27: #define FREE(x)
1.1       ohara      28:
1.35      iwane      29: #ifdef __cplusplus
                     30: extern "C" {
                     31: #endif
                     32:
1.2       ohara      33: #if !defined(__GNUC__) && !defined(__inline__)
                     34: #define __inline__
                     35: #endif
                     36:
1.7       ohara      37: /* Mathcap Local Database */
                     38: typedef struct {
1.33      takayama   39:     int tag;
                     40:     int flag;
                     41: } table;
                     42:
                     43: typedef struct mathcap {
                     44:     table *cmotbl;
                     45:     table *smtbl;
1.43      ohara      46:     char  **opts;
1.7       ohara      47: } mathcap;
                     48:
                     49: /* OpenXM File Descripter */
1.2       ohara      50: typedef struct OXFILE{
1.6       ohara      51:     int fd;
                     52:     int (*send_int32)(struct OXFILE *oxfp, int int32);
                     53:     int (*receive_int32)(struct OXFILE *oxfp);
                     54:     int serial_number;
1.9       ohara      55:     int received_serial_number;
1.6       ohara      56:     struct OXFILE *control;  /* pointer to his control server. */
                     57:     struct mathcap *mathcap;
                     58:     int error;
1.19      ohara      59:     char *wbuf;
                     60:     int wbuf_size;
                     61:     int wbuf_count;
1.28      ohara      62:     int (*send_double)(struct OXFILE *oxfp, double int64);
1.29      ohara      63:     double (*receive_double)(struct OXFILE *oxfp);
1.2       ohara      64: } OXFILE;
1.1       ohara      65:
1.42      ohara      66: #if 0
                     67: #define OX_FD_SETSIZE   FD_SETSIZE
                     68: #else
                     69: #define OX_FD_SETSIZE   32
                     70: #endif
                     71:
                     72: typedef struct {
                     73:     int count;
                     74:     fd_set fdset;
                     75:     OXFILE *p[OX_FD_SETSIZE];
                     76: } OXFILE_set;
                     77:
1.18      ohara      78: typedef struct cmo {
1.1       ohara      79:     int tag;
                     80: } cmo;
                     81:
                     82: typedef cmo cmo_null;
                     83: typedef cmo cmo_zero;
                     84: typedef cmo cmo_dms_generic;
                     85:
                     86: typedef struct {
                     87:     int tag;
                     88:     int i;
                     89: } cmo_int32;
                     90:
                     91: typedef struct {
                     92:     int tag;
                     93:     int size;
                     94:     char *body;
                     95: } cmo_datum;
                     96:
                     97: typedef struct {
                     98:     int tag;
                     99:     char *s;
                    100: } cmo_string;
                    101:
                    102: typedef struct {
                    103:     int tag;
                    104:     cmo *ob;
                    105: } cmo_mathcap;
                    106:
                    107: typedef cmo_mathcap cmo_error2;
                    108: typedef cmo_mathcap cmo_ring_by_name;
                    109: typedef cmo_mathcap cmo_indeterminate;
                    110:
1.2       ohara     111: /* a double linked list */
1.1       ohara     112: typedef struct cell {
1.18      ohara     113:     struct cmo *cmo;
1.1       ohara     114:     struct cell *next;
1.2       ohara     115:     struct cell *prev;
1.22      ohara     116:     int exp;
1.1       ohara     117: } cell;
                    118:
                    119: typedef struct {
                    120:     int tag;
                    121:     int length;   /* length of this list (unnecessary) */
                    122:     cell head[1];
                    123: } cmo_list;
                    124:
                    125: typedef struct {
                    126:     int tag;
                    127:     int length;
                    128:     int *exps;
                    129:     cmo *coef;
                    130: } cmo_monomial32;
                    131:
                    132: typedef struct {
                    133:     int tag;
                    134:     mpz_t mpz;
                    135: } cmo_zz;
                    136:
                    137: typedef struct {
                    138:     int tag;
1.34      ohara     139:     mpq_t mpq;
1.1       ohara     140: } cmo_qq;
                    141:
1.12      ohara     142: typedef struct {
                    143:     int tag;
1.36      noro      144:     mpfr_t mpfr;
                    145: } cmo_bf;
                    146:
                    147: typedef struct {
                    148:     int tag;
1.38      noro      149:     cmo *re,*im;
                    150: } cmo_complex;
                    151:
                    152: typedef struct {
                    153:     int tag;
1.12      ohara     154:     double d; /* machine dependent */
                    155: } cmo_double;
                    156:
1.1       ohara     157: /* The following is a derived class from cmo_list.
1.2       ohara     158:    that is, list_append can be used. */
1.1       ohara     159: typedef struct {
                    160:     int tag;
                    161:     int length;    /* number of monomials */
                    162:     cell head[1];  /* a list of monomials */
                    163:     cmo *ringdef;
                    164: } cmo_distributed_polynomial;
1.24      ohara     165:
                    166: /* The following is a derived class from cmo_list.
                    167:    that is, list_append can be used. */
                    168: typedef struct {
                    169:     int tag;
                    170:     int length;   /* number of monomials */
                    171:     cell head[1]; /* list of monomials */
                    172:     int var;      /* name of the main variable */
                    173: } cmo_polynomial_in_one_variable;
                    174:
                    175: typedef struct {
                    176:     int tag;
                    177:     cmo_list *ringdef; /* list of variables */
                    178:     cmo *coef;  /* ZZ, QQ, int32, Poly_in_1var, Tree, Zero, DPoly */
                    179: } cmo_recursive_polynomial;
1.1       ohara     180:
1.26      ohara     181: typedef struct {
                    182:     int tag;
                    183:     cmo_string *name;
                    184:     cmo_list *attributes;
                    185:     cmo_list *leaves;
                    186: } cmo_tree;
                    187:
                    188: typedef struct {
                    189:     int tag;
                    190:     cmo_list *args;
                    191:     cmo_tree *body;
                    192: } cmo_lambda;
                    193:
1.1       ohara     194: typedef cmo ox;
                    195:
                    196: typedef ox ox_sync_ball;
                    197:
                    198: typedef struct {
                    199:     int tag;
                    200:     int command;
                    201: } ox_command;
                    202:
                    203: typedef struct {
                    204:     int tag;
1.18      ohara     205:     struct cmo *cmo;
1.1       ohara     206: } ox_data;
                    207:
                    208: cmo_null*          new_cmo_null();
                    209: cmo_int32*         new_cmo_int32(int i);
                    210: cmo_string*        new_cmo_string(char* s);
                    211: cmo_mathcap*       new_cmo_mathcap(cmo* ob);
                    212: cmo_list*          new_cmo_list();
1.33      takayama  213: cmo_list*          new_cmo_list_array(void *a[], int n);
                    214: cmo_list*          new_cmo_list_array_map(void *a[], int n, void *(* mapf)(void *));
1.1       ohara     215: cmo_monomial32*    new_cmo_monomial32();
                    216: cmo_monomial32*    new_cmo_monomial32_size(int size);
                    217: cmo_zz*            new_cmo_zz();
                    218: cmo_zz*            new_cmo_zz_size(int size);
                    219: cmo_zz*            new_cmo_zz_set_si(int integer);
                    220: cmo_zz*            new_cmo_zz_set_mpz(mpz_ptr z);
                    221: cmo_zz*            new_cmo_zz_noinit();
                    222: cmo_zz*            new_cmo_zz_set_string(char* s);
1.34      ohara     223: cmo_qq*            new_cmo_qq();
1.30      ohara     224: cmo_qq*            new_cmo_qq_set_mpq(mpq_ptr q);
                    225: cmo_qq*            new_cmo_qq_set_mpz(mpz_ptr num, mpz_ptr den);
1.37      noro      226: cmo_bf*            new_cmo_bf();
1.36      noro      227: cmo_bf*            new_cmo_bf_set_mpfr(mpfr_ptr q);
1.38      noro      228: cmo_complex*       new_cmo_complex();
1.39      ohara     229: cmo_complex*       new_cmo_complex_set_re_im(cmo *re,cmo *im);
1.1       ohara     230: cmo_zero*          new_cmo_zero();
1.12      ohara     231: cmo_double*        new_cmo_double(double d);
1.1       ohara     232: cmo_distributed_polynomial* new_cmo_distributed_polynomial();
                    233: cmo_dms_generic*   new_cmo_dms_generic();
                    234: cmo_ring_by_name*  new_cmo_ring_by_name(cmo* ob);
                    235: cmo_indeterminate* new_cmo_indeterminate(cmo* ob);
1.44      ohara     236: cmo_indeterminate* new_cmo_indeterminate_set_name(char *s);
1.25      ohara     237: cmo_polynomial_in_one_variable* new_cmo_polynomial_in_one_variable(int var);
                    238: cmo_recursive_polynomial* new_cmo_recursive_polynomial(cmo_list* ringdef, cmo* coef);
1.26      ohara     239: cmo_tree*          new_cmo_tree(cmo_string* name, cmo_list *attributes, cmo_list *leaves);
                    240: cmo_lambda*        new_cmo_lambda(cmo_list* args, cmo_tree* body);
1.1       ohara     241: cmo_error2*        new_cmo_error2(cmo* ob);
                    242:
                    243: ox_data*           new_ox_data(cmo* c);
                    244: ox_command*        new_ox_command(int sm_code);
                    245: ox_sync_ball*      new_ox_sync_ball();
                    246:
                    247: char*              new_string_set_cmo(cmo* m);
                    248:
                    249: cmo_error2*        make_error_object(int err_code, cmo* ob);
                    250:
1.31      ohara     251: cmo*               ox_parse_lisp(char *s);
                    252:
1.1       ohara     253: /* Low level API */
1.2       ohara     254: cmo*               receive_cmo(OXFILE *fp);
1.17      ohara     255: cmo*               receive_cmo_tag(OXFILE *fp, int tag);
1.2       ohara     256: int                receive_int32(OXFILE *fp);
                    257: int                receive_ox_tag(OXFILE *fp);
                    258:
                    259: void               send_cmo(OXFILE *fp, cmo* m);
                    260: int                send_int32(OXFILE *fp, int integer);
                    261: void               send_ox(OXFILE *fp, ox* m);
                    262: void               send_ox_cmo(OXFILE *fp, cmo* m);
                    263: void               send_ox_command(OXFILE *fp, int sm_command);
                    264: int                send_ox_tag(OXFILE *fp, int tag);
1.1       ohara     265:
                    266: int                next_serial();
                    267: void               setCmotypeDisable(int type);
                    268:
                    269: /* High level API */
1.2       ohara     270: void               ox_close(OXFILE *sv);
                    271: void               ox_shutdown(OXFILE *sv);
                    272: void               ox_reset(OXFILE *sv);
                    273: void               ox_execute_string(OXFILE *sv, char* str);
                    274: cmo_mathcap*       ox_mathcap(OXFILE *sv);
                    275: char*              ox_popString(OXFILE *sv);
                    276: void               ox_pops(OXFILE *sv, int num);
                    277: cmo*               ox_pop_cmo(OXFILE *sv);
                    278: void               ox_push_cmo(OXFILE *sv, cmo *c);
                    279: void               ox_push_cmd(OXFILE *sv, int sm_code);
                    280: void               ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[]);
                    281: int                ox_flush(OXFILE *sv);
                    282:
1.16      ohara     283: cell*              list_first(cmo_list *);
                    284: int                list_endof(cmo_list *, cell *el);
1.2       ohara     285: cell*              list_next(cell *el);
1.16      ohara     286: cmo_list*          list_append(cmo_list*, cmo *ob);
1.22      ohara     287: cmo_list*          list_append_monomial(cmo_list* , cmo* coef, int exp);
1.16      ohara     288: cmo_list*          list_appendl(cmo_list*, ...);
                    289: int                list_length(cmo_list* );
                    290: cmo*               list_nth(cmo_list* , int n);
1.45      ohara     291: cell*              list_nth_cell(cmo_list* , int n);
1.41      ohara     292: cmo*               list_first_cmo(cmo_list *);
1.44      ohara     293: char*              cmo_indeterminate_get_name(cmo_indeterminate *);
1.2       ohara     294:
1.1       ohara     295: int                cmolen_cmo(cmo* m);
1.2       ohara     296: void               dump_buffer_init(char *s);
                    297: void               dump_cmo(cmo* m);
                    298: void               dump_ox_command(ox_command* m);
                    299: void               dump_ox_data(ox_data* m);
1.1       ohara     300:
1.2       ohara     301: void               print_cmo(cmo* c);
                    302: void               resize_mpz(mpz_ptr mpz, int size);
1.1       ohara     303:
1.37      noro      304: int                cmo_to_int(cmo *n);
                    305:
1.2       ohara     306: typedef cmo *(*hook_t)(OXFILE *, cmo *);
1.1       ohara     307:
                    308: int add_hook_before_send_cmo(hook_t func);
                    309: int add_hook_after_send_cmo(hook_t func);
                    310:
                    311: /* functions related to parse.c */
                    312:
                    313: #define PFLAG_ADDREV   1
                    314:
                    315: typedef struct symbol *symbol_t;
                    316:
                    317: symbol_t lookup_by_symbol(char *key);
                    318: symbol_t lookup_by_token(int tok);
                    319: symbol_t lookup_by_tag(int tag);
                    320: symbol_t lookup(int i);
1.13      ohara     321: char*    get_symbol_by_tag(int tag);
1.2       ohara     322:
                    323: /* for mathcap database */
1.6       ohara     324: mathcap *new_mathcap();
1.33      takayama  325: void mathcap_init(int ver, char *vstr, char *sysname, int cmos[], int sms[]);
1.43      ohara     326: void mathcap_init2(int ver, char *vstr, char *sysname, int cmos[], int sms[], char *options[]);
1.16      ohara     327: cmo_mathcap* mathcap_get(mathcap *);
                    328: mathcap *mathcap_update(mathcap *, cmo_mathcap *mc);
1.33      takayama  329: int mathcap_allowQ_cmo(mathcap *, cmo *ob);
1.2       ohara     330:
                    331: int oxf_read(void *buffer, size_t size, size_t num, OXFILE *oxfp);
                    332: int oxf_write(void *buffer, size_t size, size_t num, OXFILE *oxfp);
                    333:
                    334: /* for OXFILE */
1.25      ohara     335: int oxf_listen(int *portp);
1.2       ohara     336: OXFILE *oxf_connect_active(char *hostname, short port);
                    337: OXFILE *oxf_connect_passive(int listened);
                    338: OXFILE *oxf_open(int fd);
                    339: OXFILE *oxf_control_set(OXFILE *oxfp, OXFILE *control);
                    340: OXFILE *oxf_control(OXFILE *oxfp);
                    341: int  oxf_confirm_client(OXFILE *oxfp, char *passwd);
                    342: int  oxf_confirm_server(OXFILE *oxfp, char *passwd);
                    343: void oxf_flush(OXFILE *oxfp);
                    344: void oxf_close(OXFILE *oxfp);
                    345: void oxf_setopt(OXFILE *oxfp, int mode);
                    346: void oxf_determine_byteorder_client(OXFILE *oxfp);
                    347: void oxf_determine_byteorder_server(OXFILE *oxfp);
1.4       ohara     348: OXFILE *oxf_execute_cmd(OXFILE *oxfp, char *cmd);
1.8       ohara     349: cmo_mathcap *oxf_cmo_mathcap(OXFILE *oxfp);
1.6       ohara     350: void oxf_mathcap_update(OXFILE *oxfp, cmo_mathcap *ob);
1.47    ! ohara     351: int oxf_setbuffer(OXFILE *oxfp, char *buf, int size);
1.2       ohara     352:
                    353: /* example: which("xterm", getenv("PATH")); */
                    354: char *which(char *exe, const char *env);
                    355: char *generate_otp();
1.1       ohara     356:
1.10      ohara     357: int ox_stderr_init(FILE *fp);
1.11      ohara     358: int ox_printf(char *format, ...);
1.16      ohara     359:
1.46      noro      360: int gclose();
                    361: int gopen();
                    362: int gFlush();
                    363: int moveto(int x, int y);
                    364: int lineto(int x, int y);
                    365: int setpixel(int x, int y);
                    366:
1.16      ohara     367: #ifdef __cplusplus
                    368: }
                    369: #endif
                    370:
1.1       ohara     371: #endif /* _OX_TOOLKIT_H_ */

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