Annotation of freem/src/mtok.c, revision 1.2

1.1       snw         1: /*
                      2:  *                            *
                      3:  *                           * *
                      4:  *                          *   *
                      5:  *                     ***************
                      6:  *                      * *       * *
                      7:  *                       *  MUMPS  *
                      8:  *                      * *       * *
                      9:  *                     ***************
                     10:  *                          *   *
                     11:  *                           * *
                     12:  *                            *
                     13:  *
                     14:  *   mtok.c
                     15:  *    Token lookup 
                     16:  *
                     17:  *  
1.2     ! snw        18:  *   Author: Serena Willis <snw@coherent-logic.com>
1.1       snw        19:  *    Copyright (C) 1998 MUG Deutschland
                     20:  *    Copyright (C) 2020 Coherent Logic Development LLC
                     21:  *
                     22:  *
                     23:  *   This file is part of FreeM.
                     24:  *
                     25:  *   FreeM is free software: you can redistribute it and/or modify
                     26:  *   it under the terms of the GNU Affero Public License as published by
                     27:  *   the Free Software Foundation, either version 3 of the License, or
                     28:  *   (at your option) any later version.
                     29:  *
                     30:  *   FreeM is distributed in the hope that it will be useful,
                     31:  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
                     32:  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     33:  *   GNU Affero Public License for more details.
                     34:  *
                     35:  *   You should have received a copy of the GNU Affero Public License
                     36:  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
                     37:  *
                     38:  **/
                     39: 
                     40: #include <stdlib.h>
                     41: #include <string.h>
                     42: 
                     43: #include "mpsdef.h"
                     44: #include "mtok.h"
                     45: 
                     46: tok_lut toktab[] = {
                     47:     {0, "ABLOCK"},
                     48:     {'a', "ASSIGN"},
                     49:     {1, "ASTART"},
                     50:     {2, "ASTOP"},
                     51:     {3, "AUNBLOCK"},
                     52:     {'b', "BREAK"},
                     53:     {'c', "CLOSE"},
                     54:     {'d', "DO"},
                     55:     {4, "DO"},
                     56:     {'e', "ELSE"},
                     57:     {5, "ESTART"},
                     58:     {6, "ESTOP"},
                     59:     {7, "ETRIGGER"},
                     60:     {'f', "FOR"},
                     61:     {'g', "GOTO"},
                     62:     {'h', "HA"},
                     63:     {8, "HALT"},
                     64:     {9, "HANG"},
                     65:     {'i', "IF"},
                     66:     {'j', "JOB"},
                     67:     {'k', "KILL"},
                     68:     {10, "KVALUE"},
                     69:     {11, "KSUBSCRIPTS"},
                     70:     {'l', "LOCK"},
                     71:     {'m', "MERGE"},
                     72:     {'n', "NEW"},
                     73:     {'o', "OPEN"},
                     74:     {'q', "QUIT"},
                     75:     {'r', "READ"},
                     76:     {12, "RLOAD"},
                     77:     {13, "RSAVE"},
                     78:     {'s', "SET"},
                     79:     {14, "TCOMMIT"},
                     80:     {15, "THEN"},
                     81:     {16, "TRESTART"},
                     82:     {17, "TROLLBACK"},
                     83:     {18, "TSTART"},
                     84:     {'u', "USE"},
                     85:     {'v', "VIEW"},
                     86:     {'w', "WRITE"},
                     87:     {'x', "XECUTE"},
                     88:     {'A', "ZALLOCATE"},
                     89:     {'B', "ZBREAK"},
                     90:     {'D', "ZDEALLOCATE"},
                     91:     {'G', "ZGO"},
                     92:     {'H', "ZHALT"},
                     93:     {'I', "ZINSERT"},
                     94:     {'J', "ZJOB"},
                     95:     {'L', "ZLOAD"},
                     96:     {'N', "ZNAMESPACE"},
                     97:     {'P', "ZPRINT"},
                     98:     {'Q', "ZQUIT"},
                     99:     {'R', "ZREMOVE"},
                    100:     {'S', "ZSAVE"},
                    101:     {'T', "ZTRAP"},
                    102:     {'W', "ZWRITE"},
                    103:     {20, "ZWATCH"},
                    104:     {21, "ZASSERT"},
                    105:     {SP, "PRIVATE"},
                    106:     {255, NULL}
                    107: };
                    108: 
                    109: int mtok_token_to_command (char *buf, int token)
                    110: {
                    111:     tok_lut *p;
                    112:     
                    113:     for (p = toktab; p->cmd_name != NULL; ++p) {
                    114: 
                    115:         if (p->tok == token) {
                    116:             strcpy (buf, p->cmd_name);            
                    117:             stcnv_c2m (buf);
                    118:             return 1;
                    119:         }
                    120: 
                    121:     }
                    122: 
                    123:     return -1;
                    124: }
                    125: 
                    126: int mtok_command_to_token (char *cmd_name)
                    127: {
                    128:     tok_lut *p;
                    129: 
                    130:     for (p = toktab; p->cmd_name != NULL; ++p) {
                    131: 
                    132:         if (strcmp (cmd_name, p->cmd_name) == 0) {
                    133:             return p->tok;
                    134:         }
                    135: 
                    136:     }
                    137: 
                    138:     return -1;
                    139: }

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