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

Annotation of OpenXM/src/ox_maple/main.c, Revision 1.2

1.2     ! iwane       1: /* $OpenXM: OpenXM/src/ox_maple/main.c,v 1.1 2008/09/19 13:01:05 iwane Exp $ */
1.1       iwane       2: /* ***********************************************************************
                      3:  *********************************************************************** */
                      4: #define VERSION   0x00000001
1.2     ! iwane       5: #define ID_STRING "$Revision: 1.1 $"
1.1       iwane       6:
                      7: #include <stdio.h>
                      8: #include <stdlib.h>
                      9: #include <string.h>
                     10:
                     11: #include <limits.h>
                     12:
                     13:
                     14: #include "ox_toolkit.h"
                     15: #include "oxserv.h"
                     16: #include "oxstack.h"
                     17:
                     18: #include "maplec.h"
                     19:
                     20: #include "oxmaple.h"
                     21:
                     22:
                     23: static void
                     24: oxmpl_executeFunction(const char *func, oxstack_node **arg, int argc)
                     25: {
1.2     ! iwane      26:        oxstack_node *ans;
        !            27:        int i;
1.1       iwane      28:
1.2     ! iwane      29:        enum {
        !            30:                RET_CMO,
        !            31:                RET_USR,
        !            32:        };
        !            33:
        !            34:        struct {
        !            35:                const char *name;
        !            36:                oxstack_node *(*func)(oxstack_node **, int);
        !            37:                int return_type;
1.1       iwane      38:                int argmin;
                     39:                int argmax;
1.2     ! iwane      40:        } funcs[] = {
        !            41:                {"add",  oxmpl_add,  RET_USR, 2, 2},
        !            42:                {"sleep",  oxmpl_sleep,  RET_USR, 1, 1},
        !            43:                {"func", oxmpl_func, RET_USR, 1, INT_MAX}, /* $BG$0U$N4X?t$r<B9T(B */
        !            44:                {"whattype", oxmpl_whattype, RET_USR, 1, 1},
        !            45:                {NULL, NULL, 0}
        !            46:        };
1.1       iwane      47:
                     48:
1.2     ! iwane      49:        for (i = 0; funcs[i].name != NULL; i++) {
1.1       iwane      50:
1.2     ! iwane      51:                if (strcmp(func, funcs[i].name) == 0) {
1.1       iwane      52:                        if (argc < funcs[i].argmin || argc > funcs[i].argmax) {
                     53:                                cmo_error2 *err = new_cmo_error2((cmo *)new_cmo_string("invalid arguments(#)"));
                     54:                                ans = oxstack_node_init((cmo *)err);
                     55:                        } else {
1.2     ! iwane      56:                                ans = funcs[i].func(arg, argc);
1.1       iwane      57:                        }
1.2     ! iwane      58:                        oxstack_push(ans);
        !            59:                        return ;
        !            60:                }
        !            61:        }
1.1       iwane      62:
1.2     ! iwane      63:        oxstack_push_cmo((cmo *)new_cmo_error2((cmo *)new_cmo_string("Unknown Function")));
1.1       iwane      64:
                     65:
                     66: }
                     67:
                     68: int
                     69: get_cmon_tag(cmo *p)
                     70: {
                     71:        return (p->tag);
                     72: }
                     73:
                     74: int main( int argc, char *argv[] )
                     75: {
                     76:        const int fd = 3;
                     77:        int ret;
                     78:        OXFILE *oxfp;
                     79:
                     80:        for (ret = 0; ret < argc; ret++) {
                     81:                printf("argv[%2d] = %s\n", ret, argv[ret]);
                     82:        }
                     83:
1.2     ! iwane      84:        oxfp = oxf_open(fd);
        !            85:        ox_stderr_init(stderr);
1.1       iwane      86:
                     87:        oxserv_set(OXSERV_SET_EXECUTE_STRING_PARSER, (void *)oxmpl_executeStringParser, NULL);
                     88:        oxserv_set(OXSERV_SET_EXECUTE_FUNCTION, (void *)oxmpl_executeFunction, NULL);
                     89:
1.2     ! iwane      90:        oxserv_set(OXSERV_SET_GET_CMOTAG, (void *)(void (*)())get_cmon_tag, NULL);
        !            91:        oxserv_set(OXSERV_SET_CONVERT_CMO, (void *)convert_maple2cmo_, NULL);
        !            92:        oxserv_set(OXSERV_SET_CONVERT_STR, (void *)convert_maple2str_, NULL);
        !            93:        oxserv_init(oxfp, VERSION, ID_STRING, "ox_maple", NULL, NULL);
1.1       iwane      94:
                     95:        ret = oxmpl_init(1, argv);
1.2     ! iwane      96:        ret = oxserv_receive(oxfp);
1.1       iwane      97:
1.2     ! iwane      98:        oxserv_dest();
        !            99:        oxf_close(oxfp);
1.1       iwane     100:
                    101:
                    102:        return( 0 );
                    103: }
                    104:
                    105: /* EOF */
                    106:

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