[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.1

1.1     ! iwane       1: /* $OpenXM$ */
        !             2: /* ***********************************************************************
        !             3:  *********************************************************************** */
        !             4: #define VERSION   0x00000001
        !             5: #define ID_STRING "$Revision$"
        !             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: {
        !            26:         oxstack_node *ans;
        !            27:         int i;
        !            28:
        !            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;
        !            38:                int argmin;
        !            39:                int argmax;
        !            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:         };
        !            47:
        !            48:
        !            49:         for (i = 0; funcs[i].name != NULL; i++) {
        !            50:
        !            51:                 if (strcmp(func, funcs[i].name) == 0) {
        !            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 {
        !            56:                                ans = funcs[i].func(arg, argc);
        !            57:                        }
        !            58:                         oxstack_push(ans);
        !            59:                         return ;
        !            60:                 }
        !            61:         }
        !            62:
        !            63:         oxstack_push_cmo((cmo *)new_cmo_error2((cmo *)new_cmo_string("Unknown Function")));
        !            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:
        !            84:         oxfp = oxf_open(fd);
        !            85:         ox_stderr_init(stderr);
        !            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:
        !            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);
        !            94:
        !            95:        ret = oxmpl_init(1, argv);
        !            96:         ret = oxserv_receive(oxfp);
        !            97:
        !            98:         oxserv_dest();
        !            99:         oxf_close(oxfp);
        !           100:
        !           101:
        !           102:        return( 0 );
        !           103: }
        !           104:
        !           105: /* EOF */
        !           106:

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